Salome HOME
6b65965a87353255846feb5bea9c3c785c4f217f
[modules/kernel.git] / src / KernelHelpers / Test / KernelHelpersUnitTests.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "KernelHelpersUnitTests.hxx"
24
25 #include "SALOME_KernelServices.hxx"
26 #include "Basics_Utils.hxx"
27 #include "KernelBasis.hxx"
28
29 #include <SALOMEconfig.h>
30 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
31
32 // ============================================================================
33 /*!
34  * Set up the environment
35  */
36 // ============================================================================
37
38 void KernelHelpersUnitTests::setUp()
39 {
40   setSSLMode(false);
41 }
42
43 // ============================================================================
44 /*!
45  *  - delete
46  */
47 // ============================================================================
48
49 void KernelHelpersUnitTests::tearDown()
50 {
51 }
52
53 // ============================================================================
54 /*!
55  * Check SalomeApp functionality
56  */
57 // ============================================================================
58 void KernelHelpersUnitTests::TEST_corba()
59 {
60   CORBA::ORB_var orb = KERNEL::getORB();
61   CPPUNIT_ASSERT(!CORBA::is_nil(orb));
62
63
64   SALOME_NamingService_Abstract *  ns  = KERNEL::getNamingService();
65   CPPUNIT_ASSERT(ns!=NULL);
66
67   SALOME_LifeCycleCORBA * lcc = KERNEL::getLifeCycleCORBA();
68   CPPUNIT_ASSERT(lcc!=NULL);
69 }
70
71 void KernelHelpersUnitTests::TEST_getLifeCycleCORBA() {
72   Engines::EngineComponent_var component =
73     KERNEL::getLifeCycleCORBA()->FindOrLoad_Component( "FactoryServer","SalomeTestComponent" );
74
75   Engines::TestComponent_var engine = Engines::TestComponent::_narrow(component);
76   char * coucou_res = engine->Coucou(123.);
77   const char * coucou_ref = "TestComponent_i : L = 123";
78   LOG(coucou_res);
79   CPPUNIT_ASSERT( strcmp(coucou_res, coucou_ref) == 0 );
80 }
81
82 void KernelHelpersUnitTests::TEST_getStudy() {
83   SALOMEDS::Study_ptr myTestStudy = KERNEL::getStudyServant();
84   CPPUNIT_ASSERT(!CORBA::is_nil(myTestStudy));
85
86   // One can use the study to store some general properties
87   myTestStudy->SetString("material","wood");
88   myTestStudy->SetReal("volume",3.23);
89
90   // The study with properties was opened
91   LOG("TestComponentImpl::testkernel: study with properties was opened");
92 }
93
94 void KernelHelpersUnitTests::TEST_getSalomeLauncher() {
95   Engines::SalomeLauncher_var salomeLauncher = KERNEL::getSalomeLauncher();
96   try {
97     int pid = salomeLauncher->getPID();
98     SALOME_UNUSED(pid); // unused in release mode
99     LOG("SALOME launcher PID = " << pid);
100   }
101   catch (const SALOME::SALOME_Exception & ex) {
102     LOG("SALOME Exception in createJob !" <<ex.details.text.in());
103     CPPUNIT_ASSERT(false);
104   }
105   catch (const CORBA::SystemException& ex) {
106     LOG("Receive SALOME System Exception: "<<ex);
107     LOG("Check SALOME servers...");
108     CPPUNIT_ASSERT(false);
109   }
110   catch (const std::exception& ex) {
111     LOG("Receive undefined exception : "<<ex.what());
112     CPPUNIT_ASSERT(false);
113   }
114 }