attic/unittest/srs/main.cpp
Go to the documentation of this file.
1 #include "../Config.h"
2 #include <terralib/common.h>
3 
4 // cppUnit include files
5 #include <cppunit/BriefTestProgressListener.h>
6 #include <cppunit/CompilerOutputter.h>
7 #include <cppunit/extensions/HelperMacros.h>
8 #include <cppunit/extensions/TestFactoryRegistry.h>
9 #include <cppunit/TestResult.h>
10 #include <cppunit/TestResultCollector.h>
11 #include <cppunit/TestRunner.h>
12 #include <cppunit/XmlOutputter.h>
13 #include <cppunit/TextOutputter.h>
14 
15 #include <stdlib.h>
16 
17 int main(int /*argc*/, char** /*argv*/)
18 {
20 
21 // it creates the event manager and test controller
22  CPPUNIT_NS::TestResult controller;
23 
24 // it adds a listener that colllects test result
25  CPPUNIT_NS::TestResultCollector result;
26 
27  controller.addListener(&result);
28 
29 // it adds a listener that print dots as test run.
30  CPPUNIT_NS::BriefTestProgressListener progress;
31 
32  controller.addListener(&progress);
33 
34 // it adds the top suite to the test runner
35  CppUnit::Test* suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
36 
37  CPPUNIT_NS::TestRunner runner;
38 
39  runner.addTest(suite);
40 
41  runner.run(controller);
42 
43  CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() );
44 
45  outputter.write();
46 
47 // Testing different outputs
48 
49 // Print testResults in a txt file
50  std::ofstream file1( TERRALIB_REPORT_DIR "/testsResult_srs_dos.txt" );
51  CPPUNIT_NS::CompilerOutputter outputter1( &result, file1);
52  outputter1.write();
53  file1.close();
54 
55 // Printing testResult in XML file
56  // The testResult_*.xml files will be saved at TERRALIB_REPORT_DIR directory.
57  // The styleSheet 'report.xsl' should be at this directory (found originally at <third-party-lib>\cppunit-1.12.1\contrib\xml-xsl).
58  // The "data.zip" (downloaded) containing the data used in unit tests should be at TERRALIB_DATA_DIR
59  CPPUNIT_NS::OFileStream file2( TERRALIB_REPORT_DIR "/testsResult_srs_xml.xml" );
60  CPPUNIT_NS::XmlOutputter xml( &result, file2 );
61  xml.setStyleSheet( "report.xsl" );
62  xml.write();
63  file2.close();
64 
65 // Print testResult in a formated file
66  CPPUNIT_NS::OFileStream file3( TERRALIB_REPORT_DIR "/testsResult_srs_formated.txt" );
67  CPPUNIT_NS::TextOutputter outputter3( &result, file3 );
68  outputter3.write();
69  file3.close();
70 
71  bool resultStatus = result.wasSuccessful();
72 
74 
75  return resultStatus ? EXIT_SUCCESS : EXIT_FAILURE;
76 }
77 
int main(int, char **)
void finalize()
It finalizes the TerraLib Platform.
static TerraLib & getInstance()
It returns a reference to the singleton instance.
void initialize()
It initializes the TerraLib Platform.
This file contains include headers for the TerraLib Common Runtime module.