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
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 #ifndef WIN32
00036 #include <fpu_control.h>
00037 #endif
00038 
00039 // ============================================================================
00044 // ============================================================================
00045 
00046 int main(int argc, char* argv[])
00047 {
00048 #ifndef WIN32
00049   fpu_control_t cw = _FPU_DEFAULT & ~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM);
00050   _FPU_SETCW(cw);
00051 #endif
00052   // --- Create the event manager and test controller
00053   CPPUNIT_NS::TestResult controller;
00054 
00055   // ---  Add a listener that colllects test result
00056   CPPUNIT_NS::TestResultCollector result;
00057   controller.addListener( &result );        
00058 
00059   // ---  Add a listener that print dots as test run.
00060 #ifdef WIN32
00061   CPPUNIT_NS::TextTestProgressListener progress;
00062 #else
00063   CPPUNIT_NS::BriefTestProgressListener progress;
00064 #endif
00065   controller.addListener( &progress );      
00066 
00067   // ---  Get the top level suite from the registry
00068 
00069   CPPUNIT_NS::Test *suite =
00070     CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
00071 
00072   // ---  Adds the test to the list of test to run
00073 
00074   CPPUNIT_NS::TestRunner runner;
00075   runner.addTest( suite );
00076   runner.run( controller);
00077 
00078   // ---  Print test in a compiler compatible format.
00079 
00080   std::ofstream testFile;
00081   testFile.open("UnitTestsResult", std::ios::out |  std::ios::trunc);
00082   //CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
00083   CPPUNIT_NS::CompilerOutputter outputter( &result, testFile );
00084   outputter.write(); 
00085 
00086   // ---  Run the tests.
00087 
00088   bool wasSucessful = result.wasSuccessful();
00089   testFile.close();
00090 
00091   // ---  Return error code 1 if the one of test failed.
00092 
00093   return wasSucessful ? 0 : 1;
00094 }
00095 
00096 #endif