Salome HOME
Merge branch 'BR_LAND_COVER_MAP' of ssh://gitolite3@git.salome-platform.org/modules...
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_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 <stdexcept>
24 #include <TestViewer.h>
25 #include <TestLib_Listener.h>
26 #include <TestLib_Runner.h>
27 #include <OCCViewer_ViewWindow.h>
28 #include <SUIT_Session.h>
29 #include <QApplication>
30 #include <QColor>
31 #include <QTest>
32
33 int main( int argc, char* argv[] )
34 {
35   QApplication anApp( argc, argv );
36   SUIT_Session aSession;
37
38   OCCViewer_ViewWindow* aWindow = TestViewer::viewWindow();
39
40   int W = 800, H = 600;
41   aWindow->setGeometry( 200, 200, W, H );
42   aWindow->show();
43   QTest::qWaitForWindowShown( aWindow );
44
45   int dy = 34;
46   //std::cout << dx << "," << dy << std::endl;
47   aWindow->resize( W, H+dy );
48   anApp.processEvents();
49
50   std::string testPath = (argc > 1) ? std::string(argv[1]) : "";
51
52   // Create the event manager and test controller
53   CppUnit::TestResult controller;
54
55   // Add a listener that colllects test result
56   CppUnit::TestResultCollector result;
57   controller.addListener( &result );        
58
59   // Add a listener that print dots as test run.
60   TestLib_Listener progress;
61   controller.addListener( &progress );      
62
63   CppUnit::TestFactoryRegistry& registry = 
64     CppUnit::TestFactoryRegistry::getRegistry();
65   // Add the top suite to the test runner
66   TestLib_Runner runner;
67   QString aPath = qgetenv( "HYDRO_SRC_DIR" ) + "/src/tests.cfg";
68   runner.Load( aPath.toStdString() );
69   runner.addTest( registry.makeTest() );   
70   try
71   {
72     std::cout << "Running tests "  << testPath << "..." << std::endl;
73     runner.Run( controller );
74
75     std::cerr << std::endl;
76
77     // Print test in a compiler compatible format.
78     CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() );
79     outputter.write();
80   }
81   catch ( std::invalid_argument &e )  // Test path not resolved
82   {
83     std::cerr  <<  std::endl  
84       <<  "ERROR: "  <<  e.what()
85       << std::endl;
86     return 0;
87   }
88
89   //anApp.exec();
90   return result.wasSuccessful() ? 0 : 1;
91 }