Salome HOME
refs #1341: debug of automatic tests
[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_ViewFrame.h>
28 #include <SUIT_Session.h>
29 #include <QApplication>
30 #include <QColor>
31 #include <QTest>
32
33 #define _DEVDEBUG_
34 #include "HYDRO_trace.hxx"
35
36 #ifdef WIN32
37 QString REF_DATA_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test/HYDRO";
38 #else
39 QString REF_DATA_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test/HYDRO/HYDRO";
40 #endif
41
42
43 int main( int argc, char* argv[] )
44 {
45   QApplication anApp( argc, argv );
46   SUIT_Session aSession;
47   aSession.startApplication("std");
48
49   OCCViewer_ViewFrame* aWindow = TestViewer::viewWindow();
50
51   int W = 800, H = 600;
52   aWindow->setGeometry( 200, 200, W, H );
53   aWindow->show();
54   QTest::qWaitForWindowExposed( aWindow );
55
56   int dy = 34;
57   //std::cout << dx << "," << dy << std::endl;
58   aWindow->resize( W, H+dy );
59   anApp.processEvents();
60
61   std::string testPath = (argc > 1) ? std::string(argv[1]) : "";
62
63   // Create the event manager and test controller
64   CppUnit::TestResult controller;
65
66   // Add a listener that collects test result
67   CppUnit::TestResultCollector result;
68   controller.addListener( &result );        
69
70   // Add a listener that print dots as test run.
71   TestLib_Listener progress;
72   controller.addListener( &progress );      
73
74   CppUnit::TestFactoryRegistry& registry = 
75     CppUnit::TestFactoryRegistry::getRegistry();
76   // Add the top suite to the test runner
77   TestLib_Runner runner;
78 #ifdef WIN32
79   QString aPath = qgetenv( "HYDRO_SRC_DIR" ) + "/src/tests.cfg";
80 #else
81   QString aPath = "/tmp/hydro/tests.cfg";
82 #endif
83   runner.Load( aPath.toStdString() );
84   runner.addTest( registry.makeTest() );   
85   try
86   {
87     std::cout << "Running tests "  << testPath << "..." << std::endl;
88     runner.Run( controller );
89
90     std::cerr << std::endl;
91
92     // Print test in a compiler compatible format.
93     CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() );
94     outputter.write();
95   }
96   catch ( std::invalid_argument &e )  // Test path not resolved
97   {
98     std::cerr  <<  std::endl  
99       <<  "ERROR: "  <<  e.what()
100       << std::endl;
101     return 0;
102   }
103   bool isOK = result.wasSuccessful();
104
105 #ifndef WIN32
106   DEBTRACE("End of tests");
107 #endif
108
109   aWindow->close();
110   aSession.closeSession();
111   anApp.exit(!isOK);
112
113 #ifndef WIN32
114   DEBTRACE("--- TODO: exception on exit..."); // TODO: exception on exit...
115 #endif
116
117   int ms = progress.GetCompleteTimeInMS();
118   printf( "\n\n" );
119   printf( "%i TESTS in %i SUITES\n", progress.GetNbTests(), progress.GetNbSuites() );
120   printf( "COMPLETE TESTS TIME: %i ms\n", ms );
121   progress.DumpFailures();
122
123   return result.wasSuccessful() ? 0 : 1;
124 }