test_NVUtil.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- Python -*- 
00003 
00004 #  \file test_NVUtil.py
00005 #  \brief test for NameValue and NVList utility functions
00006 #  \date $Date: 2007/09/11$
00007 #  \author Shinji Kurihara
00008 # 
00009 #  Copyright (C) 2006
00010 #      Noriaki Ando
00011 #      Task-intelligence Research Group,
00012 #      Intelligent Systems Research Institute,
00013 #      National Institute of
00014 #          Advanced Industrial Science and Technology (AIST), Japan
00015 #      All rights reserved.
00016 
00017 from omniORB import *
00018 from omniORB import any
00019 import sys
00020 sys.path.insert(1,"../")
00021 
00022 import unittest
00023 import OpenRTM_aist
00024 import SDOPackage, SDOPackage__POA
00025 
00026 from NVUtil import *
00027 
00028 configsample_spec = ["implementation_id", "ConfigSample",
00029            "type_name",         "ConfigSample",
00030            "description",       "Configuration example component",
00031            "version",           "1.0",
00032            "vendor",            "Shinji Kurihara, AIST",
00033            "category",          "example",
00034            "activity_type",     "DataFlowComponent",
00035            "max_instance",      "10",
00036            "language",          "C++",
00037            "lang_type",         "compile",
00038            # Configuration variables
00039            "conf.default.int_param0", "0",
00040            "conf.default.int_param1", "1",
00041            "conf.default.double_param0", "0.11",
00042            "conf.default.double_param1", "9.9",
00043            "conf.default.str_param0", "hoge",
00044            "conf.default.str_param1", "dara",
00045            "conf.default.vector_param0", "0.0,1.0,2.0,3.0,4.0",
00046            ""]
00047 
00048 class TestNVUtil(unittest.TestCase):
00049   def setUp(self):
00050     pass
00051 
00052   def tearDown(self):
00053     OpenRTM_aist.Manager.instance().shutdownManager()
00054     return
00055 
00056   def test_newNV(self):
00057     self.assertEqual(newNV("long", 1).name, "long")
00058     self.assertEqual(newNV("long", 1).value.value(), 1)
00059     self.assertEqual(newNV("float", 1.2345).name, "float")
00060     self.assertEqual(newNV("float", 1.2345).value.value(), 1.2345)
00061     self.assertEqual(newNV("string", "test").name, "string")
00062     self.assertEqual(newNV("string", "test").value.value(), "test")
00063 
00064 
00065   def test_newNVBool(self):
00066     self.assertEqual(newNV("bool", True).name, "bool")
00067     self.assertEqual(newNV("bool", True).value.value(), True)
00068     
00069 
00070   def test_newNVOctet(self):
00071     self.assertEqual(newNV("oct", 0x01).name, "oct")
00072     self.assertEqual(newNV("oct", 0x01).value.value(), 0x01)
00073 
00074 
00075   def test_newNVAny(self):
00076     import omniORB.any
00077     self.assertEqual(omniORB.any.from_any(newNV("any",omniORB.any.to_any(12345)).value), 12345)
00078 
00079 
00080   def test_copyFromProperties(self):
00081     prop = OpenRTM_aist.Properties(defaults_str=configsample_spec)
00082     nv = []
00083     copyFromProperties(nv, prop)
00084     self.assertEqual(nv[0].name, "implementation_id")
00085     self.assertEqual(nv[0].value.value(), "ConfigSample")
00086     nv = [1,2,3]
00087     copyFromProperties(nv, prop)
00088     self.assertEqual(nv[0].name, "implementation_id")
00089     self.assertEqual(nv[0].value.value(), "ConfigSample")
00090 
00091     
00092   def test_copyToProperties(self):
00093     nv = [newNV("id0",0),newNV("id1",1),newNV("id2",2),newNV("id3",3)]
00094     prop = OpenRTM_aist.Properties(defaults_str=configsample_spec)
00095     copyToProperties(prop, nv)
00096     self.assertEqual(prop.getProperty("id0"), "0")
00097     self.assertEqual(prop.getProperty("id1"), "1")
00098     self.assertEqual(prop.getProperty("id2"), "2")
00099     self.assertEqual(prop.getProperty("id3"), "3")
00100     
00101     
00102   def test_toProperties(self):
00103     nv = [newNV("id0",0),newNV("id1",1),newNV("id2",2),newNV("id3",3)]
00104     prop = toProperties(nv)
00105     self.assertEqual(prop.getProperty("id0").value(), 0)
00106     self.assertEqual(prop.getProperty("id1").value(), 1)
00107     self.assertEqual(prop.getProperty("id2").value(), 2)
00108     self.assertEqual(prop.getProperty("id3").value(), 3)
00109     
00110 
00111   def test_find(self):
00112     nv = [newNV("id0",0),newNV("id1",1),newNV("id2",2),newNV("id3",3)]
00113     self.assertEqual(find(nv,"id0").value(), 0)
00114     self.assertEqual(find(nv,"id1").value(), 1)
00115     self.assertEqual(find(nv,"id2").value(), 2)
00116     self.assertEqual(find(nv,"id3").value(), 3)
00117 
00118     
00119   def test_find_index(self):
00120     nv = [newNV("id0",0),newNV("id1",1),newNV("id2",2),newNV("id3",3)]
00121     self.assertEqual(find_index(nv,"id0"),0)
00122     self.assertEqual(find_index(nv,"id1"),1)
00123     self.assertEqual(find_index(nv,"id2"),2)
00124     self.assertEqual(find_index(nv,"id3"),3)
00125 
00126 
00127   def test_isString(self):
00128     nv = [newNV("float",1.234),newNV("long",1234),newNV("string","test"),newNV("oct",0x01)]
00129     self.assertEqual(isString(nv,"float"),False)
00130     self.assertEqual(isString(nv,"long"),False)
00131     self.assertEqual(isString(nv,"string"),True)
00132     self.assertEqual(isString(nv,"oct"),False)
00133     
00134 
00135   def test_isStringValue(self):
00136     nv = [newNV("float",1.234),newNV("long",1234),newNV("string","test"),newNV("oct",0x01)]
00137     self.assertEqual(isStringValue(nv,"float",1.234),False)
00138     self.assertEqual(isStringValue(nv,"long",1234),False)
00139     self.assertEqual(isStringValue(nv,"string","test"),True)
00140     self.assertEqual(isStringValue(nv,"oct",0x01),False)
00141 
00142 
00143   def test_toString(self):
00144     nv = [newNV("float",1.234),newNV("long",1234),newNV("string","test"),newNV("oct",0x01)]
00145     self.assertEqual(toString(nv,"float"),"")
00146     self.assertEqual(toString(nv,"long"),"")
00147     self.assertEqual(toString(nv,"string"),"test")
00148     self.assertEqual(toString(nv,"oct"),"")
00149     
00150 
00151   def test_appendStringValue(self):
00152     nv = [newNV("string","test0, test1, test2")]
00153     self.assertEqual(appendStringValue(nv,"string","test2"),True)
00154     self.assertEqual(any.from_any(nv[0].value),"test0, test1, test2")
00155     self.assertEqual(appendStringValue(nv,"string","test3"),True)
00156     self.assertEqual(any.from_any(nv[0].value),"test0, test1, test2, test3")
00157 
00158 
00159   def test_append(self):
00160     list_ = [1,2,3]
00161     append(list_,[4,5,6])
00162     self.assertEqual(list_,[1,2,3,4,5,6])
00163     
00164 
00165   def test_dump(self):
00166     nv = [newNV("string","test0, test1, test2")]
00167     dump(nv)
00168 
00169 
00170 ############### test #################
00171 if __name__ == '__main__':
00172         unittest.main()


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Aug 27 2015 14:17:28