Back to index

salome-kernel  6.5.0
TestSALOMEDS.cxx
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 // --- include all SALOMEDS Test from basics until the present directory
00024 //
00025 #include "SALOMELocalTraceTest.hxx"
00026 #include "SALOMEDSImplTest.hxx"
00027 #include "SALOMEDSTest.hxx"
00028 
00029 // --- Registers the fixture into the 'registry'
00030 
00031 CPPUNIT_TEST_SUITE_REGISTRATION( SALOMEDSTest );
00032 CPPUNIT_TEST_SUITE_REGISTRATION( SALOMEDSTest_Embedded );
00033 
00034 #include <cppunit/CompilerOutputter.h>
00035 #include <cppunit/TestResult.h>
00036 #include <cppunit/TestResultCollector.h>
00037 #include <cppunit/TextTestProgressListener.h>
00038 #include <cppunit/BriefTestProgressListener.h>
00039 #include <cppunit/extensions/TestFactoryRegistry.h>
00040 #include <cppunit/TestRunner.h>
00041 #include <stdexcept>
00042 
00043 #include <iostream>
00044 #include <fstream>
00045 
00046 #include <SALOMEconfig.h>
00047 #include CORBA_SERVER_HEADER(SALOMEDS)
00048 #include "utilities.h"
00049 #include "Utils_SINGLETON.hxx"
00050 #include "Utils_ORB_INIT.hxx"
00051 #include "Basics_Utils.hxx"
00052 #include "SALOME_NamingService.hxx"
00053 #include "NamingService_WaitForServerReadiness.hxx"
00054 #include "SALOMEDS_StudyManager_i.hxx"
00055 
00056 
00057 // ============================================================================
00062 // ============================================================================
00063 
00064 int main(int argc, char* argv[])
00065 {
00066   // --- Run Salome without GUI
00067 
00068   setenv("SALOME_trace", "file:./traceUnitTest.log", 1); // 1: overwrite
00069 
00070   system("runSalome -t &");
00071 
00072   // --- Wait till SALOMEDS server is launched
00073   
00074   char hostname[511];
00075   int size;
00076   gethostname(hostname, size);
00077   char* chr_port = getenv("SALOMEDS_UNITTESTS_PORT");
00078   std::string port;
00079   if(chr_port) port = chr_port;
00080   if(port.empty()) port = "2810";
00081   std::string cfg_file = std::string(getenv("HOME"))+"/.omniORB_"+std::string(hostname)+"_"+port+".cfg";
00082   setenv("OMNIORB_CONFIG", cfg_file.c_str(), 1);
00083 
00084   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
00085   ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
00086   CORBA::ORB_var orb = init(argc , argv ) ;
00087 
00088   sleep(15);
00089 
00090   std::string host; // = Kernel_Utils::GetHostname();
00091   char* wait_Superv = getenv("SALOMEDS_UNITTESTS_WAIT_SUPERVISOR");
00092   if(wait_Superv) host = Kernel_Utils::GetHostname(); 
00093 
00094   SALOME_NamingService NS(orb);
00095   if(host.empty())
00096     NamingService_WaitForServerReadiness(&NS, "/myStudyManager");
00097   else {
00098     std::string serverName = "/Containers/"+host+"/SuperVisionContainer";
00099     NamingService_WaitForServerReadiness(&NS, serverName);
00100   }
00101 
00102   CORBA::Object_var obj = NS.Resolve( "/myStudyManager" );
00103   if(CORBA::is_nil(obj)) {
00104      system("killSalome.py");
00105      return 1;
00106   }
00107 
00108   //Set up the environement for Embedded case
00109   std::string kernel_root = getenv("KERNEL_ROOT_DIR");
00110   CPPUNIT_ASSERT(!kernel_root.empty());
00111   kernel_root+="/share/salome/resources/kernel";
00112 
00113   CORBA::Object_var poaObj = orb->resolve_initial_references("RootPOA");
00114   if(!CORBA::is_nil(poaObj)) {
00115                 PortableServer::POA_var poa = PortableServer::POA::_narrow(poaObj);
00116 
00117     SALOMEDS_StudyManager_i * aStudyManager_i = new  SALOMEDS_StudyManager_i(orb, poa);
00118     // Activate the objects.  This tells the POA that the objects are ready to accept requests.
00119     PortableServer::ObjectId_var aStudyManager_iid =  poa->activate_object(aStudyManager_i);
00120     aStudyManager_i->register_name("/myStudyManager_embedded");
00121       
00122     // Obtain a POAManager, and tell the POA to start accepting
00123     // requests on its objects.
00124     PortableServer::POAManager_var pman = poa->the_POAManager();
00125     pman->activate();
00126   }
00127  
00128 
00129   // --- Create the event manager and test controller
00130   CPPUNIT_NS::TestResult controller;
00131 
00132   // ---  Add a listener that colllects test result
00133   CPPUNIT_NS::TestResultCollector result;
00134   controller.addListener( &result );        
00135 
00136   // ---  Add a listener that print dots as test run.
00137 #ifdef WIN32
00138   CPPUNIT_NS::TextTestProgressListener progress;
00139 #else
00140   CPPUNIT_NS::BriefTestProgressListener progress;
00141 #endif
00142   controller.addListener( &progress );      
00143 
00144   // ---  Get the top level suite from the registry
00145 
00146   CPPUNIT_NS::Test *suite =
00147     CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
00148 
00149   // ---  Adds the test to the list of test to run
00150 
00151   CPPUNIT_NS::TestRunner runner;
00152   runner.addTest( suite );
00153   runner.run( controller);
00154 
00155   // ---  Print test in a compiler compatible format.
00156 
00157   std::ofstream testFile;
00158   testFile.open("UnitTestsResult", std::ios::out |  std::ios::trunc);
00159   //CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
00160   CPPUNIT_NS::CompilerOutputter outputter( &result, testFile );
00161   outputter.write(); 
00162 
00163   // ---  Run the tests.
00164 
00165   bool wasSucessful = result.wasSuccessful();
00166   testFile.close();
00167 
00168   // --- Kill all created Salome process
00169 
00170   system("killSalome.py");
00171 
00172   // ---  Return error code 1 if the one of test failed.
00173 
00174   return wasSucessful ? 0 : 1;
00175 }