Salome HOME
0021063: [CEA 434] Compilation using gnu compiler v4.5
[modules/kernel.git] / src / LifeCycleCORBA / Test / LifeCycleCORBATest.cxx
1 //  Copyright (C) 2007-2010  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.
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 "LifeCycleCORBATest.hxx"
24 #include "SALOME_LifeCycleCORBA.hxx"
25 #include "SALOME_FileTransferCORBA.hxx"
26 #include "Utils_ORB_INIT.hxx"
27 #include "Utils_SINGLETON.hxx"
28 #include "Basics_Utils.hxx"
29
30 #include <iostream>
31 #include <fstream>
32 #include <string>
33 #include <cstdlib>
34
35
36 // --- uncomment to have some traces on standard error
37 //     (useful only when adding new tests...)
38 //#define _DEVDEBUG_
39
40 #ifdef _DEVDEBUG_
41 #define MYDEVTRACE {std::cerr << __FILE__ << " [" << __LINE__ << "] : ";}
42 #define DEVTRACE(msg) {MYDEVTRACE; std::cerr<<msg<<std::endl<<std::flush;}
43 #else
44 #define MYDEVTRACE
45 #define DEVTRACE(msg)
46 #endif
47
48 #define TRACEFILE "/tmp/traceUnitTest.log"
49
50 // ============================================================================
51 /*!
52  * Set Trace mecanism
53  * - delete preexisting trace classes if any
54  * - set trace on file
55  * Get or initialize the orb
56  * Create a SALOME_NamingService instance
57  */
58 // ============================================================================
59
60 void 
61 LifeCycleCORBATest::setUp()
62 {
63   LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
64   CPPUNIT_ASSERT(bp1);
65   bp1->deleteInstance(bp1);
66
67   // --- trace on file
68   const char *theFileName = TRACEFILE;
69
70   std::string s = "file:";
71   s += theFileName;
72   //s="local";
73   //s="with_logger";
74   CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
75
76   std::ofstream traceFile;
77   //  traceFile.open(theFileName, std::ios::out | std::ios::trunc);
78   traceFile.open(theFileName, std::ios::out | std::ios::app);
79   CPPUNIT_ASSERT(traceFile); // file created empty, then closed
80   traceFile.close();
81
82   bp1 = LocalTraceBufferPool::instance();
83   CPPUNIT_ASSERT(bp1);
84
85   // --- Get or initialize the orb
86
87   int _argc = 1;
88   char* _argv[] = {(char*)""};
89   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
90   ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
91   _orb = init(_argc , _argv ) ;
92
93   // --- Create a SALOME_NamingService instance
94
95   _NS.init_orb(_orb) ;
96 }
97
98 // ============================================================================
99 /*!
100  *  - delete trace classes
101  */
102 // ============================================================================
103
104 void 
105 LifeCycleCORBATest::tearDown()
106 {
107
108   LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
109   CPPUNIT_ASSERT(bp1);
110   bp1->deleteInstance(bp1);
111 }
112
113 // ============================================================================
114 /*!
115  * Check FindOrLoad_Component.
116  * - get a local container (no hostname given),
117  *       load an engine, check that the CORBA object is not null.
118  * - check narrow
119  */
120 // ============================================================================
121
122 void
123 LifeCycleCORBATest::testFindOrLoad_Component_LaunchContainer()
124 {
125   SALOME_LifeCycleCORBA _LCC(&_NS);
126
127   // --- get a local container,
128   //     load an engine, check that the CORBA object is not null
129
130   std::string containerName = "myContainer";
131   Engines::Component_var mycompo =
132     _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
133   CPPUNIT_ASSERT(!CORBA::is_nil(mycompo));
134
135   // --- check narrow
136
137   Engines::TestComponent_var m1;
138   m1 = Engines::TestComponent::_narrow(mycompo);
139   CPPUNIT_ASSERT(!CORBA::is_nil(m1));
140 }
141
142 // ============================================================================
143 /*!
144  * Check FindOrLoad_Component.
145  * - Call 2 times FindOrLoad_Component with the same parameters
146  * - check if we get the same engine
147  */
148 // ============================================================================
149
150 void
151 LifeCycleCORBATest::testFindOrLoad_Component_SameInstance()
152 {
153   SALOME_LifeCycleCORBA _LCC(&_NS);
154
155   // --- get a local container,
156   //     load an engine, check that the CORBA object is not null
157
158   std::string containerName = "myContainer";
159
160   Engines::Component_var mycompo1 =
161     _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
162   CPPUNIT_ASSERT(!CORBA::is_nil(mycompo1));
163
164   Engines::Component_var mycompo2 =
165     _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
166   CPPUNIT_ASSERT(!CORBA::is_nil(mycompo2));
167
168   // --- check narrow
169
170   Engines::TestComponent_var m1;
171   m1 = Engines::TestComponent::_narrow(mycompo1);
172   CPPUNIT_ASSERT(!CORBA::is_nil(m1));
173
174   Engines::TestComponent_var m2;
175   m2 = Engines::TestComponent::_narrow(mycompo2);
176   CPPUNIT_ASSERT(!CORBA::is_nil(m2));
177
178   // --- check equality of instance names
179
180   std::string name1 = m1->instanceName();
181   std::string name2 = m2->instanceName();
182   CPPUNIT_ASSERT_EQUAL(name1, name2);
183 }
184
185 // ============================================================================
186 /*!
187  * Check FindOrLoad_Component with Python Component on C++ Container
188  *       load an engine, check that the CORBA object is not null.
189  * - check narrow
190  */
191 // ============================================================================
192
193 void
194 LifeCycleCORBATest::testFindOrLoad_Component_PythonInCppContainer()
195 {
196   SALOME_LifeCycleCORBA _LCC(&_NS);
197
198   // --- get a local container,
199   //     load an engine, check that the CORBA object is not null
200
201   std::string containerName = "myContainer";
202
203   Engines::Component_var mycompo1 =
204     _LCC.FindOrLoad_Component(containerName.c_str(),"SALOME_TestComponentPy");
205   CPPUNIT_ASSERT(!CORBA::is_nil(mycompo1));
206
207   // --- check narrow
208
209   Engines::TestComponent_var m1;
210   m1 = Engines::TestComponent::_narrow(mycompo1);
211   CPPUNIT_ASSERT(!CORBA::is_nil(m1));
212 }
213
214 // ============================================================================
215 /*!
216  * Check FindOrLoad_Component with Python Component on C++ Container
217  * - Call 2 times FindOrLoad_Component with the same parameters
218  * - check if we get the same engine
219  */
220 // ============================================================================
221
222 void
223 LifeCycleCORBATest::testFindOrLoad_Component_PythonSameInstance()
224 {
225   SALOME_LifeCycleCORBA _LCC(&_NS);
226
227   // --- get a local container (with a name based on local hostname),
228   //     load an engine, check that the CORBA object is not null
229
230   std::string containerName = "myContainer";
231
232   Engines::Component_var mycompo1 =
233     _LCC.FindOrLoad_Component(containerName.c_str(),"SALOME_TestComponentPy");
234   CPPUNIT_ASSERT(!CORBA::is_nil(mycompo1));
235
236   Engines::Component_var mycompo2 =
237     _LCC.FindOrLoad_Component(containerName.c_str(),"SALOME_TestComponentPy");
238   CPPUNIT_ASSERT(!CORBA::is_nil(mycompo2));
239
240   // --- check narrow
241
242   Engines::TestComponent_var m1;
243   m1 = Engines::TestComponent::_narrow(mycompo1);
244   CPPUNIT_ASSERT(!CORBA::is_nil(m1));
245
246   Engines::TestComponent_var m2;
247   m2 = Engines::TestComponent::_narrow(mycompo2);
248   CPPUNIT_ASSERT(!CORBA::is_nil(m2));
249
250   // --- check equality of instance names
251
252   std::string name1 = m1->instanceName();
253   std::string name2 = m2->instanceName();
254   CPPUNIT_ASSERT_EQUAL(name1, name2);
255 }
256
257 // ============================================================================
258 /*!
259  * Check FindOrLoad_Component with a component name not in catalog.
260  * See list of catalog given to module catalog server.
261  * Here, we work with KERNEL_SRC/resources/KERNELCatalog.xml that contains 
262  * only KERNEL, SalomeTestComponent and SALOME_TestComponentPy
263  */
264 // ============================================================================
265
266 void
267 LifeCycleCORBATest::testFindOrLoad_Component_UnknownInCatalog()
268 {
269   SALOME_LifeCycleCORBA _LCC(&_NS);
270
271   // --- get a local container (with a name based on local hostname),
272   //     load an engine, check that the CORBA object is not null
273
274   std::string containerName = "myContainer";
275
276   Engines::Component_var mycompo1 =
277     _LCC.FindOrLoad_Component(containerName.c_str(),"MyNewComponent");
278   CPPUNIT_ASSERT(CORBA::is_nil(mycompo1));
279 }
280
281 // ============================================================================
282 /*!
283  * Check FindOrLoad_Component with hostname given
284  * - get a local container : getHostName()/componentName,
285  *       load an engine, check that the CORBA object is not null.
286  * - check narrow
287  */
288 // ============================================================================
289
290 void
291 LifeCycleCORBATest::testFindOrLoad_Component_LaunchContainerHostname()
292 {
293   SALOME_LifeCycleCORBA _LCC(&_NS);
294
295   // --- get a local container (with a name based on local hostname),
296   //     load an engine, check that the CORBA object is not null
297
298   std::string containerName = Kernel_Utils::GetHostname();
299   containerName += "/theContainer";
300   DEVTRACE("containerName = " << containerName);
301   Engines::Component_var mycompo =
302     _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
303   CPPUNIT_ASSERT(!CORBA::is_nil(mycompo));
304
305   // --- check narrow
306
307   Engines::TestComponent_var m1;
308   m1 = Engines::TestComponent::_narrow(mycompo);
309   CPPUNIT_ASSERT(!CORBA::is_nil(m1));
310 }
311
312 // ============================================================================
313 /*!
314  * Check FindOrLoad_Component with and without local hostname given.
315  * We must get the same container, the same instance of component
316  */
317 // ============================================================================
318
319 void
320 LifeCycleCORBATest::testFindOrLoad_Component_SameContainer()
321 {
322   SALOME_LifeCycleCORBA _LCC(&_NS);
323
324   // --- get a local container (with a name based on local hostname),
325   //     load an engine, check that the CORBA object is not null
326
327   std::string containerName = "aContainer";
328
329   Engines::Component_var mycompo1 =
330     _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
331   CPPUNIT_ASSERT(!CORBA::is_nil(mycompo1));
332
333   containerName = Kernel_Utils::GetHostname();
334   containerName += "/aContainer";
335   DEVTRACE("containerName = " << containerName);
336   Engines::Component_var mycompo2 =
337     _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
338   CPPUNIT_ASSERT(!CORBA::is_nil(mycompo2));
339
340   // --- check narrow
341
342   Engines::TestComponent_var m1;
343   m1 = Engines::TestComponent::_narrow(mycompo1);
344   CPPUNIT_ASSERT(!CORBA::is_nil(m1));
345
346   Engines::TestComponent_var m2;
347   m2 = Engines::TestComponent::_narrow(mycompo2);
348   CPPUNIT_ASSERT(!CORBA::is_nil(m2));
349
350   // --- check equality of instance names
351
352   std::string name1 = m1->instanceName();
353   std::string name2 = m2->instanceName();
354   CPPUNIT_ASSERT_EQUAL(name1, name2);
355
356   // --- check containers are the same servant (same container name+hostname)
357
358   Engines::Container_var c1 = m1->GetContainerRef();
359   CPPUNIT_ASSERT(!CORBA::is_nil(c1));
360   Engines::Container_var c2 = m2->GetContainerRef();
361   CPPUNIT_ASSERT(!CORBA::is_nil(c1));
362   std::string cname1 = c1->name();
363   std::string cname2 = c2->name();
364   CPPUNIT_ASSERT_EQUAL(cname1, cname2);
365   std::string hostname1 = c1->getHostName();
366   std::string hostname2 = c2->getHostName();
367   CPPUNIT_ASSERT_EQUAL(hostname1, hostname2);
368   CORBA::Long pidc1 = c1->getPID();
369   CORBA::Long pidc2 = c2->getPID();
370   CPPUNIT_ASSERT_EQUAL(pidc1, pidc2);
371 }
372
373 // ============================================================================
374 /*!
375  * Check FindOrLoad_Component: check behaviour when ask for an unknown computer
376  * We must catch a Salome Exception with "unknown host" message
377  */
378 // ============================================================================
379
380 void
381 LifeCycleCORBATest::testFindOrLoad_Component_UnknownMachine()
382 {
383   SALOME_LifeCycleCORBA _LCC(&_NS);
384
385   // --- try to get a distant container on an unknown machine (not existing)
386   //     check that the CORBA object is null
387
388   std::string containerName = "aFarAwayComputer";
389   containerName += "/theContainer";
390 //   CPPUNIT_ASSERT_THROW(Engines::Component_var mycompo =
391 //                     _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");,SALOME::SALOME_Exception);
392   try
393     {
394       Engines::Component_var mycompo =
395         _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
396     }
397   catch(const SALOME::SALOME_Exception &ex)
398     {
399       CPPUNIT_ASSERT(true);
400 //       std::string expectedMessage = "BAD PARAM";
401 //       std::ostream os;
402 //       os << ex;
403 //       std::string actualMessage = os.str();
404 //       DEVTRACE("actual Exception Message = " << actualMessage);
405 //       CPPUNIT_ASSERT(actualMessage.find(expectedMessage) != std::string::npos);
406     }
407 }
408
409 // ============================================================================
410 /*!
411  * Check FindOrLoad_Component, empty params must give an instance
412  */
413 // ============================================================================
414
415 void
416 LifeCycleCORBATest::testFindOrLoad_Component_ParamsEmpty()
417 {
418   SALOME_LifeCycleCORBA _LCC(&_NS);
419
420   Engines::MachineParameters params;
421   _LCC.preSet(params);
422   Engines::Component_var mycompo =
423     _LCC.FindOrLoad_Component(params,"SalomeTestComponent");
424   CPPUNIT_ASSERT(!CORBA::is_nil(mycompo));
425
426   // --- check narrow
427
428   Engines::TestComponent_var m1;
429   m1 = Engines::TestComponent::_narrow(mycompo);
430 }
431
432 // ============================================================================
433 /*!
434  * Check FindOrLoad_Component params = local container 
435  */
436 // ============================================================================
437
438 void
439 LifeCycleCORBATest::testFindOrLoad_Component_ParamsLocalContainer()
440 {
441   SALOME_LifeCycleCORBA _LCC(&_NS);
442
443   Engines::MachineParameters params;
444   _LCC.preSet(params);
445   std::string hostname=Kernel_Utils::GetHostname();
446   params.hostname=hostname.c_str();
447   Engines::Component_var mycompo =
448     _LCC.FindOrLoad_Component(params,"SalomeTestComponent");
449   CPPUNIT_ASSERT(!CORBA::is_nil(mycompo));
450
451   // --- check narrow
452
453   Engines::TestComponent_var m1;
454   m1 = Engines::TestComponent::_narrow(mycompo);
455
456   // --- check that container is on local computer
457
458   CPPUNIT_ASSERT(!CORBA::is_nil(m1));
459   Engines::Container_var c1 = m1->GetContainerRef();
460   CPPUNIT_ASSERT(!CORBA::is_nil(c1));
461   std::string hostname1 = c1->getHostName();
462   CPPUNIT_ASSERT_EQUAL(hostname1, Kernel_Utils::GetHostname());
463 }
464
465
466 // ============================================================================
467 /*!
468  * Check FindOrLoad_Component params = containerName
469  */
470 // ============================================================================
471
472 void
473 LifeCycleCORBATest::testFindOrLoad_Component_ParamsContainerName()
474 {
475   SALOME_LifeCycleCORBA _LCC(&_NS);
476
477   Engines::MachineParameters params;
478   _LCC.preSet(params);
479   std::string containerName = "myContainer";
480   params.container_name = containerName.c_str();
481   Engines::Component_var mycompo =
482     _LCC.FindOrLoad_Component(params,"SalomeTestComponent");
483   CPPUNIT_ASSERT(!CORBA::is_nil(mycompo));
484
485   // --- check narrow
486
487   Engines::TestComponent_var m1;
488   m1 = Engines::TestComponent::_narrow(mycompo);
489
490   // --- check that container has good name
491
492   CPPUNIT_ASSERT(!CORBA::is_nil(m1));
493   Engines::Container_var c1 = m1->GetContainerRef();
494   CPPUNIT_ASSERT(!CORBA::is_nil(c1));
495   std::string hostname1 = c1->getHostName();
496   CPPUNIT_ASSERT_EQUAL(hostname1, Kernel_Utils::GetHostname());
497   std::string cname1 = c1->name();
498   CPPUNIT_ASSERT(cname1.find(containerName) != std::string::npos);
499 }
500
501 // ============================================================================
502 /*!
503  * Check FindOrLoad_Component on remote computer
504  */
505 // ============================================================================
506
507 void
508 LifeCycleCORBATest::testFindOrLoad_Component_RemoteComputer()
509 {
510   SALOME_LifeCycleCORBA _LCC(&_NS);
511
512   std::string remoteHost = GetRemoteHost();
513
514   std::string containerName = remoteHost;
515   containerName += "/aContainer";
516   DEVTRACE("containerName = " << containerName);
517   Engines::Component_var mycompo1 =
518     _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
519   CPPUNIT_ASSERT_MESSAGE("Test validity requires connection to remote "\
520                          "computers from ResourcesCatalog",
521                          !CORBA::is_nil(mycompo1));
522
523   // --- check narrow
524
525   Engines::TestComponent_var m1;
526   m1 = Engines::TestComponent::_narrow(mycompo1);
527
528   // --- check that container is on good computer
529
530   CPPUNIT_ASSERT(!CORBA::is_nil(m1));
531   Engines::Container_var c1 = m1->GetContainerRef();
532   CPPUNIT_ASSERT(!CORBA::is_nil(c1));
533   std::string hostname1 = c1->getHostName();
534   CPPUNIT_ASSERT_EQUAL(hostname1, remoteHost);
535 }
536
537 // ============================================================================
538 /*!
539  * Check FindOrLoad_Component with params on remote computer
540  * params empty except hostname 
541  */
542 // ============================================================================
543
544 void
545 LifeCycleCORBATest::testFindOrLoad_Component_ParamsRemoteComputer()
546 {
547   SALOME_LifeCycleCORBA _LCC(&_NS);
548
549   std::string remoteHost = GetRemoteHost();
550
551   Engines::MachineParameters params;
552   _LCC.preSet(params); 
553   params.hostname = remoteHost.c_str();
554
555   Engines::Component_var mycompo1 =
556     _LCC.FindOrLoad_Component(params,"SalomeTestComponent");
557   CPPUNIT_ASSERT_MESSAGE("Test validity requires connection to remote "\
558                          "computers from ResourcesCatalog",
559                          !CORBA::is_nil(mycompo1));
560
561   // --- check narrow
562
563   Engines::TestComponent_var m1;
564   m1 = Engines::TestComponent::_narrow(mycompo1);
565
566   // --- check that container is on good computer
567
568   CPPUNIT_ASSERT(!CORBA::is_nil(m1));
569   Engines::Container_var c1 = m1->GetContainerRef();
570   CPPUNIT_ASSERT(!CORBA::is_nil(c1));
571   std::string hostname1 = c1->getHostName();
572   CPPUNIT_ASSERT_EQUAL(hostname1, remoteHost);
573 }
574
575 // ============================================================================
576 /*!
577  * Check FindOrLoad_Component with params on remote computer
578  * params empty except hostname and container_name
579  */
580 // ============================================================================
581
582 void
583 LifeCycleCORBATest::testFindOrLoad_Component_ParamsRemoteComputer2()
584 {
585   SALOME_LifeCycleCORBA _LCC(&_NS);
586
587   std::string remoteHost = GetRemoteHost();
588
589   Engines::MachineParameters params;
590   _LCC.preSet(params); 
591   params.hostname = remoteHost.c_str();
592   params.container_name = "anotherContainer";
593
594   Engines::Component_var mycompo1 =
595     _LCC.FindOrLoad_Component(params,"SalomeTestComponent");
596   CPPUNIT_ASSERT_MESSAGE("Test validity requires connection to remote "\
597                          "computers from ResourcesCatalog",
598                          !CORBA::is_nil(mycompo1));
599
600   // --- check narrow
601
602   Engines::TestComponent_var m1;
603   m1 = Engines::TestComponent::_narrow(mycompo1);
604
605   // --- check that container is on good computer
606
607   CPPUNIT_ASSERT(!CORBA::is_nil(m1));
608   Engines::Container_var c1 = m1->GetContainerRef();
609   CPPUNIT_ASSERT(!CORBA::is_nil(c1));
610   std::string hostname1 = c1->getHostName();
611   CPPUNIT_ASSERT_EQUAL(hostname1, remoteHost);
612 }
613
614 // ============================================================================
615 /*!
616  * Check SALOME_FileTransferCORBA on local machine
617  */
618 // ============================================================================
619
620 void  LifeCycleCORBATest::testgetLocalFile_localComputer()
621 {
622   SALOME_LifeCycleCORBA _LCC(&_NS);
623   std::string origFileName = getenv("KERNEL_ROOT_DIR");
624   origFileName += "/lib/salome/libSalomeLifeCycleCORBA.so.0.0.0";
625   SALOME_FileTransferCORBA transfer( Kernel_Utils::GetHostname(),
626                                      origFileName);
627   std::string local = transfer.getLocalFile();
628   CPPUNIT_ASSERT(!local.empty());
629   CPPUNIT_ASSERT_EQUAL(local, origFileName);
630 }
631
632 // ============================================================================
633 /*!
634  * Check SALOME_FileTransferCORBA on remote machine
635  */
636 // ============================================================================
637
638 void  LifeCycleCORBATest::testgetLocalFile_remoteComputer()
639 {
640   SALOME_LifeCycleCORBA _LCC(&_NS);
641   std::string origFileName = getenv("KERNEL_ROOT_DIR");
642   origFileName += "/lib/salome/libSalomeContainer.so.0.0.0";
643   SALOME_FileTransferCORBA transfer( GetRemoteHost(),
644                                      origFileName);
645   std::string local = transfer.getLocalFile();
646   CPPUNIT_ASSERT(!local.empty());
647   std::string local2 = transfer.getLocalFile();
648   CPPUNIT_ASSERT(!local2.empty());
649   CPPUNIT_ASSERT_EQUAL(local, local2);
650 }
651
652 // ============================================================================
653 /*!
654  * Check FindOrLoad_Component params = containerName
655  */
656 // ============================================================================
657
658 // void
659 // LifeCycleCORBATest::testFindOrLoad_Component_()
660 // {
661 // }
662
663
664
665
666 // ============================================================================
667 /*!
668  *  Get a remote HostName in the Resource Catalog
669  */
670 // ============================================================================
671
672 std::string LifeCycleCORBATest::GetRemoteHost()
673 {
674   SALOME_LifeCycleCORBA _LCC(&_NS);
675
676   CORBA::Object_var obj = _NS.Resolve("/ResourcesManager");
677   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
678   Engines::ResourcesManager_var resourcesManager =
679     Engines::ResourcesManager::_narrow(obj);
680   CPPUNIT_ASSERT(!CORBA::is_nil(resourcesManager));
681
682   Engines::ContainerParameters params;
683   _LCC.preSet(params);               // empty params to get all the machines
684   params.resource_params.componentList.length(1);
685   params.resource_params.componentList[0]="SalomeTestComponent";
686
687   Engines::ResourceList_var hostList = resourcesManager->GetFittingResources(params.resource_params);
688   CPPUNIT_ASSERT(hostList->length() > 1);
689
690   std::string localHost = Kernel_Utils::GetHostname();
691   std::string remoteHost;
692   for (unsigned int i=0; i < hostList->length(); i++)
693     {
694       const char* aMachine = hostList[i];
695       Engines::ResourceDefinition_var resource_definition = resourcesManager->GetResourceDefinition(aMachine);
696       std::string machine(resource_definition->hostname.in());
697       if (machine != localHost)
698         {
699           remoteHost = machine;
700           break;
701         }
702     }
703   CPPUNIT_ASSERT(remoteHost != "");
704   return remoteHost;
705 }