SdoConfigurationTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00021 /*
00022  * $Log: SdoConfigurationTests.cpp,v $
00023  * Revision 1.3  2008/04/23 10:43:41  arafune
00024  * Modified / Added some tests.
00025  *
00026  * Revision 1.2  2008/04/17 13:21:45  arafune
00027  * Modified some tests, and added new tests.
00028  *
00029  * Revision 1.1  2007/12/20 07:50:18  arafune
00030  * *** empty log message ***
00031  *
00032  * Revision 1.2  2007/01/24 16:04:18  n-ando
00033  * The SdoConfiguration's ctor. was changed.
00034  *
00035  * Revision 1.1  2006/11/27 08:26:07  n-ando
00036  * TestSuites are devided into each directory.
00037  *
00038  * Revision 1.3  2006/11/10 07:13:44  kurihara
00039  * A test after SdoConfiguration class revision.
00040  *
00041  * Revision 1.2  2006/11/09 09:29:47  kurihara
00042  * A test after SdoConfiguration class revision.
00043  *
00044  * Revision 1.1  2006/11/01 11:23:35  kurihara
00045  * test program for SdoConfiguration class.
00046  *
00047  */
00048 
00049 #ifndef SdoConfiguration_cpp
00050 #define SdoConfiguration_cpp
00051 
00052 #include <cppunit/ui/text/TestRunner.h>
00053 #include <cppunit/TextOutputter.h>
00054 #include <cppunit/extensions/TestFactoryRegistry.h>
00055 #include <cppunit/extensions/HelperMacros.h>
00056 #include <cppunit/TestAssert.h>
00057 
00058 #include <vector>
00059 #include <string>
00060 
00061 #include <rtm/CORBA_SeqUtil.h>
00062 #include <rtm/SdoConfiguration.h>
00063 #include <rtm/RTObject.h>
00064 #include <rtm/Manager.h>
00065 #include <rtm/SdoOrganization.h>
00066 
00071 namespace SdoConfiguration
00072 {
00073   using namespace SDOPackage;
00074   using namespace std;
00075         
00076   struct ServiceProfileFinder
00077   {
00078     ServiceProfileFinder(const std::string& id) : _id(id) { }
00079                         
00080     bool operator()(const ServiceProfile& svcProf)
00081     {
00082       return (_id == std::string(svcProf.id));
00083     }
00084                         
00085     std::string _id;
00086   };
00087 
00088   class SdoConfigurationTests
00089     : public CppUnit::TestFixture
00090   {
00091     CPPUNIT_TEST_SUITE(SdoConfigurationTests);
00092 
00093     CPPUNIT_TEST(test_set_device_profile_and_getDeviceProfile);
00094     CPPUNIT_TEST(test_set_service_profile_and_getServiceProfile);
00095     CPPUNIT_TEST(test_getServiceProfiles);
00096     CPPUNIT_TEST(test_remove_service_profile);
00097     CPPUNIT_TEST(test_add_organization_and_getOrganizations);
00098     CPPUNIT_TEST(test_remove_organization);
00099     CPPUNIT_TEST(test_add_configuration_set_and_get_configuration_set);
00100     CPPUNIT_TEST(test_remove_configuration_set);
00101     CPPUNIT_TEST(test_set_configuration_set_values);
00102     CPPUNIT_TEST(test_activate_configuration_set_and_get_active_configuration_set);
00103         //CPPUNIT_TEST(test_get_configuration_parameters);       //未実装のため未テスト
00104         //CPPUNIT_TEST(test_get_configuration_parameter_values); //未実装のため未テスト
00105         //CPPUNIT_TEST(test_get_configuration_parameter_value);  //未実装のため未テスト
00106         //CPPUNIT_TEST(test_set_configuration_parameter);        //未実装のため未テスト
00107 
00108     CPPUNIT_TEST_SUITE_END();
00109         
00110   private:
00111     CORBA::ORB_ptr m_pORB;
00112     PortableServer::POA_ptr m_pPOA;
00113                 
00114   public:
00118     SdoConfigurationTests()
00119     {
00120       int argc(0);
00121       char** argv(NULL);
00122       m_pORB = CORBA::ORB_init(argc, argv);
00123       m_pPOA = PortableServer::POA::_narrow(
00124                     m_pORB->resolve_initial_references("RootPOA"));
00125       m_pPOA->the_POAManager()->activate();
00126     }
00127     
00131     ~SdoConfigurationTests()
00132     {
00133     }
00134                 
00138     virtual void setUp()
00139     {
00140       usleep(100000);
00141     }
00142                 
00146     virtual void tearDown()
00147     { 
00148     }
00149                 
00155     void test_set_device_profile_and_getDeviceProfile()
00156     {
00157 //      std::cout << "test_set_device_profile_and_getDeviceProfile() IN" << std::endl;
00158       coil::Properties cfgAdminProp;
00159       RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00160       SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00161                         
00162       // DeviceProfileを準備する
00163       SDOPackage::DeviceProfile devProf;
00164       devProf.device_type = "DEVICE_TYPE";
00165       devProf.manufacturer = "MANUFACTURER";
00166       devProf.model = "MODEL";
00167       devProf.version = "VERSION";
00168       {
00169         SDOPackage::NVList properties;
00170         properties.length(2);
00171         properties[0].name = "name 0";
00172         properties[0].value <<= CORBA::Float(3.14159);
00173         properties[1].name = "name 1";
00174         properties[1].value <<= CORBA::Float(2.71828);
00175         devProf.properties = properties;
00176       }
00177                         
00178       // set_device_profile()を呼出して、準備したDeviceProfileを設定する
00179       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->set_device_profile(devProf));
00180                         
00181       // getDeviceProfile()で設定されているDeviceProfileを取り出し、設定したものと一致することを確認する
00182       const SDOPackage::DeviceProfile devProfRet = sdoCfg->getDeviceProfile();
00183       CPPUNIT_ASSERT_EQUAL(std::string("DEVICE_TYPE"),
00184                            std::string(devProfRet.device_type));
00185       CPPUNIT_ASSERT_EQUAL(std::string("MANUFACTURER"),
00186                            std::string(devProfRet.manufacturer));
00187       CPPUNIT_ASSERT_EQUAL(std::string("MODEL"),
00188                            std::string(devProfRet.model));
00189       CPPUNIT_ASSERT_EQUAL(std::string("VERSION"),
00190                            std::string(devProfRet.version));
00191       CPPUNIT_ASSERT_EQUAL(std::string("name 0"),
00192                            std::string(devProfRet.properties[0].name));
00193       {
00194         CORBA::Float value; devProfRet.properties[0].value >>= value;
00195         CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value);
00196       }
00197       CPPUNIT_ASSERT_EQUAL(std::string("name 1"),
00198                            std::string(devProfRet.properties[1].name));
00199       {
00200         CORBA::Float value; devProfRet.properties[1].value >>= value;
00201         CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value);
00202       }
00203       sdoCfg->_remove_ref();
00204 //      std::cout << "test_set_device_profile_and_getDeviceProfile() OUT" << std::endl;
00205     }
00206                 
00212     void test_set_service_profile_and_getServiceProfile()
00213     {
00214 //      std::cout << "test_set_service_profile_and_getServiceProfile() IN" << std::endl;
00215       coil::Properties cfgAdminProp;
00216       RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00217       SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00218                         
00219       // ServiceProfileを準備する
00220       SDOPackage::ServiceProfile svcProf;
00221       svcProf.id = "ID";
00222       svcProf.interface_type = "INTERFACE_TYPE";
00223       {
00224         SDOPackage::NVList properties;
00225         properties.length(2);
00226         properties[0].name = "name 0";
00227         properties[0].value <<= CORBA::Float(3.14159);
00228         properties[1].name = "name 1";
00229         properties[1].value <<= CORBA::Float(2.71828);
00230         svcProf.properties = properties;
00231       }
00232                         
00233       // ServiceProfileを設定する
00234       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf));
00235                         
00236       // getServiceProfile()でServiceProfileを取得し、設定したものと一致しているか確認する
00237       const SDOPackage::ServiceProfile svcProfRet = sdoCfg->getServiceProfile("ID");
00238       CPPUNIT_ASSERT_EQUAL(std::string("ID"), std::string(svcProfRet.id));
00239       CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE"),
00240                            std::string(svcProfRet.interface_type));
00241       CPPUNIT_ASSERT_EQUAL(std::string("name 0"),
00242                            std::string(svcProfRet.properties[0].name));
00243       {
00244         CORBA::Float value; svcProfRet.properties[0].value >>= value;
00245         CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value);
00246       }
00247       CPPUNIT_ASSERT_EQUAL(std::string("name 1"),
00248                            std::string(svcProfRet.properties[1].name));
00249       {
00250         CORBA::Float value; svcProfRet.properties[1].value >>= value;
00251         CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value);
00252       }
00253       sdoCfg->_remove_ref();
00254 //      std::cout << "test_set_service_profile_and_getServiceProfile() OUT" << std::endl;
00255     }
00256                 
00262     void test_getServiceProfiles()
00263     {
00264 //      std::cout << "test_getServiceProfiles() IN" << std::endl;
00265       coil::Properties cfgAdminProp;
00266       RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00267       SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00268                         
00269       // ServiceProfileを準備する
00270       SDOPackage::ServiceProfile svcProf0;
00271       svcProf0.id = "ID 0";
00272       svcProf0.interface_type = "INTERFACE_TYPE 0";
00273       {
00274         SDOPackage::NVList properties;
00275         properties.length(2);
00276         properties[0].name = "name 0-0";
00277         properties[0].value <<= CORBA::Float(3.14159);
00278         properties[1].name = "name 0-1";
00279         properties[1].value <<= CORBA::Float(2.71828);
00280         svcProf0.properties = properties;
00281       }
00282         
00283       SDOPackage::ServiceProfile svcProf1;
00284       svcProf1.id = "ID 1";
00285       svcProf1.interface_type = "INTERFACE_TYPE 1";
00286       {
00287         SDOPackage::NVList properties;
00288         properties.length(2);
00289         properties[0].name = "name 1-0";
00290         properties[0].value <<= CORBA::Float(1.41421356);
00291         properties[1].name = "name 1-1";
00292         properties[1].value <<= CORBA::Float(1.7320508);
00293         svcProf1.properties = properties;
00294       }
00295                         
00296       // ServiceProfileを設定する
00297       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0));
00298       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1));
00299                         
00300       // getServiceProfiles()で設定されているServiceProfile群を取得する
00301       const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles();
00302       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), svcProfList.length());
00303                         
00304       // 設定したServiceProfileと一致しているか?
00305       {
00306         CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0"));
00307                                 
00308         CPPUNIT_ASSERT_EQUAL(std::string("ID 0"),
00309                              std::string(svcProfList[idx].id));
00310         CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 0"),
00311                              std::string(svcProfList[idx].interface_type));
00312         CPPUNIT_ASSERT_EQUAL(std::string("name 0-0"),
00313                              std::string(svcProfList[idx].properties[0].name));
00314         {
00315           CORBA::Float value; svcProfList[idx].properties[0].value >>= value;
00316           CPPUNIT_ASSERT_EQUAL(CORBA::Float(3.14159), value);
00317         }
00318         CPPUNIT_ASSERT_EQUAL(std::string("name 0-1"),
00319                              std::string(svcProfList[idx].properties[1].name));
00320         {
00321           CORBA::Float value; svcProfList[idx].properties[1].value >>= value;
00322           CPPUNIT_ASSERT_EQUAL(CORBA::Float(2.71828), value);
00323         }
00324       }
00325 
00326       {
00327         CORBA::ULong idx = CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1"));
00328                                 
00329         CPPUNIT_ASSERT_EQUAL(std::string("ID 1"),
00330                              std::string(svcProfList[idx].id));
00331         CPPUNIT_ASSERT_EQUAL(std::string("INTERFACE_TYPE 1"),
00332                              std::string(svcProfList[idx].interface_type));
00333         CPPUNIT_ASSERT_EQUAL(std::string("name 1-0"),
00334                              std::string(svcProfList[idx].properties[0].name));
00335         {
00336           CORBA::Float value; svcProfList[idx].properties[0].value >>= value;
00337           CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.41421356), value);
00338         }
00339         CPPUNIT_ASSERT_EQUAL(std::string("name 1-1"),
00340                              std::string(svcProfList[idx].properties[1].name));
00341         {
00342           CORBA::Float value; svcProfList[idx].properties[1].value >>= value;
00343           CPPUNIT_ASSERT_EQUAL(CORBA::Float(1.7320508), value);
00344         }
00345       }
00346       sdoCfg->_remove_ref();
00347 //      std::cout << "test_getServiceProfiles() OUT" << std::endl;
00348     }
00349     
00355     void test_remove_service_profile()
00356     {
00357 //      std::cout << "test_remove_service_profile() IN" << std::endl;
00358       coil::Properties cfgAdminProp;
00359       RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00360       SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00361                         
00362       // ServiceProfileを準備する
00363       SDOPackage::ServiceProfile svcProf0;
00364       svcProf0.id = "ID 0";
00365       svcProf0.interface_type = "INTERFACE_TYPE 0";
00366       {
00367         SDOPackage::NVList properties;
00368         properties.length(2);
00369         properties[0].name = "name 0-0";
00370         properties[0].value <<= CORBA::Float(3.14159);
00371         properties[1].name = "name 0-1";
00372         properties[1].value <<= CORBA::Float(2.71828);
00373         svcProf0.properties = properties;
00374       }
00375         
00376       SDOPackage::ServiceProfile svcProf1;
00377       svcProf1.id = "ID 1";
00378       svcProf1.interface_type = "INTERFACE_TYPE 1";
00379       {
00380         SDOPackage::NVList properties;
00381         properties.length(2);
00382         properties[0].name = "name 1-0";
00383         properties[0].value <<= CORBA::Float(1.41421356);
00384         properties[1].name = "name 1-1";
00385         properties[1].value <<= CORBA::Float(1.7320508);
00386         svcProf1.properties = properties;
00387       }
00388                         
00389       // ServiceProfileを設定する
00390       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf0));
00391       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_service_profile(svcProf1));
00392                         
00393       // 設定したServiceProfileのうち、片方を登録解除する
00394       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_service_profile("ID 0"));
00395                         
00396       // getServiceProfiles()で全ServiceProfileを取得し、登録解除したものが含まれないことを確認する
00397       const SDOPackage::ServiceProfileList svcProfList = sdoCfg->getServiceProfiles();
00398       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(1), svcProfList.length());
00399       CPPUNIT_ASSERT_EQUAL(CORBA::Long(-1),
00400                            CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 0")));
00401                         
00402       // 登録解除していないものは、依然として含まれているか?
00403       CPPUNIT_ASSERT_EQUAL(CORBA::Long(0),
00404                            CORBA_SeqUtil::find(svcProfList, ServiceProfileFinder("ID 1")));
00405 
00406       sdoCfg->_remove_ref();
00407 //      std::cout << "test_remove_service_profile() OUT" << std::endl;
00408     }
00409     
00410     /* 
00411      * @brief add_organization()メソッドとgetOrganizations()メソッドのテスト
00412      * 
00413      * - add_organization()でOrganization_ptrインスタンスを登録できるか?
00414      * - getOrganizations()で登録されているOrganization_ptrインスタンス群を取得できるか?
00415      */
00416     void test_add_organization_and_getOrganizations()
00417     {
00418 //      std::cout << "test_add_organization_and_getOrganizations() IN" << std::endl;
00419       coil::Properties cfgAdminProp;
00420       RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00421       SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00422                         
00423       // Organizationを2つ登録する
00424       SDOPackage::Organization_var org1;
00425       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true),
00426                            sdoCfg->add_organization(org1._retn()));
00427 
00428       SDOPackage::Organization_var org2;
00429       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true),
00430                            sdoCfg->add_organization(org2._retn()));
00431       
00432       // 取得されるOrganizationの数は、意図どおり2つか?
00433       SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations();
00434       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2), orgList.length());
00435 
00436       sdoCfg->_remove_ref();
00437 //      std::cout << "test_add_organization_and_getOrganizations() OUT" << std::endl;
00438     }
00439     
00440     /*
00441      * @brief remove_organization()のテスト
00442      * - add_organization()で登録し、remove_organization()で正しく削除できるか?
00443      */
00444     void test_remove_organization()
00445     {
00446 //      std::cout << "test_remove_organization() IN" << std::endl;
00447       coil::Properties cfgAdminProp;
00448       RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00449       SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00450       RTC::RTObject_impl* rtobj;
00451       SDOPackage::Organization_impl* m_pOi;
00452       RTC::Manager& mgr(RTC::Manager::instance());
00453       rtobj = new ::RTC::RTObject_impl(&mgr);
00454       m_pOi = new Organization_impl(rtobj->getObjRef());
00455                         
00456       // Organizationを登録する
00457       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true),
00458                            sdoCfg->add_organization(m_pOi->getObjRef()));
00459 
00460       // organization_idを取得する
00461       std::string id(m_pOi->get_organization_id());
00462 
00463       // 登録したOrganizationを削除する
00464       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true),
00465                            sdoCfg->remove_organization(id.c_str()));
00466 
00467       // 取得されるOrganizationの数は、意図どおり0件か?
00468       SDOPackage::OrganizationList orgList = sdoCfg->getOrganizations();
00469       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(0), orgList.length());
00470 
00471       m_pOi->_remove_ref();
00472       rtobj->_remove_ref();
00473       sdoCfg->_remove_ref();
00474 //      std::cout << "test_remove_organization() OUT" << std::endl;
00475     }
00476                                 
00477     /*
00478      * @brief get_configuration_parameters()のテスト
00479      */
00480     void test_get_configuration_parameters()
00481     {
00482       // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameters()が
00483       // 未実装であるため、本テストも未実装である。
00484 //      std::cout << "test_get_configuration_parameters() IN" << std::endl;
00485 //      std::cout << "test_get_configuration_parameters() OUT" << std::endl;
00486     }
00487                 
00491     void test_get_configuration_parameter_values()
00492     {
00493       // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_values()が
00494       // 未実装であるため、本テストも未実装である。
00495 //      std::cout << "test_get_configuration_parameter_values() IN" << std::endl;
00496 //      std::cout << "test_get_configuration_parameter_values() OUT" << std::endl;
00497     }
00498                 
00502     void test_get_configuration_parameter_value()
00503     {
00504       // テスト対象であるSDOPackage::Confirutaion_impl::get_configuration_parameter_value()が
00505       // 未実装であるため、本テストも未実装である。
00506 //      std::cout << "test_get_configuration_parameter_value() IN" << std::endl;
00507 //      std::cout << "test_get_configuration_parameter_value() OUT" << std::endl;
00508     }
00509                 
00513     void test_set_configuration_parameter()
00514     {
00515       // テスト対象であるSDOPackage::Confirutaion_impl::set_configuration_parameter()が
00516       // 未実装であるため、本テストも未実装である。
00517 //      std::cout << "test_set_configuration_parameter() IN" << std::endl;
00518 //      std::cout << "test_set_configuration_parameter() OUT" << std::endl;
00519     }
00520                 
00527     void test_add_configuration_set_and_get_configuration_set()
00528     {
00529 //      std::cout << "test_add_configuration_set_and_get_configuration_set() IN" << std::endl;
00530       coil::Properties cfgAdminProp;
00531       RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00532       SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00533                         
00534       // ConfigurationSetを準備する
00535       SDOPackage::ConfigurationSet cfgSet0;
00536       cfgSet0.id = "ID 0";
00537       cfgSet0.description = "DESCRIPTION 0";
00538       cfgSet0.configuration_data.length(2);
00539       cfgSet0.configuration_data[0].name = "NAME 0-0";
00540       cfgSet0.configuration_data[0].value <<= "3.14159";
00541       cfgSet0.configuration_data[1].name = "NAME 0-1";
00542       cfgSet0.configuration_data[1].value <<= "2.71828";
00543                         
00544       SDOPackage::ConfigurationSet cfgSet1;
00545       cfgSet1.id = "ID 1";
00546       cfgSet1.description = "DESCRIPTION 1";
00547       cfgSet1.configuration_data.length(2);
00548       cfgSet1.configuration_data[0].name = "NAME 1-0";
00549       cfgSet1.configuration_data[0].value <<= "1.41421356";
00550       cfgSet1.configuration_data[1].name = "NAME 1-1";
00551       cfgSet1.configuration_data[1].value <<= "1.7320508";
00552                         
00553       // 準備したConfigurationSetを登録する
00554       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0));
00555       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1));
00556                         
00557       // 登録したConfigurationSetを正しく取得できるか?
00558       SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_configuration_set("ID 0");
00559       CPPUNIT_ASSERT_EQUAL(std::string("ID 0"),
00560                            std::string(cfgSetRet0->id));
00561 //Deleted this test, because description was not used.
00562 //      CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"),
00563 //                         std::string(cfgSetRet0->description));
00564       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2),
00565                            cfgSetRet0->configuration_data.length());
00566       CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"),
00567                            std::string(cfgSetRet0->configuration_data[0].name));
00568       {
00569         const char* value; cfgSetRet0->configuration_data[0].value >>= value;
00570         CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value));
00571       }
00572       CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"),
00573                            std::string(cfgSetRet0->configuration_data[1].name));
00574       {
00575         const char* value; cfgSetRet0->configuration_data[1].value >>= value;
00576         CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value));
00577       }
00578 
00579       SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_configuration_set("ID 1");
00580       CPPUNIT_ASSERT_EQUAL(std::string("ID 1"),
00581                            std::string(cfgSetRet1->id));
00582 //Deleted this test, because description was not used.
00583 //      CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"),
00584 //                         std::string(cfgSetRet1->description));
00585       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2),
00586                            cfgSetRet1->configuration_data.length());
00587       CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"),
00588                            std::string(cfgSetRet1->configuration_data[0].name));
00589       {
00590         const char* value; cfgSetRet1->configuration_data[0].value >>= value;
00591         CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value));
00592       }
00593       CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"),
00594                            std::string(cfgSetRet1->configuration_data[1].name));
00595       {
00596         const char* value; cfgSetRet1->configuration_data[1].value >>= value;
00597         CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value));
00598       }
00599 
00600       sdoCfg->_remove_ref();
00601 //      std::cout << "test_add_configuration_set_and_get_configuration_set() OUT" << std::endl;
00602     }
00603                 
00610     void test_remove_configuration_set()
00611     {
00612 //      std::cout << "test_remove_configuration_set() IN" << std::endl;
00613       coil::Properties cfgAdminProp;
00614       RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00615       SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00616                         
00617       // ConfigurationSetを準備する
00618       SDOPackage::ConfigurationSet cfgSet0;
00619       cfgSet0.id = "ID 0";
00620       cfgSet0.description = "DESCRIPTION 0";
00621       cfgSet0.configuration_data.length(2);
00622       cfgSet0.configuration_data[0].name = "NAME 0-0";
00623       cfgSet0.configuration_data[0].value <<= "3.14159";
00624       cfgSet0.configuration_data[1].name = "NAME 0-1";
00625       cfgSet0.configuration_data[1].value <<= "2.71828";
00626                         
00627       SDOPackage::ConfigurationSet cfgSet1;
00628       cfgSet1.id = "ID 1";
00629       cfgSet1.description = "DESCRIPTION 1";
00630       cfgSet1.configuration_data.length(2);
00631       cfgSet1.configuration_data[0].name = "NAME 1-0";
00632       cfgSet1.configuration_data[0].value <<= "1.41421356";
00633       cfgSet1.configuration_data[1].name = "NAME 1-1";
00634       cfgSet1.configuration_data[1].value <<= "1.7320508";
00635                         
00636       // 準備したConfigurationSetを登録する
00637       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0));
00638       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1));
00639                         
00640       // 登録したうち、片方のConfigurationSetを登録解除する
00641       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->remove_configuration_set("ID 0"));
00642                         
00643       // 登録解除したConfigurationSetを指定して、get_configuration_set()呼出を試みて、
00644       // 意図どおりに例外がスローされるか?
00645       try
00646         {
00647           sdoCfg->get_configuration_set("ID 0");
00648           CPPUNIT_FAIL("ID 0 was not removed.");
00649         }
00650       catch (SDOPackage::InvalidParameter expected) {}
00651       catch (...) {}
00652                         
00653       // 空のidを指定して、get_configuration_set()呼出を試みて、
00654       // 意図どおりに例外がスローされるか?
00655       try
00656         {
00657           sdoCfg->get_configuration_set("");
00658           CPPUNIT_FAIL("ID Not set.");
00659         }
00660       catch (SDOPackage::InvalidParameter expected) {}
00661       catch (...) {}
00662                         
00663       // 登録解除していないConfigurationSetは、依然として取得できるか?
00664       SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1");
00665       CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id));
00666                         
00667       // 存在しないIDを指定して登録解除を試みた場合に、意図どおりに例外がスローされるか?
00668       try
00669         {
00670           sdoCfg->remove_configuration_set("inexist ID");
00671           CPPUNIT_FAIL("Exception not thrown.");
00672         }
00673       catch (SDOPackage::InvalidParameter expected) {}
00674       catch (...) {}
00675 
00676       sdoCfg->_remove_ref();
00677 //      std::cout << "test_remove_configuration_set() OUT" << std::endl;
00678     }
00679                 
00686     void test_set_configuration_set_values()
00687     {
00688 //      std::cout << "test_set_configuration_set_values() IN" << std::endl;
00689       coil::Properties cfgAdminProp;
00690       RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00691       SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00692                         
00693       // ConfigurationSetを準備する
00694       SDOPackage::ConfigurationSet cfgSet0;
00695       cfgSet0.id = "ID 0";
00696       cfgSet0.description = "DESCRIPTION 0";
00697       cfgSet0.configuration_data.length(2);
00698       cfgSet0.configuration_data[0].name = "NAME 0-0";
00699       cfgSet0.configuration_data[0].value <<= "3.14159";
00700       cfgSet0.configuration_data[1].name = "NAME 0-1";
00701       cfgSet0.configuration_data[1].value <<= "2.71828";
00702                         
00703       SDOPackage::ConfigurationSet cfgSet1;
00704       cfgSet1.id = "ID 1";
00705       cfgSet1.description = "DESCRIPTION 1";
00706       cfgSet1.configuration_data.length(2);
00707       cfgSet1.configuration_data[0].name = "NAME 1-0";
00708       cfgSet1.configuration_data[0].value <<= "1.41421356";
00709       cfgSet1.configuration_data[1].name = "NAME 1-1";
00710       cfgSet1.configuration_data[1].value <<= "1.7320508";
00711 
00712       SDOPackage::ConfigurationSet cfgSet1_Modified;
00713       cfgSet1_Modified.id = "ID 1";
00714       cfgSet1_Modified.description = "DESCRIPTION 1 M";
00715       cfgSet1_Modified.configuration_data.length(2);
00716       cfgSet1_Modified.configuration_data[0].name = "NAME 1-0";
00717       cfgSet1_Modified.configuration_data[0].value <<= "2.23620679";
00718       cfgSet1_Modified.configuration_data[1].name = "NAME 1-1";
00719       cfgSet1_Modified.configuration_data[1].value <<= "2.44948974";
00720 
00721       // 準備したConfigurationSetを登録する
00722       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0));
00723       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1));
00724                         
00725       // 登録したConfigurationSetのうち片方を、set_configuration_set_values()で更新する
00726       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true),
00727                            sdoCfg->set_configuration_set_values(cfgSet1_Modified));
00728                         
00729       // 更新したConfigurationSetを、正しく取得できるか?
00730       SDOPackage::ConfigurationSet* cfgSetRet = sdoCfg->get_configuration_set("ID 1");
00731       CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet->id));
00732 
00733 //Deleted this test, because description was not used.
00734 //      CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1 M"),
00735 //                         std::string(cfgSetRet->description));
00736       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2),
00737                            cfgSetRet->configuration_data.length());
00738 
00739       {
00740         const char* value; cfgSetRet->configuration_data[0].value >>= value;
00741         CPPUNIT_ASSERT_EQUAL(std::string("2.23620679"), std::string(value));
00742       }
00743       {
00744         const char* value; cfgSetRet->configuration_data[1].value >>= value;
00745         CPPUNIT_ASSERT_EQUAL(std::string("2.44948974"), std::string(value));
00746       }
00747                         
00748       // 空のIDを指定してset_configuration_set_values()を呼出し、
00749       // 意図どおり例外がスローされるか?
00750       try
00751         {
00752           cfgSet1_Modified.id = "";
00753           sdoCfg->set_configuration_set_values(cfgSet1_Modified);
00754           CPPUNIT_FAIL("Exception not thrown.");
00755         }
00756       catch (SDOPackage::InvalidParameter expected) {
00757         }
00758 
00759       sdoCfg->_remove_ref();
00760 //      std::cout << "test_set_configuration_set_values() OUT" << std::endl;
00761     }
00762                 
00768     void test_activate_configuration_set_and_get_active_configuration_set()
00769     {
00770 //      std::cout << "test_activate_configuration_set_and_get_active_configuration_set() IN" << std::endl;
00771       coil::Properties cfgAdminProp;
00772       RTC::ConfigAdmin cfgAdmin(cfgAdminProp);
00773       SDOPackage::Configuration_impl* sdoCfg = new Configuration_impl(cfgAdmin);
00774         
00775       // ConfigurationSetを準備する
00776       SDOPackage::ConfigurationSet cfgSet0;
00777       cfgSet0.id = "ID 0";
00778       cfgSet0.description = "DESCRIPTION 0";
00779       cfgSet0.configuration_data.length(2);
00780       cfgSet0.configuration_data[0].name = "NAME 0-0";
00781       cfgSet0.configuration_data[0].value <<= "3.14159";
00782       cfgSet0.configuration_data[1].name = "NAME 0-1";
00783       cfgSet0.configuration_data[1].value <<= "2.71828";
00784                         
00785       SDOPackage::ConfigurationSet cfgSet1;
00786       cfgSet1.id = "ID 1";
00787       cfgSet1.description = "DESCRIPTION 1";
00788       cfgSet1.configuration_data.length(2);
00789       cfgSet1.configuration_data[0].name = "NAME 1-0";
00790       cfgSet1.configuration_data[0].value <<= "1.41421356";
00791       cfgSet1.configuration_data[1].name = "NAME 1-1";
00792       cfgSet1.configuration_data[1].value <<= "1.7320508";
00793 
00794       // 準備したConfigurationSetを登録する
00795       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet0));
00796       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->add_configuration_set(cfgSet1));
00797                         
00798       // ConfigurationSet リストを取得する
00799       ConfigurationSetList_var config_sets(sdoCfg->get_configuration_sets());
00800 
00801       // 取得した件数と内容が一致しているか?
00802       CPPUNIT_ASSERT(config_sets->length() == 2);
00803       CPPUNIT_ASSERT_EQUAL(std::string("ID 0"),
00804                            std::string(config_sets[0].id));
00805       CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"),
00806                            std::string(config_sets[0].configuration_data[0].name));
00807       {
00808         const char* value; config_sets[0].configuration_data[0].value >>= value;
00809         CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value));
00810       }
00811       CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"),
00812                            std::string(config_sets[0].configuration_data[1].name));
00813       {
00814         const char* value; config_sets[0].configuration_data[1].value >>= value;
00815         CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value));
00816       }
00817 
00818       CPPUNIT_ASSERT_EQUAL(std::string("ID 1"),
00819                            std::string(config_sets[1].id));
00820       CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"),
00821                            std::string(config_sets[1].configuration_data[0].name));
00822       {
00823         const char* value; config_sets[1].configuration_data[0].value >>= value;
00824         CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value));
00825       }
00826       CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"),
00827                            std::string(config_sets[1].configuration_data[1].name));
00828       {
00829         const char* value; config_sets[1].configuration_data[1].value >>= value;
00830         CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value));
00831       }
00832 
00833       // "ID 0"のほうをアクティブ化する
00834       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 0"));
00835                         
00836       // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか?
00837       SDOPackage::ConfigurationSet* cfgSetRet0 = sdoCfg->get_active_configuration_set();
00838       CPPUNIT_ASSERT_EQUAL(std::string("ID 0"), std::string(cfgSetRet0->id));
00839 
00840 //Deleted this test, because description was not used.
00841 //      CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 0"),
00842 //                         std::string(cfgSetRet0->description));
00843       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2),
00844                            cfgSetRet0->configuration_data.length());
00845       CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-0"),
00846                            std::string(cfgSetRet0->configuration_data[0].name));
00847       {
00848         const char* value; cfgSetRet0->configuration_data[0].value >>= value;
00849         CPPUNIT_ASSERT_EQUAL(std::string("3.14159"), std::string(value));
00850       }
00851       CPPUNIT_ASSERT_EQUAL(std::string("NAME 0-1"),
00852                            std::string(cfgSetRet0->configuration_data[1].name));
00853       {
00854         const char* value; cfgSetRet0->configuration_data[1].value >>= value;
00855         CPPUNIT_ASSERT_EQUAL(std::string("2.71828"), std::string(value));
00856       }
00857 
00858       // "ID 1"のほうをアクティブ化する
00859       CPPUNIT_ASSERT_EQUAL(CORBA::Boolean(true), sdoCfg->activate_configuration_set("ID 1"));
00860                         
00861       // アクティブなConfigurationSetを取得し、それがアクティブ化したものと一致するか?
00862       SDOPackage::ConfigurationSet* cfgSetRet1 = sdoCfg->get_active_configuration_set();
00863       CPPUNIT_ASSERT_EQUAL(std::string("ID 1"), std::string(cfgSetRet1->id));
00864 
00865 //Deleted this test, because description was not used.
00866 //      CPPUNIT_ASSERT_EQUAL(std::string("DESCRIPTION 1"),
00867 //                         std::string(cfgSetRet1->description));
00868       CPPUNIT_ASSERT_EQUAL(CORBA::ULong(2),
00869                            cfgSetRet1->configuration_data.length());
00870       CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-0"),
00871                            std::string(cfgSetRet1->configuration_data[0].name));
00872       {
00873         const char* value; cfgSetRet1->configuration_data[0].value >>= value;
00874         CPPUNIT_ASSERT_EQUAL(std::string("1.41421356"), std::string(value));
00875       }
00876       CPPUNIT_ASSERT_EQUAL(std::string("NAME 1-1"),
00877                            std::string(cfgSetRet1->configuration_data[1].name));
00878       {
00879         const char* value; cfgSetRet1->configuration_data[1].value >>= value;
00880         CPPUNIT_ASSERT_EQUAL(std::string("1.7320508"), std::string(value));
00881       }
00882                         
00883       // 存在しないIDを指定してactivate_configuration_set()を呼出し、意図どおりの例外がスローされるか?
00884       try
00885         {
00886           sdoCfg->activate_configuration_set("inexist ID");
00887           CPPUNIT_FAIL("Exception not thrown.");
00888         }
00889       catch (SDOPackage::InvalidParameter expected) {}
00890 
00891       sdoCfg->_remove_ref();
00892 //      std::cout << "test_activate_configuration_set_and_get_active_configuration_set() OUT" << std::endl;
00893     }
00894 
00895   };
00896 }; // namespace SdoConfiguration
00897 
00898 /*
00899  * Register test suite
00900  */
00901 CPPUNIT_TEST_SUITE_REGISTRATION(SdoConfiguration::SdoConfigurationTests);
00902 
00903 #ifdef LOCAL_MAIN
00904 int main(int argc, char* argv[])
00905 {
00906 
00907   FORMAT format = TEXT_OUT;
00908   int target = 0;
00909   std::string xsl;
00910   std::string ns;
00911   std::string fname;
00912   std::ofstream ofs;
00913 
00914   int i(1);
00915   while (i < argc)
00916     {
00917       std::string arg(argv[i]);
00918       std::string next_arg;
00919       if (i + 1 < argc) next_arg = argv[i + 1];
00920       else              next_arg = "";
00921 
00922       if (arg == "--text") { format = TEXT_OUT; break; }
00923       if (arg == "--xml")
00924         {
00925           if (next_arg == "")
00926             {
00927               fname = argv[0];
00928               fname += ".xml";
00929             }
00930           else
00931             {
00932               fname = next_arg;
00933             }
00934           format = XML_OUT;
00935           ofs.open(fname.c_str());
00936         }
00937       if ( arg == "--compiler"  ) { format = COMPILER_OUT; break; }
00938       if ( arg == "--cerr"      ) { target = 1; break; }
00939       if ( arg == "--xsl"       )
00940         {
00941           if (next_arg == "") xsl = "default.xsl"; 
00942           else                xsl = next_arg;
00943         }
00944       if ( arg == "--namespace" )
00945         {
00946           if (next_arg == "")
00947             {
00948               std::cerr << "no namespace specified" << std::endl;
00949               exit(1); 
00950             }
00951           else
00952             {
00953               xsl = next_arg;
00954             }
00955         }
00956       ++i;
00957     }
00958   CppUnit::TextUi::TestRunner runner;
00959   if ( ns.empty() )
00960     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00961   else
00962     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
00963   CppUnit::Outputter* outputter = 0;
00964   std::ostream* stream = target ? &std::cerr : &std::cout;
00965   switch ( format )
00966     {
00967     case TEXT_OUT :
00968       outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
00969       break;
00970     case XML_OUT :
00971       std::cout << "XML_OUT" << std::endl;
00972       outputter = new CppUnit::XmlOutputter(&runner.result(),
00973                                             ofs, "shift_jis");
00974       static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
00975       break;
00976     case COMPILER_OUT :
00977       outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
00978       break;
00979     }
00980   runner.setOutputter(outputter);
00981   runner.run();
00982   return 0; // runner.run() ? 0 : 1;
00983 }
00984 #endif // MAIN
00985 #endif // SdoConfiguration_cpp


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:39