Back to index

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