Back to index

salome-med  6.5.0
BasicMainTest.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #ifndef _BASICMAINTEST_HXX_
00021 #define _BASICMAINTEST_HXX_
00022 
00023 #include <cppunit/CompilerOutputter.h>
00024 #include <cppunit/TestResult.h>
00025 #include <cppunit/TestResultCollector.h>
00026 #include <cppunit/TextTestProgressListener.h>
00027 #include <cppunit/BriefTestProgressListener.h>
00028 #include <cppunit/extensions/TestFactoryRegistry.h>
00029 #include <cppunit/TestRunner.h>
00030 #include <stdexcept>
00031 
00032 #include <iostream>
00033 #include <fstream>
00034 
00035 // ============================================================================
00040 // ============================================================================
00041 
00042 int main(int argc, char* argv[])
00043 {
00044   // --- Create the event manager and test controller
00045   CPPUNIT_NS::TestResult controller;
00046 
00047   // ---  Add a listener that colllects test result
00048   CPPUNIT_NS::TestResultCollector result;
00049   controller.addListener( &result );        
00050 
00051   // ---  Add a listener that print dots as test run.
00052 #ifdef WIN32
00053   CPPUNIT_NS::TextTestProgressListener progress;
00054 #else
00055   CPPUNIT_NS::BriefTestProgressListener progress;
00056 #endif
00057   controller.addListener( &progress );      
00058 
00059   // ---  Get the top level suite from the registry
00060 
00061   CPPUNIT_NS::Test *suite =
00062     CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
00063 
00064   // ---  Adds the test to the list of test to run
00065 
00066   CPPUNIT_NS::TestRunner runner;
00067   runner.addTest( suite );
00068   runner.run( controller);
00069 
00070   // ---  Print test in a compiler compatible format.
00071 
00072   std::ofstream testFile;
00073   testFile.open("UnitTestsResult", std::ios::out |  std::ios::trunc);
00074   //CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
00075   CPPUNIT_NS::CompilerOutputter outputter( &result, testFile );
00076   outputter.write(); 
00077 
00078   // ---  Run the tests.
00079 
00080   bool wasSucessful = result.wasSuccessful();
00081   testFile.close();
00082 
00083   // ---  Return error code 1 if the one of test failed.
00084 
00085   return wasSucessful ? 0 : 1;
00086 }
00087 
00088 #endif