test_NVUtil.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- Python -*-
3 
4 # \file test_NVUtil.py
5 # \brief test for NameValue and NVList utility functions
6 # \date $Date: 2007/09/11$
7 # \author Shinji Kurihara
8 #
9 # Copyright (C) 2006
10 # Noriaki Ando
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 from omniORB import *
18 from omniORB import any
19 import sys
20 sys.path.insert(1,"../")
21 
22 import unittest
23 import OpenRTM_aist
24 import SDOPackage, SDOPackage__POA
25 
26 from NVUtil import *
27 
28 configsample_spec = ["implementation_id", "ConfigSample",
29  "type_name", "ConfigSample",
30  "description", "Configuration example component",
31  "version", "1.0",
32  "vendor", "Shinji Kurihara, AIST",
33  "category", "example",
34  "activity_type", "DataFlowComponent",
35  "max_instance", "10",
36  "language", "C++",
37  "lang_type", "compile",
38  # Configuration variables
39  "conf.default.int_param0", "0",
40  "conf.default.int_param1", "1",
41  "conf.default.double_param0", "0.11",
42  "conf.default.double_param1", "9.9",
43  "conf.default.str_param0", "hoge",
44  "conf.default.str_param1", "dara",
45  "conf.default.vector_param0", "0.0,1.0,2.0,3.0,4.0",
46  ""]
47 
48 class TestNVUtil(unittest.TestCase):
49  def setUp(self):
50  pass
51 
52  def tearDown(self):
53  OpenRTM_aist.Manager.instance().shutdownManager()
54  return
55 
56  def test_newNV(self):
57  self.assertEqual(newNV("long", 1).name, "long")
58  self.assertEqual(newNV("long", 1).value.value(), 1)
59  self.assertEqual(newNV("float", 1.2345).name, "float")
60  self.assertEqual(newNV("float", 1.2345).value.value(), 1.2345)
61  self.assertEqual(newNV("string", "test").name, "string")
62  self.assertEqual(newNV("string", "test").value.value(), "test")
63 
64 
65  def test_newNVBool(self):
66  self.assertEqual(newNV("bool", True).name, "bool")
67  self.assertEqual(newNV("bool", True).value.value(), True)
68 
69 
70  def test_newNVOctet(self):
71  self.assertEqual(newNV("oct", 0x01).name, "oct")
72  self.assertEqual(newNV("oct", 0x01).value.value(), 0x01)
73 
74 
75  def test_newNVAny(self):
76  import omniORB.any
77  self.assertEqual(omniORB.any.from_any(newNV("any",omniORB.any.to_any(12345)).value), 12345)
78 
79 
81  prop = OpenRTM_aist.Properties(defaults_str=configsample_spec)
82  nv = []
83  copyFromProperties(nv, prop)
84  self.assertEqual(nv[0].name, "implementation_id")
85  self.assertEqual(nv[0].value.value(), "ConfigSample")
86  nv = [1,2,3]
87  copyFromProperties(nv, prop)
88  self.assertEqual(nv[0].name, "implementation_id")
89  self.assertEqual(nv[0].value.value(), "ConfigSample")
90 
91 
93  nv = [newNV("id0",0),newNV("id1",1),newNV("id2",2),newNV("id3",3)]
94  prop = OpenRTM_aist.Properties(defaults_str=configsample_spec)
95  copyToProperties(prop, nv)
96  self.assertEqual(prop.getProperty("id0"), "0")
97  self.assertEqual(prop.getProperty("id1"), "1")
98  self.assertEqual(prop.getProperty("id2"), "2")
99  self.assertEqual(prop.getProperty("id3"), "3")
100 
101 
102  def test_toProperties(self):
103  nv = [newNV("id0",0),newNV("id1",1),newNV("id2",2),newNV("id3",3)]
104  prop = toProperties(nv)
105  self.assertEqual(prop.getProperty("id0").value(), 0)
106  self.assertEqual(prop.getProperty("id1").value(), 1)
107  self.assertEqual(prop.getProperty("id2").value(), 2)
108  self.assertEqual(prop.getProperty("id3").value(), 3)
109 
110 
111  def test_find(self):
112  nv = [newNV("id0",0),newNV("id1",1),newNV("id2",2),newNV("id3",3)]
113  self.assertEqual(find(nv,"id0").value(), 0)
114  self.assertEqual(find(nv,"id1").value(), 1)
115  self.assertEqual(find(nv,"id2").value(), 2)
116  self.assertEqual(find(nv,"id3").value(), 3)
117 
118 
119  def test_find_index(self):
120  nv = [newNV("id0",0),newNV("id1",1),newNV("id2",2),newNV("id3",3)]
121  self.assertEqual(find_index(nv,"id0"),0)
122  self.assertEqual(find_index(nv,"id1"),1)
123  self.assertEqual(find_index(nv,"id2"),2)
124  self.assertEqual(find_index(nv,"id3"),3)
125 
126 
127  def test_isString(self):
128  nv = [newNV("float",1.234),newNV("long",1234),newNV("string","test"),newNV("oct",0x01)]
129  self.assertEqual(isString(nv,"float"),False)
130  self.assertEqual(isString(nv,"long"),False)
131  self.assertEqual(isString(nv,"string"),True)
132  self.assertEqual(isString(nv,"oct"),False)
133 
134 
136  nv = [newNV("float",1.234),newNV("long",1234),newNV("string","test"),newNV("oct",0x01)]
137  self.assertEqual(isStringValue(nv,"float",1.234),False)
138  self.assertEqual(isStringValue(nv,"long",1234),False)
139  self.assertEqual(isStringValue(nv,"string","test"),True)
140  self.assertEqual(isStringValue(nv,"oct",0x01),False)
141 
142 
143  def test_toString(self):
144  nv = [newNV("float",1.234),newNV("long",1234),newNV("string","test"),newNV("oct",0x01)]
145  self.assertEqual(toString(nv,"float"),"")
146  self.assertEqual(toString(nv,"long"),"")
147  self.assertEqual(toString(nv,"string"),"test")
148  self.assertEqual(toString(nv,"oct"),"")
149 
150 
152  nv = [newNV("string","test0, test1, test2")]
153  self.assertEqual(appendStringValue(nv,"string","test2"),True)
154  self.assertEqual(any.from_any(nv[0].value),"test0, test1, test2")
155  self.assertEqual(appendStringValue(nv,"string","test3"),True)
156  self.assertEqual(any.from_any(nv[0].value),"test0, test1, test2, test3")
157 
158 
159  def test_append(self):
160  list_ = [1,2,3]
161  append(list_,[4,5,6])
162  self.assertEqual(list_,[1,2,3,4,5,6])
163 
164 
165  def test_dump(self):
166  nv = [newNV("string","test0, test1, test2")]
167  dump(nv)
168 
169 
170 ############### test #################
171 if __name__ == '__main__':
172  unittest.main()
def test_copyFromProperties(self)
Definition: test_NVUtil.py:80
def test_copyToProperties(self)
Definition: test_NVUtil.py:92
def copyToProperties(prop, nvlist)
Copy to Proeprties from NVList.
Definition: NVUtil.py:118
def test_isStringValue(self)
Definition: test_NVUtil.py:135
The Properties class represents a persistent set of properties.
Definition: Properties.py:83
def appendStringValue(nv, name, value)
Definition: NVUtil.py:352
def test_toProperties(self)
Definition: test_NVUtil.py:102
def find_index(nv, name)
Definition: NVUtil.py:229
def toString(nv, name=None)
Get string value in NVList specified by name.
Definition: NVUtil.py:311
def isString(nv, name)
Definition: NVUtil.py:249
def test_newNVOctet(self)
Definition: test_NVUtil.py:70
def isStringValue(nv, name, value)
Definition: NVUtil.py:276
def find(seq, f)
Return the index of CORBA sequence element that functor matches.
def test_appendStringValue(self)
Definition: test_NVUtil.py:151
def append(dest, src)
Definition: NVUtil.py:386
def toProperties(nv)
coil::Properties toProperties(const SDOPackage::NVList& nv);
Definition: NVUtil.py:158
def copyFromProperties(nv, prop)
Copy to NVList from Proeprties.
Definition: NVUtil.py:85
def newNV(name, value)
Create NameVale.
Definition: NVUtil.py:50
def test_newNVBool(self)
Definition: test_NVUtil.py:65


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