1 #include <cppunit/BriefTestProgressListener.h>
2 #include <cppunit/CompilerOutputter.h>
3 #include <cppunit/extensions/TestFactoryRegistry.h>
4 #include <cppunit/TestResult.h>
5 #include <cppunit/TestResultCollector.h>
6 #include <cppunit/TestRunner.h>
7 #include <cppunit/XmlOutputter.h>
9 int main(int argc, char* argv[])
11 // Retrieve test path from command line first argument. Default to "" which resolve
12 // to the top level suite.
13 std::string testPath = (argc > 1) ? std::string(argv[1]) : std::string("");
15 // Create the event manager and test controller
16 CPPUNIT_NS::TestResult controller;
18 // Add a listener that collects test result
19 CPPUNIT_NS::TestResultCollector result;
21 controller.addListener( &result );
23 // Add a listener that print dots as test run.
24 CPPUNIT_NS::BriefTestProgressListener progress;
26 controller.addListener( &progress );
28 // Add the top suite to the test runner
29 CPPUNIT_NS::TestRunner runner;
30 runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
31 runner.run( controller );
33 // Print test in a compiler compatible format.
34 CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() );
37 // Uncomment this for XML output
38 std::ofstream file( "cppunit-report.xml" );
40 CPPUNIT_NS::XmlOutputter xml( &result, file );
46 return result.wasSuccessful() ? 0 : 1;