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