test_ObjectManager.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- Python -*-
3 
4 #
5 # @file test_ObjectManager.py
6 # @brief test for Object management class
7 # @date $Date: $
8 # @author Shinji Kurihara
9 #
10 # Copyright (C) 2003-2007
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 # $Id: $
18 #
19 
20 import sys
21 sys.path.insert(1,"../")
22 
23 import unittest
24 
25 from ObjectManager import *
26 import OpenRTM_aist
27 
28 class test_obj:
29  def __init__(self, name):
30  self.name = name
31 
32  def getInstanceName(self):
33  return self.name
34 
35  def getProperty(self,name):
36  return name
37 
38 
39 class TestObjectManager(unittest.TestCase):
40 
41  class InstanceName :
42  def __init__(self, name=None, factory=None):
43  if factory != None:
44  self._name = factory.getInstanceName()
45  elif name != None:
46  self._name = name
47 
48  #def func(self, factory):
49  def __call__(self, factory):
50  return self._name == factory.getInstanceName()
51 
52 
54  def __init__(self):
55  self._modlist = []
56 
57 
58  #def func(self, f):
59  def __call__(self, f):
60  self._modlist.append(f.getProperty("implementation_id"))
61 
62 
63  def setUp(self):
65 
66 
67  def tearDown(self):
68  OpenRTM_aist.Manager.instance().shutdownManager()
69  return
70 
72  obj = test_obj("test")
73  self.assertEqual(self.obj.registerObject(obj),True,"Result failed.")
74  self.assertEqual(self.obj.registerObject(obj),False,"Result failed.")
75 
76 
78  self.test_registerObject()
79  self.assertEqual(self.obj.unregisterObject("test").getInstanceName(),"test","Result failed.")
80  self.assertEqual(self.obj.unregisterObject("test"),None,"Result failed.")
81  # Failed Pattern
82  # self.assertEqual(self.obj.unregisterObject("test").getInstanceName(),"test","Result failed.")
83 
84 
85  def test_find(self):
86  self.test_registerObject()
87  self.assertEqual(self.obj.find("test").getInstanceName(),"test","Result failed.")
88  self.assertEqual(self.obj.find("testtest"),None,"Result failed.")
89 
90 
91  def test_getObjects(self):
92  obj = test_obj("test0")
93  self.obj.registerObject(obj)
94  obj = test_obj("test1")
95  self.obj.registerObject(obj)
96  obj = test_obj("test2")
97  self.obj.registerObject(obj)
98  self.assertEqual(len(self.obj.getObjects()),3,"Result failed.")
99  self.assertEqual(self.obj.getObjects()[0].getInstanceName(),"test0","Result failed.")
100  self.assertEqual(self.obj.getObjects()[1].getInstanceName(),"test1","Result failed.")
101  self.assertEqual(self.obj.getObjects()[2].getInstanceName(),"test2","Result failed.")
102 
103 
104  def test_for_each(self):
105  obj = test_obj("test0")
106  self.obj.registerObject(obj)
107  obj = test_obj("test1")
108  self.obj.registerObject(obj)
109  obj = test_obj("test2")
110  self.obj.registerObject(obj)
111 
112  self.assertEqual(len(self.obj.for_each(self.ModuleFactories)._modlist),3,"Result failed.")
113 
114 
115 ############### test #################
116 if __name__ == '__main__':
117  unittest.main()
def __init__(self, name=None, factory=None)


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