1 #include <cppunit/extensions/TestFactoryRegistry.h>
2 #include <cppunit/CompilerOutputter.h>
3 #include <cppunit/TestResult.h>
4 #include <cppunit/TestResultCollector.h>
5 #include <cppunit/TestRunner.h>
6 #include <cppunit/TextTestProgressListener.h>
10 main( int argc, char* argv[] )
12 std::string testPath = (argc > 1) ? std::string(argv[1]) : "";
14 // Create the event manager and test controller
15 CppUnit::TestResult controller;
17 // Add a listener that colllects test result
18 CppUnit::TestResultCollector result;
19 controller.addListener( &result );
21 // Add a listener that print dots as test run.
22 CppUnit::TextTestProgressListener progress;
23 controller.addListener( &progress );
25 CppUnit::TestFactoryRegistry& registry =
26 CppUnit::TestFactoryRegistry::getRegistry();
27 // Add the top suite to the test runner
28 CppUnit::TestRunner runner;
29 runner.addTest( registry.makeTest() );
32 std::cout << "Running " << testPath;
33 runner.run( controller, testPath );
35 std::cerr << std::endl;
37 // Print test in a compiler compatible format.
38 CppUnit::CompilerOutputter outputter( &result, std::cerr );
41 catch ( std::invalid_argument &e ) // Test path not resolved
43 std::cerr << std::endl
44 << "ERROR: " << e.what()
49 return result.wasSuccessful() ? 0 : 1;