test_SdoConfiguration.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- Python -*-
00003 
00004 #
00005 # \file test_SdoConfiguration.py
00006 # \brief test for RT component base class
00007 # \date $Date: 2007/09/06$
00008 # \author Shinji Kurihara
00009 #
00010 # Copyright (C) 2006
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 
00018 import sys
00019 sys.path.insert(1,"../")
00020 sys.path.insert(1,"../RTM_IDL")
00021 
00022 import unittest
00023 import OpenRTM_aist
00024 import SDOPackage, SDOPackage__POA
00025 
00026 from SdoConfiguration import *
00027 
00028 import CORBA
00029 from omniORB import CORBA, PortableServer
00030 
00031 class ServiceProf(SDOPackage__POA.SDOService):
00032   def __init__(self):
00033     pass
00034 
00035 class OrganizationTest(SDOPackage__POA.Organization):
00036   def __init__(self):
00037     pass
00038 
00039 
00040 configsample_spec = ["implementation_id", "ConfigSample",
00041            "type_name",         "ConfigSample",
00042            "description",       "Configuration example component",
00043            "version",           "1.0",
00044            "vendor",            "Shinji Kurihara, AIST",
00045            "category",          "example",
00046            "activity_type",     "DataFlowComponent",
00047            "max_instance",      "10",
00048            "language",          "C++",
00049            "lang_type",         "compile",
00050            # Configuration variables
00051            "conf.default.int_param0", "0",
00052            "conf.default.int_param1", "1",
00053            "conf.default.double_param0", "0.11",
00054            "conf.default.double_param1", "9.9",
00055            "conf.default.str_param0", "hoge",
00056            "conf.default.str_param1", "dara",
00057            "conf.default.vector_param0", "0.0,1.0,2.0,3.0,4.0",
00058            ""]
00059 
00060 configsample_mode_spec = ["conf.default.int_param0", "10",
00061               "conf.default.int_param1", "11",
00062               "conf.default.double_param0", "0.22",
00063               "conf.default.double_param1", "9999.9",
00064               "conf.default.str_param0", "hogehoge",
00065               "conf.default.str_param1", "daradaradata",
00066               "conf.default.vector_param0", "0.1,1.1,2.1,3.1,4.1",
00067               ""]
00068 
00069 
00070 class TestConfiguration_impl(unittest.TestCase):
00071   def setUp(self):
00072     self._orb = CORBA.ORB_init()
00073     self._poa = self._orb.resolve_initial_references("RootPOA")
00074     
00075     prop = OpenRTM_aist.Properties(defaults_str=configsample_spec)
00076     ca   = OpenRTM_aist.ConfigAdmin(prop.getNode("conf"))
00077     self._sdoconf = Configuration_impl(ca)
00078 
00079   def tearDown(self):
00080     OpenRTM_aist.Manager.instance().shutdownManager()
00081     return
00082 
00083   def test_set_device_profile(self):
00084     dprof = SDOPackage.DeviceProfile("test","","","0.1.0",[])
00085     self._sdoconf.set_device_profile(dprof)
00086     self.assertEqual(self._sdoconf.getDeviceProfile().device_type, "test")
00087     self.assertEqual(self._sdoconf.getDeviceProfile().version, "0.1.0")
00088     
00089     self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.set_device_profile, None )
00090 
00091 
00092   def test_add_service_profile(self):
00093     sprof = SDOPackage.ServiceProfile("test","MyService",[],ServiceProf())
00094     self._sdoconf.add_service_profile(sprof)
00095     profiles = self._sdoconf.getServiceProfiles()
00096     self.assertEqual(profiles[0].id, "test")
00097     self.assertEqual(self._sdoconf.getServiceProfile("test").id, "test")
00098     self._sdoconf.remove_service_profile("test")
00099     self.assertEqual(self._sdoconf.getServiceProfile("test").id, "")
00100 
00101     self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.add_service_profile, None )
00102     self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.remove_service_profile, None )
00103 
00104     # Failure pattern
00105     #self.assertEqual(self._sdoconf.getServiceProfile("test").id, "test")
00106 
00107   def test_add_organization(self):
00108     org = OrganizationTest()
00109     self._sdoconf.add_organization(org)
00110     self._sdoconf.add_organization(org)
00111     self._sdoconf.add_organization(org)
00112     self.assertEqual(len(self._sdoconf.getOrganizations()), 3)
00113 
00114     self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.add_organization, None )
00115     self.assertRaises(SDOPackage.InternalError, self._sdoconf.remove_organization, "aaa" )
00116     self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.remove_organization, None )
00117 
00118 
00119   def test_get_configuration_parameters(self):
00120     self._sdoconf.get_configuration_parameters()
00121 
00122 
00123   def test_get_configuration_parameter_values(self):
00124     param_val = self._sdoconf.get_configuration_parameter_values()
00125     self.assertEqual(param_val, [])
00126 
00127   def test_get_configuration_parameter_value(self):
00128     param_val = self._sdoconf.get_configuration_parameter_value("aaa")
00129     self.assertEqual(param_val, None)
00130     
00131     self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.get_configuration_parameter_value, None )
00132 
00133 
00134   def test_set_configuration_parameter(self):
00135     self.assertEqual(self._sdoconf.set_configuration_parameter("name",123), True)
00136     self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.set_configuration_parameter, None,None )
00137     self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.set_configuration_parameter, "name",None )
00138     self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.set_configuration_parameter, None,123 )
00139 
00140   def test_get_configuration_sets(self):
00141     conf_sets = self._sdoconf.get_configuration_sets()
00142     self.assertEqual(len(conf_sets), 1)
00143 
00144 
00145   def test_get_configuration_set(self):
00146     conf_set = self._sdoconf.get_configuration_set("default")
00147     self.assertEqual(conf_set.configuration_data[0].name, "int_param0")
00148     self.assertEqual(conf_set.configuration_data[0].value.value(), "0")
00149 
00150     self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.get_configuration_set, None )
00151 
00152   def test_set_configuration_set_values(self):
00153     self._sdoconf.set_configuration_set_values(SDOPackage.ConfigurationSet("default2","",[]))
00154 
00155     self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.set_configuration_set_values, None )
00156 
00157   def test_get_active_configuration_set(self):
00158     self.assertEqual(self._sdoconf.get_active_configuration_set().id, "default")
00159 
00160 
00161   def test_add_configuration_set(self):
00162     self._sdoconf.add_configuration_set(SDOPackage.ConfigurationSet("default2","",[]))
00163 
00164     self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.add_configuration_set, None )
00165 
00166   def test_remove_configuration_set(self):
00167     self._sdoconf.add_configuration_set(SDOPackage.ConfigurationSet("default2","",[]))
00168     self.assertEqual(self._sdoconf.remove_configuration_set("default2"),True)
00169     
00170     self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.remove_configuration_set, None )
00171 
00172   def test_activate_configuration_set(self):
00173     self._sdoconf.add_configuration_set(SDOPackage.ConfigurationSet("default2","",[]))
00174     self.assertEqual(self._sdoconf.activate_configuration_set("default2"),True)
00175 
00176     self.assertRaises(SDOPackage.InvalidParameter, self._sdoconf.activate_configuration_set, None )
00177 
00178   def test_getObjRef(self):
00179     self._sdoconf.getObjRef()
00180 
00181   def test_getOrganizations(self):
00182     self._sdoconf.getOrganizations()
00183 
00184   def test_getDeviceProfile(self):
00185     self._sdoconf.getDeviceProfile()
00186 
00187   def test_getServiceProfiles(self):
00188     self._sdoconf.getServiceProfiles()
00189 
00190   def test_getServiceProfile(self):
00191     self._sdoconf.getServiceProfile("default")
00192 
00193   def test_getOrganizations(self):
00194     self._sdoconf.getOrganizations()
00195 
00196   def test_getUUID(self):
00197     print self._sdoconf.getUUID()
00198 
00199 
00200 
00201 ############### test #################
00202 if __name__ == '__main__':
00203         unittest.main()


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