Salome HOME
52e496eaddd367397d6f8ae7b42a9ae4a8dda0cf
[modules/kernel.git] / src / TestContainer / TestComponentPy.py
1 #! /usr/bin/env python
2 #  Copyright (C) 2007-2008  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.
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 #  SALOME TestContainer : test of container creation and its life cycle
24 #  File   : TestComponentPy.py
25 #  Author : Paul RASCLE, EDF
26 #  Module : SALOME
27 #  $Header$
28 #
29 import os
30 import sys
31 import string
32 from omniORB import CORBA
33 import CosNaming
34 import Engines
35 from Utils_Identity import getShortHostName
36
37
38 #initialise the ORB
39 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
40
41 #obtain a reference to the root naming context
42 obj = orb.resolve_initial_references("NameService")
43 rootContext = obj._narrow(CosNaming.NamingContext)
44
45 if rootContext is None:
46     print "Name Service Reference is invalid"
47     sys.exit(1)
48
49 #resolve the name /Containers.dir/FactoryServerPy.object
50 machineName=getShortHostName()
51 containerName = "FactoryServerPy"
52 name = [CosNaming.NameComponent("Containers","dir"),
53         CosNaming.NameComponent(machineName,"dir"),
54         CosNaming.NameComponent(containerName,"object")]
55
56 try:
57     obj = rootContext.resolve(name)
58 except CosNaming.NamingContext.NotFound, ex:
59     print  containerName , " not found in Naming Service"
60     sys.exit(1)
61
62 container = obj._narrow(Engines.Container)
63 print container.getHostName()
64 comp = container.load_impl("SALOME_TestComponentPy","SALOME_TestComponentPy")
65 print comp._get_instanceName()
66 comp.ping()
67 comptest = comp._narrow(Engines.TestComponent)
68 if comptest is None:
69     print "probleme cast"
70 print comptest.Coucou(1)
71
72