1 // Copyright (C) 2007-2016 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 "KernelHelpersUnitTests.hxx"
25 #include "SALOME_KernelServices.hxx"
26 #include "Basics_Utils.hxx"
28 #include <SALOMEconfig.h>
29 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
31 // ============================================================================
33 * Set up the environment
35 // ============================================================================
37 void KernelHelpersUnitTests::setUp()
41 // ============================================================================
45 // ============================================================================
47 void KernelHelpersUnitTests::tearDown()
51 // ============================================================================
53 * Check SalomeApp functionality
55 // ============================================================================
56 void KernelHelpersUnitTests::TEST_corba()
58 CORBA::ORB_var orb = KERNEL::getORB();
59 CPPUNIT_ASSERT(!CORBA::is_nil(orb));
62 SALOME_NamingService * ns = KERNEL::getNamingService();
63 CPPUNIT_ASSERT(ns!=NULL);
65 SALOME_LifeCycleCORBA * lcc = KERNEL::getLifeCycleCORBA();
66 CPPUNIT_ASSERT(lcc!=NULL);
69 void KernelHelpersUnitTests::TEST_getLifeCycleCORBA() {
70 Engines::EngineComponent_var component =
71 KERNEL::getLifeCycleCORBA()->FindOrLoad_Component( "FactoryServer","SalomeTestComponent" );
73 Engines::TestComponent_var engine = Engines::TestComponent::_narrow(component);
74 char * coucou_res = engine->Coucou(123.);
75 const char * coucou_ref = "TestComponent_i : L = 123";
77 CPPUNIT_ASSERT( strcmp(coucou_res, coucou_ref) == 0 );
80 void KernelHelpersUnitTests::TEST_getStudyManager() {
81 SALOMEDS::StudyManager_var studyManager = KERNEL::getStudyManager();
83 #ifndef ALLOW_MULTI_STUDIES
84 SALOMEDS::ListOfOpenStudies_var _list_open_studies = studyManager->GetOpenStudies();
85 for (unsigned int ind = 0; ind < _list_open_studies->length();ind++)
87 LOG("Close study : " << _list_open_studies[ind]);
88 SALOMEDS::Study_var study = studyManager->GetStudyByName(_list_open_studies[0]);
90 studyManager->Close(study);
94 SALOMEDS::Study_ptr myTestStudy = studyManager->NewStudy(L"kerneltest");
95 CPPUNIT_ASSERT(!CORBA::is_nil(myTestStudy));
97 // One can use the study to store some general properties
98 myTestStudy->SetString("material","wood");
99 myTestStudy->SetReal("volume",3.23);
101 // The study is characterized by an ID
102 int myTestStudyId = myTestStudy->StudyId();
103 LOG("TestComponentImpl::testkernel: study id = "<<myTestStudyId);
106 void KernelHelpersUnitTests::TEST_getSalomeLauncher() {
107 Engines::SalomeLauncher_var salomeLauncher = KERNEL::getSalomeLauncher();
109 int pid = salomeLauncher->getPID();
110 LOG("SALOME launcher PID = " << pid);
112 catch (const SALOME::SALOME_Exception & ex) {
113 LOG("SALOME Exception in createJob !" <<ex.details.text.in());
114 CPPUNIT_ASSERT(false);
116 catch (const CORBA::SystemException& ex) {
117 LOG("Receive SALOME System Exception: "<<ex);
118 LOG("Check SALOME servers...");
119 CPPUNIT_ASSERT(false);
121 catch (const std::exception& ex) {
122 LOG("Receive undefined exception : "<<ex.what());
123 CPPUNIT_ASSERT(false);