Salome HOME
3a6360d64207f2ffb1f0825aceb6b27362b530f5
[modules/kernel.git] / src / KernelHelpers / KernelHelpersUseCases.cxx
1 // Copyright (C) 2007-2023  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
20 // Author: Guillaume Boulant (EDF/R&D)
21
22 #include "SALOME_KernelServices.hxx"
23 #include "Basics_Utils.hxx"
24
25 #include <SALOMEconfig.h>
26 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
27
28 bool TEST_corba() {
29   CORBA::ORB_var orb = KERNEL::getORB();
30   if ( CORBA::is_nil(orb) ) {
31     LOG("TEST_Corba: orb ERROR");
32     return false;
33   }
34   SALOME_NamingService_Abstract *  ns  = KERNEL::getNamingService();
35   if ( ns == NULL ) {
36     LOG("TEST_Corba: ns ERROR");
37     return false;
38
39   }
40   SALOME_LifeCycleCORBA * lcc = KERNEL::getLifeCycleCORBA();
41   if ( lcc == NULL ) {
42     LOG("TEST_Corba: lcc ERROR");
43     return false;
44   }
45   LOG("TEST_Corba: OK");
46   return true;
47 }
48
49 #include <string.h>
50 bool TEST_getLifeCycleCORBA() {
51   Engines::EngineComponent_var component =
52     KERNEL::getLifeCycleCORBA()->FindOrLoad_Component( "FactoryServer","SalomeTestComponent" );
53
54   Engines::TestComponent_var engine = Engines::TestComponent::_narrow(component);
55   char * coucou_res = engine->Coucou(123.);
56   const char * coucou_ref = "L = 123";
57   LOG(coucou_res);
58   if ( strcmp(coucou_res, coucou_ref) == 0 ) {
59     return false;
60   }
61   return true;
62 }
63
64 bool TEST_getStudy() {
65   SALOMEDS::Study_ptr myTestStudy = KERNEL::getStudyServant();
66   if ( CORBA::is_nil(myTestStudy) ) {
67     return false;
68   }
69
70   // One can use the study to store some general properties
71   myTestStudy->SetString("material","wood");
72   myTestStudy->SetReal("volume",3.23);
73
74   // The study with properties was opened
75   LOG("TestComponentImpl::testkernel: study with properties was opened");
76   return true;
77 }
78
79
80 bool TEST_getSalomeLauncher() {
81   Engines::SalomeLauncher_var salomeLauncher = KERNEL::getSalomeLauncher();
82   for (int i=0; i<10; i++) {
83     try {
84       int pid = salomeLauncher->getPID();
85       SALOME_UNUSED(pid); // unused in release mode
86       LOG("["<<i<<"] SALOME launcher PID = " << pid);
87     }
88     catch (const SALOME::SALOME_Exception & ex) {
89       LOG("SALOME Exception in createJob !" <<ex.details.text.in());
90       return false;
91     }
92     catch (const CORBA::SystemException& ex) {
93       LOG("Receive SALOME System Exception: "<<ex);
94       LOG("Check SALOME servers...");
95       return false;
96     }
97     catch (const std::exception& ex) {
98       LOG("Receive undefined exception : "<<ex.what());
99     }
100 #ifndef WIN32
101       sleep(2);
102 #else
103       Sleep(2000);
104 #endif
105   }
106   return true;
107 }
108
109 // TODO:
110 // - complete the coverture of the KernelService interface
111 // - provide use case for the StudyEditor
112
113
114
115 int main () {
116   TEST_corba();
117   TEST_getLifeCycleCORBA();
118   TEST_getStudy();
119   TEST_getSalomeLauncher();
120   return 0;
121 }