Salome HOME
66fcdafc3fee9f735325afc6ae630f190ed154f7
[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 <cppunit/TestRunner.h>
24 #include <cppunit/TextTestProgressListener.h>
25 #include <stdexcept>
26 #include <TestViewer.h>
27 #include <OCCViewer_ViewWindow.h>
28 #include <SUIT_Session.h>
29 #include <QApplication>
30 #include <QColor>
31
32 std::ostream& operator<<( std::ostream& theStream, const QString& theText )
33 {
34   theStream << theText.toStdString();
35   return theStream;
36 }
37
38 std::ostream& operator<<( std::ostream& theStream, const QColor& theColor )
39 {
40   theStream << "[" << theColor.red() << ", " << theColor.green() << ", " << theColor.blue() << "]";
41   return theStream;
42 }
43 #include <time.h>
44
45 int main( int argc, char* argv[] )
46 {
47   srand( time( 0 ) );
48
49   QApplication anApp( argc, argv );
50   SUIT_Session aSession;
51
52   OCCViewer_ViewWindow* aWindow = TestViewer::viewWindow();
53   aWindow->setGeometry( 200, 200, 800, 600 );
54   aWindow->show();
55
56   std::string testPath = (argc > 1) ? std::string(argv[1]) : "";
57
58   // Create the event manager and test controller
59   CppUnit::TestResult controller;
60
61   // Add a listener that colllects test result
62   CppUnit::TestResultCollector result;
63   controller.addListener( &result );        
64
65   // Add a listener that print dots as test run.
66   CppUnit::TextTestProgressListener progress;
67   controller.addListener( &progress );      
68
69   CppUnit::TestFactoryRegistry& registry = 
70     CppUnit::TestFactoryRegistry::getRegistry();
71   // Add the top suite to the test runner
72   CppUnit::TestRunner runner;
73   runner.addTest( registry.makeTest() );   
74   try
75   {
76     std::cout << "Running "  <<  testPath;
77     runner.run( controller, testPath );
78
79     std::cerr << std::endl;
80
81     // Print test in a compiler compatible format.
82     CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() );
83     outputter.write();
84   }
85   catch ( std::invalid_argument &e )  // Test path not resolved
86   {
87     std::cerr  <<  std::endl  
88       <<  "ERROR: "  <<  e.what()
89       << std::endl;
90     return 0;
91   }
92
93   //anApp.exec();
94   return result.wasSuccessful() ? 0 : 1;
95 }