From: prascle Date: Fri, 17 Mar 2006 14:39:25 +0000 (+0000) Subject: PR: add Unit Tests for LifeCycleCORBA_SWIG X-Git-Tag: T3_2_0b1_pre1~32 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1b7acf8308a2291a6e637f5cbc4e0f213e82db4e;p=modules%2Fkernel.git PR: add Unit Tests for LifeCycleCORBA_SWIG --- diff --git a/configure.ac b/configure.ac index 5a8aa38de..fe3a6b398 100644 --- a/configure.ac +++ b/configure.ac @@ -493,6 +493,7 @@ AC_OUTPUT([ \ ./src/LifeCycleCORBA/Makefile \ ./src/LifeCycleCORBA/Test/Makefile \ ./src/LifeCycleCORBA_SWIG/Makefile \ + ./src/LifeCycleCORBA_SWIG/Test/Makefile \ ./src/Logger/Makefile \ ./src/Logger/Test/Makefile \ ./src/ModuleCatalog/Makefile \ diff --git a/src/LifeCycleCORBA_SWIG/Test/LifeCycleCORBA_SWIGTest.py b/src/LifeCycleCORBA_SWIG/Test/LifeCycleCORBA_SWIGTest.py new file mode 100644 index 000000000..177ef3859 --- /dev/null +++ b/src/LifeCycleCORBA_SWIG/Test/LifeCycleCORBA_SWIGTest.py @@ -0,0 +1,192 @@ +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : LifeCycleCORBA_SWIGTest.py +# Author : Paul RASCLE, EDF +# Module : SALOME +# $Header$ + +import sys +import unittest +from omniORB import CORBA +import PYHELLO_ORB +import HELLO_ORB +import Utils_Identity +import Engines + +class LifeCycleCORBA_SWIGTest(unittest.TestCase): + def setUp(self): + import LifeCycleCORBA + self.lcc = LifeCycleCORBA.LifeCycleCORBA() + pass + + def tearDown(self): + pass + + def test001_FindOrLoad_Component_LaunchContainer(self): + """ + get a local container (no hostname given), + load an engine, check that the CORBA object is not null. + check narrow + """ + containerName = "swMyContainer" + comp=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent") + self.assertNotEqual(comp,None) + testComp=comp._narrow(Engines.TestComponent) + self.assertNotEqual(testComp,None) + pass + + def test002_FindOrLoad_Component_SameInstance(self): + """ + Check FindOrLoad_Component. + Call 2 times FindOrLoad_Component with the same parameters, + check if we get the same engine + """ + containerName = "swMyContainer" + cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent") + self.assertNotEqual(cp1,None) + cp2=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent") + self.assertNotEqual(cp2,None) + m1=cp1._narrow(Engines.TestComponent) + self.assertNotEqual(m1,None) + m2=cp2._narrow(Engines.TestComponent) + self.assertNotEqual(m2,None) + name1=m1._get_instanceName() + name2=m2._get_instanceName() + self.assertEqual(name1,name2) + pass + + def test003_FindOrLoad_Component_PythonInCppContainer(self): + """ + Check FindOrLoad_Component with Python Component on C++ Container, + load an engine, check that the CORBA object is not null. + check narrow + """ + containerName = "swMyContainer" + cp1=self.lcc.FindOrLoad_Component(containerName,"SALOME_TestComponentPy") + self.assertNotEqual(cp1,None) + m1=cp1._narrow(Engines.TestComponent) + self.assertNotEqual(m1,None) + pass + + def test004_FindOrLoad_Component_PythonSameInstance(self): + """ + Check FindOrLoad_Component with Python Component on C++ Container, + Call 2 times FindOrLoad_Component with the same parameters, + check if we get the same engine, + """ + containerName = "swMyContainer" + cp1=self.lcc.FindOrLoad_Component(containerName,"SALOME_TestComponentPy") + self.assertNotEqual(cp1,None) + cp2=self.lcc.FindOrLoad_Component(containerName,"SALOME_TestComponentPy") + self.assertNotEqual(cp2,None) + m1=cp1._narrow(Engines.TestComponent) + self.assertNotEqual(m1,None) + m2=cp2._narrow(Engines.TestComponent) + self.assertNotEqual(m2,None) + name1=m1._get_instanceName() + name2=m2._get_instanceName() + self.assertEqual(name1,name2) + pass + + def test005_FindOrLoad_Component_UnknownInCatalog(self): + """ + Check FindOrLoad_Component with a component name not in catalog. + See list of catalog given to module catalog server. + Here, we work with KERNEL_SRC/resources/KERNELCatalog.xml that contains + only KERNEL, SalomeTestComponent and SALOME_TestComponentPy + """ + containerName = "swMyContainer" + cp1=self.lcc.FindOrLoad_Component(containerName,"MyNewComponent") + self.assertEqual(cp1,None) + pass + + def test006_FindOrLoad_Component_LaunchContainerHostname(self): + """ + Check FindOrLoad_Component with hostname given. + get a local container : getHostName()/componentName, + load an engine, check that the CORBA object is not null. + check narrow + """ + containerName = Utils_Identity.getShortHostName() + containerName += "/swTheContainer" + cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent") + self.assertNotEqual(cp1,None) + m1=cp1._narrow(Engines.TestComponent) + self.assertNotEqual(m1,None) + pass + + def test007_FindOrLoad_Component_SameContainer(self): + """ + Check FindOrLoad_Component with and without local hostname given. + We must get the same container, the same instance of component + """ + containerName = "swAContainer" + cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent") + self.assertNotEqual(cp1,None) + containerName = Utils_Identity.getShortHostName() + containerName += "/swAContainer" + cp2=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent") + self.assertNotEqual(cp2,None) + m1=cp1._narrow(Engines.TestComponent) + self.assertNotEqual(m1,None) + m2=cp2._narrow(Engines.TestComponent) + self.assertNotEqual(m2,None) + name1=m1._get_instanceName() + name2=m2._get_instanceName() + self.assertEqual(name1,name2) + c1=m1.GetContainerRef() + self.assertNotEqual(c1,None) + c2=m2.GetContainerRef() + self.assertNotEqual(c2,None) + cname1=c1._get_name() + cname2=c2._get_name() + self.assertEqual(cname1,cname2) + hostname1=c1.getHostName() + hostname2=c2.getHostName() + self.assertEqual(hostname1,hostname2) + pidc1=c1.getPID() + pidc2=c2.getPID() + self.assertEqual(pidc1,pidc2) + pass + + def test008_FindOrLoad_Component_UnknownMachine(self): + """ + Check FindOrLoad_Component: check behaviour when ask for an unknown + computer. We must catch a Salome Exception with "unknown host" message + """ + containerName = "aFarAwayContainer" + containerName += "/swTheContainer" + cp1=self.lcc.FindOrLoad_Component(containerName,"SalomeTestComponent") + pass + + +def suite(): + return unittest.makeSuite(LifeCycleCORBA_SWIGTest,'test') + +def main(): + return unittest.TextTestRunner().run(suite()) + +if __name__ == '__main__': + unittest.TextTestRunner(verbosity=2).run(suite()) + pass + diff --git a/src/LifeCycleCORBA_SWIG/Test/Makefile.am b/src/LifeCycleCORBA_SWIG/Test/Makefile.am new file mode 100644 index 000000000..b060a781d --- /dev/null +++ b/src/LifeCycleCORBA_SWIG/Test/Makefile.am @@ -0,0 +1,71 @@ +####################################### +# +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : Makefile.am +# Author : Paul RASCLE (EDF) +# Module : KERNEL +# $Header$ + +include $(top_srcdir)/salome_adm/unix/make_common_starter.am + +# +# =============================================================== +# Files to be installed +# =============================================================== +# +# header files +salomeinclude_HEADERS= + +# Scripts to be installed +dist_salomescript_SCRIPTS = \ + LifeCycleCORBA_SWIGTest.py \ + TestLifeCycleCORBA_SWIG.py + +# +# =============================================================== +# Local definitions +# =============================================================== +# + +# This directory defines the subdirectory src in the top source directory. +RPATH=../.. + +# This local variable defines the list of CPPFLAGS common to all target in this package. +COMMON_CPPFLAGS= + +# This local variable defines the list of dependant libraries common to all target in this package. +COMMON_LIBS = +# +# =============================================================== +# Libraries targets +# =============================================================== +# +lib_LTLIBRARIES = + +# +# =============================================================== +# Executables targets +# =============================================================== +# +bin_PROGRAMS = diff --git a/src/LifeCycleCORBA_SWIG/Test/TestLifeCycleCORBA_SWIG.py b/src/LifeCycleCORBA_SWIG/Test/TestLifeCycleCORBA_SWIG.py new file mode 100644 index 000000000..13af3a4c5 --- /dev/null +++ b/src/LifeCycleCORBA_SWIG/Test/TestLifeCycleCORBA_SWIG.py @@ -0,0 +1,101 @@ +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : TestLifeCycleCORBA_SWIG.py +# Author : Paul RASCLE, EDF +# Module : SALOME +# $Header$ + + +import sys, os,signal,string,commands +import runSalome +import orbmodule +import TestKiller +import addToKillList + +# get SALOME environment : + +args, modules_list, modules_root_dir = runSalome.get_config() +runSalome.set_env(args, modules_list, modules_root_dir) + +# set environment for trace in logger +# (with file, servers may be killed before the write to the file...) + +#os.environ["SALOME_trace"] = "file:/tmp/traceUnitTest.log" +#os.environ["SALOME_trace"] = "local" +os.environ["SALOME_trace"] = "with_logger" + +# launch CORBA naming server + +clt=orbmodule.client() + +# launch CORBA logger server + +myServer=runSalome.LoggerServer(args) +myServer.run() +clt.waitLogger("Logger") + +# launch notify server + +myServer=runSalome.NotifyServer(args,modules_root_dir) +myServer.run() + +# launch registry server + +myServer=runSalome.RegistryServer(args) +myServer.run() +clt.waitNS("/Registry") + +# launch module catalog server + +cataServer=runSalome.CatalogServer(args) +cataServer.setpath(modules_list,modules_root_dir) +cataServer.run() +clt.waitNS("/Kernel/ModulCatalog") + +# launch container manager server + +myCmServer = runSalome.ContainerManagerServer(args) +myCmServer.setpath(modules_list,modules_root_dir) +myCmServer.run() +clt.waitNS("/ContainerManager") + +# execute Unit Test + +command = ['TestLifeCycleCORBA'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +import LifeCycleCORBA_SWIGTest +import unittest +unittest.TextTestRunner(verbosity=2).run(LifeCycleCORBA_SWIGTest.suite()) + +# kill containers created by the Container Manager + +import Engines +containerManager = clt.waitNS("/ContainerManager",Engines.ContainerManager) +containerManager.Shutdown() + +# kill Test process + +addToKillList.killList() + +TestKiller.killProcess(runSalome.process_id) diff --git a/src/LifeCycleCORBA_SWIG/libSALOME_LifeCycleCORBA.i b/src/LifeCycleCORBA_SWIG/libSALOME_LifeCycleCORBA.i index 75a8282a4..f6391d930 100644 --- a/src/LifeCycleCORBA_SWIG/libSALOME_LifeCycleCORBA.i +++ b/src/LifeCycleCORBA_SWIG/libSALOME_LifeCycleCORBA.i @@ -25,47 +25,71 @@ #include "utilities.h" #include "SALOME_LifeCycleCORBA.hxx" + using namespace std; + +//--- from omniORBpy.h (not present on Debian Sarge packages) + +struct omniORBpyAPI { + + PyObject* (*cxxObjRefToPyObjRef)(const CORBA::Object_ptr cxx_obj, + CORBA::Boolean hold_lock); + // Convert a C++ object reference to a Python object reference. + // If is true, caller holds the Python interpreter lock. + + CORBA::Object_ptr (*pyObjRefToCxxObjRef)(PyObject* py_obj, + CORBA::Boolean hold_lock); + // Convert a Python object reference to a C++ object reference. + // Raises BAD_PARAM if the Python object is not an object reference. + // If is true, caller holds the Python interpreter lock. + + + omniORBpyAPI(); + // Constructor for the singleton. Sets up the function pointers. +}; + + omniORBpyAPI* api; + %} + +%init +%{ + // init section + + PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy"); + if (!omnipy) + { + PyErr_SetString(PyExc_ImportError, + (char*)"Cannot import _omnipy"); + return; + } + PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API"); + api = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi); + Py_DECREF(pyapi); +%} + + %typemap(python,out) Engines::Container_ptr, Engines::Component_ptr { - //MESSAGE("typemap out on CORBA object ptr"); - //SCRUTE($1); - - // --- Get the Python orb - - PyObject* pdict = PyDict_New(); - PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins()); - PyRun_String("from omniORB import CORBA", Py_single_input, pdict, pdict); - PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input, - pdict, pdict); - PyObject* orb = PyDict_GetItemString(pdict, "o"); - - // --- Get the C++ orb - - int argc = 0; - char *xargv = ""; - char **argv = &xargv; - CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv); - string s = ORB->object_to_string($1); - //SCRUTE(s); - PyObject * tmp = PyString_FromString(s.c_str()); - //SCRUTE(tmp); - $result = PyObject_CallMethod(orb, "string_to_object", "O", tmp); - //SCRUTE($result); + MESSAGE("typemap out on CORBA object ptr"); + SCRUTE($1); + $result = api->cxxObjRefToPyObjRef($1, 1); + SCRUTE($result); } -%typemap(typecheck) const Engines::MachineParameters & +%typemap(typecheck) const Engines::MachineParameters &, + Engines::MachineParameters const & { - $1 = ($input != 0); + $1 = PyDict_Check($input); } + %typemap(python,in) const Engines::MachineParameters & { - printf("typemap in on Engines::MachineParameters\n"); - //MESSAGE("typemap in on Engines::MachineParameters"); + //printf("typemap in on Engines::MachineParameters\n"); + MESSAGE("typemap in on Engines::MachineParameters"); //ASSERT (PyDict_Check($input)) if (PyDict_Check($input) == 1) { @@ -121,11 +145,14 @@ } else { - printf("pas un dico\n"); + //printf("pas un dico\n"); + MESSAGE("Not a dictionnary"); + PyErr_SetString(PyExc_TypeError,"MustBe a Python Dictionnary"); return NULL; } } + %typemap(python,freearg) const Engines::MachineParameters & { MESSAGE("delete $1"); diff --git a/src/Makefile.am b/src/Makefile.am index 3b43eb7e1..c2bb3c76f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -66,6 +66,7 @@ SUBDIR_CPPUNIT_CORBA = \ Utils/Test \ NamingService/Test \ LifeCycleCORBA/Test \ + LifeCycleCORBA_SWIG/Test \ SALOMEDSImpl/Test \ SALOMEDS/Test