00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 import sys
00018 sys.path.insert(1,"../")
00019
00020 import unittest
00021
00022 import OpenRTM_aist
00023 from ConfigAdmin import *
00024
00025 configsample_spec = ["implementation_id", "ConfigSample",
00026 "type_name", "ConfigSample",
00027 "description", "Configuration example component",
00028 "version", "1.0",
00029 "vendor", "Shinji Kurihara, AIST",
00030 "category", "example",
00031 "activity_type", "DataFlowComponent",
00032 "max_instance", "10",
00033 "language", "C++",
00034 "lang_type", "compile",
00035
00036 "conf.default.int_param0", "0",
00037 "conf.default.int_param1", "1",
00038 "conf.default.double_param0", "0.11",
00039 "conf.default.double_param1", "9.9",
00040 "conf.default.str_param0", "hoge",
00041 "conf.default.str_param1", "dara",
00042 "conf.default.vector_param0", "0.0,1.0,2.0,3.0,4.0",
00043 ""]
00044
00045 configsample_mode_spec = ["conf.default.int_param0", "10",
00046 "conf.default.int_param1", "11",
00047 "conf.default.double_param0", "0.22",
00048 "conf.default.double_param1", "9999.9",
00049 "conf.default.str_param0", "hogehoge",
00050 "conf.default.str_param1", "daradaradata",
00051 "conf.default.vector_param0", "0.1,1.1,2.1,3.1,4.1",
00052 ""]
00053
00054 configsample_add_spec = ["conf.mode0.int_param0", "10",
00055 "conf.mode0.int_param1", "11",
00056 "conf.mode0.double_param0", "0.22",
00057 "conf.mode0.double_param1", "9999.9",
00058 "conf.mode0.str_param0", "hogehoge",
00059 "conf.mode0.str_param1", "daradaradata",
00060 "conf.mode0.vector_param0", "0.1,1.1,2.1,3.1,4.1",
00061 ""]
00062
00063 class TestConfigAdmin(unittest.TestCase):
00064 def setUp(self):
00065 prop = OpenRTM_aist.Properties(defaults_str=configsample_spec)
00066 self._ca = ConfigAdmin(prop.getNode("conf"))
00067
00068 def tearDown(self):
00069 OpenRTM_aist.Manager.instance().shutdownManager()
00070 return
00071
00072 def CallBack(self,*args):
00073
00074 return
00075
00076 def test_bindParameter(self):
00077 self.int_param0 = [0]
00078 self.int_param1 = [0]
00079 self.double_param0 = [0.0]
00080 self.double_param1 = [0.0]
00081 self.str_param0 = [""]
00082 self.str_param1 = [""]
00083 self.vector_param0 = [[0.0,0.0,0.0,0.0,0.0]]
00084
00085 self._ca.bindParameter("int_param0", self.int_param0, "0")
00086 self._ca.bindParameter("int_param1", self.int_param1, "1")
00087 self._ca.bindParameter("double_param0", self.double_param0, "0.11")
00088 self._ca.bindParameter("double_param1", self.double_param1, "9.9")
00089 self._ca.bindParameter("str_param0", self.str_param0, "hoge")
00090 self._ca.bindParameter("str_param1", self.str_param1, "dara")
00091 self._ca.bindParameter("vector_param0", self.vector_param0, "0.0,1.0,2.0,3.0,4.0")
00092 return
00093
00094 def test_update(self):
00095 self._ca.update(config_set="default")
00096 self._ca.update("default","int_param0")
00097 self._ca.update()
00098 return
00099
00100 def test_isExist(self):
00101 varName = "name"
00102 prop = OpenRTM_aist.Properties()
00103 ca = ConfigAdmin(prop)
00104
00105 varName = "name"
00106 var = [0.0]
00107 default_value = "3.14159"
00108
00109 self.assertEqual(True, ca.bindParameter(varName,var,default_value))
00110 self.assertEqual(3.14159,var[0])
00111
00112
00113 self.assertEqual(True, ca.isExist("name"))
00114
00115
00116 self.assertEqual(False, ca.isExist("inexist name"))
00117
00118 return
00119
00120 def test_isChanged(self):
00121 self.assertEqual(self._ca.isChanged(),False)
00122 return
00123
00124
00125 def test_getActiveId(self):
00126 self.assertEqual(self._ca.getActiveId(),"default")
00127 return
00128
00129
00130 def test_haveConfig(self):
00131 self.assertEqual(self._ca.haveConfig("default"),True)
00132
00133
00134 return
00135
00136
00137 def test_isActive(self):
00138 self.assertEqual(self._ca.isActive(),True)
00139 return
00140
00141
00142 def test_getConfigurationSets(self):
00143 self.assertEqual(self._ca.getConfigurationSets()[0].name,"default")
00144 return
00145
00146
00147 def test_getConfigurationSet(self):
00148 self.assertEqual(self._ca.getConfigurationSet("default").name, "default")
00149 return
00150
00151 def test_setConfigurationSetValues(self):
00152 prop = OpenRTM_aist.Properties(defaults_str=configsample_mode_spec)
00153 self.assertEqual(self._ca.setConfigurationSetValues(prop.getNode("conf.default")),True)
00154 return
00155
00156 def test_getActiveConfigurationSet(self):
00157 self.assertEqual(self._ca.getActiveConfigurationSet().getName(),"default")
00158 return
00159
00160 def test_addConfigurationSet(self):
00161 prop = OpenRTM_aist.Properties(defaults_str=configsample_add_spec)
00162 self.assertEqual(self._ca.addConfigurationSet(prop.getNode("conf.mode0")),True)
00163 return
00164
00165 def test_removeConfigurationSet(self):
00166 prop = OpenRTM_aist.Properties(defaults_str=configsample_add_spec)
00167 self.assertEqual(self._ca.addConfigurationSet(prop.getNode("conf.mode0")),True)
00168 self.assertEqual(self._ca.removeConfigurationSet("mode0"),True)
00169 return
00170
00171
00172 def test_activateConfigurationSet(self):
00173 prop = OpenRTM_aist.Properties(defaults_str=configsample_add_spec)
00174 self.assertEqual(self._ca.addConfigurationSet(prop.getNode("conf.mode0")),True)
00175 self.assertEqual(self._ca.activateConfigurationSet("mode0"),True)
00176 self.assertEqual(self._ca.activateConfigurationSet("default"),True)
00177 self.assertEqual(self._ca.activateConfigurationSet("mode0"),True)
00178
00179
00180 return
00181
00182 def test_setOnUpdate(self):
00183 self._ca.setOnUpdate(None)
00184 return
00185
00186 def test_setOnUpdateParam(self):
00187 self._ca.setOnUpdateParam(None)
00188 return
00189
00190 def test_setOnSetConfigurationSet(self):
00191 self._ca.setOnSetConfigurationSet(None)
00192 return
00193
00194 def test_setOnAddConfigurationSet(self):
00195 self._ca.setOnAddConfigurationSet(None)
00196 return
00197
00198
00199 def test_setOnRemoveConfigurationSet(self):
00200 self._ca.setOnRemoveConfigurationSet(None)
00201 return
00202
00203
00204 def test_setOnActivateSet(self):
00205 self._ca.setOnActivateSet(None)
00206 return
00207
00208
00209 def test_onUpdate(self):
00210 self._ca.setOnUpdate(self.CallBack)
00211 self._ca.onUpdate("onUpdate")
00212 return
00213
00214
00215 def test_onUpdateParam(self):
00216 self._ca.setOnUpdateParam(self.CallBack)
00217 self._ca.onUpdateParam("onUpdateParam","Param")
00218 return
00219
00220
00221 def test_onSetConfigurationSet(self):
00222 self._ca.setOnSetConfigurationSet(self.CallBack)
00223 self._ca.onSetConfigurationSet("onSetConfigurationSet")
00224 return
00225
00226
00227 def test_onAddConfigurationSet(self):
00228 self._ca.setOnAddConfigurationSet(self.CallBack)
00229 self._ca.onAddConfigurationSet("onAddConfigurationSet")
00230 return
00231
00232
00233 def test_onRemoveConfigurationSet(self):
00234 self._ca.setOnRemoveConfigurationSet(self.CallBack)
00235 self._ca.onRemoveConfigurationSet("onRemoveConfigurationSet")
00236 return
00237
00238
00239 def test_onActivateSet(self):
00240 self._ca.setOnActivateSet(self.CallBack)
00241 self._ca.onActivateSet("ActivateSet")
00242 return
00243
00244
00245 def test_addremoveConfigurationParamListener(self):
00246 listener = ConfigParamListenerCallback()
00247 self._ca.addConfigurationParamListener(OpenRTM_aist.ConfigurationParamListenerType.ON_UPDATE_CONFIG_PARAM,
00248 listener)
00249 self._ca.onUpdateParam("","")
00250 self._ca.removeConfigurationParamListener(OpenRTM_aist.ConfigurationParamListenerType.ON_UPDATE_CONFIG_PARAM,
00251 listener)
00252 return
00253
00254 def test_addremoveConfigurationSetListener(self):
00255 listener = ConfigSetListenerCallback()
00256 self._ca.addConfigurationSetListener(OpenRTM_aist.ConfigurationSetListenerType.ON_SET_CONFIG_SET,
00257 listener)
00258 self._ca.onSetConfigurationSet(None)
00259 self._ca.removeConfigurationSetListener(OpenRTM_aist.ConfigurationSetListenerType.ON_SET_CONFIG_SET,
00260 listener)
00261 self._ca.addConfigurationSetListener(OpenRTM_aist.ConfigurationSetListenerType.ON_ADD_CONFIG_SET,
00262 listener)
00263 self._ca.onSetConfigurationSet(None)
00264 self._ca.removeConfigurationSetListener(OpenRTM_aist.ConfigurationSetListenerType.ON_ADD_CONFIG_SET,
00265 listener)
00266 return
00267
00268 def test_addremoveConfigurationSetNameListener(self):
00269 listener = ConfigSetNameListenerCallback()
00270 self._ca.addConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListenerType.ON_UPDATE_CONFIG_SET,
00271 listener)
00272 self._ca.onUpdate("")
00273 self._ca.removeConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListenerType.ON_UPDATE_CONFIG_SET,
00274 listener)
00275
00276 self._ca.addConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListenerType.ON_REMOVE_CONFIG_SET,
00277 listener)
00278 self._ca.onUpdate("")
00279 self._ca.removeConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListenerType.ON_REMOVE_CONFIG_SET,
00280 listener)
00281
00282 self._ca.addConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListenerType.ON_ACTIVATE_CONFIG_SET,
00283 listener)
00284 self._ca.onUpdate("")
00285 self._ca.removeConfigurationSetNameListener(OpenRTM_aist.ConfigurationSetNameListenerType.ON_ACTIVATE_CONFIG_SET,
00286 listener)
00287 return
00288
00289 class ConfigParamListenerCallback(OpenRTM_aist.ConfigurationParamListener):
00290 def __init__(self):
00291 OpenRTM_aist.ConfigurationParamListener.__init__(self)
00292 return
00293
00294 def __call__(self, config_set_name, config_param_name):
00295 print "ConfigParamListenerCallback called"
00296 return
00297
00298 class ConfigSetListenerCallback(OpenRTM_aist.ConfigurationSetListener):
00299 def __init__(self):
00300 OpenRTM_aist.ConfigurationSetListener.__init__(self)
00301 return
00302
00303 def __call__(self, config_set):
00304 print "ConfigSetListenerCallback called"
00305 return
00306
00307 class ConfigSetNameListenerCallback(OpenRTM_aist.ConfigurationSetNameListener):
00308 def __init__(self):
00309 OpenRTM_aist.ConfigurationSetNameListener.__init__(self)
00310 return
00311
00312 def __call__(self, config_set_name):
00313 print "ConfigSetNameListenerCallback called"
00314 return
00315
00316
00317
00318 if __name__ == '__main__':
00319 unittest.main()