1 // Copyright (C) 2007-2023 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, or (at your option) any later version.
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
23 // --- include all SALOMEDS Test from basics until the present directory
25 #include "SALOMELocalTraceTest.hxx"
26 #include "SALOMEDSImplTest.hxx"
27 #include "SALOMEDSTest.hxx"
29 // --- Registers the fixture into the 'registry'
31 CPPUNIT_TEST_SUITE_REGISTRATION( SALOMEDSTest );
32 CPPUNIT_TEST_SUITE_REGISTRATION( SALOMEDSTest_Embedded );
34 #include <cppunit/CompilerOutputter.h>
35 #include <cppunit/TestResult.h>
36 #include <cppunit/TestResultCollector.h>
37 #include <cppunit/TextTestProgressListener.h>
38 #include <cppunit/BriefTestProgressListener.h>
39 #include <cppunit/extensions/TestFactoryRegistry.h>
40 #include <cppunit/TestRunner.h>
46 #include <SALOMEconfig.h>
47 #include CORBA_SERVER_HEADER(SALOMEDS)
48 #include "utilities.h"
49 #include "ArgvKeeper.hxx"
51 #include "Basics_Utils.hxx"
52 #include "SALOME_NamingService.hxx"
53 #include "NamingService_WaitForServerReadiness.hxx"
54 #include "SALOMEDS_Study_i.hxx"
58 #define setenv Kernel_Utils::setenv
61 // ============================================================================
63 * Main program source for Unit Tests with cppunit package does not depend
64 * on actual tests, so we use the same for all partial unit tests.
66 // ============================================================================
68 int main(int argc, char* argv[])
70 SetArgcArgv(argc, argv);
71 CORBA::ORB_var orb = KERNEL::GetRefToORB();
72 std::string host; // = Kernel_Utils::GetHostname();
73 char* wait_Superv = getenv("SALOMEDS_UNITTESTS_WAIT_SUPERVISOR");
74 if(wait_Superv) host = Kernel_Utils::GetHostname();
76 SALOME_NamingService NS(orb);
78 NamingService_WaitForServerReadiness(&NS, "/Study");
80 std::string serverName = "/Containers/"+host+"/SuperVisionContainer";
81 NamingService_WaitForServerReadiness(&NS, serverName);
84 CORBA::Object_var obj = NS.Resolve( "/Study" );
85 if(CORBA::is_nil(obj)) {
86 system("killSalome.py");
90 //Set up the environment for Embedded case
91 std::string kernel_root = getenv("KERNEL_ROOT_DIR");
92 CPPUNIT_ASSERT(!kernel_root.empty());
93 kernel_root+="/share/salome/resources/kernel";
95 CORBA::Object_var poaObj = orb->resolve_initial_references("RootPOA");
96 if(!CORBA::is_nil(poaObj)) {
97 PortableServer::POA_var poa = PortableServer::POA::_narrow(poaObj);
99 SALOMEDS_Study_i* aStudy_i = new SALOMEDS_Study_i(orb);
100 // Activate the objects. This tells the POA that the objects are ready to accept requests.
101 PortableServer::ObjectId_var aStudy_iid = poa->activate_object(aStudy_i);
102 SALOMEDS::Study_var Study = aStudy_i->_this();
103 NS.Register(Study.in(), "/Study_embedded");
105 // Obtain a POAManager, and tell the POA to start accepting
106 // requests on its objects.
107 PortableServer::POAManager_var pman = poa->the_POAManager();
112 // --- Create the event manager and test controller
113 CPPUNIT_NS::TestResult controller;
115 // --- Add a listener that colllects test result
116 CPPUNIT_NS::TestResultCollector result;
117 controller.addListener( &result );
119 // --- Add a listener that print dots as test run.
121 CPPUNIT_NS::TextTestProgressListener progress;
123 CPPUNIT_NS::BriefTestProgressListener progress;
125 controller.addListener( &progress );
127 // --- Get the top level suite from the registry
129 CPPUNIT_NS::Test *suite =
130 CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
132 // --- Adds the test to the list of test to run
134 CPPUNIT_NS::TestRunner runner;
135 runner.addTest( suite );
136 runner.run( controller);
138 // --- Print test in a compiler compatible format.
140 std::ofstream testFile;
141 testFile.open("UnitTestsResult", std::ios::out | std::ios::trunc);
142 //CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
143 CPPUNIT_NS::CompilerOutputter outputter( &result, testFile );
146 // --- Run the tests.
148 bool wasSucessful = result.wasSuccessful();
151 // --- Return error code 1 if the one of test failed.
153 return wasSucessful ? 0 : 1;