Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / INTERP_KERNELTest / BasicMainTest.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
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.
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 #ifndef _BASICMAINTEST_HXX_
20 #define _BASICMAINTEST_HXX_
21
22 #include <cppunit/CompilerOutputter.h>
23 #include <cppunit/TestResult.h>
24 #include <cppunit/TestResultCollector.h>
25 #include <cppunit/TextTestProgressListener.h>
26 #include <cppunit/BriefTestProgressListener.h>
27 #include <cppunit/extensions/TestFactoryRegistry.h>
28 #include <cppunit/TestRunner.h>
29 #include <stdexcept>
30
31 #include <iostream>
32 #include <fstream>
33
34 // ============================================================================
35 /*!
36  *  Main program source for Unit Tests with cppunit package does not depend
37  *  on actual tests, so we use the same for all partial unit tests.
38  */
39 // ============================================================================
40
41 int main(int argc, char* argv[])
42 {
43   // --- Create the event manager and test controller
44   CPPUNIT_NS::TestResult controller;
45
46   // ---  Add a listener that colllects test result
47   CPPUNIT_NS::TestResultCollector result;
48   controller.addListener( &result );        
49
50   // ---  Add a listener that print dots as test run.
51 #ifdef WIN32
52   CPPUNIT_NS::TextTestProgressListener progress;
53 #else
54   CPPUNIT_NS::BriefTestProgressListener progress;
55 #endif
56   controller.addListener( &progress );      
57
58   // ---  Get the top level suite from the registry
59
60   CPPUNIT_NS::Test *suite =
61     CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
62
63   // ---  Adds the test to the list of test to run
64
65   CPPUNIT_NS::TestRunner runner;
66   runner.addTest( suite );
67   runner.run( controller);
68
69   // ---  Print test in a compiler compatible format.
70
71   std::ofstream testFile;
72   testFile.open("UnitTestsResult", std::ios::out |  std::ios::trunc);
73   //CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
74   CPPUNIT_NS::CompilerOutputter outputter( &result, testFile );
75   outputter.write(); 
76
77   // ---  Run the tests.
78
79   bool wasSucessful = result.wasSuccessful();
80   testFile.close();
81
82   // ---  Return error code 1 if the one of test failed.
83
84   return wasSucessful ? 0 : 1;
85 }
86
87 #endif