Back to index

salome-kernel  6.5.0
LifeCycleCORBA_SWIGTest.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 #  File   : LifeCycleCORBA_SWIGTest.py
00025 #  Author : Paul RASCLE, EDF
00026 #  Module : SALOME
00027 #  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/LifeCycleCORBA_SWIG/Test/LifeCycleCORBA_SWIGTest.py,v 1.5.2.3.14.2.12.1 2012-04-12 14:05:16 vsr Exp $
00028 #
00029 import sys
00030 import unittest
00031 from omniORB import CORBA
00032 import PYHELLO_ORB
00033 import HELLO_ORB
00034 import Utils_Identity
00035 import Engines
00036 
00037 class LifeCycleCORBA_SWIGTest(unittest.TestCase):
00038     def setUp(self):
00039         import LifeCycleCORBA
00040         self.lcc = LifeCycleCORBA.LifeCycleCORBA()
00041         pass
00042 
00043     def tearDown(self):
00044         pass
00045     
00046     def test001_FindOrLoad_Component_LaunchContainer(self):
00047         """
00048         get a local container (no hostname given),
00049         load an engine, check that the CORBA object is not null.
00050         check narrow        
00051         """
00052         containerName = "swMyContainer"
00053         comp=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
00054         self.assertNotEqual(comp,None)
00055         testComp=comp._narrow(Engines.TestComponent)
00056         self.assertNotEqual(testComp,None)
00057         pass
00058 
00059     def test002_FindOrLoad_Component_SameInstance(self):
00060         """
00061         Check FindOrLoad_Component.
00062         Call 2 times FindOrLoad_Component with the same parameters,
00063         check if we get the same engine      
00064         """
00065         containerName = "swMyContainer"
00066         cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
00067         self.assertNotEqual(cp1,None)
00068         cp2=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
00069         self.assertNotEqual(cp2,None)
00070         m1=cp1._narrow(Engines.TestComponent)
00071         self.assertNotEqual(m1,None)
00072         m2=cp2._narrow(Engines.TestComponent)
00073         self.assertNotEqual(m2,None)
00074         name1=m1._get_instanceName()
00075         name2=m2._get_instanceName()
00076         self.assertEqual(name1,name2)
00077         pass
00078 
00079     def test003_FindOrLoad_Component_PythonInCppContainer(self):
00080         """
00081         Check FindOrLoad_Component with Python Component on C++ Container,
00082         load an engine, check that the CORBA object is not null.
00083         check narrow
00084         """
00085         containerName = "swMyContainer"
00086         cp1=self.lcc.FindOrLoad_Component(containerName,"SALOME_TestComponentPy")
00087         self.assertNotEqual(cp1,None)
00088         m1=cp1._narrow(Engines.TestComponent)
00089         self.assertNotEqual(m1,None)
00090         pass        
00091 
00092     def test004_FindOrLoad_Component_PythonSameInstance(self):
00093         """
00094         Check FindOrLoad_Component with Python Component on C++ Container,
00095         Call 2 times FindOrLoad_Component with the same parameters,
00096         check if we get the same engine,
00097         """
00098         containerName = "swMyContainer"
00099         cp1=self.lcc.FindOrLoad_Component(containerName,"SALOME_TestComponentPy")
00100         self.assertNotEqual(cp1,None)
00101         cp2=self.lcc.FindOrLoad_Component(containerName,"SALOME_TestComponentPy")
00102         self.assertNotEqual(cp2,None)
00103         m1=cp1._narrow(Engines.TestComponent)
00104         self.assertNotEqual(m1,None)
00105         m2=cp2._narrow(Engines.TestComponent)
00106         self.assertNotEqual(m2,None)
00107         name1=m1._get_instanceName()
00108         name2=m2._get_instanceName()
00109         self.assertEqual(name1,name2)
00110         pass
00111 
00112     def test005_FindOrLoad_Component_UnknownInCatalog(self):
00113         """
00114         Check FindOrLoad_Component with a component name not in catalog.
00115         See list of catalog given to module catalog server.
00116         Here, we work with KERNEL_SRC/resources/KERNELCatalog.xml that contains 
00117         only KERNEL, SalomeTestComponent and SALOME_TestComponentPy
00118         """
00119         containerName = "swMyContainer"
00120         cp1=self.lcc.FindOrLoad_Component(containerName,"MyNewComponent")
00121         self.assertEqual(cp1,None)
00122         pass
00123 
00124     def test006_FindOrLoad_Component_LaunchContainerHostname(self):
00125         """
00126         Check FindOrLoad_Component with hostname given.
00127         get a local container : getHostName()/componentName,
00128         load an engine, check that the CORBA object is not null.
00129         check narrow
00130         """
00131         containerName = Utils_Identity.getShortHostName()
00132         containerName += "/swTheContainer"
00133         cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
00134         self.assertNotEqual(cp1,None)
00135         m1=cp1._narrow(Engines.TestComponent)
00136         self.assertNotEqual(m1,None)
00137         pass
00138 
00139     def test007_FindOrLoad_Component_SameContainer(self):
00140         """
00141         Check FindOrLoad_Component with and without local hostname given.
00142         We must get the same container, the same instance of component
00143         """
00144         containerName = "swAContainer"
00145         cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
00146         self.assertNotEqual(cp1,None)
00147         containerName = Utils_Identity.getShortHostName()
00148         containerName += "/swAContainer"
00149         cp2=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
00150         self.assertNotEqual(cp2,None)
00151         m1=cp1._narrow(Engines.TestComponent)
00152         self.assertNotEqual(m1,None)
00153         m2=cp2._narrow(Engines.TestComponent)
00154         self.assertNotEqual(m2,None)
00155         name1=m1._get_instanceName()
00156         name2=m2._get_instanceName()
00157         self.assertEqual(name1,name2)
00158         c1=m1.GetContainerRef()
00159         self.assertNotEqual(c1,None)
00160         c2=m2.GetContainerRef()
00161         self.assertNotEqual(c2,None)
00162         cname1=c1._get_name()
00163         cname2=c2._get_name()
00164         self.assertEqual(cname1,cname2)
00165         hostname1=c1.getHostName()
00166         hostname2=c2.getHostName()
00167         self.assertEqual(hostname1,hostname2)
00168         pidc1=c1.getPID()
00169         pidc2=c2.getPID()
00170         self.assertEqual(pidc1,pidc2)        
00171         pass
00172     
00173     def test008_FindOrLoad_Component_UnknownMachine(self):
00174         """
00175         Check FindOrLoad_Component: check behaviour when ask for an unknown
00176         computer. We must catch a Salome Exception with "unknown host" message
00177         """
00178         containerName = "aFarAwayContainer"
00179         containerName += "/swTheContainer"
00180         try:
00181             cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent")
00182         except RuntimeError,ex :
00183             self.assertEqual(ex.args[0],'unknown host')
00184         pass
00185        
00186     
00187 def suite():
00188     return unittest.makeSuite(LifeCycleCORBA_SWIGTest,'test')
00189 
00190 def main():
00191     return unittest.TextTestRunner().run(suite())
00192 
00193 if __name__ == '__main__':
00194     unittest.TextTestRunner(verbosity=2).run(suite())
00195     pass
00196