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>
14
main( int argc, char* argv[] )
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("");
20
// Create the event manager and test controller
21
CPPUNIT_NS::TestResult controller;
23
// Add a listener that colllects test result
24
CPPUNIT_NS::TestResultCollector result;
25
controller.addListener( &result );
27
// Add a listener that print dots as test run.
29
CPPUNIT_NS::TextTestProgressListener progress;
31
CPPUNIT_NS::BriefTestProgressListener progress;
33
controller.addListener( &progress );
35
// Add the top suite to the test runner
36
CPPUNIT_NS::TestRunner runner;
37
runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
40
std::cout << "Running " << testPath;
41
runner.run( controller, testPath );
43
std::cerr << std::endl;
45
// Print test in a compiler compatible format.
46
CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
49
// Uncomment this for XML output
50
// std::ofstream file( "tests.xml" );
51
// CPPUNIT_NS::XmlOutputter xml( &result, file );
52
// xml.setStyleSheet( "report.xsl" );
56
catch ( std::invalid_argument &e ) // Test path not resolved
58
std::cerr << std::endl
59
<< "ERROR: " << e.what()
64
return result.wasSuccessful() ? 0 : 1;