Salome HOME
d348124e8dc425e25b2e9fc6d9a2d8a2a7727bb0
[tools/py2cpp.git] / src / Test / TestMain.cxx
1 // Copyright (C) 2019-2024 EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include <cppunit/CompilerOutputter.h>
20 #include <cppunit/TestResult.h>
21 #include <cppunit/TestResultCollector.h>
22 #include <cppunit/TextTestProgressListener.h>
23 #include <cppunit/BriefTestProgressListener.h>
24 #include <cppunit/extensions/TestFactoryRegistry.h>
25 #include <cppunit/TestRunner.h>
26 #include <cppunit/TextTestRunner.h>
27 #include <stdexcept>
28
29 #include <iostream>
30 #include <fstream>
31 #include <stdlib.h>
32
33 // ============================================================================
34 /*!
35  *  Main program source for Unit Tests with cppunit package does not depend
36  *  on actual tests, so we use the same for all partial unit tests.
37  */
38 // ============================================================================
39
40 int main(int argc, char* argv[])
41 {
42   // --- Create the event manager and test controller
43   CPPUNIT_NS::TestResult controller;
44
45   // ---  Add a listener that collects test result
46   CPPUNIT_NS::TestResultCollector result;
47   controller.addListener( &result );        
48
49   // ---  Add a listener that print dots as test run.
50 #ifdef WIN32
51   CPPUNIT_NS::TextTestProgressListener progress;
52 #else
53   CPPUNIT_NS::BriefTestProgressListener progress;
54 #endif
55   controller.addListener( &progress );      
56
57   // ---  Get the top level suite from the registry
58
59   CPPUNIT_NS::Test *suite =
60     CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
61
62   // ---  Adds the test to the list of test to run
63
64   CPPUNIT_NS::TestRunner runner;
65   runner.addTest( suite );
66   runner.run( controller);
67
68   // ---  Print test in a compiler compatible format.
69   std::ofstream testFile;
70   testFile.open("test.log", std::ios::out | std::ios::app);
71   testFile << "------ Idefix test log:" << std::endl;
72   CPPUNIT_NS::CompilerOutputter outputter( &result, testFile );
73   outputter.write(); 
74
75   // ---  Run the tests.
76
77   bool wasSucessful = result.wasSuccessful();
78   testFile.close();
79
80   // ---  Return error code 1 if the one of test failed.
81
82   return wasSucessful ? 0 : 1;
83 }