test_CorbaNaming.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- Python -*-
00003 
00004 
00005 ## \file test_CorbaNaming.py
00006 ## \brief test for CORBA naming service helper class
00007 ## \author Shinji Kurihara
00008 #
00009 # Copyright (C) 2006
00010 #     Noriaki Ando
00011 #     Task-intelligence Research Group,
00012 #     Intelligent Systems Research Institute,
00013 #     National Institute of
00014 #         Advanced Industrial Science and Technology (AIST), Japan
00015 #     All rights reserved.
00016 #
00017 
00018 import sys
00019 sys.path.insert(1,"../")
00020 
00021 import unittest
00022 import time
00023 
00024 from CorbaNaming import *
00025 import OpenRTM_aist
00026 
00027 class TestCorbaNaming(unittest.TestCase):
00028 
00029   def setUp(self):
00030     self.orb = OpenRTM_aist.Manager.instance().getORB()
00031     self.naming = CorbaNaming(self.orb, "localhost:2809")
00032     #self.naming.clearAll()
00033     self.name_list = []
00034     self.name_list.append(CosNaming.NameComponent("Mon","mon_cxt"))
00035     self.name_list.append(CosNaming.NameComponent("Tus","tus_cxt"))
00036     self.name_list.append(CosNaming.NameComponent("Wed","wed_cxt"))
00037     self.name_list.append(CosNaming.NameComponent("Thu","thu_cxt"))
00038     self.name_list.append(CosNaming.NameComponent("Fri","fri_cxt"))
00039     self.name_list.append(CosNaming.NameComponent("Sat","sat_cxt"))
00040     self.name_list.append(CosNaming.NameComponent("Sun","sun_cxt"))
00041       
00042     return
00043   
00044 
00045   def tearDown(self):
00046     OpenRTM_aist.Manager.instance().shutdownManager()
00047     del self
00048     return
00049 
00050   def test_init(self):
00051     try:
00052       self.naming.init("localhost")
00053     except:
00054       print "Exeption at naming init."
00055 
00056 
00057   def test_bind(self):
00058     self.naming.clearAll()
00059     self.bind_test_sequence(self.name_list)
00060     
00061 
00062   def bind_test_sequence(self, sname):
00063     obj = self.naming.newContext()
00064     self.naming.bind(sname, obj)
00065 
00066     # resolve test
00067     new_obj = self.naming.resolve(sname)
00068     self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
00069     return True
00070 
00071 
00072   def test_bindByString(self):
00073     name = "localhost.host_cxt\/Manager123456.mgr_cxt/MobileRobot.cat_cxt/Kani0.rtc"
00074 
00075     lname = []
00076     lname.append(CosNaming.NameComponent("localhost.host_cxt\/Manager123456","mgr_cxt"))
00077     lname.append(CosNaming.NameComponent("MobileRobot","cat_cxt"))
00078     lname.append(CosNaming.NameComponent("Kani0","rtc"))
00079 
00080     obj = self.naming.newContext()
00081     self.naming.bindByString(name, obj)
00082     new_obj = self.naming.resolve(name)
00083     self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
00084     new_obj = self.naming.resolve(lname)
00085     self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
00086 
00087 
00088   #def test_bindRecursive(self):
00089   # pass
00090 
00091   def test_rebind(self):
00092     obj = self.naming.newContext()
00093 
00094     self.naming.bind(self.name_list, obj)
00095     new_obj = self.naming.resolve(self.name_list)
00096     self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
00097 
00098     self.naming.rebind(self.name_list, obj)
00099     new_obj = self.naming.resolve(self.name_list)
00100     self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
00101     
00102 
00103   #def test_rebindByString(self):
00104   # pass
00105     
00106 
00107   def test_rebindRecursive(self):
00108     obj = self.naming.newContext()
00109 
00110     self.naming.bind(self.name_list, obj)
00111     new_obj = self.naming.resolve(self.name_list)
00112     self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
00113 
00114     self.naming.rebindRecursive(self.naming.getRootContext(), self.name_list, obj)
00115     new_obj = self.naming.resolve(self.name_list)
00116     self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
00117 
00118 
00119   def test_bindContext(self):
00120     obj = self.naming.newContext()
00121     name = []
00122     name.append(CosNaming.NameComponent("bindcxt","bindcxt_cxt"))
00123 
00124     self.naming.bindContext("bindcxt.bindcxt_cxt", obj)
00125     new_obj = self.naming.resolve(name)
00126     self.assertEqual(obj._is_equivalent(new_obj), True,"Resolve failed.")
00127 
00128 
00129   def test_unbind(self):
00130     obj = self.naming.newContext()
00131 
00132     self.naming.bind(self.name_list, obj)
00133     self.naming.unbind(self.name_list)
00134   
00135 
00136   def test_bindNewContext(self):
00137     name = []
00138     name.append(CosNaming.NameComponent("newContext","new_cxt"))
00139 
00140     self.naming.bindNewContext(name)
00141     new_obj = self.naming.resolve(name)
00142 
00143 
00144   def test_destroy(self):
00145     obj = self.naming.newContext()
00146     name = []
00147     name.append(CosNaming.NameComponent("destroy","destroy_cxt"))
00148 
00149     self.naming.bind(name, obj)
00150     self.naming.destroy(obj)
00151 
00152 
00153   def test_destroyRecursive(self):
00154     obj = self.naming.newContext()
00155     name = []
00156     name.append(CosNaming.NameComponent("desRec0","desRec0_cxt"))
00157     name.append(CosNaming.NameComponent("desRec1","desRec1_cxt"))
00158     name.append(CosNaming.NameComponent("desRec2","desRec2_cxt"))
00159 
00160     self.naming.bind(name, obj)
00161     self.naming.destroyRecursive(obj)
00162 
00163   def test_list(self):
00164     bl = []
00165     bi = []
00166     self.naming.list(self.naming.getRootContext(), 100, bl, bi)
00167     print bl[0][0].binding_name[0].id
00168   
00169 
00170   def test_toString(self):
00171     name = []
00172     name.append(CosNaming.NameComponent("desRec0","desRec0_cxt"))
00173     name.append(CosNaming.NameComponent("desRec1","desRec1_cxt"))
00174     name.append(CosNaming.NameComponent("desRec2","desRec2_cxt"))
00175 
00176     string_name = self.naming.toString(name)
00177     self.assertEqual(str("desRec0.desRec0_cxt/desRec1.desRec1_cxt/desRec2.desRec2_cxt/"),str(string_name))
00178     print ".",string_name,"."
00179 
00180 ############### test #################
00181 if __name__ == '__main__':
00182   unittest.main()


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Aug 27 2015 14:17:28