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