Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 import sys
00021 sys.path.insert(1,"../")
00022
00023 import unittest
00024
00025 from ObjectManager import *
00026 import OpenRTM_aist
00027
00028 class test_obj:
00029 def __init__(self, name):
00030 self.name = name
00031
00032 def getInstanceName(self):
00033 return self.name
00034
00035 def getProperty(self,name):
00036 return name
00037
00038
00039 class TestObjectManager(unittest.TestCase):
00040
00041 class InstanceName :
00042 def __init__(self, name=None, factory=None):
00043 if factory != None:
00044 self._name = factory.getInstanceName()
00045 elif name != None:
00046 self._name = name
00047
00048
00049 def __call__(self, factory):
00050 return self._name == factory.getInstanceName()
00051
00052
00053 class ModuleFactories :
00054 def __init__(self):
00055 self._modlist = []
00056
00057
00058
00059 def __call__(self, f):
00060 self._modlist.append(f.getProperty("implementation_id"))
00061
00062
00063 def setUp(self):
00064 self.obj = ObjectManager(self.InstanceName)
00065
00066
00067 def tearDown(self):
00068 OpenRTM_aist.Manager.instance().shutdownManager()
00069 return
00070
00071 def test_registerObject(self):
00072 obj = test_obj("test")
00073 self.assertEqual(self.obj.registerObject(obj),True,"Result failed.")
00074 self.assertEqual(self.obj.registerObject(obj),False,"Result failed.")
00075
00076
00077 def test_unregisterObject(self):
00078 self.test_registerObject()
00079 self.assertEqual(self.obj.unregisterObject("test").getInstanceName(),"test","Result failed.")
00080 self.assertEqual(self.obj.unregisterObject("test"),None,"Result failed.")
00081
00082
00083
00084
00085 def test_find(self):
00086 self.test_registerObject()
00087 self.assertEqual(self.obj.find("test").getInstanceName(),"test","Result failed.")
00088 self.assertEqual(self.obj.find("testtest"),None,"Result failed.")
00089
00090
00091 def test_getObjects(self):
00092 obj = test_obj("test0")
00093 self.obj.registerObject(obj)
00094 obj = test_obj("test1")
00095 self.obj.registerObject(obj)
00096 obj = test_obj("test2")
00097 self.obj.registerObject(obj)
00098 self.assertEqual(len(self.obj.getObjects()),3,"Result failed.")
00099 self.assertEqual(self.obj.getObjects()[0].getInstanceName(),"test0","Result failed.")
00100 self.assertEqual(self.obj.getObjects()[1].getInstanceName(),"test1","Result failed.")
00101 self.assertEqual(self.obj.getObjects()[2].getInstanceName(),"test2","Result failed.")
00102
00103
00104 def test_for_each(self):
00105 obj = test_obj("test0")
00106 self.obj.registerObject(obj)
00107 obj = test_obj("test1")
00108 self.obj.registerObject(obj)
00109 obj = test_obj("test2")
00110 self.obj.registerObject(obj)
00111
00112 self.assertEqual(len(self.obj.for_each(self.ModuleFactories)._modlist),3,"Result failed.")
00113
00114
00115
00116 if __name__ == '__main__':
00117 unittest.main()