Salome HOME
Revert "Synchronize adm files"
[modules/kernel.git] / src / KernelHelpers / Test / KernelHelpersUnitTests.cxx
1 // Copyright (C) 2007-2014  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
28 #include <SALOMEconfig.h>
29 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
30
31 // ============================================================================
32 /*!
33  * Set up the environment
34  */
35 // ============================================================================
36
37 void KernelHelpersUnitTests::setUp()
38 {
39 }
40
41 // ============================================================================
42 /*!
43  *  - delete 
44  */
45 // ============================================================================
46
47 void KernelHelpersUnitTests::tearDown()
48 {
49 }
50
51 // ============================================================================
52 /*!
53  * Check SalomeApp functionality
54  */
55 // ============================================================================
56 void KernelHelpersUnitTests::TEST_corba()
57 {
58   CORBA::ORB_var orb = KERNEL::getORB();
59   CPPUNIT_ASSERT(!CORBA::is_nil(orb));
60
61   
62   SALOME_NamingService *  ns  = KERNEL::getNamingService();
63   CPPUNIT_ASSERT(ns!=NULL);
64
65   SALOME_LifeCycleCORBA * lcc = KERNEL::getLifeCycleCORBA();
66   CPPUNIT_ASSERT(lcc!=NULL);
67 }
68
69 void KernelHelpersUnitTests::TEST_getLifeCycleCORBA() {
70   Engines::EngineComponent_var component =
71     KERNEL::getLifeCycleCORBA()->FindOrLoad_Component( "FactoryServer","SalomeTestComponent" );
72   
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";
76   LOG(coucou_res);
77   CPPUNIT_ASSERT( strcmp(coucou_res, coucou_ref) == 0 );
78 }
79
80 void KernelHelpersUnitTests::TEST_getStudyManager() {
81   SALOMEDS::Study_ptr myTestStudy = KERNEL::getStudyManager()->NewStudy("kerneltest");
82   CPPUNIT_ASSERT(!CORBA::is_nil(myTestStudy));
83
84   // One can use the study to store some general properties
85   myTestStudy->SetString("material","wood");
86   myTestStudy->SetReal("volume",3.23);
87
88   // The study is characterized by an ID
89   int myTestStudyId = myTestStudy->StudyId();
90   LOG("TestComponentImpl::testkernel: study id = "<<myTestStudyId);
91 }
92
93 void KernelHelpersUnitTests::TEST_getSalomeLauncher() {
94   Engines::SalomeLauncher_var salomeLauncher = KERNEL::getSalomeLauncher();
95   try {
96     int pid = salomeLauncher->getPID();
97     LOG("SALOME launcher PID = " << pid);
98   }
99   catch (const SALOME::SALOME_Exception & ex) {
100     LOG("SALOME Exception in createJob !" <<ex.details.text.in());
101     CPPUNIT_ASSERT(false);
102   }
103   catch (const CORBA::SystemException& ex) {
104     LOG("Receive SALOME System Exception: "<<ex);
105     LOG("Check SALOME servers...");
106     CPPUNIT_ASSERT(false);
107   }
108   catch (const std::exception& ex) {
109     LOG("Receive undefined exception : "<<ex.what());
110     CPPUNIT_ASSERT(false);
111   }
112 }