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