cppUnitTestRunner.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifdef NICE_USELIB_CPPUNIT
  2. #include <cppunit/CompilerOutputter.h>
  3. #include <cppunit/extensions/TestFactoryRegistry.h>
  4. #include <cppunit/ui/text/TestRunner.h>
  5. #include <cppunit/TestResult.h>
  6. #include <cppunit/TestResultCollector.h>
  7. #include <cppunit/XmlOutputter.h>
  8. #endif
  9. /**
  10. * CppUnit-Testrunner
  11. */
  12. int main(int argc, char* argv[]) {
  13. // shut up warnings
  14. (void)argc;
  15. (void)argv;
  16. #ifdef NICE_USELIB_CPPUNIT
  17. CppUnit::TestResult controller;
  18. CppUnit::TestResultCollector result;
  19. controller.addListener(&result);
  20. // Get the top level suite from the registry
  21. CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
  22. // Adds the test to the list of test to run
  23. CppUnit::TestRunner runner;
  24. runner.addTest( suite );
  25. // Change the default outputter to a compiler error format outputter
  26. // Print test in a compiler compatible format.
  27. CppUnit::CompilerOutputter outputter( &result, std::cerr );
  28. outputter.write();
  29. // Run the tests
  30. runner.run( controller );
  31. std::string sTestName = suite->getName();
  32. //std::string sTestName = runner.getName();
  33. sTestName.append( "_testresults.xml");
  34. //std::cout << sTestName <<std::endl;
  35. std::ofstream xmlFileOut(sTestName.c_str());
  36. CppUnit::XmlOutputter xmlOut(&result, xmlFileOut);
  37. xmlOut.write();
  38. // Return error code 1 if one of tests failed.
  39. return result.wasSuccessful() ? 0 : 1;
  40. #else
  41. #error "Install cppunit (http://cppunit.sourceforge.net/cppunit-wiki)"
  42. return 1;
  43. #endif
  44. }