1 // Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef _MAINTEST_HXX_
21 #define _MAINTEST_HXX_
23 #include <cppunit/CompilerOutputter.h>
24 #include <cppunit/TestResult.h>
25 #include <cppunit/TestResultCollector.h>
26 #include <cppunit/TextTestProgressListener.h>
27 #include <cppunit/BriefTestProgressListener.h>
28 #include <cppunit/extensions/TestFactoryRegistry.h>
29 #include <cppunit/TestRunner.h>
35 // ============================================================================
37 * Main program source for Unit Tests with cppunit package does not depend
38 * on actual tests, so we use the same for all partial unit tests.
40 // ============================================================================
42 int main(int argc, char* argv[])
44 // --- Create the event manager and test controller
45 CPPUNIT_NS::TestResult controller;
47 // --- Add a listener that colllects test result
48 CPPUNIT_NS::TestResultCollector result;
49 controller.addListener( &result );
51 // --- Add a listener that print dots as test run.
53 CPPUNIT_NS::TextTestProgressListener progress;
55 CPPUNIT_NS::BriefTestProgressListener progress;
57 controller.addListener( &progress );
59 // --- Get the top level suite from the registry
61 CPPUNIT_NS::Test *suite =
62 CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
64 // --- Adds the test to the list of test to run
66 CPPUNIT_NS::TestRunner runner;
67 runner.addTest( suite );
68 runner.run( controller);
70 // --- Print test in a compiler compatible format.
72 std::ofstream testFile;
73 testFile.open("UnitTestsResult.txt", std::ios::out | std::ios::trunc);
74 // CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
75 CPPUNIT_NS::CompilerOutputter outputter( &result, testFile );
80 bool wasSucessful = result.wasSuccessful();
83 // --- Return error code 1 if the one of test failed.
85 return wasSucessful ? 0 : 1;