00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import sys
00019 sys.path.insert(1,"../")
00020
00021 import unittest
00022
00023 from Properties import *
00024 import OpenRTM_aist
00025
00026
00027 configsample_spec = ["implementation_id", "ConfigSample",
00028 "type_name", "ConfigSample",
00029 "description", "Configuration example component",
00030 "version", "1.0",
00031 "vendor", "Shinji Kurihara, AIST",
00032 "category", "example",
00033 "activity_type", "DataFlowComponent",
00034 "max_instance", "10",
00035 "language", "C++",
00036 "lang_type", "compile",
00037
00038 "conf.default.int_param0", "0",
00039 "conf.default.int_param1", "1",
00040 "conf.default.double_param0", "0.11",
00041 "conf.default.double_param1", "9.9",
00042 "conf.default.str_param0", "hoge",
00043 "conf.default.str_param1", "dara",
00044 "conf.default.vector_param0", "0.0,1.0,2.0,3.0,4.0",
00045 ""]
00046
00047 class TestProperties(unittest.TestCase) :
00048
00049 def setUp(self):
00050
00051 self.prop = Properties(defaults_str=configsample_spec)
00052
00053 def tearDown(self):
00054 OpenRTM_aist.Manager.instance().shutdownManager()
00055 return
00056
00057 def test_getName(self):
00058 self.assertEqual(self.prop.getName(), "", "Result failed.")
00059
00060
00061 def test_getVlue(self):
00062 self.assertEqual(self.prop.getValue(), "", "Result failed.")
00063
00064
00065 def test_getDefaultValue(self):
00066 self.assertEqual(self.prop.getDefaultValue(), "", "Result failed.")
00067
00068
00069
00070 def test_getLeaf(self):
00071
00072
00073
00074 self.assertEqual(self.prop.getLeaf()[0].getName(), "implementation_id", "Result failed.")
00075 self.assertEqual(self.prop.getLeaf()[1].getName(), "type_name", "Result failed.")
00076 self.assertEqual(self.prop.getLeaf()[2].getName(), "description", "Result failed.")
00077 self.assertEqual(self.prop.getLeaf()[3].getName(), "version", "Result failed.")
00078 self.assertEqual(self.prop.getLeaf()[4].getName(), "vendor", "Result failed.")
00079 self.assertEqual(self.prop.getLeaf()[5].getName(), "category", "Result failed.")
00080 self.assertEqual(self.prop.getLeaf()[6].getName(), "activity_type", "Result failed.")
00081 self.assertEqual(self.prop.getLeaf()[7].getName(), "max_instance", "Result failed.")
00082 self.assertEqual(self.prop.getLeaf()[8].getName(), "language", "Result failed.")
00083 self.assertEqual(self.prop.getLeaf()[9].getName(), "lang_type", "Result failed.")
00084 self.assertEqual(self.prop.getLeaf()[10].getLeaf()[0].getLeaf()[0].getName(), "int_param0", "Result failed.")
00085 self.assertEqual(self.prop.getLeaf()[10].getLeaf()[0].getLeaf()[1].getName(), "int_param1", "Result failed.")
00086 self.assertEqual(self.prop.getLeaf()[10].getLeaf()[0].getLeaf()[2].getName(), "double_param0", "Result failed.")
00087 self.assertEqual(self.prop.getLeaf()[10].getLeaf()[0].getLeaf()[3].getName(), "double_param1", "Result failed.")
00088 self.assertEqual(self.prop.getLeaf()[10].getLeaf()[0].getLeaf()[4].getName(), "str_param0", "Result failed.")
00089 self.assertEqual(self.prop.getLeaf()[10].getLeaf()[0].getLeaf()[5].getName(), "str_param1", "Result failed.")
00090 self.assertEqual(self.prop.getLeaf()[10].getLeaf()[0].getLeaf()[6].getName(), "vector_param0", "Result failed.")
00091
00092
00093
00094
00095
00096 def test_getRoot(self):
00097 self.assertEqual(self.prop.getRoot(), None, "Result failed.")
00098 self.assertEqual(self.prop.getLeaf()[10].getRoot().getRoot(), None, "Result failed.")
00099 self.assertEqual(self.prop.getLeaf()[10].getLeaf()[0].getRoot().getName(), "conf", "Result failed.")
00100 self.assertEqual(self.prop.getLeaf()[10].getLeaf()[0].getLeaf()[0].getRoot().getName(), "default", "Result failed.")
00101
00102
00103 def test_getProperty(self):
00104 self.assertEqual(self.prop.getProperty("implementation_id"), "ConfigSample", "Result failed.")
00105 self.assertEqual(self.prop.getProperty("type_name"), "ConfigSample", "Result failed.")
00106 self.assertEqual(self.prop.getProperty("description"), "Configuration example component","Result failed.")
00107 self.assertEqual(self.prop.getProperty("version"), "1.0","Result failed.")
00108 self.assertEqual(self.prop.getProperty("vendor"),"Shinji Kurihara, AIST", "Result failed.")
00109 self.assertEqual(self.prop.getProperty("category"), "example","Result failed.")
00110 self.assertEqual(self.prop.getProperty("activity_type"), "DataFlowComponent", "Result failed.")
00111 self.assertEqual(self.prop.getProperty("max_instance"), "10", "Result failed.")
00112 self.assertEqual(self.prop.getProperty("language"), "C++", "Result failed.")
00113 self.assertEqual(self.prop.getProperty("lang_type"), "compile", "Result failed.")
00114 self.assertEqual(self.prop.getProperty("conf.default.int_param0"), "0", "Result failed.")
00115 self.assertEqual(self.prop.getProperty("conf.default.int_param1"), "1", "Result failed.")
00116 self.assertEqual(self.prop.getProperty("conf.default.double_param0"), "0.11", "Result failed.")
00117 self.assertEqual(self.prop.getProperty("conf.default.double_param1"), "9.9", "Result failed.")
00118 self.assertEqual(self.prop.getProperty("conf.default.str_param0"), "hoge", "Result failed.")
00119 self.assertEqual(self.prop.getProperty("conf.default.str_param1"), "dara", "Result failed.")
00120 self.assertEqual(self.prop.getProperty("conf.default.vector_param0"), "0.0,1.0,2.0,3.0,4.0","Result failed.")
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 def test_getDefault(self):
00133 self.assertEqual(self.prop.getDefault("implementation_id"), "ConfigSample", "Result failed.")
00134 self.assertEqual(self.prop.getDefault("type_name"), "ConfigSample", "Result failed.")
00135 self.assertEqual(self.prop.getDefault("description"), "Configuration example component","Result failed.")
00136 self.assertEqual(self.prop.getDefault("version"), "1.0","Result failed.")
00137 self.assertEqual(self.prop.getDefault("vendor"),"Shinji Kurihara, AIST", "Result failed.")
00138 self.assertEqual(self.prop.getDefault("category"), "example","Result failed.")
00139 self.assertEqual(self.prop.getDefault("activity_type"), "DataFlowComponent", "Result failed.")
00140 self.assertEqual(self.prop.getDefault("max_instance"), "10", "Result failed.")
00141 self.assertEqual(self.prop.getDefault("language"), "C++", "Result failed.")
00142 self.assertEqual(self.prop.getDefault("lang_type"), "compile", "Result failed.")
00143 self.assertEqual(self.prop.getDefault("conf.default.int_param0"), "0", "Result failed.")
00144 self.assertEqual(self.prop.getDefault("conf.default.int_param1"), "1", "Result failed.")
00145 self.assertEqual(self.prop.getDefault("conf.default.double_param0"), "0.11", "Result failed.")
00146 self.assertEqual(self.prop.getDefault("conf.default.double_param1"), "9.9", "Result failed.")
00147 self.assertEqual(self.prop.getDefault("conf.default.str_param0"), "hoge", "Result failed.")
00148 self.assertEqual(self.prop.getDefault("conf.default.str_param1"), "dara", "Result failed.")
00149 self.assertEqual(self.prop.getDefault("conf.default.vector_param0"), "0.0,1.0,2.0,3.0,4.0","Result failed.")
00150
00151
00152 def test_setProperty(self):
00153 self.prop.setProperty("implementation_id", "ConfigSample_test")
00154 self.prop.setProperty("type_name", "ConfigSample_test")
00155 self.prop.setProperty("description", "Configuration example component test")
00156 self.prop.setProperty("version", "2.0")
00157 self.prop.setProperty("vendor","Shinji Kurihara")
00158 self.prop.setProperty("category", "example_test")
00159 self.prop.setProperty("activity_type", "DataFlowComponent")
00160 self.prop.setProperty("max_instance", "1")
00161 self.prop.setProperty("language", "C++")
00162 self.prop.setProperty("lang_type", "compile")
00163 self.prop.setProperty("conf.default.int_param0", "111")
00164 self.prop.setProperty("conf.default.int_param1", "222")
00165 self.prop.setProperty("conf.default.double_param0", "2.22")
00166 self.prop.setProperty("conf.default.double_param1", "9.99")
00167 self.prop.setProperty("conf.default.str_param0", "hogehoge")
00168 self.prop.setProperty("conf.default.str_param1", "daradara")
00169 self.prop.setProperty("conf.default.vector_param0", "0.0,1.1,2.2,3.3,4.4")
00170
00171 self.assertEqual(self.prop.getProperty("implementation_id"), "ConfigSample_test", "Result failed.")
00172 self.assertEqual(self.prop.getProperty("type_name"), "ConfigSample_test", "Result failed.")
00173 self.assertEqual(self.prop.getProperty("description"), "Configuration example component test","Result failed.")
00174 self.assertEqual(self.prop.getProperty("version"), "2.0","Result failed.")
00175 self.assertEqual(self.prop.getProperty("vendor"),"Shinji Kurihara", "Result failed.")
00176 self.assertEqual(self.prop.getProperty("category"), "example_test","Result failed.")
00177 self.assertEqual(self.prop.getProperty("activity_type"), "DataFlowComponent", "Result failed.")
00178 self.assertEqual(self.prop.getProperty("max_instance"), "1", "Result failed.")
00179 self.assertEqual(self.prop.getProperty("language"), "C++", "Result failed.")
00180 self.assertEqual(self.prop.getProperty("lang_type"), "compile", "Result failed.")
00181 self.assertEqual(self.prop.getProperty("conf.default.int_param0"), "111", "Result failed.")
00182 self.assertEqual(self.prop.getProperty("conf.default.int_param1"), "222", "Result failed.")
00183 self.assertEqual(self.prop.getProperty("conf.default.double_param0"), "2.22", "Result failed.")
00184 self.assertEqual(self.prop.getProperty("conf.default.double_param1"), "9.99", "Result failed.")
00185 self.assertEqual(self.prop.getProperty("conf.default.str_param0"), "hogehoge", "Result failed.")
00186 self.assertEqual(self.prop.getProperty("conf.default.str_param1"), "daradara", "Result failed.")
00187 self.assertEqual(self.prop.getProperty("conf.default.vector_param0"), "0.0,1.1,2.2,3.3,4.4","Result failed.")
00188
00189
00190 def test_setDefault(self):
00191 self.prop.setDefault("implementation_id", "ConfigSample")
00192 self.prop.setDefault("type_name", "ConfigSample")
00193 self.prop.setDefault("description", "Configuration example component")
00194 self.prop.setDefault("version", "1.0")
00195 self.prop.setDefault("vendor","Shinji Kurihara")
00196 self.prop.setDefault("category", "example")
00197 self.prop.setDefault("activity_type", "DataFlowComponent")
00198 self.prop.setDefault("max_instance", "10")
00199 self.prop.setDefault("language", "C++")
00200 self.prop.setDefault("lang_type", "compile")
00201 self.prop.setDefault("conf.default.int_param0", "0")
00202 self.prop.setDefault("conf.default.int_param1", "1")
00203 self.prop.setDefault("conf.default.double_param0", "0.11")
00204 self.prop.setDefault("conf.default.double_param1", "9.9")
00205 self.prop.setDefault("conf.default.str_param0", "hoge")
00206 self.prop.setDefault("conf.default.str_param1", "dara")
00207 self.prop.setDefault("conf.default.vector_param0", "0.0,1.0,2.0,3.0,4.0")
00208
00209 self.assertEqual(self.prop.getDefault("implementation_id"), "ConfigSample", "Result failed.")
00210 self.assertEqual(self.prop.getDefault("type_name"), "ConfigSample", "Result failed.")
00211 self.assertEqual(self.prop.getDefault("description"), "Configuration example component","Result failed.")
00212 self.assertEqual(self.prop.getDefault("version"), "1.0","Result failed.")
00213 self.assertEqual(self.prop.getDefault("vendor"),"Shinji Kurihara", "Result failed.")
00214 self.assertEqual(self.prop.getDefault("category"), "example","Result failed.")
00215 self.assertEqual(self.prop.getDefault("activity_type"), "DataFlowComponent", "Result failed.")
00216 self.assertEqual(self.prop.getDefault("max_instance"), "10", "Result failed.")
00217 self.assertEqual(self.prop.getDefault("language"), "C++", "Result failed.")
00218 self.assertEqual(self.prop.getDefault("lang_type"), "compile", "Result failed.")
00219 self.assertEqual(self.prop.getDefault("conf.default.int_param0"), "0", "Result failed.")
00220 self.assertEqual(self.prop.getDefault("conf.default.int_param1"), "1", "Result failed.")
00221 self.assertEqual(self.prop.getDefault("conf.default.double_param0"), "0.11", "Result failed.")
00222 self.assertEqual(self.prop.getDefault("conf.default.double_param1"), "9.9", "Result failed.")
00223 self.assertEqual(self.prop.getDefault("conf.default.str_param0"), "hoge", "Result failed.")
00224 self.assertEqual(self.prop.getDefault("conf.default.str_param1"), "dara", "Result failed.")
00225 self.assertEqual(self.prop.getDefault("conf.default.vector_param0"), "0.0,1.0,2.0,3.0,4.0","Result failed.")
00226
00227
00228 def test_setDefaults(self):
00229 self.prop.setDefaults(configsample_spec)
00230
00231 self.assertEqual(self.prop.getDefault("implementation_id"), "ConfigSample", "Result failed.")
00232 self.assertEqual(self.prop.getDefault("type_name"), "ConfigSample", "Result failed.")
00233 self.assertEqual(self.prop.getDefault("description"), "Configuration example component","Result failed.")
00234 self.assertEqual(self.prop.getDefault("version"), "1.0","Result failed.")
00235 self.assertEqual(self.prop.getDefault("vendor"),"Shinji Kurihara, AIST", "Result failed.")
00236 self.assertEqual(self.prop.getDefault("category"), "example","Result failed.")
00237 self.assertEqual(self.prop.getDefault("activity_type"), "DataFlowComponent", "Result failed.")
00238 self.assertEqual(self.prop.getDefault("max_instance"), "10", "Result failed.")
00239 self.assertEqual(self.prop.getDefault("language"), "C++", "Result failed.")
00240 self.assertEqual(self.prop.getDefault("lang_type"), "compile", "Result failed.")
00241 self.assertEqual(self.prop.getDefault("conf.default.int_param0"), "0", "Result failed.")
00242 self.assertEqual(self.prop.getDefault("conf.default.int_param1"), "1", "Result failed.")
00243 self.assertEqual(self.prop.getDefault("conf.default.double_param0"), "0.11", "Result failed.")
00244 self.assertEqual(self.prop.getDefault("conf.default.double_param1"), "9.9", "Result failed.")
00245 self.assertEqual(self.prop.getDefault("conf.default.str_param0"), "hoge", "Result failed.")
00246 self.assertEqual(self.prop.getDefault("conf.default.str_param1"), "dara", "Result failed.")
00247 self.assertEqual(self.prop.getDefault("conf.default.vector_param0"), "0.0,1.0,2.0,3.0,4.0","Result failed.")
00248
00249
00250 def test_list(self):
00251
00252 pass
00253
00254
00255 def test_load(self):
00256 fp = file("configsample.conf","r")
00257 self.prop.load(fp)
00258 self.assertEqual(self.prop.getProperty("conf.mode0.int_param0"), "12345", "Result failed.")
00259 self.assertEqual(self.prop.getProperty("conf.mode0.int_param1"), "98765", "Result failed.")
00260 self.assertEqual(self.prop.getProperty("conf.mode0.double_param0"), "3.141592653589793238462643383279")
00261 self.assertEqual(self.prop.getProperty("conf.mode0.double_param1"), "2.718281828459045235360287471352", "Result failed.")
00262 self.assertEqual(self.prop.getProperty("conf.mode0.str_param0"), "bar", "Result failed.")
00263 self.assertEqual(self.prop.getProperty("conf.mode0.str_param1"), "foo", "Result failed.")
00264 self.assertEqual(self.prop.getProperty("conf.mode0.vector_param0"), "0.0,0.1,0.2,0.3,0.4","Result failed.")
00265
00266
00267 def test_save(self):
00268 fp = file("test_save.data","w")
00269 self.prop.save(fp,"test Properties")
00270
00271
00272 def test_store(self):
00273 fp = file("test_store.data","w")
00274 self.prop.store(fp,"test Properties")
00275
00276
00277 def test_propertyNames(self):
00278 keys = self.prop.propertyNames()
00279 self.assertEqual(keys[0],"implementation_id", "Result failed.")
00280 self.assertEqual(keys[1],"type_name", "Result failed.")
00281 self.assertEqual(keys[2],"description","Result failed.")
00282 self.assertEqual(keys[3],"version","Result failed.")
00283 self.assertEqual(keys[4],"vendor", "Result failed.")
00284 self.assertEqual(keys[5],"category","Result failed.")
00285 self.assertEqual(keys[6],"activity_type", "Result failed.")
00286 self.assertEqual(keys[7],"max_instance", "Result failed.")
00287 self.assertEqual(keys[8],"language", "Result failed.")
00288 self.assertEqual(keys[9],"lang_type", "Result failed.")
00289 self.assertEqual(keys[10],"conf.default.int_param0", "Result failed.")
00290 self.assertEqual(keys[11],"conf.default.int_param1", "Result failed.")
00291 self.assertEqual(keys[12],"conf.default.double_param0", "Result failed.")
00292 self.assertEqual(keys[13],"conf.default.double_param1", "Result failed.")
00293 self.assertEqual(keys[14],"conf.default.str_param0", "Result failed.")
00294 self.assertEqual(keys[15],"conf.default.str_param1", "Result failed.")
00295 self.assertEqual(keys[16],"conf.default.vector_param0","Result failed.")
00296
00297
00298 def test_size(self):
00299 self.assertEqual(self.prop.size(),17,"Result failed.")
00300
00301
00302 def test_findNode(self):
00303 self.assertEqual(self.prop.findNode("implementation_id").getDefaultValue(), "ConfigSample", "Result failed.")
00304
00305 def test_getNode(self):
00306 self.assertEqual(self.prop.getNode("implementation_id").getDefaultValue(), "ConfigSample", "Result failed.")
00307 self.assertEqual(self.prop.getNode("type_name").getDefaultValue(), "ConfigSample", "Result failed.")
00308 self.assertEqual(self.prop.getNode("description").getDefaultValue(), "Configuration example component","Result failed.")
00309 self.assertEqual(self.prop.getNode("version").getDefaultValue(), "1.0","Result failed.")
00310 self.assertEqual(self.prop.getNode("vendor").getDefaultValue(),"Shinji Kurihara, AIST", "Result failed.")
00311 self.assertEqual(self.prop.getNode("category").getDefaultValue(), "example","Result failed.")
00312 self.assertEqual(self.prop.getNode("activity_type").getDefaultValue(), "DataFlowComponent", "Result failed.")
00313 self.assertEqual(self.prop.getNode("max_instance").getDefaultValue(), "10", "Result failed.")
00314 self.assertEqual(self.prop.getNode("language").getDefaultValue(), "C++", "Result failed.")
00315 self.assertEqual(self.prop.getNode("lang_type").getDefaultValue(), "compile", "Result failed.")
00316 self.assertEqual(self.prop.getNode("conf.default.int_param0").getDefaultValue(), "0", "Result failed.")
00317 self.assertEqual(self.prop.getNode("conf.default.int_param1").getDefaultValue(), "1", "Result failed.")
00318 self.assertEqual(self.prop.getNode("conf.default.double_param0").getDefaultValue(), "0.11", "Result failed.")
00319 self.assertEqual(self.prop.getNode("conf.default.double_param1").getDefaultValue(), "9.9", "Result failed.")
00320 self.assertEqual(self.prop.getNode("conf.default.str_param0").getDefaultValue(), "hoge", "Result failed.")
00321 self.assertEqual(self.prop.getNode("conf.default.str_param1").getDefaultValue(), "dara", "Result failed.")
00322 self.assertEqual(self.prop.getNode("conf.default.vector_param0").getDefaultValue(), "0.0,1.0,2.0,3.0,4.0","Result failed.")
00323
00324
00325 def test_createNode(self):
00326 self.assertEqual(self.prop.createNode("conf.default.int_param.0"),True, "Result failed.")
00327 self.assertEqual(self.prop.createNode("conf.add.int_param1"),True, "Result failed.")
00328 self.assertEqual(len(self.prop.getNode("conf.default").leaf), 8, "Result failed.")
00329 self.assertEqual(len(self.prop.getNode("conf.add").leaf), 1, "Result failed.")
00330
00331
00332 def test_removeNode(self):
00333 node = self.prop.getNode("conf.default")
00334 node.removeNode("int_param0")
00335 self.assertEqual( len(self.prop.getNode("conf.default").leaf),6, "Result failed.")
00336
00337 node = self.prop.getNode("conf")
00338 node.removeNode("default")
00339 self.assertEqual( len(self.prop.getNode("conf").leaf),0, "Result failed.")
00340
00341
00342 def test_hasKey(self):
00343 node = self.prop.getNode("conf")
00344 self.assertEqual(len(node.hasKey("default").leaf),7, "Result failed.")
00345
00346 self.assertEqual(self.prop.hasKey("default"),None, "Result failed.")
00347
00348
00349 def test_clear(self):
00350 self.prop.clear()
00351 self.assertEqual(self.prop.getProperty("implementation_id"), "", "Result failed.")
00352
00353
00354
00355
00356
00357 def test_splitKeyValue(self):
00358 key=[]
00359 val=[]
00360 self.prop.splitKeyValue("key:value",key,val)
00361 self.assertEqual(key[0],"key")
00362 self.assertEqual(val[0],"value")
00363
00364
00365 def test_split(self):
00366 val=[]
00367 self.prop.split("test.split,hoge",".",val)
00368
00369 self.assertEqual(val, ["test","split,hoge"])
00370
00371
00372 def test_mergeProperties(self):
00373 self.prop.mergeProperties(self.prop)
00374 self.assertEqual(self.prop.getProperty("implementation_id"), "ConfigSample", "Result failed.")
00375
00376
00377 def test_dump(self):
00378 print self.prop
00379
00380
00381
00382
00383 if __name__ == '__main__':
00384 unittest.main()