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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <cppunit/extensions/TestFactoryRegistry.h>
20 #include <cppunit/CompilerOutputter.h>
21 #include <cppunit/TestResult.h>
22 #include <cppunit/TestResultCollector.h>
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>
34 #include "HYDRO_trace.hxx"
37 QString REF_DATA_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test/HYDRO";
38 QString TMP_DIR = QDir::tempPath();
40 QString REF_DATA_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test/HYDRO";
41 QString TMP_DIR = qgetenv( "HYDRO_ROOT_DIR" ) + "/test_ref";
45 int MAIN_W = 800, MAIN_H = 600;
47 int main( int argc, char* argv[] )
49 QApplication anApp( argc, argv );
50 SUIT_Session aSession;
51 aSession.startApplication("std");
53 QDir().mkdir( TMP_DIR );
55 OCCViewer_ViewFrame* aWindow = TestViewer::viewWindow();
57 aWindow->setGeometry( 400, 100, MAIN_W, MAIN_H );
59 QTest::qWaitForWindowExposed( aWindow );
62 //std::cout << dx << "," << dy << std::endl;
63 aWindow->resize( MAIN_W, MAIN_H+dy );
64 anApp.processEvents();
66 std::string testPath = (argc > 1) ? std::string(argv[1]) : "";
68 // Create the event manager and test controller
69 CppUnit::TestResult controller;
71 // Add a listener that collects test result
72 CppUnit::TestResultCollector result;
73 controller.addListener( &result );
75 // Add a listener that print dots as test run.
76 TestLib_Listener progress;
77 controller.addListener( &progress );
79 CppUnit::TestFactoryRegistry& registry =
80 CppUnit::TestFactoryRegistry::getRegistry();
81 // Add the top suite to the test runner
82 TestLib_Runner runner;
84 QString aPath = qgetenv( "HYDRO_SRC_DIR" ) + "/src/tests.cfg";
86 QString aPath = qgetenv( "HYDRO_ROOT_DIR" ) + "/tests.cfg";
88 runner.Load( aPath.toStdString() );
89 runner.addTest( registry.makeTest() );
92 std::cout << "Running tests " << testPath << "..." << std::endl;
93 runner.Run( controller );
95 std::cerr << std::endl;
97 // Print test in a compiler compatible format.
98 CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() );
101 catch ( std::invalid_argument &e ) // Test path not resolved
103 std::cerr << std::endl
104 << "ERROR: " << e.what()
108 bool isOK = result.wasSuccessful();
111 DEBTRACE("End of tests");
115 aSession.closeSession();
119 DEBTRACE("--- TODO: exception on exit..."); // TODO: exception on exit...
122 int ms = progress.GetCompleteTimeInMS();
124 printf( "%i TESTS in %i SUITES\n", progress.GetNbTests(), progress.GetNbSuites() );
125 printf( "COMPLETE TESTS TIME: %i ms\n", ms );
126 progress.DumpFailures();
128 return result.wasSuccessful() ? 0 : 1;