1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 # File : LifeCycleCORBA_SWIGTest.py
25 # Author : Paul RASCLE, EDF
31 from omniORB import CORBA
35 class LifeCycleCORBA_SWIGTest(unittest.TestCase):
38 self.lcc = LifeCycleCORBA.LifeCycleCORBA()
44 def test001_FindOrLoad_Component_LaunchContainer(self):
46 get a local container (no hostname given),
47 load an engine, check that the CORBA object is not null.
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)
57 def test002_FindOrLoad_Component_SameInstance(self):
59 Check FindOrLoad_Component.
60 Call 2 times FindOrLoad_Component with the same parameters,
61 check if we get the same engine
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)
77 def test003_FindOrLoad_Component_PythonInCppContainer(self):
79 Check FindOrLoad_Component with Python Component on C++ Container,
80 load an engine, check that the CORBA object is not null.
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)
90 def test004_FindOrLoad_Component_PythonSameInstance(self):
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,
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)
110 def test005_FindOrLoad_Component_UnknownInCatalog(self):
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
117 containerName = "swMyContainer"
118 cp1=self.lcc.FindOrLoad_Component(containerName,"MyNewComponent")
119 self.assertEqual(cp1,None)
122 def test006_FindOrLoad_Component_LaunchContainerHostname(self):
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.
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)
137 def test007_FindOrLoad_Component_SameContainer(self):
139 Check FindOrLoad_Component with and without local hostname given.
140 We must get the same container, the same instance of component
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)
168 self.assertEqual(pidc1,pidc2)
171 def test008_FindOrLoad_Component_UnknownMachine(self):
173 Check FindOrLoad_Component: check behaviour when ask for an unknown
174 computer. We must catch a Salome Exception with "unknown host" message
176 containerName = "aFarAwayContainer"
177 containerName += "/swTheContainer"
179 cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
180 except RuntimeError,ex :
181 self.assertEqual(ex.args[0],'unknown host')
186 return unittest.makeSuite(LifeCycleCORBA_SWIGTest,'test')
189 return unittest.TextTestRunner().run(suite())
191 if __name__ == '__main__':
192 #unittest.TextTestRunner(verbosity=2).run(suite())