test_CorbaNaming.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- Python -*-
3 
4 
5 ## \file test_CorbaNaming.py
6 ## \brief test for CORBA naming service helper class
7 ## \author Shinji Kurihara
8 #
9 # Copyright (C) 2006
10 # Noriaki Ando
11 # Task-intelligence Research Group,
12 # Intelligent Systems Research Institute,
13 # National Institute of
14 # Advanced Industrial Science and Technology (AIST), Japan
15 # All rights reserved.
16 #
17 
18 import sys
19 sys.path.insert(1,"../")
20 
21 import unittest
22 import time
23 
24 from CorbaNaming import *
25 import OpenRTM_aist
26 
27 class TestCorbaNaming(unittest.TestCase):
28 
29  def setUp(self):
30  self.orb = OpenRTM_aist.Manager.instance().getORB()
31  self.naming = CorbaNaming(self.orb, "localhost:2809")
32  #self.naming.clearAll()
33  self.name_list = []
34  self.name_list.append(CosNaming.NameComponent("Mon","mon_cxt"))
35  self.name_list.append(CosNaming.NameComponent("Tus","tus_cxt"))
36  self.name_list.append(CosNaming.NameComponent("Wed","wed_cxt"))
37  self.name_list.append(CosNaming.NameComponent("Thu","thu_cxt"))
38  self.name_list.append(CosNaming.NameComponent("Fri","fri_cxt"))
39  self.name_list.append(CosNaming.NameComponent("Sat","sat_cxt"))
40  self.name_list.append(CosNaming.NameComponent("Sun","sun_cxt"))
41 
42  return
43 
44 
45  def tearDown(self):
46  OpenRTM_aist.Manager.instance().shutdownManager()
47  del self
48  return
49 
50  def test_init(self):
51  try:
52  self.naming.init("localhost")
53  except:
54  print "Exeption at naming init."
55 
56 
57  def test_bind(self):
58  self.naming.clearAll()
59  self.bind_test_sequence(self.name_list)
60 
61 
62  def bind_test_sequence(self, sname):
63  obj = self.naming.newContext()
64  self.naming.bind(sname, obj)
65 
66  # resolve test
67  new_obj = self.naming.resolve(sname)
68  self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
69  return True
70 
71 
72  def test_bindByString(self):
73  name = "localhost.host_cxt\/Manager123456.mgr_cxt/MobileRobot.cat_cxt/Kani0.rtc"
74 
75  lname = []
76  lname.append(CosNaming.NameComponent("localhost.host_cxt\/Manager123456","mgr_cxt"))
77  lname.append(CosNaming.NameComponent("MobileRobot","cat_cxt"))
78  lname.append(CosNaming.NameComponent("Kani0","rtc"))
79 
80  obj = self.naming.newContext()
81  self.naming.bindByString(name, obj)
82  new_obj = self.naming.resolve(name)
83  self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
84  new_obj = self.naming.resolve(lname)
85  self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
86 
87 
88  #def test_bindRecursive(self):
89  # pass
90 
91  def test_rebind(self):
92  obj = self.naming.newContext()
93 
94  self.naming.bind(self.name_list, obj)
95  new_obj = self.naming.resolve(self.name_list)
96  self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
97 
98  self.naming.rebind(self.name_list, obj)
99  new_obj = self.naming.resolve(self.name_list)
100  self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
101 
102 
103  #def test_rebindByString(self):
104  # pass
105 
106 
108  obj = self.naming.newContext()
109 
110  self.naming.bind(self.name_list, obj)
111  new_obj = self.naming.resolve(self.name_list)
112  self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
113 
114  self.naming.rebindRecursive(self.naming.getRootContext(), self.name_list, obj)
115  new_obj = self.naming.resolve(self.name_list)
116  self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
117 
118 
119  def test_bindContext(self):
120  obj = self.naming.newContext()
121  name = []
122  name.append(CosNaming.NameComponent("bindcxt","bindcxt_cxt"))
123 
124  self.naming.bindContext("bindcxt.bindcxt_cxt", obj)
125  new_obj = self.naming.resolve(name)
126  self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
127 
128 
129  def test_unbind(self):
130  obj = self.naming.newContext()
131 
132  self.naming.bind(self.name_list, obj)
133  self.naming.unbind(self.name_list)
134 
135 
137  name = []
138  name.append(CosNaming.NameComponent("newContext","new_cxt"))
139 
140  self.naming.bindNewContext(name)
141  new_obj = self.naming.resolve(name)
142 
143 
144  def test_destroy(self):
145  obj = self.naming.newContext()
146  name = []
147  name.append(CosNaming.NameComponent("destroy","destroy_cxt"))
148 
149  self.naming.bind(name, obj)
150  self.naming.destroy(obj)
151 
152 
154  obj = self.naming.newContext()
155  name = []
156  name.append(CosNaming.NameComponent("desRec0","desRec0_cxt"))
157  name.append(CosNaming.NameComponent("desRec1","desRec1_cxt"))
158  name.append(CosNaming.NameComponent("desRec2","desRec2_cxt"))
159 
160  self.naming.bind(name, obj)
161  self.naming.destroyRecursive(obj)
162 
163  def test_list(self):
164  bl = []
165  bi = []
166  self.naming.list(self.naming.getRootContext(), 100, bl, bi)
167  print bl[0][0].binding_name[0].id
168 
169 
170  def test_toString(self):
171  name = []
172  name.append(CosNaming.NameComponent("desRec0","desRec0_cxt"))
173  name.append(CosNaming.NameComponent("desRec1","desRec1_cxt"))
174  name.append(CosNaming.NameComponent("desRec2","desRec2_cxt"))
175 
176  string_name = self.naming.toString(name)
177  self.assertEqual(str("desRec0.desRec0_cxt/desRec1.desRec1_cxt/desRec2.desRec2_cxt/"),str(string_name))
178  print ".",string_name,"."
179 
180 ############### test #################
181 if __name__ == '__main__':
182  unittest.main()


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Jun 6 2019 19:11:34