test_ConfigAdmin.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 
4 #
5 # \file test_ConfigAdmin.py
6 # \brief test for Configuration Administration classes
7 # \date $Date: 2007/09/04$
8 # \author Shinji Kurihara
9 #
10 # Copyright (C) 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 import sys
18 sys.path.insert(1,"../")
19 
20 import unittest
21 
22 import OpenRTM_aist
23 from ConfigAdmin import *
24 
25 configsample_spec = ["implementation_id", "ConfigSample",
26  "type_name", "ConfigSample",
27  "description", "Configuration example component",
28  "version", "1.0",
29  "vendor", "Shinji Kurihara, AIST",
30  "category", "example",
31  "activity_type", "DataFlowComponent",
32  "max_instance", "10",
33  "language", "C++",
34  "lang_type", "compile",
35  # Configuration variables
36  "conf.default.int_param0", "0",
37  "conf.default.int_param1", "1",
38  "conf.default.double_param0", "0.11",
39  "conf.default.double_param1", "9.9",
40  "conf.default.str_param0", "hoge",
41  "conf.default.str_param1", "dara",
42  "conf.default.vector_param0", "0.0,1.0,2.0,3.0,4.0",
43  ""]
44 
45 configsample_mode_spec = ["conf.default.int_param0", "10",
46  "conf.default.int_param1", "11",
47  "conf.default.double_param0", "0.22",
48  "conf.default.double_param1", "9999.9",
49  "conf.default.str_param0", "hogehoge",
50  "conf.default.str_param1", "daradaradata",
51  "conf.default.vector_param0", "0.1,1.1,2.1,3.1,4.1",
52  ""]
53 
54 configsample_add_spec = ["conf.mode0.int_param0", "10",
55  "conf.mode0.int_param1", "11",
56  "conf.mode0.double_param0", "0.22",
57  "conf.mode0.double_param1", "9999.9",
58  "conf.mode0.str_param0", "hogehoge",
59  "conf.mode0.str_param1", "daradaradata",
60  "conf.mode0.vector_param0", "0.1,1.1,2.1,3.1,4.1",
61  ""]
62 
63 class TestConfigAdmin(unittest.TestCase):
64  def setUp(self):
65  prop = OpenRTM_aist.Properties(defaults_str=configsample_spec)
66  self._ca = ConfigAdmin(prop.getNode("conf"))
67 
68  def tearDown(self):
69  OpenRTM_aist.Manager.instance().shutdownManager()
70  return
71 
72  def CallBack(self,*args):
73  #print args
74  return
75 
76  def test_bindParameter(self):
77  self.int_param0 = [0]
78  self.int_param1 = [0]
79  self.double_param0 = [0.0]
80  self.double_param1 = [0.0]
81  self.str_param0 = [""]
82  self.str_param1 = [""]
83  self.vector_param0 = [[0.0,0.0,0.0,0.0,0.0]]
84 
85  self._ca.bindParameter("int_param0", self.int_param0, "0")
86  self._ca.bindParameter("int_param1", self.int_param1, "1")
87  self._ca.bindParameter("double_param0", self.double_param0, "0.11")
88  self._ca.bindParameter("double_param1", self.double_param1, "9.9")
89  self._ca.bindParameter("str_param0", self.str_param0, "hoge")
90  self._ca.bindParameter("str_param1", self.str_param1, "dara")
91  self._ca.bindParameter("vector_param0", self.vector_param0, "0.0,1.0,2.0,3.0,4.0")
92  return
93 
94  def test_update(self):
95  self._ca.update(config_set="default")
96  self._ca.update("default","int_param0")
97  self._ca.update()
98  return
99 
100  def test_isExist(self):
101  varName = "name"
102  prop = OpenRTM_aist.Properties()
103  ca = ConfigAdmin(prop)
104 
105  varName = "name"
106  var = [0.0]
107  default_value = "3.14159"
108 
109  self.assertEqual(True, ca.bindParameter(varName,var,default_value))
110  self.assertEqual(3.14159,var[0])
111 
112  # バインドした変数の名称でisExist()を呼出し、真値が得られるか?
113  self.assertEqual(True, ca.isExist("name"))
114 
115  # バインドしていない名称でisExist()を呼出し、偽値が得られるか?
116  self.assertEqual(False, ca.isExist("inexist name"))
117 
118  return
119 
120  def test_isChanged(self):
121  self.assertEqual(self._ca.isChanged(),False)
122  return
123 
124 
125  def test_getActiveId(self):
126  self.assertEqual(self._ca.getActiveId(),"default")
127  return
128 
129 
130  def test_haveConfig(self):
131  self.assertEqual(self._ca.haveConfig("default"),True)
132  # Failure pattern
133  # self.assertEqual(self._ca.haveConfig("int_param0"),True)
134  return
135 
136 
137  def test_isActive(self):
138  self.assertEqual(self._ca.isActive(),True)
139  return
140 
141 
143  self.assertEqual(self._ca.getConfigurationSets()[0].name,"default")
144  return
145 
146 
148  self.assertEqual(self._ca.getConfigurationSet("default").name, "default")
149  return
150 
152  prop = OpenRTM_aist.Properties(defaults_str=configsample_mode_spec)
153  self.assertEqual(self._ca.setConfigurationSetValues(prop.getNode("conf.default")),True)
154  return
155 
157  self.assertEqual(self._ca.getActiveConfigurationSet().getName(),"default")
158  return
159 
161  prop = OpenRTM_aist.Properties(defaults_str=configsample_add_spec)
162  self.assertEqual(self._ca.addConfigurationSet(prop.getNode("conf.mode0")),True)
163  return
164 
166  prop = OpenRTM_aist.Properties(defaults_str=configsample_add_spec)
167  self.assertEqual(self._ca.addConfigurationSet(prop.getNode("conf.mode0")),True)
168  self.assertEqual(self._ca.removeConfigurationSet("mode0"),True)
169  return
170 
171 
173  prop = OpenRTM_aist.Properties(defaults_str=configsample_add_spec)
174  self.assertEqual(self._ca.addConfigurationSet(prop.getNode("conf.mode0")),True)
175  self.assertEqual(self._ca.activateConfigurationSet("mode0"),True)
176  self.assertEqual(self._ca.activateConfigurationSet("default"),True)
177  self.assertEqual(self._ca.activateConfigurationSet("mode0"),True)
178  # Failure pattern
179  # self.assertEqual(self._ca.activateConfigurationSet("mode1"),True)
180  return
181 
182  def test_setOnUpdate(self):
183  self._ca.setOnUpdate(None)
184  return
185 
187  self._ca.setOnUpdateParam(None)
188  return
189 
191  self._ca.setOnSetConfigurationSet(None)
192  return
193 
195  self._ca.setOnAddConfigurationSet(None)
196  return
197 
198 
200  self._ca.setOnRemoveConfigurationSet(None)
201  return
202 
203 
205  self._ca.setOnActivateSet(None)
206  return
207 
208 
209  def test_onUpdate(self):
210  self._ca.setOnUpdate(self.CallBack)
211  self._ca.onUpdate("onUpdate")
212  return
213 
214 
216  self._ca.setOnUpdateParam(self.CallBack)
217  self._ca.onUpdateParam("onUpdateParam","Param")
218  return
219 
220 
222  self._ca.setOnSetConfigurationSet(self.CallBack)
223  self._ca.onSetConfigurationSet("onSetConfigurationSet")
224  return
225 
226 
228  self._ca.setOnAddConfigurationSet(self.CallBack)
229  self._ca.onAddConfigurationSet("onAddConfigurationSet")
230  return
231 
232 
234  self._ca.setOnRemoveConfigurationSet(self.CallBack)
235  self._ca.onRemoveConfigurationSet("onRemoveConfigurationSet")
236  return
237 
238 
240  self._ca.setOnActivateSet(self.CallBack)
241  self._ca.onActivateSet("ActivateSet")
242  return
243 
244 
246  listener = ConfigParamListenerCallback()
247  self._ca.addConfigurationParamListener(OpenRTM_aist.ConfigurationParamListenerType.ON_UPDATE_CONFIG_PARAM,
248  listener)
249  self._ca.onUpdateParam("","")
250  self._ca.removeConfigurationParamListener(OpenRTM_aist.ConfigurationParamListenerType.ON_UPDATE_CONFIG_PARAM,
251  listener)
252  return
253 
255  listener = ConfigSetListenerCallback()
256  self._ca.addConfigurationSetListener(OpenRTM_aist.ConfigurationSetListenerType.ON_SET_CONFIG_SET,
257  listener)
258  self._ca.onSetConfigurationSet(None)
259  self._ca.removeConfigurationSetListener(OpenRTM_aist.ConfigurationSetListenerType.ON_SET_CONFIG_SET,
260  listener)
261  self._ca.addConfigurationSetListener(OpenRTM_aist.ConfigurationSetListenerType.ON_ADD_CONFIG_SET,
262  listener)
263  self._ca.onSetConfigurationSet(None)
264  self._ca.removeConfigurationSetListener(OpenRTM_aist.ConfigurationSetListenerType.ON_ADD_CONFIG_SET,
265  listener)
266  return
267 
269  listener = ConfigSetNameListenerCallback()
270  self._ca.addConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListenerType.ON_UPDATE_CONFIG_SET,
271  listener)
272  self._ca.onUpdate("")
273  self._ca.removeConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListenerType.ON_UPDATE_CONFIG_SET,
274  listener)
275 
276  self._ca.addConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListenerType.ON_REMOVE_CONFIG_SET,
277  listener)
278  self._ca.onUpdate("")
279  self._ca.removeConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListenerType.ON_REMOVE_CONFIG_SET,
280  listener)
281 
282  self._ca.addConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListenerType.ON_ACTIVATE_CONFIG_SET,
283  listener)
284  self._ca.onUpdate("")
285  self._ca.removeConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListenerType.ON_ACTIVATE_CONFIG_SET,
286  listener)
287  return
288 
290  def __init__(self):
291  OpenRTM_aist.ConfigurationParamListener.__init__(self)
292  return
293 
294  def __call__(self, config_set_name, config_param_name):
295  print "ConfigParamListenerCallback called"
296  return
297 
299  def __init__(self):
300  OpenRTM_aist.ConfigurationSetListener.__init__(self)
301  return
302 
303  def __call__(self, config_set):
304  print "ConfigSetListenerCallback called"
305  return
306 
308  def __init__(self):
309  OpenRTM_aist.ConfigurationSetNameListener.__init__(self)
310  return
311 
312  def __call__(self, config_set_name):
313  print "ConfigSetNameListenerCallback called"
314  return
315 
316 
317 
318 if __name__ == '__main__':
319  unittest.main()
The Properties class represents a persistent set of properties.
Definition: Properties.py:83
def __call__(self, config_set_name, config_param_name)


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Mon Feb 28 2022 23:01:06