Back to home page

Project CMSSW displayed by LXR

 
 

    


Warning, /Utilities/Testing/interface/CppUnit_testdriver.icpp is written in an unsupported language. File is not indexed.

0001 #include <cppunit/extensions/TestFactoryRegistry.h>
0002 #include <cppunit/CompilerOutputter.h>
0003 #include <cppunit/TestResult.h>
0004 #include <cppunit/TestResultCollector.h>
0005 #include <cppunit/TestRunner.h>
0006 #include <cppunit/TextTestProgressListener.h>
0007 #include <stdexcept>
0008 
0009 /**  Main body for all the CppUnit test classes  
0010 *
0011 *
0012 *  From the CppUnit cookbook
0013 *  \note No Modication needed
0014 *
0015 */
0016 
0017 int main(int argc, char* argv[]) {
0018   std::string testPath = (argc > 1) ? std::string(argv[1]) : "";
0019 
0020   // Create the event manager and test controller
0021   CppUnit::TestResult controller;
0022 
0023   // Add a listener that colllects test result
0024   CppUnit::TestResultCollector result;
0025   controller.addListener(&result);
0026 
0027   // Add a listener that print dots as test run.
0028   CppUnit::TextTestProgressListener progress;
0029   controller.addListener(&progress);
0030 
0031   // Add the top suite to the test runner
0032   CppUnit::TestRunner runner;
0033   runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
0034   try {
0035     std::cout << "Running " << testPath;
0036     runner.run(controller, testPath);
0037 
0038     std::cerr << std::endl;
0039 
0040     // Print test in a compiler compatible format.
0041     CppUnit::CompilerOutputter outputter(&result, std::cerr);
0042     outputter.write();
0043   } catch (std::invalid_argument& e)  // Test path not resolved
0044   {
0045     std::cerr << std::endl << "ERROR: " << e.what() << std::endl;
0046     return 0;
0047   }
0048 
0049   return result.wasSuccessful() ? 0 : 1;
0050 }