SdoConfigurationTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
21 /*
22  * $Log: SdoConfigurationTests.cpp,v $
23  * Revision 1.3 2008/04/23 10:43:41 arafune
24  * Modified / Added some tests.
25  *
26  * Revision 1.2 2008/04/17 13:21:45 arafune
27  * Modified some tests, and added new tests.
28  *
29  * Revision 1.1 2007/12/20 07:50:18 arafune
30  * *** empty log message ***
31  *
32  * Revision 1.2 2007/01/24 16:04:18 n-ando
33  * The SdoConfiguration's ctor. was changed.
34  *
35  * Revision 1.1 2006/11/27 08:26:07 n-ando
36  * TestSuites are devided into each directory.
37  *
38  * Revision 1.3 2006/11/10 07:13:44 kurihara
39  * A test after SdoConfiguration class revision.
40  *
41  * Revision 1.2 2006/11/09 09:29:47 kurihara
42  * A test after SdoConfiguration class revision.
43  *
44  * Revision 1.1 2006/11/01 11:23:35 kurihara
45  * test program for SdoConfiguration class.
46  *
47  */
48 
49 #ifndef SdoConfiguration_cpp
50 #define SdoConfiguration_cpp
51 
52 #include <cppunit/ui/text/TestRunner.h>
53 #include <cppunit/TextOutputter.h>
54 #include <cppunit/extensions/TestFactoryRegistry.h>
55 #include <cppunit/extensions/HelperMacros.h>
56 #include <cppunit/TestAssert.h>
57 
58 #include <vector>
59 #include <string>
60 
61 #include <rtm/CORBA_SeqUtil.h>
62 #include <rtm/SdoConfiguration.h>
63 #include <rtm/RTObject.h>
64 #include <rtm/Manager.h>
65 #include <rtm/SdoOrganization.h>
66 
72 {
73  using namespace SDOPackage;
74  using namespace std;
75 
77  {
78  ServiceProfileFinder(const std::string& id) : _id(id) { }
79 
80  bool operator()(const ServiceProfile& svcProf)
81  {
82  return (_id == std::string(svcProf.id));
83  }
84 
85  std::string _id;
86  };
87 
89  : public CppUnit::TestFixture
90  {
91  CPPUNIT_TEST_SUITE(SdoConfigurationTests);
92 
93  CPPUNIT_TEST(test_set_device_profile_and_getDeviceProfile);
94  CPPUNIT_TEST(test_set_service_profile_and_getServiceProfile);
95  CPPUNIT_TEST(test_getServiceProfiles);
96  CPPUNIT_TEST(test_remove_service_profile);
97  CPPUNIT_TEST(test_add_organization_and_getOrganizations);
98  CPPUNIT_TEST(test_remove_organization);
99  CPPUNIT_TEST(test_add_configuration_set_and_get_configuration_set);
100  CPPUNIT_TEST(test_remove_configuration_set);
101  CPPUNIT_TEST(test_set_configuration_set_values);
102  CPPUNIT_TEST(test_activate_configuration_set_and_get_active_configuration_set);
103  //CPPUNIT_TEST(test_get_configuration_parameters); //未実装のため未テスト //CPPUNIT_TEST(test_get_configuration_parameter_values); //未実装のため未テスト //CPPUNIT_TEST(test_get_configuration_parameter_value); //未実装のため未テスト //CPPUNIT_TEST(test_set_configuration_parameter); //未実装のため未テスト CPPUNIT_TEST_SUITE_END(); private: CORBA::ORB_ptr m_pORB; PortableServer::POA_ptr m_pPOA; public: /*! * @brief Constructor */ SdoConfigurationTests() { int argc(0); char** argv(NULL); m_pORB = CORBA::ORB_init(argc, argv); m_pPOA = PortableServer::POA::_narrow( m_pORB->resolve_initial_references("RootPOA")); m_pPOA->the_POAManager()->activate(); } /*! * @brief Destructor */ ~SdoConfigurationTests() { } /*! * @brief Test initialization */ virtual void setUp() { usleep(100000); } /*! * @brief Test finalization */ virtual void tearDown() { } /*! * set_device_profile()メソッドとgetDeviceProfile()メソッドのテスト * * - set_device_profile()で設定したDeviceProfileを、getDeviceProfile()で正しく取得できるか? */ void test_set_device_profile_and_getDeviceProfile() { // std::cout << "test_set_device_profile_and_getDeviceProfile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // DeviceProfileを準備する SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 1"; properties[1].value <<= CORBA::Float(2.71828); devProf.properties = properties; } // set_device_profile()を呼出して、準備したDeviceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_device_profile(devProf)); // getDeviceProfile()で設定されているDeviceProfileを取り出し、設定したものと一致することを確認する const SDOPackage::DeviceProfile devProfRet = sdoCfg->getDeviceProfile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet.device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet.manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet.model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet.version)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(devProfRet.properties[0].name)); { CORBA::Float value; devProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(devProfRet.properties[1].name)); { CORBA::Float value; devProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_device_profile_and_getDeviceProfile() OUT" << std::endl; } /*! * @brief set_service_profile()メソッドとgetServiceProfile()メソッドのテスト * * - set_service_profile()で設定したServiceProfileを、getServiceProfile()で正しく取得できるか? */ void test_set_service_profile_and_getServiceProfile() { // std::cout << "test_set_service_profile_and_getServiceProfile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf; svcProf.id = "ID"; svcProf.interface_type = "INTERFACE_TYPE"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 1"; properties[1].value <<= CORBA::Float(2.71828); svcProf.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf)); // getServiceProfile()でServiceProfileを取得し、設定したものと一致しているか確認する const SDOPackage::ServiceProfile svcProfRet = sdoCfg->getServiceProfile("ID"); CPPUNIT_ASSERT_EQUAL(std::string("ID"), std::string(svcProfRet.id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"), std::string(svcProfRet.interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(svcProfRet.properties[0].name)); { CORBA::Float value; svcProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(svcProfRet.properties[1].name)); { CORBA::Float value; svcProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_service_profile_and_getServiceProfile() OUT" << std::endl; } /*! * @brief getServiceProfiles()メソッドのテスト * * - 登録されている複数のServiceProfileを、getServiceProfiles()で正しく取得できるか? */ void test_getServiceProfiles() { // std::cout << "test_getServiceProfiles() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // getServiceProfiles()で設定されているServiceProfile群を取得する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length()); // 設定したServiceProfileと一致しているか? { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } } { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value); } } sdoCfg->_remove_ref(); // std::cout << "test_getServiceProfiles() OUT" << std::endl; } /*! * @brief remove_service_profile()メソッドのテスト * * - 指定したIDを持つServiceProfileを正しく登録解除できるか? */ void test_remove_service_profile() { // std::cout << "test_remove_service_profile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
104  //CPPUNIT_TEST(test_get_configuration_parameter_values); //未実装のため未テスト //CPPUNIT_TEST(test_get_configuration_parameter_value); //未実装のため未テスト //CPPUNIT_TEST(test_set_configuration_parameter); //未実装のため未テスト CPPUNIT_TEST_SUITE_END(); private: CORBA::ORB_ptr m_pORB; PortableServer::POA_ptr m_pPOA; public: /*! * @brief Constructor */ SdoConfigurationTests() { int argc(0); char** argv(NULL); m_pORB = CORBA::ORB_init(argc, argv); m_pPOA = PortableServer::POA::_narrow( m_pORB->resolve_initial_references("RootPOA")); m_pPOA->the_POAManager()->activate(); } /*! * @brief Destructor */ ~SdoConfigurationTests() { } /*! * @brief Test initialization */ virtual void setUp() { usleep(100000); } /*! * @brief Test finalization */ virtual void tearDown() { } /*! * set_device_profile()メソッドとgetDeviceProfile()メソッドのテスト * * - set_device_profile()で設定したDeviceProfileを、getDeviceProfile()で正しく取得できるか? */ void test_set_device_profile_and_getDeviceProfile() { // std::cout << "test_set_device_profile_and_getDeviceProfile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // DeviceProfileを準備する SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 1"; properties[1].value <<= CORBA::Float(2.71828); devProf.properties = properties; } // set_device_profile()を呼出して、準備したDeviceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_device_profile(devProf)); // getDeviceProfile()で設定されているDeviceProfileを取り出し、設定したものと一致することを確認する const SDOPackage::DeviceProfile devProfRet = sdoCfg->getDeviceProfile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet.device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet.manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet.model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet.version)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(devProfRet.properties[0].name)); { CORBA::Float value; devProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(devProfRet.properties[1].name)); { CORBA::Float value; devProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_device_profile_and_getDeviceProfile() OUT" << std::endl; } /*! * @brief set_service_profile()メソッドとgetServiceProfile()メソッドのテスト * * - set_service_profile()で設定したServiceProfileを、getServiceProfile()で正しく取得できるか? */ void test_set_service_profile_and_getServiceProfile() { // std::cout << "test_set_service_profile_and_getServiceProfile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf; svcProf.id = "ID"; svcProf.interface_type = "INTERFACE_TYPE"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 1"; properties[1].value <<= CORBA::Float(2.71828); svcProf.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf)); // getServiceProfile()でServiceProfileを取得し、設定したものと一致しているか確認する const SDOPackage::ServiceProfile svcProfRet = sdoCfg->getServiceProfile("ID"); CPPUNIT_ASSERT_EQUAL(std::string("ID"), std::string(svcProfRet.id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"), std::string(svcProfRet.interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(svcProfRet.properties[0].name)); { CORBA::Float value; svcProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(svcProfRet.properties[1].name)); { CORBA::Float value; svcProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_service_profile_and_getServiceProfile() OUT" << std::endl; } /*! * @brief getServiceProfiles()メソッドのテスト * * - 登録されている複数のServiceProfileを、getServiceProfiles()で正しく取得できるか? */ void test_getServiceProfiles() { // std::cout << "test_getServiceProfiles() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // getServiceProfiles()で設定されているServiceProfile群を取得する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length()); // 設定したServiceProfileと一致しているか? { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } } { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value); } } sdoCfg->_remove_ref(); // std::cout << "test_getServiceProfiles() OUT" << std::endl; } /*! * @brief remove_service_profile()メソッドのテスト * * - 指定したIDを持つServiceProfileを正しく登録解除できるか? */ void test_remove_service_profile() { // std::cout << "test_remove_service_profile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
105  //CPPUNIT_TEST(test_get_configuration_parameter_value); //未実装のため未テスト //CPPUNIT_TEST(test_set_configuration_parameter); //未実装のため未テスト CPPUNIT_TEST_SUITE_END(); private: CORBA::ORB_ptr m_pORB; PortableServer::POA_ptr m_pPOA; public: /*! * @brief Constructor */ SdoConfigurationTests() { int argc(0); char** argv(NULL); m_pORB = CORBA::ORB_init(argc, argv); m_pPOA = PortableServer::POA::_narrow( m_pORB->resolve_initial_references("RootPOA")); m_pPOA->the_POAManager()->activate(); } /*! * @brief Destructor */ ~SdoConfigurationTests() { } /*! * @brief Test initialization */ virtual void setUp() { usleep(100000); } /*! * @brief Test finalization */ virtual void tearDown() { } /*! * set_device_profile()メソッドとgetDeviceProfile()メソッドのテスト * * - set_device_profile()で設定したDeviceProfileを、getDeviceProfile()で正しく取得できるか? */ void test_set_device_profile_and_getDeviceProfile() { // std::cout << "test_set_device_profile_and_getDeviceProfile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // DeviceProfileを準備する SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 1"; properties[1].value <<= CORBA::Float(2.71828); devProf.properties = properties; } // set_device_profile()を呼出して、準備したDeviceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_device_profile(devProf)); // getDeviceProfile()で設定されているDeviceProfileを取り出し、設定したものと一致することを確認する const SDOPackage::DeviceProfile devProfRet = sdoCfg->getDeviceProfile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet.device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet.manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet.model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet.version)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(devProfRet.properties[0].name)); { CORBA::Float value; devProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(devProfRet.properties[1].name)); { CORBA::Float value; devProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_device_profile_and_getDeviceProfile() OUT" << std::endl; } /*! * @brief set_service_profile()メソッドとgetServiceProfile()メソッドのテスト * * - set_service_profile()で設定したServiceProfileを、getServiceProfile()で正しく取得できるか? */ void test_set_service_profile_and_getServiceProfile() { // std::cout << "test_set_service_profile_and_getServiceProfile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf; svcProf.id = "ID"; svcProf.interface_type = "INTERFACE_TYPE"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 1"; properties[1].value <<= CORBA::Float(2.71828); svcProf.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf)); // getServiceProfile()でServiceProfileを取得し、設定したものと一致しているか確認する const SDOPackage::ServiceProfile svcProfRet = sdoCfg->getServiceProfile("ID"); CPPUNIT_ASSERT_EQUAL(std::string("ID"), std::string(svcProfRet.id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"), std::string(svcProfRet.interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(svcProfRet.properties[0].name)); { CORBA::Float value; svcProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(svcProfRet.properties[1].name)); { CORBA::Float value; svcProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_service_profile_and_getServiceProfile() OUT" << std::endl; } /*! * @brief getServiceProfiles()メソッドのテスト * * - 登録されている複数のServiceProfileを、getServiceProfiles()で正しく取得できるか? */ void test_getServiceProfiles() { // std::cout << "test_getServiceProfiles() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // getServiceProfiles()で設定されているServiceProfile群を取得する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length()); // 設定したServiceProfileと一致しているか? { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } } { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value); } } sdoCfg->_remove_ref(); // std::cout << "test_getServiceProfiles() OUT" << std::endl; } /*! * @brief remove_service_profile()メソッドのテスト * * - 指定したIDを持つServiceProfileを正しく登録解除できるか? */ void test_remove_service_profile() { // std::cout << "test_remove_service_profile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
106  //CPPUNIT_TEST(test_set_configuration_parameter); //未実装のため未テスト CPPUNIT_TEST_SUITE_END(); private: CORBA::ORB_ptr m_pORB; PortableServer::POA_ptr m_pPOA; public: /*! * @brief Constructor */ SdoConfigurationTests() { int argc(0); char** argv(NULL); m_pORB = CORBA::ORB_init(argc, argv); m_pPOA = PortableServer::POA::_narrow( m_pORB->resolve_initial_references("RootPOA")); m_pPOA->the_POAManager()->activate(); } /*! * @brief Destructor */ ~SdoConfigurationTests() { } /*! * @brief Test initialization */ virtual void setUp() { usleep(100000); } /*! * @brief Test finalization */ virtual void tearDown() { } /*! * set_device_profile()メソッドとgetDeviceProfile()メソッドのテスト * * - set_device_profile()で設定したDeviceProfileを、getDeviceProfile()で正しく取得できるか? */ void test_set_device_profile_and_getDeviceProfile() { // std::cout << "test_set_device_profile_and_getDeviceProfile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // DeviceProfileを準備する SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 1"; properties[1].value <<= CORBA::Float(2.71828); devProf.properties = properties; } // set_device_profile()を呼出して、準備したDeviceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_device_profile(devProf)); // getDeviceProfile()で設定されているDeviceProfileを取り出し、設定したものと一致することを確認する const SDOPackage::DeviceProfile devProfRet = sdoCfg->getDeviceProfile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet.device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet.manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet.model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet.version)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(devProfRet.properties[0].name)); { CORBA::Float value; devProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(devProfRet.properties[1].name)); { CORBA::Float value; devProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_device_profile_and_getDeviceProfile() OUT" << std::endl; } /*! * @brief set_service_profile()メソッドとgetServiceProfile()メソッドのテスト * * - set_service_profile()で設定したServiceProfileを、getServiceProfile()で正しく取得できるか? */ void test_set_service_profile_and_getServiceProfile() { // std::cout << "test_set_service_profile_and_getServiceProfile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf; svcProf.id = "ID"; svcProf.interface_type = "INTERFACE_TYPE"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 1"; properties[1].value <<= CORBA::Float(2.71828); svcProf.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf)); // getServiceProfile()でServiceProfileを取得し、設定したものと一致しているか確認する const SDOPackage::ServiceProfile svcProfRet = sdoCfg->getServiceProfile("ID"); CPPUNIT_ASSERT_EQUAL(std::string("ID"), std::string(svcProfRet.id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"), std::string(svcProfRet.interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(svcProfRet.properties[0].name)); { CORBA::Float value; svcProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(svcProfRet.properties[1].name)); { CORBA::Float value; svcProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_service_profile_and_getServiceProfile() OUT" << std::endl; } /*! * @brief getServiceProfiles()メソッドのテスト * * - 登録されている複数のServiceProfileを、getServiceProfiles()で正しく取得できるか? */ void test_getServiceProfiles() { // std::cout << "test_getServiceProfiles() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // getServiceProfiles()で設定されているServiceProfile群を取得する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length()); // 設定したServiceProfileと一致しているか? { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } } { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value); } } sdoCfg->_remove_ref(); // std::cout << "test_getServiceProfiles() OUT" << std::endl; } /*! * @brief remove_service_profile()メソッドのテスト * * - 指定したIDを持つServiceProfileを正しく登録解除できるか? */ void test_remove_service_profile() { // std::cout << "test_remove_service_profile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
107 
108  CPPUNIT_TEST_SUITE_END();
109 
110  private:
111  CORBA::ORB_ptr m_pORB;
112  PortableServer::POA_ptr m_pPOA;
113 
114  public:
119  {
120  int argc(0);
121  char** argv(NULL);
122  m_pORB = CORBA::ORB_init(argc, argv);
123  m_pPOA = PortableServer::POA::_narrow(
124  m_pORB->resolve_initial_references("RootPOA"));
125  m_pPOA->the_POAManager()->activate();
126  }
127 
132  {
133  }
134 
138  virtual void setUp()
139  {
140  usleep(100000);
141  }
142 
146  virtual void tearDown()
147  {
148  }
149 
156  {
157 // std::cout << "test_set_device_profile_and_getDeviceProfile() IN" << std::endl;
158  coil::Properties cfgAdminProp;
159  RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
160  SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
161 
162  // DeviceProfileを準備する SDOPackage::DeviceProfile devProf; devProf.device_type = "DEVICE_TYPE"; devProf.manufacturer = "MANUFACTURER"; devProf.model = "MODEL"; devProf.version = "VERSION"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 1"; properties[1].value <<= CORBA::Float(2.71828); devProf.properties = properties; } // set_device_profile()を呼出して、準備したDeviceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_device_profile(devProf)); // getDeviceProfile()で設定されているDeviceProfileを取り出し、設定したものと一致することを確認する const SDOPackage::DeviceProfile devProfRet = sdoCfg->getDeviceProfile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet.device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet.manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet.model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet.version)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(devProfRet.properties[0].name)); { CORBA::Float value; devProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(devProfRet.properties[1].name)); { CORBA::Float value; devProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_device_profile_and_getDeviceProfile() OUT" << std::endl; } /*! * @brief set_service_profile()メソッドとgetServiceProfile()メソッドのテスト * * - set_service_profile()で設定したServiceProfileを、getServiceProfile()で正しく取得できるか? */ void test_set_service_profile_and_getServiceProfile() { // std::cout << "test_set_service_profile_and_getServiceProfile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf; svcProf.id = "ID"; svcProf.interface_type = "INTERFACE_TYPE"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 1"; properties[1].value <<= CORBA::Float(2.71828); svcProf.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf)); // getServiceProfile()でServiceProfileを取得し、設定したものと一致しているか確認する const SDOPackage::ServiceProfile svcProfRet = sdoCfg->getServiceProfile("ID"); CPPUNIT_ASSERT_EQUAL(std::string("ID"), std::string(svcProfRet.id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"), std::string(svcProfRet.interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(svcProfRet.properties[0].name)); { CORBA::Float value; svcProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(svcProfRet.properties[1].name)); { CORBA::Float value; svcProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_service_profile_and_getServiceProfile() OUT" << std::endl; } /*! * @brief getServiceProfiles()メソッドのテスト * * - 登録されている複数のServiceProfileを、getServiceProfiles()で正しく取得できるか? */ void test_getServiceProfiles() { // std::cout << "test_getServiceProfiles() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // getServiceProfiles()で設定されているServiceProfile群を取得する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length()); // 設定したServiceProfileと一致しているか? { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } } { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value); } } sdoCfg->_remove_ref(); // std::cout << "test_getServiceProfiles() OUT" << std::endl; } /*! * @brief remove_service_profile()メソッドのテスト * * - 指定したIDを持つServiceProfileを正しく登録解除できるか? */ void test_remove_service_profile() { // std::cout << "test_remove_service_profile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
163  SDOPackage::DeviceProfile devProf;
164  devProf.device_type = "DEVICE_TYPE";
165  devProf.manufacturer = "MANUFACTURER";
166  devProf.model = "MODEL";
167  devProf.version = "VERSION";
168  {
169  SDOPackage::NVList properties;
170  properties.length(2);
171  properties[0].name = "name 0";
172  properties[0].value <<= CORBA::Float(3.14159);
173  properties[1].name = "name 1";
174  properties[1].value <<= CORBA::Float(2.71828);
175  devProf.properties = properties;
176  }
177 
178  // set_device_profile()を呼出して、準備したDeviceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_device_profile(devProf)); // getDeviceProfile()で設定されているDeviceProfileを取り出し、設定したものと一致することを確認する const SDOPackage::DeviceProfile devProfRet = sdoCfg->getDeviceProfile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet.device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet.manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet.model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet.version)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(devProfRet.properties[0].name)); { CORBA::Float value; devProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(devProfRet.properties[1].name)); { CORBA::Float value; devProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_device_profile_and_getDeviceProfile() OUT" << std::endl; } /*! * @brief set_service_profile()メソッドとgetServiceProfile()メソッドのテスト * * - set_service_profile()で設定したServiceProfileを、getServiceProfile()で正しく取得できるか? */ void test_set_service_profile_and_getServiceProfile() { // std::cout << "test_set_service_profile_and_getServiceProfile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf; svcProf.id = "ID"; svcProf.interface_type = "INTERFACE_TYPE"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 1"; properties[1].value <<= CORBA::Float(2.71828); svcProf.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf)); // getServiceProfile()でServiceProfileを取得し、設定したものと一致しているか確認する const SDOPackage::ServiceProfile svcProfRet = sdoCfg->getServiceProfile("ID"); CPPUNIT_ASSERT_EQUAL(std::string("ID"), std::string(svcProfRet.id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"), std::string(svcProfRet.interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(svcProfRet.properties[0].name)); { CORBA::Float value; svcProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(svcProfRet.properties[1].name)); { CORBA::Float value; svcProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_service_profile_and_getServiceProfile() OUT" << std::endl; } /*! * @brief getServiceProfiles()メソッドのテスト * * - 登録されている複数のServiceProfileを、getServiceProfiles()で正しく取得できるか? */ void test_getServiceProfiles() { // std::cout << "test_getServiceProfiles() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // getServiceProfiles()で設定されているServiceProfile群を取得する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length()); // 設定したServiceProfileと一致しているか? { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } } { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value); } } sdoCfg->_remove_ref(); // std::cout << "test_getServiceProfiles() OUT" << std::endl; } /*! * @brief remove_service_profile()メソッドのテスト * * - 指定したIDを持つServiceProfileを正しく登録解除できるか? */ void test_remove_service_profile() { // std::cout << "test_remove_service_profile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
179  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_device_profile(devProf));
180 
181  // getDeviceProfile()で設定されているDeviceProfileを取り出し、設定したものと一致することを確認する const SDOPackage::DeviceProfile devProfRet = sdoCfg->getDeviceProfile(); CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"), std::string(devProfRet.device_type)); CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"), std::string(devProfRet.manufacturer)); CPPUNIT_ASSERT_EQUAL(std::string("MODEL"), std::string(devProfRet.model)); CPPUNIT_ASSERT_EQUAL(std::string("VERSION"), std::string(devProfRet.version)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(devProfRet.properties[0].name)); { CORBA::Float value; devProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(devProfRet.properties[1].name)); { CORBA::Float value; devProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_device_profile_and_getDeviceProfile() OUT" << std::endl; } /*! * @brief set_service_profile()メソッドとgetServiceProfile()メソッドのテスト * * - set_service_profile()で設定したServiceProfileを、getServiceProfile()で正しく取得できるか? */ void test_set_service_profile_and_getServiceProfile() { // std::cout << "test_set_service_profile_and_getServiceProfile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf; svcProf.id = "ID"; svcProf.interface_type = "INTERFACE_TYPE"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 1"; properties[1].value <<= CORBA::Float(2.71828); svcProf.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf)); // getServiceProfile()でServiceProfileを取得し、設定したものと一致しているか確認する const SDOPackage::ServiceProfile svcProfRet = sdoCfg->getServiceProfile("ID"); CPPUNIT_ASSERT_EQUAL(std::string("ID"), std::string(svcProfRet.id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"), std::string(svcProfRet.interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(svcProfRet.properties[0].name)); { CORBA::Float value; svcProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(svcProfRet.properties[1].name)); { CORBA::Float value; svcProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_service_profile_and_getServiceProfile() OUT" << std::endl; } /*! * @brief getServiceProfiles()メソッドのテスト * * - 登録されている複数のServiceProfileを、getServiceProfiles()で正しく取得できるか? */ void test_getServiceProfiles() { // std::cout << "test_getServiceProfiles() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // getServiceProfiles()で設定されているServiceProfile群を取得する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length()); // 設定したServiceProfileと一致しているか? { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } } { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value); } } sdoCfg->_remove_ref(); // std::cout << "test_getServiceProfiles() OUT" << std::endl; } /*! * @brief remove_service_profile()メソッドのテスト * * - 指定したIDを持つServiceProfileを正しく登録解除できるか? */ void test_remove_service_profile() { // std::cout << "test_remove_service_profile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
182  const SDOPackage::DeviceProfile devProfRet = sdoCfg->getDeviceProfile();
183  CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"),
184  std::string(devProfRet.device_type));
185  CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"),
186  std::string(devProfRet.manufacturer));
187  CPPUNIT_ASSERT_EQUAL(std::string("MODEL"),
188  std::string(devProfRet.model));
189  CPPUNIT_ASSERT_EQUAL(std::string("VERSION"),
190  std::string(devProfRet.version));
191  CPPUNIT_ASSERT_EQUAL(std::string("name 0"),
192  std::string(devProfRet.properties[0].name));
193  {
194  CORBA::Float value; devProfRet.properties[0].value >>= value;
195  CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value);
196  }
197  CPPUNIT_ASSERT_EQUAL(std::string("name 1"),
198  std::string(devProfRet.properties[1].name));
199  {
200  CORBA::Float value; devProfRet.properties[1].value >>= value;
201  CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value);
202  }
203  sdoCfg->_remove_ref();
204 // std::cout << "test_set_device_profile_and_getDeviceProfile() OUT" << std::endl;
205  }
206 
213  {
214 // std::cout << "test_set_service_profile_and_getServiceProfile() IN" << std::endl;
215  coil::Properties cfgAdminProp;
216  RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
217  SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
218 
219  // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf; svcProf.id = "ID"; svcProf.interface_type = "INTERFACE_TYPE"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 1"; properties[1].value <<= CORBA::Float(2.71828); svcProf.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf)); // getServiceProfile()でServiceProfileを取得し、設定したものと一致しているか確認する const SDOPackage::ServiceProfile svcProfRet = sdoCfg->getServiceProfile("ID"); CPPUNIT_ASSERT_EQUAL(std::string("ID"), std::string(svcProfRet.id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"), std::string(svcProfRet.interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(svcProfRet.properties[0].name)); { CORBA::Float value; svcProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(svcProfRet.properties[1].name)); { CORBA::Float value; svcProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_service_profile_and_getServiceProfile() OUT" << std::endl; } /*! * @brief getServiceProfiles()メソッドのテスト * * - 登録されている複数のServiceProfileを、getServiceProfiles()で正しく取得できるか? */ void test_getServiceProfiles() { // std::cout << "test_getServiceProfiles() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // getServiceProfiles()で設定されているServiceProfile群を取得する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length()); // 設定したServiceProfileと一致しているか? { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } } { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value); } } sdoCfg->_remove_ref(); // std::cout << "test_getServiceProfiles() OUT" << std::endl; } /*! * @brief remove_service_profile()メソッドのテスト * * - 指定したIDを持つServiceProfileを正しく登録解除できるか? */ void test_remove_service_profile() { // std::cout << "test_remove_service_profile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
220  SDOPackage::ServiceProfile svcProf;
221  svcProf.id = "ID";
222  svcProf.interface_type = "INTERFACE_TYPE";
223  {
224  SDOPackage::NVList properties;
225  properties.length(2);
226  properties[0].name = "name 0";
227  properties[0].value <<= CORBA::Float(3.14159);
228  properties[1].name = "name 1";
229  properties[1].value <<= CORBA::Float(2.71828);
230  svcProf.properties = properties;
231  }
232 
233  // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf)); // getServiceProfile()でServiceProfileを取得し、設定したものと一致しているか確認する const SDOPackage::ServiceProfile svcProfRet = sdoCfg->getServiceProfile("ID"); CPPUNIT_ASSERT_EQUAL(std::string("ID"), std::string(svcProfRet.id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"), std::string(svcProfRet.interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(svcProfRet.properties[0].name)); { CORBA::Float value; svcProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(svcProfRet.properties[1].name)); { CORBA::Float value; svcProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_service_profile_and_getServiceProfile() OUT" << std::endl; } /*! * @brief getServiceProfiles()メソッドのテスト * * - 登録されている複数のServiceProfileを、getServiceProfiles()で正しく取得できるか? */ void test_getServiceProfiles() { // std::cout << "test_getServiceProfiles() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // getServiceProfiles()で設定されているServiceProfile群を取得する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length()); // 設定したServiceProfileと一致しているか? { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } } { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value); } } sdoCfg->_remove_ref(); // std::cout << "test_getServiceProfiles() OUT" << std::endl; } /*! * @brief remove_service_profile()メソッドのテスト * * - 指定したIDを持つServiceProfileを正しく登録解除できるか? */ void test_remove_service_profile() { // std::cout << "test_remove_service_profile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
234  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf));
235 
236  // getServiceProfile()でServiceProfileを取得し、設定したものと一致しているか確認する const SDOPackage::ServiceProfile svcProfRet = sdoCfg->getServiceProfile("ID"); CPPUNIT_ASSERT_EQUAL(std::string("ID"), std::string(svcProfRet.id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"), std::string(svcProfRet.interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0"), std::string(svcProfRet.properties[0].name)); { CORBA::Float value; svcProfRet.properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1"), std::string(svcProfRet.properties[1].name)); { CORBA::Float value; svcProfRet.properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } sdoCfg->_remove_ref(); // std::cout << "test_set_service_profile_and_getServiceProfile() OUT" << std::endl; } /*! * @brief getServiceProfiles()メソッドのテスト * * - 登録されている複数のServiceProfileを、getServiceProfiles()で正しく取得できるか? */ void test_getServiceProfiles() { // std::cout << "test_getServiceProfiles() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // getServiceProfiles()で設定されているServiceProfile群を取得する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length()); // 設定したServiceProfileと一致しているか? { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } } { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value); } } sdoCfg->_remove_ref(); // std::cout << "test_getServiceProfiles() OUT" << std::endl; } /*! * @brief remove_service_profile()メソッドのテスト * * - 指定したIDを持つServiceProfileを正しく登録解除できるか? */ void test_remove_service_profile() { // std::cout << "test_remove_service_profile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
237  const SDOPackage::ServiceProfile svcProfRet = sdoCfg->getServiceProfile("ID");
238  CPPUNIT_ASSERT_EQUAL(std::string("ID"), std::string(svcProfRet.id));
239  CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"),
240  std::string(svcProfRet.interface_type));
241  CPPUNIT_ASSERT_EQUAL(std::string("name 0"),
242  std::string(svcProfRet.properties[0].name));
243  {
244  CORBA::Float value; svcProfRet.properties[0].value >>= value;
245  CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value);
246  }
247  CPPUNIT_ASSERT_EQUAL(std::string("name 1"),
248  std::string(svcProfRet.properties[1].name));
249  {
250  CORBA::Float value; svcProfRet.properties[1].value >>= value;
251  CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value);
252  }
253  sdoCfg->_remove_ref();
254 // std::cout << "test_set_service_profile_and_getServiceProfile() OUT" << std::endl;
255  }
256 
263  {
264 // std::cout << "test_getServiceProfiles() IN" << std::endl;
265  coil::Properties cfgAdminProp;
266  RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
267  SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
268 
269  // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // getServiceProfiles()で設定されているServiceProfile群を取得する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length()); // 設定したServiceProfileと一致しているか? { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } } { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value); } } sdoCfg->_remove_ref(); // std::cout << "test_getServiceProfiles() OUT" << std::endl; } /*! * @brief remove_service_profile()メソッドのテスト * * - 指定したIDを持つServiceProfileを正しく登録解除できるか? */ void test_remove_service_profile() { // std::cout << "test_remove_service_profile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
270  SDOPackage::ServiceProfile svcProf0;
271  svcProf0.id = "ID 0";
272  svcProf0.interface_type = "INTERFACE_TYPE 0";
273  {
274  SDOPackage::NVList properties;
275  properties.length(2);
276  properties[0].name = "name 0-0";
277  properties[0].value <<= CORBA::Float(3.14159);
278  properties[1].name = "name 0-1";
279  properties[1].value <<= CORBA::Float(2.71828);
280  svcProf0.properties = properties;
281  }
282 
283  SDOPackage::ServiceProfile svcProf1;
284  svcProf1.id = "ID 1";
285  svcProf1.interface_type = "INTERFACE_TYPE 1";
286  {
287  SDOPackage::NVList properties;
288  properties.length(2);
289  properties[0].name = "name 1-0";
290  properties[0].value <<= CORBA::Float(1.41421356);
291  properties[1].name = "name 1-1";
292  properties[1].value <<= CORBA::Float(1.7320508);
293  svcProf1.properties = properties;
294  }
295 
296  // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // getServiceProfiles()で設定されているServiceProfile群を取得する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length()); // 設定したServiceProfileと一致しているか? { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } } { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value); } } sdoCfg->_remove_ref(); // std::cout << "test_getServiceProfiles() OUT" << std::endl; } /*! * @brief remove_service_profile()メソッドのテスト * * - 指定したIDを持つServiceProfileを正しく登録解除できるか? */ void test_remove_service_profile() { // std::cout << "test_remove_service_profile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
297  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0));
298  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1));
299 
300  // getServiceProfiles()で設定されているServiceProfile群を取得する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length()); // 設定したServiceProfileと一致しているか? { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value); } } { CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(svcProfList[idx].id)); CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"), std::string(svcProfList[idx].interface_type)); CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"), std::string(svcProfList[idx].properties[0].name)); { CORBA::Float value; svcProfList[idx].properties[0].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value); } CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"), std::string(svcProfList[idx].properties[1].name)); { CORBA::Float value; svcProfList[idx].properties[1].value >>= value; CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value); } } sdoCfg->_remove_ref(); // std::cout << "test_getServiceProfiles() OUT" << std::endl; } /*! * @brief remove_service_profile()メソッドのテスト * * - 指定したIDを持つServiceProfileを正しく登録解除できるか? */ void test_remove_service_profile() { // std::cout << "test_remove_service_profile() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
301  const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles();
302  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length());
303 
304  // 設定したServiceProfileと一致しているか?
305  {
306  CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"));
307 
308  CPPUNIT_ASSERT_EQUAL(std::string("ID 0"),
309  std::string(svcProfList[idx].id));
310  CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"),
311  std::string(svcProfList[idx].interface_type));
312  CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"),
313  std::string(svcProfList[idx].properties[0].name));
314  {
315  CORBA::Float value; svcProfList[idx].properties[0].value >>= value;
316  CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value);
317  }
318  CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"),
319  std::string(svcProfList[idx].properties[1].name));
320  {
321  CORBA::Float value; svcProfList[idx].properties[1].value >>= value;
322  CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value);
323  }
324  }
325 
326  {
327  CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"));
328 
329  CPPUNIT_ASSERT_EQUAL(std::string("ID 1"),
330  std::string(svcProfList[idx].id));
331  CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"),
332  std::string(svcProfList[idx].interface_type));
333  CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"),
334  std::string(svcProfList[idx].properties[0].name));
335  {
336  CORBA::Float value; svcProfList[idx].properties[0].value >>= value;
337  CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value);
338  }
339  CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"),
340  std::string(svcProfList[idx].properties[1].name));
341  {
342  CORBA::Float value; svcProfList[idx].properties[1].value >>= value;
343  CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value);
344  }
345  }
346  sdoCfg->_remove_ref();
347 // std::cout << "test_getServiceProfiles() OUT" << std::endl;
348  }
349 
356  {
357 // std::cout << "test_remove_service_profile() IN" << std::endl;
358  coil::Properties cfgAdminProp;
359  RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
360  SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
361 
362  // ServiceProfileを準備する SDOPackage::ServiceProfile svcProf0; svcProf0.id = "ID 0"; svcProf0.interface_type = "INTERFACE_TYPE 0"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 0-0"; properties[0].value <<= CORBA::Float(3.14159); properties[1].name = "name 0-1"; properties[1].value <<= CORBA::Float(2.71828); svcProf0.properties = properties; } SDOPackage::ServiceProfile svcProf1; svcProf1.id = "ID 1"; svcProf1.interface_type = "INTERFACE_TYPE 1"; { SDOPackage::NVList properties; properties.length(2); properties[0].name = "name 1-0"; properties[0].value <<= CORBA::Float(1.41421356); properties[1].name = "name 1-1"; properties[1].value <<= CORBA::Float(1.7320508); svcProf1.properties = properties; } // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
363  SDOPackage::ServiceProfile svcProf0;
364  svcProf0.id = "ID 0";
365  svcProf0.interface_type = "INTERFACE_TYPE 0";
366  {
367  SDOPackage::NVList properties;
368  properties.length(2);
369  properties[0].name = "name 0-0";
370  properties[0].value <<= CORBA::Float(3.14159);
371  properties[1].name = "name 0-1";
372  properties[1].value <<= CORBA::Float(2.71828);
373  svcProf0.properties = properties;
374  }
375 
376  SDOPackage::ServiceProfile svcProf1;
377  svcProf1.id = "ID 1";
378  svcProf1.interface_type = "INTERFACE_TYPE 1";
379  {
380  SDOPackage::NVList properties;
381  properties.length(2);
382  properties[0].name = "name 1-0";
383  properties[0].value <<= CORBA::Float(1.41421356);
384  properties[1].name = "name 1-1";
385  properties[1].value <<= CORBA::Float(1.7320508);
386  svcProf1.properties = properties;
387  }
388 
389  // ServiceProfileを設定する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1)); // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
390  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0));
391  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1));
392 
393  // 設定したServiceProfileのうち、片方を登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0")); // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
394  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0"));
395 
396  // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length()); CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"))); // 登録解除していないものは、依然として含まれているか? CPPUNIT_ASSERT_EQUAL(CORBA::Long(0), CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"))); sdoCfg->_remove_ref(); // std::cout << "test_remove_service_profile() OUT" << std::endl; } /* * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
397  const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles();
398  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length());
399  CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1),
400  CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")));
401 
402  // 登録解除していないものは、依然として含まれているか?
403  CPPUNIT_ASSERT_EQUAL(CORBA::Long(0),
404  CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")));
405 
406  sdoCfg->_remove_ref();
407 // std::cout << "test_remove_service_profile() OUT" << std::endl;
408  }
409 
410  /*
411  * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト * * - add_organization()でOrganization_ptrインスタンスを登録できるか? * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか? */ void test_add_organization_and_getOrganizations() { // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
412  *
413  * - add_organization()でOrganization_ptrインスタンスを登録できるか?
414  * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか?
415  */
417  {
418 // std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl;
419  coil::Properties cfgAdminProp;
420  RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
421  SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
422 
423  // Organizationを2つ登録する SDOPackage::Organization_var org1; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org1._retn())); SDOPackage::Organization_var org2; CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(org2._retn())); // 取得されるOrganizationの数は、意図どおり2つか? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length()); sdoCfg->_remove_ref(); // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl; } /* * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
424  SDOPackage::Organization_var org1;
425  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true),
426  sdoCfg->add_organization(org1._retn()));
427 
428  SDOPackage::Organization_var org2;
429  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true),
430  sdoCfg->add_organization(org2._retn()));
431 
432  // 取得されるOrganizationの数は、意図どおり2つか?
433  SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations();
434  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length());
435 
436  sdoCfg->_remove_ref();
437 // std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl;
438  }
439 
440  /*
441  * @brief remove_organization()のテスト * - add_organization()で登録し、remove_organization()で正しく削除できるか? */ void test_remove_organization() { // std::cout << "test_remove_organization() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); RTC::RTObject_impl* rtobj; SDOPackage::Organization_impl* m_pOi; RTC::Manager& mgr(RTC::Manager::instance()); rtobj = new ::RTC::RTObject_impl(&mgr); m_pOi = new Organization_impl(rtobj->getObjRef()); // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
442  * - add_organization()で登録し、remove_organization()で正しく削除できるか?
443  */
445  {
446 // std::cout << "test_remove_organization() IN" << std::endl;
447  coil::Properties cfgAdminProp;
448  RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
449  SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
450  RTC::RTObject_impl* rtobj;
453  rtobj = new ::RTC::RTObject_impl(&mgr);
454  m_pOi = new Organization_impl(rtobj->getObjRef());
455 
456  // Organizationを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_organization(m_pOi->getObjRef())); // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
457  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true),
458  sdoCfg->add_organization(m_pOi->getObjRef()));
459 
460  // organization_idを取得する std::string id(m_pOi->get_organization_id()); // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
461  std::string id(m_pOi->get_organization_id());
462 
463  // 登録したOrganizationを削除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_organization(id.c_str())); // 取得されるOrganizationの数は、意図どおり0件か? SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations(); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length()); m_pOi->_remove_ref(); rtobj->_remove_ref(); sdoCfg->_remove_ref(); // std::cout << "test_remove_organization() OUT" << std::endl; } /* * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
464  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true),
465  sdoCfg->remove_organization(id.c_str()));
466 
467  // 取得されるOrganizationの数は、意図どおり0件か?
468  SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations();
469  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length());
470 
471  m_pOi->_remove_ref();
472  rtobj->_remove_ref();
473  sdoCfg->_remove_ref();
474 // std::cout << "test_remove_organization() OUT" << std::endl;
475  }
476 
477  /*
478  * @brief get_configuration_parameters()のテスト */ void test_get_configuration_parameters() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameters() IN" << std::endl; // std::cout << "test_get_configuration_parameters() OUT" << std::endl; } /*! * @brief get_configuration_parameter_values()のテスト */ void test_get_configuration_parameter_values() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl; // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl; } /*! * @brief get_configuration_parameter_value()のテスト */ void test_get_configuration_parameter_value() { // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl; // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl; } /*! * @brief set_configuration_parameter()のテスト */ void test_set_configuration_parameter() { // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が // 未実装であるため、本テストも未実装である。 // std::cout << "test_set_configuration_parameter() IN" << std::endl; // std::cout << "test_set_configuration_parameter() OUT" << std::endl; } /*! * @brief add/get_configuration_set()メソッドのテスト * * - ConfigurationSetをadd_configuration_set()で正常に登録できるか? * - add_configuration_set()で登録したConfigurationSetを、get_configuration_set()で正しく取得できるか? */ void test_add_configuration_set_and_get_configuration_set() { // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
479  */
481  {
482  // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が
483  // 未実装であるため、本テストも未実装である。
484 // std::cout << "test_get_configuration_parameters() IN" << std::endl;
485 // std::cout << "test_get_configuration_parameters() OUT" << std::endl;
486  }
487 
492  {
493  // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が
494  // 未実装であるため、本テストも未実装である。
495 // std::cout << "test_get_configuration_parameter_values() IN" << std::endl;
496 // std::cout << "test_get_configuration_parameter_values() OUT" << std::endl;
497  }
498 
503  {
504  // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が
505  // 未実装であるため、本テストも未実装である。
506 // std::cout << "test_get_configuration_parameter_value() IN" << std::endl;
507 // std::cout << "test_get_configuration_parameter_value() OUT" << std::endl;
508  }
509 
514  {
515  // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が
516  // 未実装であるため、本テストも未実装である。
517 // std::cout << "test_set_configuration_parameter() IN" << std::endl;
518 // std::cout << "test_set_configuration_parameter() OUT" << std::endl;
519  }
520 
528  {
529 // std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl;
530  coil::Properties cfgAdminProp;
531  RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
532  SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
533 
534  // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
535  SDOPackage::ConfigurationSet cfgSet0;
536  cfgSet0.id = "ID 0";
537  cfgSet0.description = "DESCRIPTION 0";
538  cfgSet0.configuration_data.length(2);
539  cfgSet0.configuration_data[0].name = "NAME 0-0";
540  cfgSet0.configuration_data[0].value <<= "3.14159";
541  cfgSet0.configuration_data[1].name = "NAME 0-1";
542  cfgSet0.configuration_data[1].value <<= "2.71828";
543 
544  SDOPackage::ConfigurationSet cfgSet1;
545  cfgSet1.id = "ID 1";
546  cfgSet1.description = "DESCRIPTION 1";
547  cfgSet1.configuration_data.length(2);
548  cfgSet1.configuration_data[0].name = "NAME 1-0";
549  cfgSet1.configuration_data[0].value <<= "1.41421356";
550  cfgSet1.configuration_data[1].name = "NAME 1-1";
551  cfgSet1.configuration_data[1].value <<= "1.7320508";
552 
553  // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetを正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0"); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } sdoCfg->_remove_ref(); // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl; } /*! * @brief remove_configuration_set()メソッドのテスト * * - 登録済みのConfigurationSetを正しく登録解除できるか? * - 登録されていないIDを指定した場合、意図どおり例外がスローされるか? */ void test_remove_configuration_set() { // std::cout << "test_remove_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
554  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0));
555  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1));
556 
557  // 登録したConfigurationSetを正しく取得できるか?
558  SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0");
559  CPPUNIT_ASSERT_EQUAL(std::string("ID 0"),
560  std::string(cfgSetRet0->id));
561 //Deleted this test, because description was not used.
562 // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"),
563 // std::string(cfgSetRet0->description));
564  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2),
565  cfgSetRet0->configuration_data.length());
566  CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"),
567  std::string(cfgSetRet0->configuration_data[0].name));
568  {
569  const char* value; cfgSetRet0->configuration_data[0].value >>= value;
570  CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value));
571  }
572  CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"),
573  std::string(cfgSetRet0->configuration_data[1].name));
574  {
575  const char* value; cfgSetRet0->configuration_data[1].value >>= value;
576  CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value));
577  }
578 
579  SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1");
580  CPPUNIT_ASSERT_EQUAL(std::string("ID 1"),
581  std::string(cfgSetRet1->id));
582 //Deleted this test, because description was not used.
583 // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"),
584 // std::string(cfgSetRet1->description));
585  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2),
586  cfgSetRet1->configuration_data.length());
587  CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"),
588  std::string(cfgSetRet1->configuration_data[0].name));
589  {
590  const char* value; cfgSetRet1->configuration_data[0].value >>= value;
591  CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value));
592  }
593  CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"),
594  std::string(cfgSetRet1->configuration_data[1].name));
595  {
596  const char* value; cfgSetRet1->configuration_data[1].value >>= value;
597  CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value));
598  }
599 
600  sdoCfg->_remove_ref();
601 // std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl;
602  }
603 
611  {
612 // std::cout << "test_remove_configuration_set() IN" << std::endl;
613  coil::Properties cfgAdminProp;
614  RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
615  SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
616 
617  // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
618  SDOPackage::ConfigurationSet cfgSet0;
619  cfgSet0.id = "ID 0";
620  cfgSet0.description = "DESCRIPTION 0";
621  cfgSet0.configuration_data.length(2);
622  cfgSet0.configuration_data[0].name = "NAME 0-0";
623  cfgSet0.configuration_data[0].value <<= "3.14159";
624  cfgSet0.configuration_data[1].name = "NAME 0-1";
625  cfgSet0.configuration_data[1].value <<= "2.71828";
626 
627  SDOPackage::ConfigurationSet cfgSet1;
628  cfgSet1.id = "ID 1";
629  cfgSet1.description = "DESCRIPTION 1";
630  cfgSet1.configuration_data.length(2);
631  cfgSet1.configuration_data[0].name = "NAME 1-0";
632  cfgSet1.configuration_data[0].value <<= "1.41421356";
633  cfgSet1.configuration_data[1].name = "NAME 1-1";
634  cfgSet1.configuration_data[1].value <<= "1.7320508";
635 
636  // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
637  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0));
638  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1));
639 
640  // 登録したうち、片方のConfigurationSetを登録解除する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0")); // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set("ID 0"); CPPUNIT_FAIL("ID 0 was not removed."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 空のidを指定して、get_configuration_set()呼出を試みて、 // 意図どおりに例外がスローされるか? try { sdoCfg->get_configuration_set(""); CPPUNIT_FAIL("ID Not set."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} // 登録解除していないConfigurationSetは、依然として取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか? try { sdoCfg->remove_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} catch (...) {} sdoCfg->_remove_ref(); // std::cout << "test_remove_configuration_set() OUT" << std::endl; } /*! * @brief set_configuration_set_values()メソッドのテスト * * - 登録済みのConfigurationSetのIDを指定して、正しくConfigurationSetを更新できるか? * - 存在しないIDを指定した場合に、意図どおりに例外がスローされるか? */ void test_set_configuration_set_values() { // std::cout << "test_set_configuration_set_values() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
641  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0"));
642 
643  // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、
644  // 意図どおりに例外がスローされるか?
645  try
646  {
647  sdoCfg->get_configuration_set("ID 0");
648  CPPUNIT_FAIL("ID 0 was not removed.");
649  }
650  catch (SDOPackage::InvalidParameter expected) {}
651  catch (...) {}
652 
653  // 空のidを指定して、get_configuration_set()呼出を試みて、
654  // 意図どおりに例外がスローされるか?
655  try
656  {
657  sdoCfg->get_configuration_set("");
658  CPPUNIT_FAIL("ID Not set.");
659  }
660  catch (SDOPackage::InvalidParameter expected) {}
661  catch (...) {}
662 
663  // 登録解除していないConfigurationSetは、依然として取得できるか?
664  SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1");
665  CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id));
666 
667  // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか?
668  try
669  {
670  sdoCfg->remove_configuration_set("inexist ID");
671  CPPUNIT_FAIL("Exception not thrown.");
672  }
673  catch (SDOPackage::InvalidParameter expected) {}
674  catch (...) {}
675 
676  sdoCfg->_remove_ref();
677 // std::cout << "test_remove_configuration_set() OUT" << std::endl;
678  }
679 
687  {
688 // std::cout << "test_set_configuration_set_values() IN" << std::endl;
689  coil::Properties cfgAdminProp;
690  RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
691  SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
692 
693  // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; SDOPackage::ConfigurationSet cfgSet1_Modified; cfgSet1_Modified.id = "ID 1"; cfgSet1_Modified.description = "DESCRIPTION 1 M"; cfgSet1_Modified.configuration_data.length(2); cfgSet1_Modified.configuration_data[0].name = "NAME 1-0"; cfgSet1_Modified.configuration_data[0].value <<= "2.23620679"; cfgSet1_Modified.configuration_data[1].name = "NAME 1-1"; cfgSet1_Modified.configuration_data[1].value <<= "2.44948974"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
694  SDOPackage::ConfigurationSet cfgSet0;
695  cfgSet0.id = "ID 0";
696  cfgSet0.description = "DESCRIPTION 0";
697  cfgSet0.configuration_data.length(2);
698  cfgSet0.configuration_data[0].name = "NAME 0-0";
699  cfgSet0.configuration_data[0].value <<= "3.14159";
700  cfgSet0.configuration_data[1].name = "NAME 0-1";
701  cfgSet0.configuration_data[1].value <<= "2.71828";
702 
703  SDOPackage::ConfigurationSet cfgSet1;
704  cfgSet1.id = "ID 1";
705  cfgSet1.description = "DESCRIPTION 1";
706  cfgSet1.configuration_data.length(2);
707  cfgSet1.configuration_data[0].name = "NAME 1-0";
708  cfgSet1.configuration_data[0].value <<= "1.41421356";
709  cfgSet1.configuration_data[1].name = "NAME 1-1";
710  cfgSet1.configuration_data[1].value <<= "1.7320508";
711 
712  SDOPackage::ConfigurationSet cfgSet1_Modified;
713  cfgSet1_Modified.id = "ID 1";
714  cfgSet1_Modified.description = "DESCRIPTION 1 M";
715  cfgSet1_Modified.configuration_data.length(2);
716  cfgSet1_Modified.configuration_data[0].name = "NAME 1-0";
717  cfgSet1_Modified.configuration_data[0].value <<= "2.23620679";
718  cfgSet1_Modified.configuration_data[1].name = "NAME 1-1";
719  cfgSet1_Modified.configuration_data[1].value <<= "2.44948974";
720 
721  // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
722  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0));
723  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1));
724 
725  // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_configuration_set_values(cfgSet1_Modified)); // 更新したConfigurationSetを、正しく取得できるか? SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1"); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"), // std::string(cfgSetRet->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet->configuration_data.length()); { const char* value; cfgSetRet->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value)); } { const char* value; cfgSetRet->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value)); } // 空のIDを指定してset_configuration_set_values()を呼出し、 // 意図どおり例外がスローされるか? try { cfgSet1_Modified.id = ""; sdoCfg->set_configuration_set_values(cfgSet1_Modified); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) { } sdoCfg->_remove_ref(); // std::cout << "test_set_configuration_set_values() OUT" << std::endl; } /*! * @brief activate_configuration_set()メソッド、get_active_configuration_set()メソッド、 * get_configuration_sets()メソッドのテスト * */ void test_activate_configuration_set_and_get_active_configuration_set() { // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl; coil::Properties cfgAdminProp; RTC::ConfigAdmin cfgAdmin(cfgAdminProp); SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin); // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
726  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true),
727  sdoCfg->set_configuration_set_values(cfgSet1_Modified));
728 
729  // 更新したConfigurationSetを、正しく取得できるか?
730  SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1");
731  CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id));
732 
733 //Deleted this test, because description was not used.
734 // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"),
735 // std::string(cfgSetRet->description));
736  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2),
737  cfgSetRet->configuration_data.length());
738 
739  {
740  const char* value; cfgSetRet->configuration_data[0].value >>= value;
741  CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value));
742  }
743  {
744  const char* value; cfgSetRet->configuration_data[1].value >>= value;
745  CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value));
746  }
747 
748  // 空のIDを指定してset_configuration_set_values()を呼出し、
749  // 意図どおり例外がスローされるか?
750  try
751  {
752  cfgSet1_Modified.id = "";
753  sdoCfg->set_configuration_set_values(cfgSet1_Modified);
754  CPPUNIT_FAIL("Exception not thrown.");
755  }
756  catch (SDOPackage::InvalidParameter expected) {
757  }
758 
759  sdoCfg->_remove_ref();
760 // std::cout << "test_set_configuration_set_values() OUT" << std::endl;
761  }
762 
769  {
770 // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl;
771  coil::Properties cfgAdminProp;
772  RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
773  SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
774 
775  // ConfigurationSetを準備する SDOPackage::ConfigurationSet cfgSet0; cfgSet0.id = "ID 0"; cfgSet0.description = "DESCRIPTION 0"; cfgSet0.configuration_data.length(2); cfgSet0.configuration_data[0].name = "NAME 0-0"; cfgSet0.configuration_data[0].value <<= "3.14159"; cfgSet0.configuration_data[1].name = "NAME 0-1"; cfgSet0.configuration_data[1].value <<= "2.71828"; SDOPackage::ConfigurationSet cfgSet1; cfgSet1.id = "ID 1"; cfgSet1.description = "DESCRIPTION 1"; cfgSet1.configuration_data.length(2); cfgSet1.configuration_data[0].name = "NAME 1-0"; cfgSet1.configuration_data[0].value <<= "1.41421356"; cfgSet1.configuration_data[1].name = "NAME 1-1"; cfgSet1.configuration_data[1].value <<= "1.7320508"; // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
776  SDOPackage::ConfigurationSet cfgSet0;
777  cfgSet0.id = "ID 0";
778  cfgSet0.description = "DESCRIPTION 0";
779  cfgSet0.configuration_data.length(2);
780  cfgSet0.configuration_data[0].name = "NAME 0-0";
781  cfgSet0.configuration_data[0].value <<= "3.14159";
782  cfgSet0.configuration_data[1].name = "NAME 0-1";
783  cfgSet0.configuration_data[1].value <<= "2.71828";
784 
785  SDOPackage::ConfigurationSet cfgSet1;
786  cfgSet1.id = "ID 1";
787  cfgSet1.description = "DESCRIPTION 1";
788  cfgSet1.configuration_data.length(2);
789  cfgSet1.configuration_data[0].name = "NAME 1-0";
790  cfgSet1.configuration_data[0].value <<= "1.41421356";
791  cfgSet1.configuration_data[1].name = "NAME 1-1";
792  cfgSet1.configuration_data[1].value <<= "1.7320508";
793 
794  // 準備したConfigurationSetを登録する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0)); CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1)); // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
795  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0));
796  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1));
797 
798  // ConfigurationSet リストを取得する ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets()); // 取得した件数と内容が一致しているか? CPPUNIT_ASSERT(config_sets->length() == 2); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(config_sets[0].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(config_sets[0].configuration_data[0].name)); { const char* value; config_sets[0].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(config_sets[0].configuration_data[1].name)); { const char* value; config_sets[0].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(config_sets[1].id)); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(config_sets[1].configuration_data[0].name)); { const char* value; config_sets[1].configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(config_sets[1].configuration_data[1].name)); { const char* value; config_sets[1].configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
799  ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets());
800 
801  // 取得した件数と内容が一致しているか?
802  CPPUNIT_ASSERT(config_sets->length() == 2);
803  CPPUNIT_ASSERT_EQUAL(std::string("ID 0"),
804  std::string(config_sets[0].id));
805  CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"),
806  std::string(config_sets[0].configuration_data[0].name));
807  {
808  const char* value; config_sets[0].configuration_data[0].value >>= value;
809  CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value));
810  }
811  CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"),
812  std::string(config_sets[0].configuration_data[1].name));
813  {
814  const char* value; config_sets[0].configuration_data[1].value >>= value;
815  CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value));
816  }
817 
818  CPPUNIT_ASSERT_EQUAL(std::string("ID 1"),
819  std::string(config_sets[1].id));
820  CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"),
821  std::string(config_sets[1].configuration_data[0].name));
822  {
823  const char* value; config_sets[1].configuration_data[0].value >>= value;
824  CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value));
825  }
826  CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"),
827  std::string(config_sets[1].configuration_data[1].name));
828  {
829  const char* value; config_sets[1].configuration_data[1].value >>= value;
830  CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value));
831  }
832 
833  // "ID 0"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"), // std::string(cfgSetRet0->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet0->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"), std::string(cfgSetRet0->configuration_data[0].name)); { const char* value; cfgSetRet0->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"), std::string(cfgSetRet0->configuration_data[1].name)); { const char* value; cfgSetRet0->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value)); } // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
834  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0"));
835 
836  // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか?
837  SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set();
838  CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id));
839 
840 //Deleted this test, because description was not used.
841 // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"),
842 // std::string(cfgSetRet0->description));
843  CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2),
844  cfgSetRet0->configuration_data.length());
845  CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"),
846  std::string(cfgSetRet0->configuration_data[0].name));
847  {
848  const char* value; cfgSetRet0->configuration_data[0].value >>= value;
849  CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value));
850  }
851  CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"),
852  std::string(cfgSetRet0->configuration_data[1].name));
853  {
854  const char* value; cfgSetRet0->configuration_data[1].value >>= value;
855  CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value));
856  }
857 
858  // "ID 1"のほうをアクティブ化する CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1")); // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか? SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set(); CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id)); //Deleted this test, because description was not used. // CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"), // std::string(cfgSetRet1->description)); CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), cfgSetRet1->configuration_data.length()); CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"), std::string(cfgSetRet1->configuration_data[0].name)); { const char* value; cfgSetRet1->configuration_data[0].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value)); } CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"), std::string(cfgSetRet1->configuration_data[1].name)); { const char* value; cfgSetRet1->configuration_data[1].value >>= value; CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value)); } // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか? try { sdoCfg->activate_configuration_set("inexist ID"); CPPUNIT_FAIL("Exception not thrown."); } catch (SDOPackage::InvalidParameter expected) {} sdoCfg->_remove_ref(); // std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl; } }; }; // namespace SdoConfiguration /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests); #ifdef LOCAL_MAIN int main(int argc, char* argv[]) { FORMAT format = TEXT_OUT; int target = 0; std::string xsl; std::string ns; std::string fname; std::ofstream ofs; int i(1); while (i < argc) { std::string arg(argv[i]); std::string next_arg; if (i + 1 < argc) next_arg = argv[i + 1]; else next_arg = ""; if (arg == "--text") { format = TEXT_OUT; break; } if (arg == "--xml") { if (next_arg == "") { fname = argv[0]; fname += ".xml"; } else { fname = next_arg; } format = XML_OUT; ofs.open(fname.c_str()); } if ( arg == "--compiler" ) { format = COMPILER_OUT; break; } if ( arg == "--cerr" ) { target = 1; break; } if ( arg == "--xsl" ) { if (next_arg == "") xsl = "default.xsl"; else xsl = next_arg; } if ( arg == "--namespace" ) { if (next_arg == "") { std::cerr << "no namespace specified" << std::endl; exit(1); } else { xsl = next_arg; } } ++i; } CppUnit::TextUi::TestRunner runner; if ( ns.empty() ) runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); else runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest()); CppUnit::Outputter* outputter = 0; std::ostream* stream = target ? &std::cerr : &std::cout; switch ( format ) { case TEXT_OUT : outputter = new CppUnit::TextOutputter(&runner.result(),*stream); break; case XML_OUT : std::cout << "XML_OUT" << std::endl; outputter = new CppUnit::XmlOutputter(&runner.result(), ofs, "shift_jis"); static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl); break; case COMPILER_OUT : outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream); break; } runner.setOutputter(outputter); runner.run(); return 0; // runner.run() ? 0 : 1; } #endif // MAIN #endif // SdoConfiguration_cpp
859  CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set(