Salome HOME
Update mechanism is corrected (Bug #182).
[modules/hydro.git] / src / HYDROData / test_HYDROData_Main.cxx
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>
7 #include <stdexcept>
8
9 int 
10   main( int argc, char* argv[] )
11 {
12   std::string testPath = (argc > 1) ? std::string(argv[1]) : "";
13
14   // Create the event manager and test controller
15   CppUnit::TestResult controller;
16
17   // Add a listener that colllects test result
18   CppUnit::TestResultCollector result;
19   controller.addListener( &result );        
20
21   // Add a listener that print dots as test run.
22   CppUnit::TextTestProgressListener progress;
23   controller.addListener( &progress );      
24
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() );   
30   try
31   {
32     std::cout << "Running "  <<  testPath;
33     runner.run( controller, testPath );
34
35     std::cerr << std::endl;
36
37     // Print test in a compiler compatible format.
38     CppUnit::CompilerOutputter outputter( &result, std::cerr );
39     outputter.write();                      
40   }
41   catch ( std::invalid_argument &e )  // Test path not resolved
42   {
43     std::cerr  <<  std::endl  
44       <<  "ERROR: "  <<  e.what()
45       << std::endl;
46     return 0;
47   }
48
49   return result.wasSuccessful() ? 0 : 1;
50 }