SdoOrganizationTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00021 /*
00022  * $Log: SdoOrganizationTests.cpp,v $
00023  * Revision 1.1  2007/12/20 07:50:17  arafune
00024  * *** empty log message ***
00025  *
00026  * Revision 1.1  2006/11/27 08:37:43  n-ando
00027  * TestSuites are devided into each directory.
00028  *
00029  *
00030  */
00031 
00032 #ifndef SdoOrganization_cpp
00033 #define SdoOrganization_cpp
00034 
00035 #include <cppunit/ui/text/TestRunner.h>
00036 #include <cppunit/TextOutputter.h>
00037 #include <cppunit/extensions/TestFactoryRegistry.h>
00038 #include <cppunit/extensions/HelperMacros.h>
00039 #include <cppunit/TestAssert.h>
00040 #include <rtm/RTObject.h>
00041 #include <rtm/Manager.h>
00042 #include <rtm/SdoOrganization.h>
00043 
00044 
00049 namespace SdoOrganization
00050 {
00051   using namespace SDOPackage;
00052   using namespace std;
00053   
00054   class SdoOrganizationTests
00055     : public CppUnit::TestFixture
00056   {
00057     CPPUNIT_TEST_SUITE(SdoOrganizationTests);
00058 
00059     CPPUNIT_TEST(test_get_organization_id);
00060     CPPUNIT_TEST(test_set_get_organization_property);
00061     CPPUNIT_TEST(test_set_get_organization_property_value);
00062     CPPUNIT_TEST(test_remove_organization_property);
00063     CPPUNIT_TEST(test_set_get_owner);
00064     CPPUNIT_TEST(test_set_get_members);
00065     CPPUNIT_TEST(test_add_remove_members);
00066     CPPUNIT_TEST(test_set_get_dependency);
00067 
00068     CPPUNIT_TEST_SUITE_END();
00069     
00070   private:
00071     ::RTC::RTObject_impl* rtobj;
00072     Organization_impl* m_pOi;
00073     char* m_id;
00074   public:
00075     
00079     SdoOrganizationTests()
00080     {
00081     }
00082     
00086     ~SdoOrganizationTests()
00087     {
00088     }
00089     
00093     virtual void setUp()
00094     {
00095       ::RTC::Manager& mgr(RTC::Manager::instance());
00096       rtobj = new ::RTC::RTObject_impl(&mgr);
00097       m_pOi = new Organization_impl(rtobj->getObjRef());
00098     }
00099     
00103     virtual void tearDown()
00104     {
00105       m_pOi->_remove_ref();
00106       rtobj->_remove_ref();
00107     }
00108 
00109 
00113     void test_get_organization_id() {
00114 //      std::cout << "test_get_organization_id IN" << std::endl;
00115       m_id = m_pOi->get_organization_id();
00116       CPPUNIT_ASSERT(m_id != NULL);
00117 //      std::cout << "test_get_organization_id OUT" << std::endl;
00118     }
00119     
00120     
00124     void test_set_get_organization_property() {
00125 //      std::cout << "test_set_get_organization_property IN" << std::endl;
00126       OrganizationProperty_var get_prop;
00127       OrganizationProperty set_prop;
00128       CORBA::Boolean ret;
00129       CORBA::Short st;
00130       CORBA::Long lg;
00131       CORBA::Float ft;
00132       CORBA::Double db;
00133       //    char* strg;
00134       
00135       CORBA::Short rst;
00136       CORBA::Long rlg;
00137       CORBA::Float rft;
00138       CORBA::Double rdb;
00139       //    char* rstrg;
00140       
00141       NVList nvList;
00142       NameValue nv;
00143       string str;
00144       
00145       try {
00146         // プロパティの取得 length 0のプロパティが返される。
00147         get_prop = m_pOi->get_organization_property();
00148 //      cout << endl << "get property length: " << get_prop->properties.length() << endl;
00149         
00150         
00151         // 空のOrganizationPropertyをセットする。 OK.
00152         ret = m_pOi->add_organization_property(set_prop);
00153         
00154         
00155         nv.name = "hoge";
00156         str = "hoge"; 
00157         ft = 11.111;
00158         nv.value <<= ft;
00159         
00160         nvList.length(1);
00161         nvList[0] = nv;
00162         
00163         set_prop.properties = nvList;
00164         // プロパティのセット
00165         ret = m_pOi->add_organization_property(set_prop);
00166         
00167         // プロパティの取得 length 1のプロパティリストを持つOrganizationPropertyが返される。
00168         get_prop = m_pOi->get_organization_property();
00169 //      cout << "get property length: " << get_prop->properties.length() << endl;
00170         
00171         str = (get_prop->properties[0]).name;
00172         (get_prop->properties[0]).value >>= rft;
00173         CPPUNIT_ASSERT(str == "hoge");
00174         CPPUNIT_ASSERT(rft == ft);
00175         
00176         
00177         nv.name = "hogehoge";
00178         ft = 22.2;
00179         nv.value <<= ft;
00180         
00181         nvList.length(1);
00182         nvList[0] = nv;
00183         
00184         set_prop.properties = nvList;
00185         // プロパティのセット
00186         ret = m_pOi->add_organization_property(set_prop);
00187         
00188         // プロパティの取得
00189         get_prop = m_pOi->get_organization_property();
00190 //      cout << "get property length: " << get_prop->properties.length() << endl;
00191         
00192         
00193         str = ((get_prop->properties[0]).name);
00194         (get_prop->properties[0]).value >>= rft;
00195         CPPUNIT_ASSERT(str == "hogehoge");
00196         CPPUNIT_ASSERT(rft == ft);
00197         
00198         //      nvList.length(5);
00199         nvList.length(4);
00200         
00201 //      cout << "short" << endl;
00202         nv.name = "short";
00203         st = 1;
00204         nv.value <<= st;
00205         nvList[0] = nv;
00206         
00207 //      cout << "long" << endl;
00208         nv.name = "long";
00209         lg = 2222;
00210         nv.value <<= lg;
00211         nvList[1] = nv;
00212         
00213 //      cout << "float" << endl;
00214         nv.name = "float";
00215         ft = 33.3;
00216         nv.value <<= ft;
00217         nvList[2] = nv;
00218         
00219 //      cout << "double" << endl;
00220         nv.name = "double";
00221         db = 3.3;
00222         nv.value <<= db;
00223         nvList[3] = nv;
00224         
00225         //      nv.name = "char";
00226         //      strg = "STRING";
00227         //      nv.value <<= CORBA::Any::from_char('C'); // ここでセグメントエラー発生
00228         //      cout << "char" << endl;
00229         //      nvList[4] = nv;
00230         
00231         
00232         //      cout << "string" << endl;
00233         //      nv.name = "string";
00234         //      strg = "STRING";
00235         //      char * p = "STRING";
00236         //      nv.value <<= CORBA::Any::from_string(p,7); // ここでセグメントエラー発生
00237         //      nvList[4] = nv;
00238         
00239 //      cout << "set_prop.properties" << endl;
00240         set_prop.properties = nvList;
00241         
00242 //      cout << "set in" << endl;
00243         ret = m_pOi->add_organization_property(set_prop);
00244 //      cout << "set out" << endl;
00245         
00246         get_prop = m_pOi->get_organization_property();
00247 //      cout << "get property length: " << get_prop->properties.length() << endl;
00248         
00249         str = ((get_prop->properties[0]).name);
00250         (get_prop->properties[0]).value >>= rst;
00251         CPPUNIT_ASSERT(str == "short");
00252         CPPUNIT_ASSERT(rst == st);
00253         
00254         str = ((get_prop->properties[1]).name);
00255         (get_prop->properties[1]).value >>= rlg;
00256         CPPUNIT_ASSERT(str == "long");
00257         CPPUNIT_ASSERT(rlg == lg);
00258         
00259         str = ((get_prop->properties[2]).name);
00260         (get_prop->properties[2]).value >>= rft;
00261         CPPUNIT_ASSERT(str == "float");
00262         CPPUNIT_ASSERT(rft == ft);
00263         
00264         str = ((get_prop->properties[3]).name);
00265         (get_prop->properties[3]).value >>= rdb;
00266         CPPUNIT_ASSERT(str == "double");
00267         CPPUNIT_ASSERT(rdb == db);
00268         
00269         //      str = ((get_prop->properties[4]).name);
00270         //      (get_prop->properties[4]).value >>= (CORBA::Any::to_char(rch));
00271         //      CPPUNIT_ASSERT(str == "char");
00272         //      CPPUNIT_ASSERT(rch == ch);
00273         
00274         //      str = ((get_prop->properties[4]).name);
00275         //      char * retp;
00276         //      (get_prop->properties[4]).value >>= CORBA::Any::to_string(retp,7);
00277         //      CPPUNIT_ASSERT(str == "string");
00278         //      CPPUNIT_ASSERT(*retp == *p);
00279         
00280       }
00281       catch (InvalidParameter ip) {
00282         cout << "InvalidParameter exception." << endl;
00283       }
00284       catch (NotAvailable na) {
00285         cout << "NotAvailable exception." << endl;
00286       }
00287       catch (InternalError ip) {
00288         cout << "InternalError exception." << endl;
00289       }
00290       catch (...) {
00291         cout << "othrer exception." << endl;
00292       }
00293 //      std::cout << "test_set_get_organization_property OUT" << std::endl;
00294     }
00295 
00299     void test_set_get_organization_property_value() {
00300 //      std::cout << "test_set_get_organization_property_value IN" << std::endl;
00301       OrganizationProperty_var get_prop;
00302       OrganizationProperty set_prop;
00303       CORBA::Boolean ret;
00304       CORBA::Short st;
00305 //      CORBA::Long lg;
00306       CORBA::Float ft;
00307 //      CORBA::Double db;
00308       CORBA::Any any;
00309       
00310       CORBA::Short rst;
00311 //      CORBA::Long rlg;
00312       CORBA::Float rft;
00313 //      CORBA::Double rdb;
00314       CORBA::Any* rany;
00315 
00316       NVList nvList;
00317       NameValue nv;
00318       string str;
00319       
00320       try {
00321         // プロパティの取得 length 0のプロパティが返される。
00322         get_prop = m_pOi->get_organization_property();
00323 //      cout << endl << "get property length: " << get_prop->properties.length() << endl;
00324         
00325         // 空のOrganizationPropertyをセットする。 OK.
00326         ret = m_pOi->add_organization_property(set_prop);
00327         CPPUNIT_ASSERT(ret);
00328         
00329         // プロパティの設定時、true が返されるか?
00330         ft = 11.111;
00331         any <<= ft;
00332         ret = m_pOi->set_organization_property_value("hoge1", any);
00333         CPPUNIT_ASSERT(ret);
00334 
00335         // プロパティの設定値取得時、 設定値が返されるか?
00336         rany = m_pOi->get_organization_property_value("hoge1");
00337         (*rany) >>= rft;
00338         CPPUNIT_ASSERT_EQUAL(ft, rft);
00339 
00340 
00341         // プロパティの設定時、true が返されるか?
00342         st = 123;
00343         any <<= st;
00344         ret = m_pOi->set_organization_property_value("hoge2", any);
00345         CPPUNIT_ASSERT(ret);
00346 
00347         // プロパティの設定値取得時、 設定値が返されるか?
00348         rany = m_pOi->get_organization_property_value("hoge2");
00349         (*rany) >>= rst;
00350         CPPUNIT_ASSERT_EQUAL(st, rst);
00351 
00352 
00353         // プロパティの更新時、true が返されるか?
00354         st = 456;
00355         any <<= st;
00356         ret = m_pOi->set_organization_property_value("hoge2", any);
00357         CPPUNIT_ASSERT(ret);
00358 
00359         // プロパティの更新値取得時、 設定値が返されるか?
00360         rany = m_pOi->get_organization_property_value("hoge2");
00361         (*rany) >>= rst;
00362         CPPUNIT_ASSERT_EQUAL(st, rst);
00363 
00364         // プロパティの設定時、name 未設定による InvalidParameter が返されるか?
00365         short sflg = -1;
00366         try {
00367           ret = m_pOi->set_organization_property_value("", any);
00368           sflg = 0;
00369         }
00370         catch (InvalidParameter ip) {
00371 //        cout << "InvalidParameter exception." << endl;
00372           sflg = 1;
00373         }
00374         CPPUNIT_ASSERT(sflg == 1);
00375 
00376         // プロパティの設定値取得時、name 未設定による InvalidParameter が返されるか?
00377         sflg = -1;
00378         try {
00379           ret = m_pOi->get_organization_property_value("");
00380           sflg = 0;
00381         }
00382         catch (InvalidParameter ip) {
00383 //        cout << "InvalidParameter exception." << endl;
00384           sflg = 1;
00385         }
00386         CPPUNIT_ASSERT(sflg == 1);
00387 
00388         // プロパティの設定値取得時、name 未登録による InvalidParameter が返されるか?
00389         sflg = -1;
00390         try {
00391           ret = m_pOi->get_organization_property_value("hoge99");
00392           sflg = 0;
00393         }
00394         catch (InvalidParameter ip) {
00395 //        cout << "InvalidParameter exception." << endl;
00396           sflg = 1;
00397         }
00398         CPPUNIT_ASSERT(sflg == 1);
00399       }
00400       catch (InvalidParameter ip) {
00401         cout << "InvalidParameter exception." << endl;
00402       }
00403       catch (NotAvailable na) {
00404         cout << "NotAvailable exception." << endl;
00405       }
00406       catch (InternalError ip) {
00407         cout << "InternalError exception." << endl;
00408       }
00409       catch (...) {
00410         cout << "othrer exception." << endl;
00411       }
00412 
00413 //      std::cout << "test_set_get_organization_property_value OUT" << std::endl;
00414     }
00415 
00419     void test_remove_organization_property() {
00420 //      std::cout << "test_remove_organization_property IN" << std::endl;
00421       OrganizationProperty set_prop;
00422       CORBA::Boolean ret;
00423       CORBA::Float ft;
00424       NVList nvList;
00425       NameValue nv;
00426       string str;
00427 
00428       nv.name = "hoge";
00429       str = "hoge"; 
00430       ft = 11.111;
00431       nv.value <<= ft;
00432 
00433       nvList.length(1);
00434       nvList[0] = nv;
00435 
00436       set_prop.properties = nvList;
00437       // プロパティのセット
00438       ret = m_pOi->add_organization_property(set_prop);
00439       CPPUNIT_ASSERT(ret);
00440 
00441       // InvalidParameter exceptionを確認
00442       short sflg = -1;
00443       try {
00444         ret = m_pOi->remove_organization_property("short");
00445         if (!ret) {
00446           cout << "Couldn't remove name: short" << endl;
00447         }
00448         sflg = 0;
00449       }
00450       catch (InvalidParameter ip) {
00451 //      cout << "InvalidParameter exception." << endl;
00452         sflg = 1;
00453       }
00454       catch (NotAvailable na) {
00455         cout << "NotAvailable exception." << endl;
00456         sflg = 2;
00457       }
00458       catch (InternalError ip) {
00459         cout << "InternalError exception." << endl;
00460         sflg = 3;
00461       }
00462       catch (...) {
00463         cout << "othrer exception." << endl;
00464         sflg = 4;
00465       }
00466       CPPUNIT_ASSERT(sflg == 1);
00467       
00468       // 戻り値:true を確認
00469       sflg = -1;
00470       try {
00471         ret = m_pOi->remove_organization_property("hoge");
00472         if (!ret) {
00473           cout << "Couldn't remove name: hoge" << endl;
00474         }
00475         CPPUNIT_ASSERT(ret);
00476         sflg = 0;
00477       }
00478       catch (InvalidParameter ip) {
00479         cout << "InvalidParameter exception." << endl;
00480         sflg = 1;
00481       }
00482       catch (NotAvailable na) {
00483         cout << "NotAvailable exception." << endl;
00484         sflg = 2;
00485       }
00486       catch (InternalError ip) {
00487         cout << "InternalError exception." << endl;
00488         sflg = 3;
00489       }
00490       catch (...) {
00491         cout << "othrer exception." << endl;
00492         sflg = 4;
00493       }
00494       CPPUNIT_ASSERT(sflg == 0);
00495 //      std::cout << "test_remove_organization_property OUT" << std::endl;
00496     }
00497 
00498 
00502     void test_set_get_owner() {
00503 //      std::cout << "test_set_get_owner IN" << std::endl;
00504       CORBA::Boolean ret;
00505       SDOPackage::SDOSystemElement_var varOwner;
00506       SDOPackage::SDOSystemElement_ptr ptrOwner;
00507 
00508       try {
00509         // オーナー取得が行えるか?
00510         varOwner = m_pOi->get_owner();
00511         CPPUNIT_ASSERT(!::CORBA::is_nil(varOwner));
00512 
00513         // InvalidParameter exceptionを確認
00514         short sflg = -1;
00515         try {
00516           // オーナー設定時、InvalidParameter が返されるか?
00517           ptrOwner = SDOPackage::SDOSystemElement::_nil();
00518           ret = m_pOi->set_owner(ptrOwner);
00519           CPPUNIT_ASSERT(ret);
00520           sflg = 0;
00521         }
00522         catch (InvalidParameter ip) {
00523 //        cout << "InvalidParameter exception." << endl;
00524           sflg = 1;
00525         }
00526         catch (NotAvailable na) {
00527           cout << "NotAvailable exception." << endl;
00528           sflg = 2;
00529         }
00530         catch (InternalError ip) {
00531           cout << "InternalError exception." << endl;
00532           sflg = 3;
00533         }
00534         catch (...) {
00535           cout << "othrer exception." << endl;
00536           sflg = 4;
00537         }
00538         CPPUNIT_ASSERT(sflg == 1);
00539 
00540         // 戻り値:true を確認
00541         sflg = -1;
00542         try {
00543           // オーナー設定時、true が返されるか?
00544           ::RTC::RTObject_impl* rtobj2;
00545           ::RTC::Manager& mgr2(RTC::Manager::instance());
00546           rtobj2 = new ::RTC::RTObject_impl(&mgr2);
00547           ptrOwner = rtobj2->getObjRef();
00548 
00549           ret = m_pOi->set_owner(ptrOwner);
00550           CPPUNIT_ASSERT(ret);
00551           sflg = 0;
00552           rtobj2->_remove_ref();
00553         }
00554         catch (InvalidParameter ip) {
00555           cout << "InvalidParameter exception." << endl;
00556           sflg = 1;
00557         }
00558         catch (NotAvailable na) {
00559           cout << "NotAvailable exception." << endl;
00560           sflg = 2;
00561         }
00562         catch (InternalError ip) {
00563           cout << "InternalError exception." << endl;
00564           sflg = 3;
00565         }
00566         catch (...) {
00567           cout << "othrer exception." << endl;
00568           sflg = 4;
00569         }
00570         CPPUNIT_ASSERT(sflg == 0);
00571       }
00572       catch (InvalidParameter ip) {
00573         cout << "InvalidParameter exception." << endl;
00574       }
00575       catch (NotAvailable na) {
00576         cout << "NotAvailable exception." << endl;
00577       }
00578       catch (InternalError ip) {
00579         cout << "InternalError exception." << endl;
00580       }
00581       catch (...) {
00582         cout << "othrer exception." << endl;
00583       }
00584 //      std::cout << "test_set_get_owner OUT" << std::endl;
00585     }
00586 
00587 
00591     void test_set_get_members() {
00592 //      std::cout << "test_set_get_members IN" << std::endl;
00593       CORBA::Boolean ret;
00594       SDOPackage::SDO_var sdo;
00595       SDOPackage::SDOList slist;
00596       SDOPackage::SDOList* rslist;
00597 
00598       // SDO のセット時、InvalidParameter を取得できるか?
00599       // set_members()に、NULL や 空のリストを渡してもlength()=0となるため
00600       // InvalidParameterを返すケースはない。
00601       // SDOList のセット時、空のリストを渡して取得できるか?
00602       short sflg = -1;
00603       try {
00604         slist = NULL;
00605         ret = m_pOi->set_members(slist);
00606         CPPUNIT_ASSERT(ret);
00607         sflg = 0;
00608       }
00609       catch (InvalidParameter ip) {
00610         cout << "InvalidParameter exception." << endl;
00611         sflg = 1;
00612       }
00613       catch (NotAvailable na) {
00614         cout << "NotAvailable exception." << endl;
00615         sflg = 2;
00616       }
00617       catch (InternalError ip) {
00618         cout << "InternalError exception." << endl;
00619         sflg = 3;
00620       }
00621       catch (...) {
00622         cout << "othrer exception." << endl;
00623         sflg = 4;
00624       }
00625       CPPUNIT_ASSERT(sflg == 0);
00626 
00627       // 0件のSDOList取得が行えるか?
00628       rslist = m_pOi->get_members();
00629       CPPUNIT_ASSERT(rslist->length() == 0);
00630 
00631 
00632       // SDOList のセット時、リストをセットして true を取得できるか?
00633       sflg = -1;
00634       try {
00635         RTC::RTObject_impl* rtobj2;
00636         RTC::Manager& mgr2(RTC::Manager::instance());
00637         rtobj2 = new ::RTC::RTObject_impl(&mgr2);
00638         sdo = SDOPackage::SDO::_duplicate(rtobj2->getObjRef());
00639         CORBA_SeqUtil::push_back(slist, sdo);
00640         ret = m_pOi->set_members(slist);
00641         CPPUNIT_ASSERT(ret);
00642         sflg = 0;
00643         rtobj2->_remove_ref();
00644       }
00645       catch (InvalidParameter ip) {
00646         cout << "InvalidParameter exception." << endl;
00647         sflg = 1;
00648       }
00649       catch (NotAvailable na) {
00650         cout << "NotAvailable exception." << endl;
00651         sflg = 2;
00652       }
00653       catch (InternalError ip) {
00654         cout << "InternalError exception." << endl;
00655         sflg = 3;
00656       }
00657       catch (...) {
00658         cout << "othrer exception." << endl;
00659         sflg = 4;
00660       }
00661       CPPUNIT_ASSERT(sflg == 0);
00662 
00663       // 1件のSDOList取得が行えるか?
00664       rslist = m_pOi->get_members();
00665       CPPUNIT_ASSERT(rslist->length() == 1);
00666 //      std::cout << "test_set_get_members OUT" << std::endl;
00667     }
00668 
00669 
00673     void test_add_remove_members() {
00674 //      std::cout << "test_add_remove_members IN" << std::endl;
00675       CORBA::Boolean ret;
00676       SDOPackage::SDO_var sdo;
00677       SDOPackage::SDOList slist;
00678       SDOPackage::SDOList* rslist;
00679       Organization_impl* m_pOi2;
00680       std::string str;
00681       CORBA::Any any;
00682 
00683       RTC::RTObject_impl* rtobj2;
00684       RTC::Manager& mgr2(RTC::Manager::instance());
00685       mgr2.activateManager();
00686       rtobj2 = new ::RTC::RTObject_impl(&mgr2);
00687       m_pOi2 = new Organization_impl(rtobj2->getObjRef());
00688 
00689       // SDO のセット時、InvalidParameter を取得できるか?
00690       // add_members()に、NULL や 空のリストを渡してもlength()=0となるため
00691       // InvalidParameterを返すケースはない。
00692       // SDOList のセット時、空のリストを渡して true を取得できるか?
00693 
00694       short sflg = -1;
00695       try {
00696         slist = NULL;
00697         ret = m_pOi->add_members(slist);
00698         CPPUNIT_ASSERT(ret);
00699         sflg = 0;
00700       }
00701       catch (InvalidParameter ip) {
00702         cout << "InvalidParameter exception." << endl;
00703         sflg = 1;
00704       }
00705       catch (NotAvailable na) {
00706         cout << "NotAvailable exception." << endl;
00707         sflg = 2;
00708       }
00709       catch (InternalError ip) {
00710         cout << "InternalError exception." << endl;
00711         sflg = 3;
00712       }
00713       catch (...) {
00714         cout << "othrer exception." << endl;
00715         sflg = 4;
00716       }
00717       CPPUNIT_ASSERT(sflg == 0);
00718 
00719       // SDOList のセット時、リストをセットして true を取得できるか?
00720       sflg = -1;
00721       try {
00722         sdo = SDOPackage::SDO::_duplicate(rtobj2->getObjRef());
00723         CORBA_SeqUtil::push_back(slist, sdo);
00724         rtobj2->setInstanceName("hoge1");
00725 
00726         // SDOメンバーの追加が成功するか?
00727         ret = m_pOi2->add_members(slist);
00728         CPPUNIT_ASSERT(ret);
00729         sflg = 0;
00730 
00731         str = m_pOi2->get_organization_id(); 
00732         any <<= str.c_str();
00733         ret = m_pOi2->set_organization_property_value("instance_name", any);
00734       }
00735       catch (InvalidParameter ip) {
00736         cout << "InvalidParameter exception." << endl;
00737         sflg = 1;
00738       }
00739       catch (NotAvailable na) {
00740         cout << "NotAvailable exception." << endl;
00741         sflg = 2;
00742       }
00743       catch (InternalError ip) {
00744         cout << "InternalError exception." << endl;
00745         sflg = 3;
00746       }
00747       catch (...) {
00748         cout << "othrer exception." << endl;
00749         sflg = 4;
00750       }
00751       CPPUNIT_ASSERT(sflg == 0);
00752 
00753       // 1件のSDOList取得が行えるか?
00754       rslist = m_pOi2->get_members();
00755       CPPUNIT_ASSERT(rslist->length() == 1);
00756 
00757       // SDOList削除時、引数未定義でInvalidParameterを取得できるか?
00758       sflg = -1;
00759       try {
00760         ret = m_pOi2->remove_member("");
00761         CPPUNIT_ASSERT(ret);
00762         sflg = 0;
00763       }
00764       catch (InvalidParameter ip) {
00765 //        cout << "InvalidParameter exception." << endl;
00766         sflg = 1;
00767       }
00768       catch (NotAvailable na) {
00769         cout << "NotAvailable exception." << endl;
00770         sflg = 2;
00771       }
00772       catch (InternalError ip) {
00773         cout << "InternalError exception." << endl;
00774         sflg = 3;
00775       }
00776       catch (...) {
00777         cout << "othrer exception." << endl;
00778         sflg = 4;
00779       }
00780       CPPUNIT_ASSERT(sflg == 1);
00781 
00782       // SDOList削除時、引数不正でInvalidParameterを取得できるか?
00783       sflg = -1;
00784       try {
00785         ret = m_pOi2->remove_member("dummy");
00786         CPPUNIT_ASSERT(ret);
00787         sflg = 0;
00788       }
00789       catch (InvalidParameter ip) {
00790 //        cout << "InvalidParameter exception." << endl;
00791         sflg = 1;
00792       }
00793       catch (NotAvailable na) {
00794         cout << "NotAvailable exception." << endl;
00795         sflg = 2;
00796       }
00797       catch (InternalError ip) {
00798         cout << "InternalError exception." << endl;
00799         sflg = 3;
00800       }
00801       catch (...) {
00802         cout << "othrer exception." << endl;
00803         sflg = 4;
00804       }
00805       CPPUNIT_ASSERT(sflg == 1);
00806 
00807       // SDOList削除時、正しい引数で削除できるか?
00808       sflg = -1;
00809       try {
00810         ret = m_pOi2->remove_member("hoge1");
00811         CPPUNIT_ASSERT(ret);
00812         sflg = 0;
00813       }
00814       catch (InvalidParameter ip) {
00815         cout << "InvalidParameter exception." << endl;
00816         sflg = 1;
00817       }
00818       catch (NotAvailable na) {
00819         cout << "NotAvailable exception." << endl;
00820         sflg = 2;
00821       }
00822       catch (InternalError ip) {
00823         cout << "InternalError exception." << endl;
00824         sflg = 3;
00825       }
00826       catch (...) {
00827         cout << "othrer exception." << endl;
00828         sflg = 4;
00829       }
00830       CPPUNIT_ASSERT(sflg == 0);
00831 
00832       // 0件のSDOList取得が行えるか?
00833       rslist = m_pOi2->get_members();
00834       CPPUNIT_ASSERT(rslist->length() == 0);
00835 
00836       if ( !CORBA::is_nil( mgr2.getPOA()) ) {
00837         if ( !CORBA::is_nil(mgr2.getPOAManager()) ) {
00838           mgr2.getPOAManager()->deactivate(false, true);
00839         }
00840       }
00841       rtobj2->_remove_ref();
00842       m_pOi2->_remove_ref();
00843 //      std::cout << "test_add_remove_members OUT" << std::endl;
00844     }
00845 
00846 
00850     void test_set_get_dependency() {
00851 //      std::cout << "test_set_get_dependency IN" << std::endl;
00852       DependencyType depType;
00853       
00854       // Success case.
00855       // default return value is 0.
00856       depType = m_pOi->get_dependency();
00857 //      cout << "depType: " << depType << endl;
00858       CPPUNIT_ASSERT(depType == 0);
00859       
00860       m_pOi->set_dependency(NO_DEPENDENCY);
00861       // returned value is 2.
00862       depType = m_pOi->get_dependency();
00863       CPPUNIT_ASSERT(depType == 2);
00864 //      cout << "depType: " << depType << endl;
00865       
00866       // Failure case.
00867       //    m_pOi->set_dependency(0); // コンパイルエラー
00868       //    CPPUNIT_ASSERT(depType == 3);
00869       //    cout << "depType: " << depType << endl;
00870 //      std::cout << "test_set_get_dependency OUT" << std::endl;
00871     }
00872 
00873   };
00874 }; // namespace SdoOrganization
00875 
00876 /*
00877  * Register test suite
00878  */
00879 CPPUNIT_TEST_SUITE_REGISTRATION(SdoOrganization::SdoOrganizationTests);
00880 
00881 #ifdef LOCAL_MAIN
00882 int main(int argc, char* argv[])
00883 {
00884 
00885   FORMAT format = TEXT_OUT;
00886   int target = 0;
00887   std::string xsl;
00888   std::string ns;
00889   std::string fname;
00890   std::ofstream ofs;
00891 
00892   int i(1);
00893   while (i < argc)
00894     {
00895       std::string arg(argv[i]);
00896       std::string next_arg;
00897       if (i + 1 < argc) next_arg = argv[i + 1];
00898       else              next_arg = "";
00899 
00900       if (arg == "--text") { format = TEXT_OUT; break; }
00901       if (arg == "--xml")
00902         {
00903           if (next_arg == "")
00904             {
00905               fname = argv[0];
00906               fname += ".xml";
00907             }
00908           else
00909             {
00910               fname = next_arg;
00911             }
00912           format = XML_OUT;
00913           ofs.open(fname.c_str());
00914         }
00915       if ( arg == "--compiler"  ) { format = COMPILER_OUT; break; }
00916       if ( arg == "--cerr"      ) { target = 1; break; }
00917       if ( arg == "--xsl"       )
00918         {
00919           if (next_arg == "") xsl = "default.xsl"; 
00920           else                xsl = next_arg;
00921         }
00922       if ( arg == "--namespace" )
00923         {
00924           if (next_arg == "")
00925             {
00926               std::cerr << "no namespace specified" << std::endl;
00927               exit(1); 
00928             }
00929           else
00930             {
00931               xsl = next_arg;
00932             }
00933         }
00934       ++i;
00935     }
00936   CppUnit::TextUi::TestRunner runner;
00937   if ( ns.empty() )
00938     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00939   else
00940     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
00941   CppUnit::Outputter* outputter = 0;
00942   std::ostream* stream = target ? &std::cerr : &std::cout;
00943   switch ( format )
00944     {
00945     case TEXT_OUT :
00946       outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
00947       break;
00948     case XML_OUT :
00949       std::cout << "XML_OUT" << std::endl;
00950       outputter = new CppUnit::XmlOutputter(&runner.result(),
00951                                             ofs, "shift_jis");
00952       static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
00953       break;
00954     case COMPILER_OUT :
00955       outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
00956       break;
00957     }
00958   runner.setOutputter(outputter);
00959   runner.run();
00960   return 0; // runner.run() ? 0 : 1;
00961 }
00962 #endif // MAIN
00963 #endif // SdoOrganization_cpp


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:17