1 #include <cppunit/CompilerOutputter.h>
2 #include <cppunit/TestResult.h>
3 #include <cppunit/TestResultCollector.h>
4 #include <cppunit/TestRunner.h>
5 #include <cppunit/TextTestProgressListener.h>
6 #include <cppunit/BriefTestProgressListener.h>
7 #include <cppunit/XmlOutputter.h>
8 #include <cppunit/extensions/TestFactoryRegistry.h>
9 #include <stdexcept>
10 #include <fstream>
11 
12 
13 int
main(int argc,char * argv[])14 main( int argc, char* argv[] )
15 {
16   // Retreive test path from command line first argument. Default to "" which resolve
17   // to the top level suite.
18   std::string testPath = (argc > 1) ? std::string(argv[1]) : std::string("");
19 
20   // Create the event manager and test controller
21   CPPUNIT_NS::TestResult controller;
22 
23   // Add a listener that colllects test result
24   CPPUNIT_NS::TestResultCollector result;
25   controller.addListener( &result );
26 
27   // Add a listener that print dots as test run.
28 #ifdef WIN32
29   CPPUNIT_NS::TextTestProgressListener progress;
30 #else
31   CPPUNIT_NS::BriefTestProgressListener progress;
32 #endif
33   controller.addListener( &progress );
34 
35   // Add the top suite to the test runner
36   CPPUNIT_NS::TestRunner runner;
37   runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
38   try
39   {
40     CPPUNIT_NS::stdCOut() << "Running "  <<  testPath;
41     runner.run( controller, testPath );
42 
43     CPPUNIT_NS::stdCOut() << "\n";
44 
45     // Print test in a compiler compatible format.
46     CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() );
47     outputter.write();
48 
49 // Uncomment this for XML output
50 //    std::ofstream file( "tests.xml" );
51 //    CPPUNIT_NS::XmlOutputter xml( &result, file );
52 //    xml.setStyleSheet( "report.xsl" );
53 //    xml.write();
54 //    file.close();
55   }
56   catch ( std::invalid_argument &e )  // Test path not resolved
57   {
58     CPPUNIT_NS::stdCOut()  <<  "\n"
59                             <<  "ERROR: "  <<  e.what()
60                             << "\n";
61     return 0;
62   }
63 
64   return result.wasSuccessful() ? 0 : 1;
65 }
66 
67