Salome HOME
Merge Python 3 porting: additional chnages.
[modules/kernel.git] / src / KernelHelpers / KernelHelpersUseCases.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author: Guillaume Boulant (EDF/R&D)
20
21 #include "SALOME_KernelServices.hxx"
22 #include "Basics_Utils.hxx"
23
24 #include <SALOMEconfig.h>
25 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
26
27 bool TEST_corba() {
28   CORBA::ORB_var orb = KERNEL::getORB();
29   if ( CORBA::is_nil(orb) ) {
30     LOG("TEST_Corba: orb ERROR");
31     return false;
32   }
33   SALOME_NamingService *  ns  = KERNEL::getNamingService();
34   if ( ns == NULL ) {
35     LOG("TEST_Corba: ns ERROR");
36     return false;
37
38   }
39   SALOME_LifeCycleCORBA * lcc = KERNEL::getLifeCycleCORBA();
40   if ( lcc == NULL ) {
41     LOG("TEST_Corba: lcc ERROR");
42     return false;
43   }
44   LOG("TEST_Corba: OK");
45   return true;
46 }
47
48 #include <string.h>
49 bool TEST_getLifeCycleCORBA() {
50   Engines::EngineComponent_var component =
51     KERNEL::getLifeCycleCORBA()->FindOrLoad_Component( "FactoryServer","SalomeTestComponent" );
52
53   Engines::TestComponent_var engine = Engines::TestComponent::_narrow(component);
54   char * coucou_res = engine->Coucou(123.);
55   const char * coucou_ref = "L = 123";
56   LOG(coucou_res);
57   if ( strcmp(coucou_res, coucou_ref) == 0 ) {
58     return false;
59   }
60   return true;
61 }
62
63 bool TEST_getStudy() {
64   SALOMEDS::Study_ptr myTestStudy = KERNEL::getStudyServant();
65   if ( CORBA::is_nil(myTestStudy) ) {
66     return false;
67   }
68
69   // One can use the study to store some general properties
70   myTestStudy->SetString("material","wood");
71   myTestStudy->SetReal("volume",3.23);
72
73   // The study with properties was opened
74   LOG("TestComponentImpl::testkernel: study with properties was opened");
75   return true;
76 }
77
78
79 bool TEST_getSalomeLauncher() {
80   Engines::SalomeLauncher_var salomeLauncher = KERNEL::getSalomeLauncher();
81   for (int i=0; i<10; i++) {
82     try {
83       int pid = salomeLauncher->getPID();
84       LOG("["<<i<<"] SALOME launcher PID = " << pid);
85     }
86     catch (const SALOME::SALOME_Exception & ex) {
87       LOG("SALOME Exception in createJob !" <<ex.details.text.in());
88       return false;
89     }
90     catch (const CORBA::SystemException& ex) {
91       LOG("Receive SALOME System Exception: "<<ex);
92       LOG("Check SALOME servers...");
93       return false;
94     }
95     catch (const std::exception& ex) {
96       LOG("Receive undefined exception : "<<ex.what());
97     }
98 #ifndef WIN32
99       sleep(2);
100 #else
101       Sleep(2000);
102 #endif
103   }
104   return true;
105 }
106
107 // TODO:
108 // - complete the coverture of the KernelService interface
109 // - provide use case for the StudyEditor
110
111
112
113 int main (int argc, char * argv[]) {
114   TEST_corba();
115   TEST_getLifeCycleCORBA();
116   TEST_getStudy();
117   TEST_getSalomeLauncher();
118   return 0;
119 }