Salome HOME
Merge branch 'V7_dev'
[modules/yacs.git] / src / LifeCycleCORBA_SWIG / Test / LifeCycleCORBA_SWIGTest.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016  CEA/DEN, EDF R&D, 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 PYHELLO_ORB
33 import HELLO_ORB
34 import Utils_Identity
35 import Engines
36
37 class LifeCycleCORBA_SWIGTest(unittest.TestCase):
38     def setUp(self):
39         import LifeCycleCORBA
40         self.lcc = LifeCycleCORBA.LifeCycleCORBA()
41         pass
42
43     def tearDown(self):
44         pass
45     
46     def test001_FindOrLoad_Component_LaunchContainer(self):
47         """
48         get a local container (no hostname given),
49         load an engine, check that the CORBA object is not null.
50         check narrow        
51         """
52         containerName = "swMyContainer"
53         comp=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
54         self.assertNotEqual(comp,None)
55         testComp=comp._narrow(Engines.TestComponent)
56         self.assertNotEqual(testComp,None)
57         pass
58
59     def test002_FindOrLoad_Component_SameInstance(self):
60         """
61         Check FindOrLoad_Component.
62         Call 2 times FindOrLoad_Component with the same parameters,
63         check if we get the same engine      
64         """
65         containerName = "swMyContainer"
66         cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
67         self.assertNotEqual(cp1,None)
68         cp2=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
69         self.assertNotEqual(cp2,None)
70         m1=cp1._narrow(Engines.TestComponent)
71         self.assertNotEqual(m1,None)
72         m2=cp2._narrow(Engines.TestComponent)
73         self.assertNotEqual(m2,None)
74         name1=m1._get_instanceName()
75         name2=m2._get_instanceName()
76         self.assertEqual(name1,name2)
77         pass
78
79     def test003_FindOrLoad_Component_PythonInCppContainer(self):
80         """
81         Check FindOrLoad_Component with Python Component on C++ Container,
82         load an engine, check that the CORBA object is not null.
83         check narrow
84         """
85         containerName = "swMyContainer"
86         cp1=self.lcc.FindOrLoad_Component(containerName,"SALOME_TestComponentPy")
87         self.assertNotEqual(cp1,None)
88         m1=cp1._narrow(Engines.TestComponent)
89         self.assertNotEqual(m1,None)
90         pass        
91
92     def test004_FindOrLoad_Component_PythonSameInstance(self):
93         """
94         Check FindOrLoad_Component with Python Component on C++ Container,
95         Call 2 times FindOrLoad_Component with the same parameters,
96         check if we get the same engine,
97         """
98         containerName = "swMyContainer"
99         cp1=self.lcc.FindOrLoad_Component(containerName,"SALOME_TestComponentPy")
100         self.assertNotEqual(cp1,None)
101         cp2=self.lcc.FindOrLoad_Component(containerName,"SALOME_TestComponentPy")
102         self.assertNotEqual(cp2,None)
103         m1=cp1._narrow(Engines.TestComponent)
104         self.assertNotEqual(m1,None)
105         m2=cp2._narrow(Engines.TestComponent)
106         self.assertNotEqual(m2,None)
107         name1=m1._get_instanceName()
108         name2=m2._get_instanceName()
109         self.assertEqual(name1,name2)
110         pass
111
112     def test005_FindOrLoad_Component_UnknownInCatalog(self):
113         """
114         Check FindOrLoad_Component with a component name not in catalog.
115         See list of catalog given to module catalog server.
116         Here, we work with KERNEL_SRC/resources/KERNELCatalog.xml that contains 
117         only KERNEL, SalomeTestComponent and SALOME_TestComponentPy
118         """
119         containerName = "swMyContainer"
120         cp1=self.lcc.FindOrLoad_Component(containerName,"MyNewComponent")
121         self.assertEqual(cp1,None)
122         pass
123
124     def test006_FindOrLoad_Component_LaunchContainerHostname(self):
125         """
126         Check FindOrLoad_Component with hostname given.
127         get a local container : getHostName()/componentName,
128         load an engine, check that the CORBA object is not null.
129         check narrow
130         """
131         containerName = Utils_Identity.getShortHostName()
132         containerName += "/swTheContainer"
133         cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
134         self.assertNotEqual(cp1,None)
135         m1=cp1._narrow(Engines.TestComponent)
136         self.assertNotEqual(m1,None)
137         pass
138
139     def test007_FindOrLoad_Component_SameContainer(self):
140         """
141         Check FindOrLoad_Component with and without local hostname given.
142         We must get the same container, the same instance of component
143         """
144         containerName = "swAContainer"
145         cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
146         self.assertNotEqual(cp1,None)
147         containerName = Utils_Identity.getShortHostName()
148         containerName += "/swAContainer"
149         cp2=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
150         self.assertNotEqual(cp2,None)
151         m1=cp1._narrow(Engines.TestComponent)
152         self.assertNotEqual(m1,None)
153         m2=cp2._narrow(Engines.TestComponent)
154         self.assertNotEqual(m2,None)
155         name1=m1._get_instanceName()
156         name2=m2._get_instanceName()
157         self.assertEqual(name1,name2)
158         c1=m1.GetContainerRef()
159         self.assertNotEqual(c1,None)
160         c2=m2.GetContainerRef()
161         self.assertNotEqual(c2,None)
162         cname1=c1._get_name()
163         cname2=c2._get_name()
164         self.assertEqual(cname1,cname2)
165         hostname1=c1.getHostName()
166         hostname2=c2.getHostName()
167         self.assertEqual(hostname1,hostname2)
168         pidc1=c1.getPID()
169         pidc2=c2.getPID()
170         self.assertEqual(pidc1,pidc2)        
171         pass
172     
173     def test008_FindOrLoad_Component_UnknownMachine(self):
174         """
175         Check FindOrLoad_Component: check behaviour when ask for an unknown
176         computer. We must catch a Salome Exception with "unknown host" message
177         """
178         containerName = "aFarAwayContainer"
179         containerName += "/swTheContainer"
180         try:
181             cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
182         except RuntimeError,ex :
183             self.assertEqual(ex.args[0],'unknown host')
184         pass
185        
186     
187 def suite():
188     return unittest.makeSuite(LifeCycleCORBA_SWIGTest,'test')
189
190 def main():
191     return unittest.TextTestRunner().run(suite())
192
193 if __name__ == '__main__':
194     unittest.TextTestRunner(verbosity=2).run(suite())
195     pass
196