Salome HOME
updated copyright message
[modules/kernel.git] / src / LifeCycleCORBA_SWIG / Test / LifeCycleCORBA_SWIGTest.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 #  File   : LifeCycleCORBA_SWIGTest.py
25 #  Author : Paul RASCLE, EDF
26 #  Module : SALOME
27 #  $Header$
28 #
29 import sys
30 import unittest
31 from omniORB import CORBA
32 import Utils_Identity
33 import Engines
34
35 class LifeCycleCORBA_SWIGTest(unittest.TestCase):
36     def setUp(self):
37         import LifeCycleCORBA
38         self.lcc = LifeCycleCORBA.LifeCycleCORBA()
39         pass
40
41     def tearDown(self):
42         pass
43
44     def test001_FindOrLoad_Component_LaunchContainer(self):
45         """
46         get a local container (no hostname given),
47         load an engine, check that the CORBA object is not null.
48         check narrow
49         """
50         containerName = "swMyContainer"
51         comp=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
52         self.assertNotEqual(comp,None)
53         testComp=comp._narrow(Engines.TestComponent)
54         self.assertNotEqual(testComp,None)
55         pass
56
57     def test002_FindOrLoad_Component_SameInstance(self):
58         """
59         Check FindOrLoad_Component.
60         Call 2 times FindOrLoad_Component with the same parameters,
61         check if we get the same engine
62         """
63         containerName = "swMyContainer"
64         cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
65         self.assertNotEqual(cp1,None)
66         cp2=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
67         self.assertNotEqual(cp2,None)
68         m1=cp1._narrow(Engines.TestComponent)
69         self.assertNotEqual(m1,None)
70         m2=cp2._narrow(Engines.TestComponent)
71         self.assertNotEqual(m2,None)
72         name1=m1._get_instanceName()
73         name2=m2._get_instanceName()
74         self.assertEqual(name1,name2)
75         pass
76
77     def test003_FindOrLoad_Component_PythonInCppContainer(self):
78         """
79         Check FindOrLoad_Component with Python Component on C++ Container,
80         load an engine, check that the CORBA object is not null.
81         check narrow
82         """
83         containerName = "swMyContainer"
84         cp1=self.lcc.FindOrLoad_Component(containerName,"SALOME_TestComponentPy")
85         self.assertNotEqual(cp1,None)
86         m1=cp1._narrow(Engines.TestComponent)
87         self.assertNotEqual(m1,None)
88         pass
89
90     def test004_FindOrLoad_Component_PythonSameInstance(self):
91         """
92         Check FindOrLoad_Component with Python Component on C++ Container,
93         Call 2 times FindOrLoad_Component with the same parameters,
94         check if we get the same engine,
95         """
96         containerName = "swMyContainer"
97         cp1=self.lcc.FindOrLoad_Component(containerName,"SALOME_TestComponentPy")
98         self.assertNotEqual(cp1,None)
99         cp2=self.lcc.FindOrLoad_Component(containerName,"SALOME_TestComponentPy")
100         self.assertNotEqual(cp2,None)
101         m1=cp1._narrow(Engines.TestComponent)
102         self.assertNotEqual(m1,None)
103         m2=cp2._narrow(Engines.TestComponent)
104         self.assertNotEqual(m2,None)
105         name1=m1._get_instanceName()
106         name2=m2._get_instanceName()
107         self.assertEqual(name1,name2)
108         pass
109
110     def test005_FindOrLoad_Component_UnknownInCatalog(self):
111         """
112         Check FindOrLoad_Component with a component name not in catalog.
113         See list of catalog given to module catalog server.
114         Here, we work with KERNEL_SRC/resources/KERNELCatalog.xml that contains
115         only KERNEL, SalomeTestComponent and SALOME_TestComponentPy
116         """
117         containerName = "swMyContainer"
118         cp1=self.lcc.FindOrLoad_Component(containerName,"MyNewComponent")
119         self.assertEqual(cp1,None)
120         pass
121
122     def test006_FindOrLoad_Component_LaunchContainerHostname(self):
123         """
124         Check FindOrLoad_Component with hostname given.
125         get a local container : getHostName()/componentName,
126         load an engine, check that the CORBA object is not null.
127         check narrow
128         """
129         containerName = Utils_Identity.getShortHostName()
130         containerName += "/swTheContainer"
131         cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
132         self.assertNotEqual(cp1,None)
133         m1=cp1._narrow(Engines.TestComponent)
134         self.assertNotEqual(m1,None)
135         pass
136
137     def test007_FindOrLoad_Component_SameContainer(self):
138         """
139         Check FindOrLoad_Component with and without local hostname given.
140         We must get the same container, the same instance of component
141         """
142         containerName = "swAContainer"
143         cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
144         self.assertNotEqual(cp1,None)
145         containerName = Utils_Identity.getShortHostName()
146         containerName += "/swAContainer"
147         cp2=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
148         self.assertNotEqual(cp2,None)
149         m1=cp1._narrow(Engines.TestComponent)
150         self.assertNotEqual(m1,None)
151         m2=cp2._narrow(Engines.TestComponent)
152         self.assertNotEqual(m2,None)
153         name1=m1._get_instanceName()
154         name2=m2._get_instanceName()
155         self.assertEqual(name1,name2)
156         c1=m1.GetContainerRef()
157         self.assertNotEqual(c1,None)
158         c2=m2.GetContainerRef()
159         self.assertNotEqual(c2,None)
160         cname1=c1._get_name()
161         cname2=c2._get_name()
162         self.assertEqual(cname1,cname2)
163         hostname1=c1.getHostName()
164         hostname2=c2.getHostName()
165         self.assertEqual(hostname1,hostname2)
166         pidc1=c1.getPID()
167         pidc2=c2.getPID()
168         self.assertEqual(pidc1,pidc2)
169         pass
170
171     def test008_FindOrLoad_Component_UnknownMachine(self):
172         """
173         Check FindOrLoad_Component: check behaviour when ask for an unknown
174         computer. We must catch a Salome Exception with "unknown host" message
175         """
176         containerName = "aFarAwayContainer"
177         containerName += "/swTheContainer"
178         try:
179             cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
180         except RuntimeError as ex :
181             self.assertEqual(ex.args[0],'unknown host')
182         pass
183
184
185 def suite():
186     return unittest.makeSuite(LifeCycleCORBA_SWIGTest,'test')
187
188 def main():
189     return unittest.TextTestRunner().run(suite())
190
191 if __name__ == '__main__':
192     #unittest.TextTestRunner(verbosity=2).run(suite())
193     unittest.main()