Salome HOME
refs #1327: debug of automatic tests
[modules/hydro.git] / src / HYDRO_tests / test_HYDROGUI_Main.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <cppunit/extensions/TestFactoryRegistry.h>
20 #include <cppunit/CompilerOutputter.h>
21 #include <cppunit/TestResult.h>
22 #include <cppunit/TestResultCollector.h>
23 #include <cppunit/TestRunner.h>
24 #include <cppunit/TextTestProgressListener.h>
25 #include <stdexcept>
26 #include <QApplication>
27
28 int main( int argc, char* argv[] )
29 {
30   QApplication anApp( argc, argv );
31
32   std::string testPath = (argc > 1) ? std::string(argv[1]) : "";
33
34   // Create the event manager and test controller
35   CppUnit::TestResult controller;
36
37   // Add a listener that colllects test result
38   CppUnit::TestResultCollector result;
39   controller.addListener( &result );        
40
41   // Add a listener that print dots as test run.
42   CppUnit::TextTestProgressListener progress;
43   controller.addListener( &progress );      
44
45   CppUnit::TestFactoryRegistry& registry = 
46     CppUnit::TestFactoryRegistry::getRegistry();
47   // Add the top suite to the test runner
48   CppUnit::TestRunner runner;
49   runner.addTest( registry.makeTest() );   
50   try
51   {
52     std::cout << "Running "  <<  testPath;
53     runner.run( controller, testPath );
54
55     std::cerr << std::endl;
56
57     // Print test in a compiler compatible format.
58     CppUnit::CompilerOutputter outputter( &result, std::cerr );
59     outputter.write();                      
60   }
61   catch ( std::invalid_argument &e )  // Test path not resolved
62   {
63     std::cerr  <<  std::endl  
64       <<  "ERROR: "  <<  e.what()
65       << std::endl;
66     return 0;
67   }
68
69   return result.wasSuccessful() ? 0 : 1;
70 }