Salome HOME
Base implementation of dumping study document in to Python script (Feature #14).
[modules/hydro.git] / src / HYDROOperations / test_HYDROOperations_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 #include <QApplication>
9
10 int 
11   main( int argc, char* argv[] )
12 {
13   // to perform "drawing" qt tests
14   QApplication app(argc, argv);
15
16   std::string testPath = (argc > 1) ? std::string(argv[1]) : "";
17
18   // Create the event manager and test controller
19   CppUnit::TestResult controller;
20
21   // Add a listener that colllects test result
22   CppUnit::TestResultCollector result;
23   controller.addListener( &result );        
24
25   // Add a listener that print dots as test run.
26   CppUnit::TextTestProgressListener progress;
27   controller.addListener( &progress );      
28
29   CppUnit::TestFactoryRegistry& registry = 
30     CppUnit::TestFactoryRegistry::getRegistry();
31   // Add the top suite to the test runner
32   CppUnit::TestRunner runner;
33   runner.addTest( registry.makeTest() );   
34   try
35   {
36     std::cout << "Running "  <<  testPath;
37     runner.run( controller, testPath );
38
39     std::cerr << std::endl;
40
41     // Print test in a compiler compatible format.
42     CppUnit::CompilerOutputter outputter( &result, std::cerr );
43     outputter.write();                      
44   }
45   catch ( std::invalid_argument &e )  // Test path not resolved
46   {
47     std::cerr  <<  std::endl  
48       <<  "ERROR: "  <<  e.what()
49       << std::endl;
50     return 0;
51   }
52
53   return result.wasSuccessful() ? 0 : 1;
54 }