1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // --- include all SALOMEDS Test from basics until the present directory
24 #include "SALOMELocalTraceTest.hxx"
25 #include "SALOMEDSImplTest.hxx"
26 #include "SALOMEDSTest.hxx"
28 // --- Registers the fixture into the 'registry'
30 CPPUNIT_TEST_SUITE_REGISTRATION( SALOMEDSTest );
31 CPPUNIT_TEST_SUITE_REGISTRATION( SALOMEDSTest_Embedded );
33 #include <cppunit/CompilerOutputter.h>
34 #include <cppunit/TestResult.h>
35 #include <cppunit/TestResultCollector.h>
36 #include <cppunit/TextTestProgressListener.h>
37 #include <cppunit/BriefTestProgressListener.h>
38 #include <cppunit/extensions/TestFactoryRegistry.h>
39 #include <cppunit/TestRunner.h>
45 #include <SALOMEconfig.h>
46 #include CORBA_SERVER_HEADER(SALOMEDS)
47 #include "utilities.h"
48 #include "Utils_SINGLETON.hxx"
49 #include "Utils_ORB_INIT.hxx"
50 #include "Basics_Utils.hxx"
51 #include "SALOME_NamingService.hxx"
52 #include "NamingService_WaitForServerReadiness.hxx"
53 #include "SALOMEDS_StudyManager_i.hxx"
57 // ============================================================================
59 * Main program source for Unit Tests with cppunit package does not depend
60 * on actual tests, so we use the same for all partial unit tests.
62 // ============================================================================
64 int main(int argc, char* argv[])
66 // --- Run Salome without GUI
68 setenv("SALOME_trace", "file:./traceUnitTest.log", 1); // 1: overwrite
70 system("runSalome -t &");
72 // --- Wait till SALOMEDS server is launched
76 gethostname(hostname, size);
77 char* chr_port = getenv("SALOMEDS_UNITTESTS_PORT");
79 if(chr_port) port = chr_port;
80 if(port.empty()) port = "2810";
81 string cfg_file = string(getenv("HOME"))+"/.omniORB_"+string(hostname)+"_"+port+".cfg";
82 setenv("OMNIORB_CONFIG", cfg_file.c_str(), 1);
84 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
85 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
86 CORBA::ORB_var orb = init(argc , argv ) ;
90 string host; // = Kernel_Utils::GetHostname();
91 char* wait_Superv = getenv("SALOMEDS_UNITTESTS_WAIT_SUPERVISOR");
92 if(wait_Superv) host = Kernel_Utils::GetHostname();
94 SALOME_NamingService NS(orb);
96 NamingService_WaitForServerReadiness(&NS, "/myStudyManager");
98 string serverName = "/Containers/"+host+"/SuperVisionContainer";
99 NamingService_WaitForServerReadiness(&NS, serverName);
102 CORBA::Object_var obj = NS.Resolve( "/myStudyManager" );
103 if(CORBA::is_nil(obj)) {
104 system("killSalome.py");
108 //Set up the environement for Embedded case
109 string kernel_root = getenv("KERNEL_ROOT_DIR");
110 CPPUNIT_ASSERT(!kernel_root.empty());
111 kernel_root+="/share/salome/resources/kernel";
113 CORBA::Object_var poaObj = orb->resolve_initial_references("RootPOA");
114 if(!CORBA::is_nil(poaObj)) {
115 PortableServer::POA_var poa = PortableServer::POA::_narrow(poaObj);
117 SALOMEDS_StudyManager_i * aStudyManager_i = new SALOMEDS_StudyManager_i(orb, poa);
118 // Activate the objects. This tells the POA that the objects are ready to accept requests.
119 PortableServer::ObjectId_var aStudyManager_iid = poa->activate_object(aStudyManager_i);
120 aStudyManager_i->register_name("/myStudyManager_embedded");
122 // Obtain a POAManager, and tell the POA to start accepting
123 // requests on its objects.
124 PortableServer::POAManager_var pman = poa->the_POAManager();
129 // --- Create the event manager and test controller
130 CPPUNIT_NS::TestResult controller;
132 // --- Add a listener that colllects test result
133 CPPUNIT_NS::TestResultCollector result;
134 controller.addListener( &result );
136 // --- Add a listener that print dots as test run.
138 CPPUNIT_NS::TextTestProgressListener progress;
140 CPPUNIT_NS::BriefTestProgressListener progress;
142 controller.addListener( &progress );
144 // --- Get the top level suite from the registry
146 CPPUNIT_NS::Test *suite =
147 CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
149 // --- Adds the test to the list of test to run
151 CPPUNIT_NS::TestRunner runner;
152 runner.addTest( suite );
153 runner.run( controller);
155 // --- Print test in a compiler compatible format.
157 std::ofstream testFile;
158 testFile.open("UnitTestsResult", std::ios::out | std::ios::trunc);
159 //CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
160 CPPUNIT_NS::CompilerOutputter outputter( &result, testFile );
163 // --- Run the tests.
165 bool wasSucessful = result.wasSuccessful();
168 // --- Kill all created Salome process
170 system("killSalome.py");
172 // --- Return error code 1 if the one of test failed.
174 return wasSucessful ? 0 : 1;