test_SdoConfiguration.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- Python -*-
3 
4 #
5 # \file test_SdoConfiguration.py
6 # \brief test for RT component base class
7 # \date $Date: 2007/09/06$
8 # \author Shinji Kurihara
9 #
10 # Copyright (C) 2006
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 
18 import sys
19 sys.path.insert(1,"../")
20 sys.path.insert(1,"../RTM_IDL")
21 
22 import unittest
23 import OpenRTM_aist
24 import SDOPackage, SDOPackage__POA
25 
26 from SdoConfiguration import *
27 
28 import CORBA
29 from omniORB import CORBA, PortableServer
30 
31 class ServiceProf(SDOPackage__POA.SDOService):
32  def __init__(self):
33  pass
34 
35 class OrganizationTest(SDOPackage__POA.Organization):
36  def __init__(self):
37  pass
38 
39 
40 configsample_spec = ["implementation_id", "ConfigSample",
41  "type_name", "ConfigSample",
42  "description", "Configuration example component",
43  "version", "1.0",
44  "vendor", "Shinji Kurihara, AIST",
45  "category", "example",
46  "activity_type", "DataFlowComponent",
47  "max_instance", "10",
48  "language", "C++",
49  "lang_type", "compile",
50  # Configuration variables
51  "conf.default.int_param0", "0",
52  "conf.default.int_param1", "1",
53  "conf.default.double_param0", "0.11",
54  "conf.default.double_param1", "9.9",
55  "conf.default.str_param0", "hoge",
56  "conf.default.str_param1", "dara",
57  "conf.default.vector_param0", "0.0,1.0,2.0,3.0,4.0",
58  ""]
59 
60 configsample_mode_spec = ["conf.default.int_param0", "10",
61  "conf.default.int_param1", "11",
62  "conf.default.double_param0", "0.22",
63  "conf.default.double_param1", "9999.9",
64  "conf.default.str_param0", "hogehoge",
65  "conf.default.str_param1", "daradaradata",
66  "conf.default.vector_param0", "0.1,1.1,2.1,3.1,4.1",
67  ""]
68 
69 
70 class TestConfiguration_impl(unittest.TestCase):
71  def setUp(self):
72  self._orb = CORBA.ORB_init()
73  self._poa = self._orb.resolve_initial_references("RootPOA")
74 
75  prop = OpenRTM_aist.Properties(defaults_str=configsample_spec)
76  ca = OpenRTM_aist.ConfigAdmin(prop.getNode("conf"))
77  self._sdoconf = Configuration_impl(ca)
78 
79  def tearDown(self):
80  OpenRTM_aist.Manager.instance().shutdownManager()
81  return
82 
84  dprof = SDOPackage.DeviceProfile("test","","","0.1.0",[])
85  self._sdoconf.set_device_profile(dprof)
86  self.assertEqual(self._sdoconf.getDeviceProfile().device_type, "test")
87  self.assertEqual(self._sdoconf.getDeviceProfile().version, "0.1.0")
88 
89  self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.set_device_profile, None )
90 
91 
93  sprof = SDOPackage.ServiceProfile("test","MyService",[],ServiceProf())
94  self._sdoconf.add_service_profile(sprof)
95  profiles = self._sdoconf.getServiceProfiles()
96  self.assertEqual(profiles[0].id, "test")
97  self.assertEqual(self._sdoconf.getServiceProfile("test").id, "test")
98  self._sdoconf.remove_service_profile("test")
99  self.assertEqual(self._sdoconf.getServiceProfile("test").id, "")
100 
101  self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.add_service_profile, None )
102  self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.remove_service_profile, None )
103 
104  # Failure pattern
105  #self.assertEqual(self._sdoconf.getServiceProfile("test").id, "test")
106 
108  org = OrganizationTest()
109  self._sdoconf.add_organization(org)
110  self._sdoconf.add_organization(org)
111  self._sdoconf.add_organization(org)
112  self.assertEqual(len(self._sdoconf.getOrganizations()), 3)
113 
114  self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.add_organization, None )
115  self.assertRaises(SDOPackage.InternalError, self._sdoconf.remove_organization, "aaa" )
116  self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.remove_organization, None )
117 
118 
120  self._sdoconf.get_configuration_parameters()
121 
122 
124  param_val = self._sdoconf.get_configuration_parameter_values()
125  self.assertEqual(param_val, [])
126 
128  param_val = self._sdoconf.get_configuration_parameter_value("aaa")
129  self.assertEqual(param_val, None)
130 
131  self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.get_configuration_parameter_value, None )
132 
133 
135  self.assertEqual(self._sdoconf.set_configuration_parameter("name",123), True)
136  self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.set_configuration_parameter, None,None )
137  self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.set_configuration_parameter, "name",None )
138  self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.set_configuration_parameter, None,123 )
139 
141  conf_sets = self._sdoconf.get_configuration_sets()
142  self.assertEqual(len(conf_sets), 1)
143 
144 
146  conf_set = self._sdoconf.get_configuration_set("default")
147  self.assertEqual(conf_set.configuration_data[0].name, "int_param0")
148  self.assertEqual(conf_set.configuration_data[0].value.value(), "0")
149 
150  self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.get_configuration_set, None )
151 
153  self._sdoconf.set_configuration_set_values(SDOPackage.ConfigurationSet("default2","",[]))
154 
155  self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.set_configuration_set_values, None )
156 
158  self.assertEqual(self._sdoconf.get_active_configuration_set().id, "default")
159 
160 
162  self._sdoconf.add_configuration_set(SDOPackage.ConfigurationSet("default2","",[]))
163 
164  self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.add_configuration_set, None )
165 
167  self._sdoconf.add_configuration_set(SDOPackage.ConfigurationSet("default2","",[]))
168  self.assertEqual(self._sdoconf.remove_configuration_set("default2"),True)
169 
170  self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.remove_configuration_set, None )
171 
173  self._sdoconf.add_configuration_set(SDOPackage.ConfigurationSet("default2","",[]))
174  self.assertEqual(self._sdoconf.activate_configuration_set("default2"),True)
175 
176  self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.activate_configuration_set, None )
177 
178  def test_getObjRef(self):
179  self._sdoconf.getObjRef()
180 
182  self._sdoconf.getOrganizations()
183 
185  self._sdoconf.getDeviceProfile()
186 
188  self._sdoconf.getServiceProfiles()
189 
191  self._sdoconf.getServiceProfile("default")
192 
194  self._sdoconf.getOrganizations()
195 
196  def test_getUUID(self):
197  print self._sdoconf.getUUID()
198 
199 
200 
201 
202 if __name__ == '__main__':
203  unittest.main()
The Properties class represents a persistent set of properties.
Definition: Properties.py:83


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