SdoOrganizationTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
21 /*
22  * $Log: SdoOrganizationTests.cpp,v $
23  * Revision 1.1 2007/12/20 07:50:17 arafune
24  * *** empty log message ***
25  *
26  * Revision 1.1 2006/11/27 08:37:43 n-ando
27  * TestSuites are devided into each directory.
28  *
29  *
30  */
31 
32 #ifndef SdoOrganization_cpp
33 #define SdoOrganization_cpp
34 
35 #include <cppunit/ui/text/TestRunner.h>
36 #include <cppunit/TextOutputter.h>
37 #include <cppunit/extensions/TestFactoryRegistry.h>
38 #include <cppunit/extensions/HelperMacros.h>
39 #include <cppunit/TestAssert.h>
40 #include <rtm/RTObject.h>
41 #include <rtm/Manager.h>
42 #include <rtm/SdoOrganization.h>
43 
44 
49 namespace SdoOrganization
50 {
51  using namespace SDOPackage;
52  using namespace std;
53 
55  : public CppUnit::TestFixture
56  {
57  CPPUNIT_TEST_SUITE(SdoOrganizationTests);
58 
59  CPPUNIT_TEST(test_get_organization_id);
60  CPPUNIT_TEST(test_set_get_organization_property);
61  CPPUNIT_TEST(test_set_get_organization_property_value);
62  CPPUNIT_TEST(test_remove_organization_property);
63  CPPUNIT_TEST(test_set_get_owner);
64  CPPUNIT_TEST(test_set_get_members);
65  CPPUNIT_TEST(test_add_remove_members);
66  CPPUNIT_TEST(test_set_get_dependency);
67 
68  CPPUNIT_TEST_SUITE_END();
69 
70  private:
73  char* m_id;
74  public:
75 
80  {
81  }
82 
87  {
88  }
89 
93  virtual void setUp()
94  {
96  rtobj = new ::RTC::RTObject_impl(&mgr);
97  m_pOi = new Organization_impl(rtobj->getObjRef());
98  }
99 
103  virtual void tearDown()
104  {
105  m_pOi->_remove_ref();
106  rtobj->_remove_ref();
107  }
108 
109 
114 // std::cout << "test_get_organization_id IN" << std::endl;
115  m_id = m_pOi->get_organization_id();
116  CPPUNIT_ASSERT(m_id != NULL);
117 // std::cout << "test_get_organization_id OUT" << std::endl;
118  }
119 
120 
125 // std::cout << "test_set_get_organization_property IN" << std::endl;
126  OrganizationProperty_var get_prop;
127  OrganizationProperty set_prop;
128  CORBA::Boolean ret;
129  CORBA::Short st;
130  CORBA::Long lg;
131  CORBA::Float ft;
132  CORBA::Double db;
133  // char* strg;
134 
135  CORBA::Short rst;
136  CORBA::Long rlg;
137  CORBA::Float rft;
138  CORBA::Double rdb;
139  // char* rstrg;
140 
141  NVList nvList;
142  NameValue nv;
143  string str;
144 
145  try {
146  // プロパティの取得 length 0のプロパティが返される。
147  get_prop = m_pOi->get_organization_property();
148 // cout << endl << "get property length: " << get_prop->properties.length() << endl;
149 
150 
151  // 空のOrganizationPropertyをセットする。 OK.
152  ret = m_pOi->add_organization_property(set_prop);
153 
154 
155  nv.name = "hoge";
156  str = "hoge";
157  ft = 11.111;
158  nv.value <<= ft;
159 
160  nvList.length(1);
161  nvList[0] = nv;
162 
163  set_prop.properties = nvList;
164  // プロパティのセット ret = m_pOi->add_organization_property(set_prop); // プロパティの取得 length 1のプロパティリストを持つOrganizationPropertyが返される。 get_prop = m_pOi->get_organization_property(); // cout << "get property length: " << get_prop->properties.length() << endl; str = (get_prop->properties[0]).name; (get_prop->properties[0]).value >>= rft; CPPUNIT_ASSERT(str == "hoge"); CPPUNIT_ASSERT(rft == ft); nv.name = "hogehoge"; ft = 22.2; nv.value <<= ft; nvList.length(1); nvList[0] = nv; set_prop.properties = nvList; // プロパティのセット ret = m_pOi->add_organization_property(set_prop); // プロパティの取得 get_prop = m_pOi->get_organization_property(); // cout << "get property length: " << get_prop->properties.length() << endl; str = ((get_prop->properties[0]).name); (get_prop->properties[0]).value >>= rft; CPPUNIT_ASSERT(str == "hogehoge"); CPPUNIT_ASSERT(rft == ft); // nvList.length(5); nvList.length(4); // cout << "short" << endl; nv.name = "short"; st = 1; nv.value <<= st; nvList[0] = nv; // cout << "long" << endl; nv.name = "long"; lg = 2222; nv.value <<= lg; nvList[1] = nv; // cout << "float" << endl; nv.name = "float"; ft = 33.3; nv.value <<= ft; nvList[2] = nv; // cout << "double" << endl; nv.name = "double"; db = 3.3; nv.value <<= db; nvList[3] = nv; // nv.name = "char"; // strg = "STRING"; // nv.value <<= CORBA::Any::from_char('C'); // ここでセグメントエラー発生 // cout << "char" << endl; // nvList[4] = nv; // cout << "string" << endl; // nv.name = "string"; // strg = "STRING"; // char * p = "STRING"; // nv.value <<= CORBA::Any::from_string(p,7); // ここでセグメントエラー発生 // nvList[4] = nv; // cout << "set_prop.properties" << endl; set_prop.properties = nvList; // cout << "set in" << endl; ret = m_pOi->add_organization_property(set_prop); // cout << "set out" << endl; get_prop = m_pOi->get_organization_property(); // cout << "get property length: " << get_prop->properties.length() << endl; str = ((get_prop->properties[0]).name); (get_prop->properties[0]).value >>= rst; CPPUNIT_ASSERT(str == "short"); CPPUNIT_ASSERT(rst == st); str = ((get_prop->properties[1]).name); (get_prop->properties[1]).value >>= rlg; CPPUNIT_ASSERT(str == "long"); CPPUNIT_ASSERT(rlg == lg); str = ((get_prop->properties[2]).name); (get_prop->properties[2]).value >>= rft; CPPUNIT_ASSERT(str == "float"); CPPUNIT_ASSERT(rft == ft); str = ((get_prop->properties[3]).name); (get_prop->properties[3]).value >>= rdb; CPPUNIT_ASSERT(str == "double"); CPPUNIT_ASSERT(rdb == db); // str = ((get_prop->properties[4]).name); // (get_prop->properties[4]).value >>= (CORBA::Any::to_char(rch)); // CPPUNIT_ASSERT(str == "char"); // CPPUNIT_ASSERT(rch == ch); // str = ((get_prop->properties[4]).name); // char * retp; // (get_prop->properties[4]).value >>= CORBA::Any::to_string(retp,7); // CPPUNIT_ASSERT(str == "string"); // CPPUNIT_ASSERT(*retp == *p); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; } catch (InternalError ip) { cout << "InternalError exception." << endl; } catch (...) { cout << "othrer exception." << endl; } // std::cout << "test_set_get_organization_property OUT" << std::endl; } /*! * @brief set_organization_property_value() and get_organization_property_value() */ void test_set_get_organization_property_value() { // std::cout << "test_set_get_organization_property_value IN" << std::endl; OrganizationProperty_var get_prop; OrganizationProperty set_prop; CORBA::Boolean ret; CORBA::Short st; // CORBA::Long lg; CORBA::Float ft; // CORBA::Double db; CORBA::Any any; CORBA::Short rst; // CORBA::Long rlg; CORBA::Float rft; // CORBA::Double rdb; CORBA::Any* rany; NVList nvList; NameValue nv; string str; try { // プロパティの取得 length 0のプロパティが返される。 get_prop = m_pOi->get_organization_property(); // cout << endl << "get property length: " << get_prop->properties.length() << endl; // 空のOrganizationPropertyをセットする。 OK. ret = m_pOi->add_organization_property(set_prop); CPPUNIT_ASSERT(ret); // プロパティの設定時、true が返されるか? ft = 11.111; any <<= ft; ret = m_pOi->set_organization_property_value("hoge1", any); CPPUNIT_ASSERT(ret); // プロパティの設定値取得時、 設定値が返されるか? rany = m_pOi->get_organization_property_value("hoge1"); (*rany) >>= rft; CPPUNIT_ASSERT_EQUAL(ft, rft); // プロパティの設定時、true が返されるか? st = 123; any <<= st; ret = m_pOi->set_organization_property_value("hoge2", any); CPPUNIT_ASSERT(ret); // プロパティの設定値取得時、 設定値が返されるか? rany = m_pOi->get_organization_property_value("hoge2"); (*rany) >>= rst; CPPUNIT_ASSERT_EQUAL(st, rst); // プロパティの更新時、true が返されるか? st = 456; any <<= st; ret = m_pOi->set_organization_property_value("hoge2", any); CPPUNIT_ASSERT(ret); // プロパティの更新値取得時、 設定値が返されるか? rany = m_pOi->get_organization_property_value("hoge2"); (*rany) >>= rst; CPPUNIT_ASSERT_EQUAL(st, rst); // プロパティの設定時、name 未設定による InvalidParameter が返されるか? short sflg = -1; try { ret = m_pOi->set_organization_property_value("", any); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } CPPUNIT_ASSERT(sflg == 1); // プロパティの設定値取得時、name 未設定による InvalidParameter が返されるか? sflg = -1; try { ret = m_pOi->get_organization_property_value(""); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } CPPUNIT_ASSERT(sflg == 1); // プロパティの設定値取得時、name 未登録による InvalidParameter が返されるか? sflg = -1; try { ret = m_pOi->get_organization_property_value("hoge99"); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } CPPUNIT_ASSERT(sflg == 1); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; } catch (InternalError ip) { cout << "InternalError exception." << endl; } catch (...) { cout << "othrer exception." << endl; } // std::cout << "test_set_get_organization_property_value OUT" << std::endl; } /*! * @brief add_organization_property() and remove_organization_property() */ void test_remove_organization_property() { // std::cout << "test_remove_organization_property IN" << std::endl; OrganizationProperty set_prop; CORBA::Boolean ret; CORBA::Float ft; NVList nvList; NameValue nv; string str; nv.name = "hoge"; str = "hoge"; ft = 11.111; nv.value <<= ft; nvList.length(1); nvList[0] = nv; set_prop.properties = nvList; // プロパティのセット ret = m_pOi->add_organization_property(set_prop); CPPUNIT_ASSERT(ret); // InvalidParameter exceptionを確認 short sflg = -1; try { ret = m_pOi->remove_organization_property("short"); if (!ret) { cout << "Couldn't remove name: short" << endl; } sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // 戻り値:true を確認 sflg = -1; try { ret = m_pOi->remove_organization_property("hoge"); if (!ret) { cout << "Couldn't remove name: hoge" << endl; } CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // std::cout << "test_remove_organization_property OUT" << std::endl; } /*! * @brief set_owner() and get_owner() */ void test_set_get_owner() { // std::cout << "test_set_get_owner IN" << std::endl; CORBA::Boolean ret; SDOPackage::SDOSystemElement_var varOwner; SDOPackage::SDOSystemElement_ptr ptrOwner; try { // オーナー取得が行えるか? varOwner = m_pOi->get_owner(); CPPUNIT_ASSERT(!::CORBA::is_nil(varOwner)); // InvalidParameter exceptionを確認 short sflg = -1; try { // オーナー設定時、InvalidParameter が返されるか? ptrOwner = SDOPackage::SDOSystemElement::_nil(); ret = m_pOi->set_owner(ptrOwner); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // 戻り値:true を確認 sflg = -1; try { // オーナー設定時、true が返されるか? ::RTC::RTObject_impl* rtobj2; ::RTC::Manager& mgr2(RTC::Manager::instance()); rtobj2 = new ::RTC::RTObject_impl(&mgr2); ptrOwner = rtobj2->getObjRef(); ret = m_pOi->set_owner(ptrOwner); CPPUNIT_ASSERT(ret); sflg = 0; rtobj2->_remove_ref(); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; } catch (InternalError ip) { cout << "InternalError exception." << endl; } catch (...) { cout << "othrer exception." << endl; } // std::cout << "test_set_get_owner OUT" << std::endl; } /*! * @brief set_members() and get_members() */ void test_set_get_members() { // std::cout << "test_set_get_members IN" << std::endl; CORBA::Boolean ret; SDOPackage::SDO_var sdo; SDOPackage::SDOList slist; SDOPackage::SDOList* rslist; // SDO のセット時、InvalidParameter を取得できるか? // set_members()に、NULL や 空のリストを渡してもlength()=0となるため // InvalidParameterを返すケースはない。 // SDOList のセット時、空のリストを渡して取得できるか? short sflg = -1; try { slist = NULL; ret = m_pOi->set_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 0件のSDOList取得が行えるか? rslist = m_pOi->get_members(); CPPUNIT_ASSERT(rslist->length() == 0); // SDOList のセット時、リストをセットして true を取得できるか? sflg = -1; try { RTC::RTObject_impl* rtobj2; RTC::Manager& mgr2(RTC::Manager::instance()); rtobj2 = new ::RTC::RTObject_impl(&mgr2); sdo = SDOPackage::SDO::_duplicate(rtobj2->getObjRef()); CORBA_SeqUtil::push_back(slist, sdo); ret = m_pOi->set_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; rtobj2->_remove_ref(); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 1件のSDOList取得が行えるか? rslist = m_pOi->get_members(); CPPUNIT_ASSERT(rslist->length() == 1); // std::cout << "test_set_get_members OUT" << std::endl; } /*! * @brief add_members() and remove_member() */ void test_add_remove_members() { // std::cout << "test_add_remove_members IN" << std::endl; CORBA::Boolean ret; SDOPackage::SDO_var sdo; SDOPackage::SDOList slist; SDOPackage::SDOList* rslist; Organization_impl* m_pOi2; std::string str; CORBA::Any any; RTC::RTObject_impl* rtobj2; RTC::Manager& mgr2(RTC::Manager::instance()); mgr2.activateManager(); rtobj2 = new ::RTC::RTObject_impl(&mgr2); m_pOi2 = new Organization_impl(rtobj2->getObjRef()); // SDO のセット時、InvalidParameter を取得できるか? // add_members()に、NULL や 空のリストを渡してもlength()=0となるため // InvalidParameterを返すケースはない。 // SDOList のセット時、空のリストを渡して true を取得できるか? short sflg = -1; try { slist = NULL; ret = m_pOi->add_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // SDOList のセット時、リストをセットして true を取得できるか? sflg = -1; try { sdo = SDOPackage::SDO::_duplicate(rtobj2->getObjRef()); CORBA_SeqUtil::push_back(slist, sdo); rtobj2->setInstanceName("hoge1"); // SDOメンバーの追加が成功するか? ret = m_pOi2->add_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; str = m_pOi2->get_organization_id(); any <<= str.c_str(); ret = m_pOi2->set_organization_property_value("instance_name", any); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 1件のSDOList取得が行えるか? rslist = m_pOi2->get_members(); CPPUNIT_ASSERT(rslist->length() == 1); // SDOList削除時、引数未定義でInvalidParameterを取得できるか? sflg = -1; try { ret = m_pOi2->remove_member(""); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // SDOList削除時、引数不正でInvalidParameterを取得できるか? sflg = -1; try { ret = m_pOi2->remove_member("dummy"); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // SDOList削除時、正しい引数で削除できるか? sflg = -1; try { ret = m_pOi2->remove_member("hoge1"); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 0件のSDOList取得が行えるか? rslist = m_pOi2->get_members(); CPPUNIT_ASSERT(rslist->length() == 0); if ( !CORBA::is_nil( mgr2.getPOA()) ) { if ( !CORBA::is_nil(mgr2.getPOAManager()) ) { mgr2.getPOAManager()->deactivate(false, true); } } rtobj2->_remove_ref(); m_pOi2->_remove_ref(); // std::cout << "test_add_remove_members OUT" << std::endl; } /*! * @brief set_dependency() and get_dependency() */ void test_set_get_dependency() { // std::cout << "test_set_get_dependency IN" << std::endl; DependencyType depType; // Success case. // default return value is 0. depType = m_pOi->get_dependency(); // cout << "depType: " << depType << endl; CPPUNIT_ASSERT(depType == 0); m_pOi->set_dependency(NO_DEPENDENCY); // returned value is 2. depType = m_pOi->get_dependency(); CPPUNIT_ASSERT(depType == 2); // cout << "depType: " << depType << endl; // Failure case. // m_pOi->set_dependency(0); // コンパイルエラー // CPPUNIT_ASSERT(depType == 3); // cout << "depType: " << depType << endl; // std::cout << "test_set_get_dependency OUT" << std::endl; } }; }; // namespace SdoOrganization /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoOrganization::SdoOrganizationTests); #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 // SdoOrganization_cpp
165  ret = m_pOi->add_organization_property(set_prop);
166 
167  // プロパティの取得 length 1のプロパティリストを持つOrganizationPropertyが返される。
168  get_prop = m_pOi->get_organization_property();
169 // cout << "get property length: " << get_prop->properties.length() << endl;
170 
171  str = (get_prop->properties[0]).name;
172  (get_prop->properties[0]).value >>= rft;
173  CPPUNIT_ASSERT(str == "hoge");
174  CPPUNIT_ASSERT(rft == ft);
175 
176 
177  nv.name = "hogehoge";
178  ft = 22.2;
179  nv.value <<= ft;
180 
181  nvList.length(1);
182  nvList[0] = nv;
183 
184  set_prop.properties = nvList;
185  // プロパティのセット ret = m_pOi->add_organization_property(set_prop); // プロパティの取得 get_prop = m_pOi->get_organization_property(); // cout << "get property length: " << get_prop->properties.length() << endl; str = ((get_prop->properties[0]).name); (get_prop->properties[0]).value >>= rft; CPPUNIT_ASSERT(str == "hogehoge"); CPPUNIT_ASSERT(rft == ft); // nvList.length(5); nvList.length(4); // cout << "short" << endl; nv.name = "short"; st = 1; nv.value <<= st; nvList[0] = nv; // cout << "long" << endl; nv.name = "long"; lg = 2222; nv.value <<= lg; nvList[1] = nv; // cout << "float" << endl; nv.name = "float"; ft = 33.3; nv.value <<= ft; nvList[2] = nv; // cout << "double" << endl; nv.name = "double"; db = 3.3; nv.value <<= db; nvList[3] = nv; // nv.name = "char"; // strg = "STRING"; // nv.value <<= CORBA::Any::from_char('C'); // ここでセグメントエラー発生 // cout << "char" << endl; // nvList[4] = nv; // cout << "string" << endl; // nv.name = "string"; // strg = "STRING"; // char * p = "STRING"; // nv.value <<= CORBA::Any::from_string(p,7); // ここでセグメントエラー発生 // nvList[4] = nv; // cout << "set_prop.properties" << endl; set_prop.properties = nvList; // cout << "set in" << endl; ret = m_pOi->add_organization_property(set_prop); // cout << "set out" << endl; get_prop = m_pOi->get_organization_property(); // cout << "get property length: " << get_prop->properties.length() << endl; str = ((get_prop->properties[0]).name); (get_prop->properties[0]).value >>= rst; CPPUNIT_ASSERT(str == "short"); CPPUNIT_ASSERT(rst == st); str = ((get_prop->properties[1]).name); (get_prop->properties[1]).value >>= rlg; CPPUNIT_ASSERT(str == "long"); CPPUNIT_ASSERT(rlg == lg); str = ((get_prop->properties[2]).name); (get_prop->properties[2]).value >>= rft; CPPUNIT_ASSERT(str == "float"); CPPUNIT_ASSERT(rft == ft); str = ((get_prop->properties[3]).name); (get_prop->properties[3]).value >>= rdb; CPPUNIT_ASSERT(str == "double"); CPPUNIT_ASSERT(rdb == db); // str = ((get_prop->properties[4]).name); // (get_prop->properties[4]).value >>= (CORBA::Any::to_char(rch)); // CPPUNIT_ASSERT(str == "char"); // CPPUNIT_ASSERT(rch == ch); // str = ((get_prop->properties[4]).name); // char * retp; // (get_prop->properties[4]).value >>= CORBA::Any::to_string(retp,7); // CPPUNIT_ASSERT(str == "string"); // CPPUNIT_ASSERT(*retp == *p); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; } catch (InternalError ip) { cout << "InternalError exception." << endl; } catch (...) { cout << "othrer exception." << endl; } // std::cout << "test_set_get_organization_property OUT" << std::endl; } /*! * @brief set_organization_property_value() and get_organization_property_value() */ void test_set_get_organization_property_value() { // std::cout << "test_set_get_organization_property_value IN" << std::endl; OrganizationProperty_var get_prop; OrganizationProperty set_prop; CORBA::Boolean ret; CORBA::Short st; // CORBA::Long lg; CORBA::Float ft; // CORBA::Double db; CORBA::Any any; CORBA::Short rst; // CORBA::Long rlg; CORBA::Float rft; // CORBA::Double rdb; CORBA::Any* rany; NVList nvList; NameValue nv; string str; try { // プロパティの取得 length 0のプロパティが返される。 get_prop = m_pOi->get_organization_property(); // cout << endl << "get property length: " << get_prop->properties.length() << endl; // 空のOrganizationPropertyをセットする。 OK. ret = m_pOi->add_organization_property(set_prop); CPPUNIT_ASSERT(ret); // プロパティの設定時、true が返されるか? ft = 11.111; any <<= ft; ret = m_pOi->set_organization_property_value("hoge1", any); CPPUNIT_ASSERT(ret); // プロパティの設定値取得時、 設定値が返されるか? rany = m_pOi->get_organization_property_value("hoge1"); (*rany) >>= rft; CPPUNIT_ASSERT_EQUAL(ft, rft); // プロパティの設定時、true が返されるか? st = 123; any <<= st; ret = m_pOi->set_organization_property_value("hoge2", any); CPPUNIT_ASSERT(ret); // プロパティの設定値取得時、 設定値が返されるか? rany = m_pOi->get_organization_property_value("hoge2"); (*rany) >>= rst; CPPUNIT_ASSERT_EQUAL(st, rst); // プロパティの更新時、true が返されるか? st = 456; any <<= st; ret = m_pOi->set_organization_property_value("hoge2", any); CPPUNIT_ASSERT(ret); // プロパティの更新値取得時、 設定値が返されるか? rany = m_pOi->get_organization_property_value("hoge2"); (*rany) >>= rst; CPPUNIT_ASSERT_EQUAL(st, rst); // プロパティの設定時、name 未設定による InvalidParameter が返されるか? short sflg = -1; try { ret = m_pOi->set_organization_property_value("", any); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } CPPUNIT_ASSERT(sflg == 1); // プロパティの設定値取得時、name 未設定による InvalidParameter が返されるか? sflg = -1; try { ret = m_pOi->get_organization_property_value(""); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } CPPUNIT_ASSERT(sflg == 1); // プロパティの設定値取得時、name 未登録による InvalidParameter が返されるか? sflg = -1; try { ret = m_pOi->get_organization_property_value("hoge99"); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } CPPUNIT_ASSERT(sflg == 1); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; } catch (InternalError ip) { cout << "InternalError exception." << endl; } catch (...) { cout << "othrer exception." << endl; } // std::cout << "test_set_get_organization_property_value OUT" << std::endl; } /*! * @brief add_organization_property() and remove_organization_property() */ void test_remove_organization_property() { // std::cout << "test_remove_organization_property IN" << std::endl; OrganizationProperty set_prop; CORBA::Boolean ret; CORBA::Float ft; NVList nvList; NameValue nv; string str; nv.name = "hoge"; str = "hoge"; ft = 11.111; nv.value <<= ft; nvList.length(1); nvList[0] = nv; set_prop.properties = nvList; // プロパティのセット ret = m_pOi->add_organization_property(set_prop); CPPUNIT_ASSERT(ret); // InvalidParameter exceptionを確認 short sflg = -1; try { ret = m_pOi->remove_organization_property("short"); if (!ret) { cout << "Couldn't remove name: short" << endl; } sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // 戻り値:true を確認 sflg = -1; try { ret = m_pOi->remove_organization_property("hoge"); if (!ret) { cout << "Couldn't remove name: hoge" << endl; } CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // std::cout << "test_remove_organization_property OUT" << std::endl; } /*! * @brief set_owner() and get_owner() */ void test_set_get_owner() { // std::cout << "test_set_get_owner IN" << std::endl; CORBA::Boolean ret; SDOPackage::SDOSystemElement_var varOwner; SDOPackage::SDOSystemElement_ptr ptrOwner; try { // オーナー取得が行えるか? varOwner = m_pOi->get_owner(); CPPUNIT_ASSERT(!::CORBA::is_nil(varOwner)); // InvalidParameter exceptionを確認 short sflg = -1; try { // オーナー設定時、InvalidParameter が返されるか? ptrOwner = SDOPackage::SDOSystemElement::_nil(); ret = m_pOi->set_owner(ptrOwner); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // 戻り値:true を確認 sflg = -1; try { // オーナー設定時、true が返されるか? ::RTC::RTObject_impl* rtobj2; ::RTC::Manager& mgr2(RTC::Manager::instance()); rtobj2 = new ::RTC::RTObject_impl(&mgr2); ptrOwner = rtobj2->getObjRef(); ret = m_pOi->set_owner(ptrOwner); CPPUNIT_ASSERT(ret); sflg = 0; rtobj2->_remove_ref(); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; } catch (InternalError ip) { cout << "InternalError exception." << endl; } catch (...) { cout << "othrer exception." << endl; } // std::cout << "test_set_get_owner OUT" << std::endl; } /*! * @brief set_members() and get_members() */ void test_set_get_members() { // std::cout << "test_set_get_members IN" << std::endl; CORBA::Boolean ret; SDOPackage::SDO_var sdo; SDOPackage::SDOList slist; SDOPackage::SDOList* rslist; // SDO のセット時、InvalidParameter を取得できるか? // set_members()に、NULL や 空のリストを渡してもlength()=0となるため // InvalidParameterを返すケースはない。 // SDOList のセット時、空のリストを渡して取得できるか? short sflg = -1; try { slist = NULL; ret = m_pOi->set_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 0件のSDOList取得が行えるか? rslist = m_pOi->get_members(); CPPUNIT_ASSERT(rslist->length() == 0); // SDOList のセット時、リストをセットして true を取得できるか? sflg = -1; try { RTC::RTObject_impl* rtobj2; RTC::Manager& mgr2(RTC::Manager::instance()); rtobj2 = new ::RTC::RTObject_impl(&mgr2); sdo = SDOPackage::SDO::_duplicate(rtobj2->getObjRef()); CORBA_SeqUtil::push_back(slist, sdo); ret = m_pOi->set_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; rtobj2->_remove_ref(); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 1件のSDOList取得が行えるか? rslist = m_pOi->get_members(); CPPUNIT_ASSERT(rslist->length() == 1); // std::cout << "test_set_get_members OUT" << std::endl; } /*! * @brief add_members() and remove_member() */ void test_add_remove_members() { // std::cout << "test_add_remove_members IN" << std::endl; CORBA::Boolean ret; SDOPackage::SDO_var sdo; SDOPackage::SDOList slist; SDOPackage::SDOList* rslist; Organization_impl* m_pOi2; std::string str; CORBA::Any any; RTC::RTObject_impl* rtobj2; RTC::Manager& mgr2(RTC::Manager::instance()); mgr2.activateManager(); rtobj2 = new ::RTC::RTObject_impl(&mgr2); m_pOi2 = new Organization_impl(rtobj2->getObjRef()); // SDO のセット時、InvalidParameter を取得できるか? // add_members()に、NULL や 空のリストを渡してもlength()=0となるため // InvalidParameterを返すケースはない。 // SDOList のセット時、空のリストを渡して true を取得できるか? short sflg = -1; try { slist = NULL; ret = m_pOi->add_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // SDOList のセット時、リストをセットして true を取得できるか? sflg = -1; try { sdo = SDOPackage::SDO::_duplicate(rtobj2->getObjRef()); CORBA_SeqUtil::push_back(slist, sdo); rtobj2->setInstanceName("hoge1"); // SDOメンバーの追加が成功するか? ret = m_pOi2->add_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; str = m_pOi2->get_organization_id(); any <<= str.c_str(); ret = m_pOi2->set_organization_property_value("instance_name", any); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 1件のSDOList取得が行えるか? rslist = m_pOi2->get_members(); CPPUNIT_ASSERT(rslist->length() == 1); // SDOList削除時、引数未定義でInvalidParameterを取得できるか? sflg = -1; try { ret = m_pOi2->remove_member(""); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // SDOList削除時、引数不正でInvalidParameterを取得できるか? sflg = -1; try { ret = m_pOi2->remove_member("dummy"); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // SDOList削除時、正しい引数で削除できるか? sflg = -1; try { ret = m_pOi2->remove_member("hoge1"); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 0件のSDOList取得が行えるか? rslist = m_pOi2->get_members(); CPPUNIT_ASSERT(rslist->length() == 0); if ( !CORBA::is_nil( mgr2.getPOA()) ) { if ( !CORBA::is_nil(mgr2.getPOAManager()) ) { mgr2.getPOAManager()->deactivate(false, true); } } rtobj2->_remove_ref(); m_pOi2->_remove_ref(); // std::cout << "test_add_remove_members OUT" << std::endl; } /*! * @brief set_dependency() and get_dependency() */ void test_set_get_dependency() { // std::cout << "test_set_get_dependency IN" << std::endl; DependencyType depType; // Success case. // default return value is 0. depType = m_pOi->get_dependency(); // cout << "depType: " << depType << endl; CPPUNIT_ASSERT(depType == 0); m_pOi->set_dependency(NO_DEPENDENCY); // returned value is 2. depType = m_pOi->get_dependency(); CPPUNIT_ASSERT(depType == 2); // cout << "depType: " << depType << endl; // Failure case. // m_pOi->set_dependency(0); // コンパイルエラー // CPPUNIT_ASSERT(depType == 3); // cout << "depType: " << depType << endl; // std::cout << "test_set_get_dependency OUT" << std::endl; } }; }; // namespace SdoOrganization /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoOrganization::SdoOrganizationTests); #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 // SdoOrganization_cpp
186  ret = m_pOi->add_organization_property(set_prop);
187 
188  // プロパティの取得 get_prop = m_pOi->get_organization_property(); // cout << "get property length: " << get_prop->properties.length() << endl; str = ((get_prop->properties[0]).name); (get_prop->properties[0]).value >>= rft; CPPUNIT_ASSERT(str == "hogehoge"); CPPUNIT_ASSERT(rft == ft); // nvList.length(5); nvList.length(4); // cout << "short" << endl; nv.name = "short"; st = 1; nv.value <<= st; nvList[0] = nv; // cout << "long" << endl; nv.name = "long"; lg = 2222; nv.value <<= lg; nvList[1] = nv; // cout << "float" << endl; nv.name = "float"; ft = 33.3; nv.value <<= ft; nvList[2] = nv; // cout << "double" << endl; nv.name = "double"; db = 3.3; nv.value <<= db; nvList[3] = nv; // nv.name = "char"; // strg = "STRING"; // nv.value <<= CORBA::Any::from_char('C'); // ここでセグメントエラー発生 // cout << "char" << endl; // nvList[4] = nv; // cout << "string" << endl; // nv.name = "string"; // strg = "STRING"; // char * p = "STRING"; // nv.value <<= CORBA::Any::from_string(p,7); // ここでセグメントエラー発生 // nvList[4] = nv; // cout << "set_prop.properties" << endl; set_prop.properties = nvList; // cout << "set in" << endl; ret = m_pOi->add_organization_property(set_prop); // cout << "set out" << endl; get_prop = m_pOi->get_organization_property(); // cout << "get property length: " << get_prop->properties.length() << endl; str = ((get_prop->properties[0]).name); (get_prop->properties[0]).value >>= rst; CPPUNIT_ASSERT(str == "short"); CPPUNIT_ASSERT(rst == st); str = ((get_prop->properties[1]).name); (get_prop->properties[1]).value >>= rlg; CPPUNIT_ASSERT(str == "long"); CPPUNIT_ASSERT(rlg == lg); str = ((get_prop->properties[2]).name); (get_prop->properties[2]).value >>= rft; CPPUNIT_ASSERT(str == "float"); CPPUNIT_ASSERT(rft == ft); str = ((get_prop->properties[3]).name); (get_prop->properties[3]).value >>= rdb; CPPUNIT_ASSERT(str == "double"); CPPUNIT_ASSERT(rdb == db); // str = ((get_prop->properties[4]).name); // (get_prop->properties[4]).value >>= (CORBA::Any::to_char(rch)); // CPPUNIT_ASSERT(str == "char"); // CPPUNIT_ASSERT(rch == ch); // str = ((get_prop->properties[4]).name); // char * retp; // (get_prop->properties[4]).value >>= CORBA::Any::to_string(retp,7); // CPPUNIT_ASSERT(str == "string"); // CPPUNIT_ASSERT(*retp == *p); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; } catch (InternalError ip) { cout << "InternalError exception." << endl; } catch (...) { cout << "othrer exception." << endl; } // std::cout << "test_set_get_organization_property OUT" << std::endl; } /*! * @brief set_organization_property_value() and get_organization_property_value() */ void test_set_get_organization_property_value() { // std::cout << "test_set_get_organization_property_value IN" << std::endl; OrganizationProperty_var get_prop; OrganizationProperty set_prop; CORBA::Boolean ret; CORBA::Short st; // CORBA::Long lg; CORBA::Float ft; // CORBA::Double db; CORBA::Any any; CORBA::Short rst; // CORBA::Long rlg; CORBA::Float rft; // CORBA::Double rdb; CORBA::Any* rany; NVList nvList; NameValue nv; string str; try { // プロパティの取得 length 0のプロパティが返される。 get_prop = m_pOi->get_organization_property(); // cout << endl << "get property length: " << get_prop->properties.length() << endl; // 空のOrganizationPropertyをセットする。 OK. ret = m_pOi->add_organization_property(set_prop); CPPUNIT_ASSERT(ret); // プロパティの設定時、true が返されるか? ft = 11.111; any <<= ft; ret = m_pOi->set_organization_property_value("hoge1", any); CPPUNIT_ASSERT(ret); // プロパティの設定値取得時、 設定値が返されるか? rany = m_pOi->get_organization_property_value("hoge1"); (*rany) >>= rft; CPPUNIT_ASSERT_EQUAL(ft, rft); // プロパティの設定時、true が返されるか? st = 123; any <<= st; ret = m_pOi->set_organization_property_value("hoge2", any); CPPUNIT_ASSERT(ret); // プロパティの設定値取得時、 設定値が返されるか? rany = m_pOi->get_organization_property_value("hoge2"); (*rany) >>= rst; CPPUNIT_ASSERT_EQUAL(st, rst); // プロパティの更新時、true が返されるか? st = 456; any <<= st; ret = m_pOi->set_organization_property_value("hoge2", any); CPPUNIT_ASSERT(ret); // プロパティの更新値取得時、 設定値が返されるか? rany = m_pOi->get_organization_property_value("hoge2"); (*rany) >>= rst; CPPUNIT_ASSERT_EQUAL(st, rst); // プロパティの設定時、name 未設定による InvalidParameter が返されるか? short sflg = -1; try { ret = m_pOi->set_organization_property_value("", any); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } CPPUNIT_ASSERT(sflg == 1); // プロパティの設定値取得時、name 未設定による InvalidParameter が返されるか? sflg = -1; try { ret = m_pOi->get_organization_property_value(""); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } CPPUNIT_ASSERT(sflg == 1); // プロパティの設定値取得時、name 未登録による InvalidParameter が返されるか? sflg = -1; try { ret = m_pOi->get_organization_property_value("hoge99"); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } CPPUNIT_ASSERT(sflg == 1); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; } catch (InternalError ip) { cout << "InternalError exception." << endl; } catch (...) { cout << "othrer exception." << endl; } // std::cout << "test_set_get_organization_property_value OUT" << std::endl; } /*! * @brief add_organization_property() and remove_organization_property() */ void test_remove_organization_property() { // std::cout << "test_remove_organization_property IN" << std::endl; OrganizationProperty set_prop; CORBA::Boolean ret; CORBA::Float ft; NVList nvList; NameValue nv; string str; nv.name = "hoge"; str = "hoge"; ft = 11.111; nv.value <<= ft; nvList.length(1); nvList[0] = nv; set_prop.properties = nvList; // プロパティのセット ret = m_pOi->add_organization_property(set_prop); CPPUNIT_ASSERT(ret); // InvalidParameter exceptionを確認 short sflg = -1; try { ret = m_pOi->remove_organization_property("short"); if (!ret) { cout << "Couldn't remove name: short" << endl; } sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // 戻り値:true を確認 sflg = -1; try { ret = m_pOi->remove_organization_property("hoge"); if (!ret) { cout << "Couldn't remove name: hoge" << endl; } CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // std::cout << "test_remove_organization_property OUT" << std::endl; } /*! * @brief set_owner() and get_owner() */ void test_set_get_owner() { // std::cout << "test_set_get_owner IN" << std::endl; CORBA::Boolean ret; SDOPackage::SDOSystemElement_var varOwner; SDOPackage::SDOSystemElement_ptr ptrOwner; try { // オーナー取得が行えるか? varOwner = m_pOi->get_owner(); CPPUNIT_ASSERT(!::CORBA::is_nil(varOwner)); // InvalidParameter exceptionを確認 short sflg = -1; try { // オーナー設定時、InvalidParameter が返されるか? ptrOwner = SDOPackage::SDOSystemElement::_nil(); ret = m_pOi->set_owner(ptrOwner); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // 戻り値:true を確認 sflg = -1; try { // オーナー設定時、true が返されるか? ::RTC::RTObject_impl* rtobj2; ::RTC::Manager& mgr2(RTC::Manager::instance()); rtobj2 = new ::RTC::RTObject_impl(&mgr2); ptrOwner = rtobj2->getObjRef(); ret = m_pOi->set_owner(ptrOwner); CPPUNIT_ASSERT(ret); sflg = 0; rtobj2->_remove_ref(); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; } catch (InternalError ip) { cout << "InternalError exception." << endl; } catch (...) { cout << "othrer exception." << endl; } // std::cout << "test_set_get_owner OUT" << std::endl; } /*! * @brief set_members() and get_members() */ void test_set_get_members() { // std::cout << "test_set_get_members IN" << std::endl; CORBA::Boolean ret; SDOPackage::SDO_var sdo; SDOPackage::SDOList slist; SDOPackage::SDOList* rslist; // SDO のセット時、InvalidParameter を取得できるか? // set_members()に、NULL や 空のリストを渡してもlength()=0となるため // InvalidParameterを返すケースはない。 // SDOList のセット時、空のリストを渡して取得できるか? short sflg = -1; try { slist = NULL; ret = m_pOi->set_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 0件のSDOList取得が行えるか? rslist = m_pOi->get_members(); CPPUNIT_ASSERT(rslist->length() == 0); // SDOList のセット時、リストをセットして true を取得できるか? sflg = -1; try { RTC::RTObject_impl* rtobj2; RTC::Manager& mgr2(RTC::Manager::instance()); rtobj2 = new ::RTC::RTObject_impl(&mgr2); sdo = SDOPackage::SDO::_duplicate(rtobj2->getObjRef()); CORBA_SeqUtil::push_back(slist, sdo); ret = m_pOi->set_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; rtobj2->_remove_ref(); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 1件のSDOList取得が行えるか? rslist = m_pOi->get_members(); CPPUNIT_ASSERT(rslist->length() == 1); // std::cout << "test_set_get_members OUT" << std::endl; } /*! * @brief add_members() and remove_member() */ void test_add_remove_members() { // std::cout << "test_add_remove_members IN" << std::endl; CORBA::Boolean ret; SDOPackage::SDO_var sdo; SDOPackage::SDOList slist; SDOPackage::SDOList* rslist; Organization_impl* m_pOi2; std::string str; CORBA::Any any; RTC::RTObject_impl* rtobj2; RTC::Manager& mgr2(RTC::Manager::instance()); mgr2.activateManager(); rtobj2 = new ::RTC::RTObject_impl(&mgr2); m_pOi2 = new Organization_impl(rtobj2->getObjRef()); // SDO のセット時、InvalidParameter を取得できるか? // add_members()に、NULL や 空のリストを渡してもlength()=0となるため // InvalidParameterを返すケースはない。 // SDOList のセット時、空のリストを渡して true を取得できるか? short sflg = -1; try { slist = NULL; ret = m_pOi->add_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // SDOList のセット時、リストをセットして true を取得できるか? sflg = -1; try { sdo = SDOPackage::SDO::_duplicate(rtobj2->getObjRef()); CORBA_SeqUtil::push_back(slist, sdo); rtobj2->setInstanceName("hoge1"); // SDOメンバーの追加が成功するか? ret = m_pOi2->add_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; str = m_pOi2->get_organization_id(); any <<= str.c_str(); ret = m_pOi2->set_organization_property_value("instance_name", any); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 1件のSDOList取得が行えるか? rslist = m_pOi2->get_members(); CPPUNIT_ASSERT(rslist->length() == 1); // SDOList削除時、引数未定義でInvalidParameterを取得できるか? sflg = -1; try { ret = m_pOi2->remove_member(""); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // SDOList削除時、引数不正でInvalidParameterを取得できるか? sflg = -1; try { ret = m_pOi2->remove_member("dummy"); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // SDOList削除時、正しい引数で削除できるか? sflg = -1; try { ret = m_pOi2->remove_member("hoge1"); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 0件のSDOList取得が行えるか? rslist = m_pOi2->get_members(); CPPUNIT_ASSERT(rslist->length() == 0); if ( !CORBA::is_nil( mgr2.getPOA()) ) { if ( !CORBA::is_nil(mgr2.getPOAManager()) ) { mgr2.getPOAManager()->deactivate(false, true); } } rtobj2->_remove_ref(); m_pOi2->_remove_ref(); // std::cout << "test_add_remove_members OUT" << std::endl; } /*! * @brief set_dependency() and get_dependency() */ void test_set_get_dependency() { // std::cout << "test_set_get_dependency IN" << std::endl; DependencyType depType; // Success case. // default return value is 0. depType = m_pOi->get_dependency(); // cout << "depType: " << depType << endl; CPPUNIT_ASSERT(depType == 0); m_pOi->set_dependency(NO_DEPENDENCY); // returned value is 2. depType = m_pOi->get_dependency(); CPPUNIT_ASSERT(depType == 2); // cout << "depType: " << depType << endl; // Failure case. // m_pOi->set_dependency(0); // コンパイルエラー // CPPUNIT_ASSERT(depType == 3); // cout << "depType: " << depType << endl; // std::cout << "test_set_get_dependency OUT" << std::endl; } }; }; // namespace SdoOrganization /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoOrganization::SdoOrganizationTests); #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 // SdoOrganization_cpp
189  get_prop = m_pOi->get_organization_property();
190 // cout << "get property length: " << get_prop->properties.length() << endl;
191 
192 
193  str = ((get_prop->properties[0]).name);
194  (get_prop->properties[0]).value >>= rft;
195  CPPUNIT_ASSERT(str == "hogehoge");
196  CPPUNIT_ASSERT(rft == ft);
197 
198  // nvList.length(5);
199  nvList.length(4);
200 
201 // cout << "short" << endl;
202  nv.name = "short";
203  st = 1;
204  nv.value <<= st;
205  nvList[0] = nv;
206 
207 // cout << "long" << endl;
208  nv.name = "long";
209  lg = 2222;
210  nv.value <<= lg;
211  nvList[1] = nv;
212 
213 // cout << "float" << endl;
214  nv.name = "float";
215  ft = 33.3;
216  nv.value <<= ft;
217  nvList[2] = nv;
218 
219 // cout << "double" << endl;
220  nv.name = "double";
221  db = 3.3;
222  nv.value <<= db;
223  nvList[3] = nv;
224 
225  // nv.name = "char";
226  // strg = "STRING";
227  // nv.value <<= CORBA::Any::from_char('C'); // ここでセグメントエラー発生
228  // cout << "char" << endl;
229  // nvList[4] = nv;
230 
231 
232  // cout << "string" << endl;
233  // nv.name = "string";
234  // strg = "STRING";
235  // char * p = "STRING";
236  // nv.value <<= CORBA::Any::from_string(p,7); // ここでセグメントエラー発生
237  // nvList[4] = nv;
238 
239 // cout << "set_prop.properties" << endl;
240  set_prop.properties = nvList;
241 
242 // cout << "set in" << endl;
243  ret = m_pOi->add_organization_property(set_prop);
244 // cout << "set out" << endl;
245 
246  get_prop = m_pOi->get_organization_property();
247 // cout << "get property length: " << get_prop->properties.length() << endl;
248 
249  str = ((get_prop->properties[0]).name);
250  (get_prop->properties[0]).value >>= rst;
251  CPPUNIT_ASSERT(str == "short");
252  CPPUNIT_ASSERT(rst == st);
253 
254  str = ((get_prop->properties[1]).name);
255  (get_prop->properties[1]).value >>= rlg;
256  CPPUNIT_ASSERT(str == "long");
257  CPPUNIT_ASSERT(rlg == lg);
258 
259  str = ((get_prop->properties[2]).name);
260  (get_prop->properties[2]).value >>= rft;
261  CPPUNIT_ASSERT(str == "float");
262  CPPUNIT_ASSERT(rft == ft);
263 
264  str = ((get_prop->properties[3]).name);
265  (get_prop->properties[3]).value >>= rdb;
266  CPPUNIT_ASSERT(str == "double");
267  CPPUNIT_ASSERT(rdb == db);
268 
269  // str = ((get_prop->properties[4]).name);
270  // (get_prop->properties[4]).value >>= (CORBA::Any::to_char(rch));
271  // CPPUNIT_ASSERT(str == "char");
272  // CPPUNIT_ASSERT(rch == ch);
273 
274  // str = ((get_prop->properties[4]).name);
275  // char * retp;
276  // (get_prop->properties[4]).value >>= CORBA::Any::to_string(retp,7);
277  // CPPUNIT_ASSERT(str == "string");
278  // CPPUNIT_ASSERT(*retp == *p);
279 
280  }
281  catch (InvalidParameter ip) {
282  cout << "InvalidParameter exception." << endl;
283  }
284  catch (NotAvailable na) {
285  cout << "NotAvailable exception." << endl;
286  }
287  catch (InternalError ip) {
288  cout << "InternalError exception." << endl;
289  }
290  catch (...) {
291  cout << "othrer exception." << endl;
292  }
293 // std::cout << "test_set_get_organization_property OUT" << std::endl;
294  }
295 
300 // std::cout << "test_set_get_organization_property_value IN" << std::endl;
301  OrganizationProperty_var get_prop;
302  OrganizationProperty set_prop;
303  CORBA::Boolean ret;
304  CORBA::Short st;
305 // CORBA::Long lg;
306  CORBA::Float ft;
307 // CORBA::Double db;
308  CORBA::Any any;
309 
310  CORBA::Short rst;
311 // CORBA::Long rlg;
312  CORBA::Float rft;
313 // CORBA::Double rdb;
314  CORBA::Any* rany;
315 
316  NVList nvList;
317  NameValue nv;
318  string str;
319 
320  try {
321  // プロパティの取得 length 0のプロパティが返される。
322  get_prop = m_pOi->get_organization_property();
323 // cout << endl << "get property length: " << get_prop->properties.length() << endl;
324 
325  // 空のOrganizationPropertyをセットする。 OK.
326  ret = m_pOi->add_organization_property(set_prop);
327  CPPUNIT_ASSERT(ret);
328 
329  // プロパティの設定時、true が返されるか?
330  ft = 11.111;
331  any <<= ft;
332  ret = m_pOi->set_organization_property_value("hoge1", any);
333  CPPUNIT_ASSERT(ret);
334 
335  // プロパティの設定値取得時、 設定値が返されるか?
336  rany = m_pOi->get_organization_property_value("hoge1");
337  (*rany) >>= rft;
338  CPPUNIT_ASSERT_EQUAL(ft, rft);
339 
340 
341  // プロパティの設定時、true が返されるか?
342  st = 123;
343  any <<= st;
344  ret = m_pOi->set_organization_property_value("hoge2", any);
345  CPPUNIT_ASSERT(ret);
346 
347  // プロパティの設定値取得時、 設定値が返されるか?
348  rany = m_pOi->get_organization_property_value("hoge2");
349  (*rany) >>= rst;
350  CPPUNIT_ASSERT_EQUAL(st, rst);
351 
352 
353  // プロパティの更新時、true が返されるか?
354  st = 456;
355  any <<= st;
356  ret = m_pOi->set_organization_property_value("hoge2", any);
357  CPPUNIT_ASSERT(ret);
358 
359  // プロパティの更新値取得時、 設定値が返されるか?
360  rany = m_pOi->get_organization_property_value("hoge2");
361  (*rany) >>= rst;
362  CPPUNIT_ASSERT_EQUAL(st, rst);
363 
364  // プロパティの設定時、name 未設定による InvalidParameter が返されるか?
365  short sflg = -1;
366  try {
367  ret = m_pOi->set_organization_property_value("", any);
368  sflg = 0;
369  }
370  catch (InvalidParameter ip) {
371 // cout << "InvalidParameter exception." << endl;
372  sflg = 1;
373  }
374  CPPUNIT_ASSERT(sflg == 1);
375 
376  // プロパティの設定値取得時、name 未設定による InvalidParameter が返されるか?
377  sflg = -1;
378  try {
379  ret = m_pOi->get_organization_property_value("");
380  sflg = 0;
381  }
382  catch (InvalidParameter ip) {
383 // cout << "InvalidParameter exception." << endl;
384  sflg = 1;
385  }
386  CPPUNIT_ASSERT(sflg == 1);
387 
388  // プロパティの設定値取得時、name 未登録による InvalidParameter が返されるか?
389  sflg = -1;
390  try {
391  ret = m_pOi->get_organization_property_value("hoge99");
392  sflg = 0;
393  }
394  catch (InvalidParameter ip) {
395 // cout << "InvalidParameter exception." << endl;
396  sflg = 1;
397  }
398  CPPUNIT_ASSERT(sflg == 1);
399  }
400  catch (InvalidParameter ip) {
401  cout << "InvalidParameter exception." << endl;
402  }
403  catch (NotAvailable na) {
404  cout << "NotAvailable exception." << endl;
405  }
406  catch (InternalError ip) {
407  cout << "InternalError exception." << endl;
408  }
409  catch (...) {
410  cout << "othrer exception." << endl;
411  }
412 
413 // std::cout << "test_set_get_organization_property_value OUT" << std::endl;
414  }
415 
420 // std::cout << "test_remove_organization_property IN" << std::endl;
421  OrganizationProperty set_prop;
422  CORBA::Boolean ret;
423  CORBA::Float ft;
424  NVList nvList;
425  NameValue nv;
426  string str;
427 
428  nv.name = "hoge";
429  str = "hoge";
430  ft = 11.111;
431  nv.value <<= ft;
432 
433  nvList.length(1);
434  nvList[0] = nv;
435 
436  set_prop.properties = nvList;
437  // プロパティのセット ret = m_pOi->add_organization_property(set_prop); CPPUNIT_ASSERT(ret); // InvalidParameter exceptionを確認 short sflg = -1; try { ret = m_pOi->remove_organization_property("short"); if (!ret) { cout << "Couldn't remove name: short" << endl; } sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // 戻り値:true を確認 sflg = -1; try { ret = m_pOi->remove_organization_property("hoge"); if (!ret) { cout << "Couldn't remove name: hoge" << endl; } CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // std::cout << "test_remove_organization_property OUT" << std::endl; } /*! * @brief set_owner() and get_owner() */ void test_set_get_owner() { // std::cout << "test_set_get_owner IN" << std::endl; CORBA::Boolean ret; SDOPackage::SDOSystemElement_var varOwner; SDOPackage::SDOSystemElement_ptr ptrOwner; try { // オーナー取得が行えるか? varOwner = m_pOi->get_owner(); CPPUNIT_ASSERT(!::CORBA::is_nil(varOwner)); // InvalidParameter exceptionを確認 short sflg = -1; try { // オーナー設定時、InvalidParameter が返されるか? ptrOwner = SDOPackage::SDOSystemElement::_nil(); ret = m_pOi->set_owner(ptrOwner); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // 戻り値:true を確認 sflg = -1; try { // オーナー設定時、true が返されるか? ::RTC::RTObject_impl* rtobj2; ::RTC::Manager& mgr2(RTC::Manager::instance()); rtobj2 = new ::RTC::RTObject_impl(&mgr2); ptrOwner = rtobj2->getObjRef(); ret = m_pOi->set_owner(ptrOwner); CPPUNIT_ASSERT(ret); sflg = 0; rtobj2->_remove_ref(); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; } catch (InternalError ip) { cout << "InternalError exception." << endl; } catch (...) { cout << "othrer exception." << endl; } // std::cout << "test_set_get_owner OUT" << std::endl; } /*! * @brief set_members() and get_members() */ void test_set_get_members() { // std::cout << "test_set_get_members IN" << std::endl; CORBA::Boolean ret; SDOPackage::SDO_var sdo; SDOPackage::SDOList slist; SDOPackage::SDOList* rslist; // SDO のセット時、InvalidParameter を取得できるか? // set_members()に、NULL や 空のリストを渡してもlength()=0となるため // InvalidParameterを返すケースはない。 // SDOList のセット時、空のリストを渡して取得できるか? short sflg = -1; try { slist = NULL; ret = m_pOi->set_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 0件のSDOList取得が行えるか? rslist = m_pOi->get_members(); CPPUNIT_ASSERT(rslist->length() == 0); // SDOList のセット時、リストをセットして true を取得できるか? sflg = -1; try { RTC::RTObject_impl* rtobj2; RTC::Manager& mgr2(RTC::Manager::instance()); rtobj2 = new ::RTC::RTObject_impl(&mgr2); sdo = SDOPackage::SDO::_duplicate(rtobj2->getObjRef()); CORBA_SeqUtil::push_back(slist, sdo); ret = m_pOi->set_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; rtobj2->_remove_ref(); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 1件のSDOList取得が行えるか? rslist = m_pOi->get_members(); CPPUNIT_ASSERT(rslist->length() == 1); // std::cout << "test_set_get_members OUT" << std::endl; } /*! * @brief add_members() and remove_member() */ void test_add_remove_members() { // std::cout << "test_add_remove_members IN" << std::endl; CORBA::Boolean ret; SDOPackage::SDO_var sdo; SDOPackage::SDOList slist; SDOPackage::SDOList* rslist; Organization_impl* m_pOi2; std::string str; CORBA::Any any; RTC::RTObject_impl* rtobj2; RTC::Manager& mgr2(RTC::Manager::instance()); mgr2.activateManager(); rtobj2 = new ::RTC::RTObject_impl(&mgr2); m_pOi2 = new Organization_impl(rtobj2->getObjRef()); // SDO のセット時、InvalidParameter を取得できるか? // add_members()に、NULL や 空のリストを渡してもlength()=0となるため // InvalidParameterを返すケースはない。 // SDOList のセット時、空のリストを渡して true を取得できるか? short sflg = -1; try { slist = NULL; ret = m_pOi->add_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // SDOList のセット時、リストをセットして true を取得できるか? sflg = -1; try { sdo = SDOPackage::SDO::_duplicate(rtobj2->getObjRef()); CORBA_SeqUtil::push_back(slist, sdo); rtobj2->setInstanceName("hoge1"); // SDOメンバーの追加が成功するか? ret = m_pOi2->add_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; str = m_pOi2->get_organization_id(); any <<= str.c_str(); ret = m_pOi2->set_organization_property_value("instance_name", any); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 1件のSDOList取得が行えるか? rslist = m_pOi2->get_members(); CPPUNIT_ASSERT(rslist->length() == 1); // SDOList削除時、引数未定義でInvalidParameterを取得できるか? sflg = -1; try { ret = m_pOi2->remove_member(""); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // SDOList削除時、引数不正でInvalidParameterを取得できるか? sflg = -1; try { ret = m_pOi2->remove_member("dummy"); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // SDOList削除時、正しい引数で削除できるか? sflg = -1; try { ret = m_pOi2->remove_member("hoge1"); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 0件のSDOList取得が行えるか? rslist = m_pOi2->get_members(); CPPUNIT_ASSERT(rslist->length() == 0); if ( !CORBA::is_nil( mgr2.getPOA()) ) { if ( !CORBA::is_nil(mgr2.getPOAManager()) ) { mgr2.getPOAManager()->deactivate(false, true); } } rtobj2->_remove_ref(); m_pOi2->_remove_ref(); // std::cout << "test_add_remove_members OUT" << std::endl; } /*! * @brief set_dependency() and get_dependency() */ void test_set_get_dependency() { // std::cout << "test_set_get_dependency IN" << std::endl; DependencyType depType; // Success case. // default return value is 0. depType = m_pOi->get_dependency(); // cout << "depType: " << depType << endl; CPPUNIT_ASSERT(depType == 0); m_pOi->set_dependency(NO_DEPENDENCY); // returned value is 2. depType = m_pOi->get_dependency(); CPPUNIT_ASSERT(depType == 2); // cout << "depType: " << depType << endl; // Failure case. // m_pOi->set_dependency(0); // コンパイルエラー // CPPUNIT_ASSERT(depType == 3); // cout << "depType: " << depType << endl; // std::cout << "test_set_get_dependency OUT" << std::endl; } }; }; // namespace SdoOrganization /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoOrganization::SdoOrganizationTests); #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 // SdoOrganization_cpp
438  ret = m_pOi->add_organization_property(set_prop);
439  CPPUNIT_ASSERT(ret);
440 
441  // InvalidParameter exceptionを確認
442  short sflg = -1;
443  try {
444  ret = m_pOi->remove_organization_property("short");
445  if (!ret) {
446  cout << "Couldn't remove name: short" << endl;
447  }
448  sflg = 0;
449  }
450  catch (InvalidParameter ip) {
451 // cout << "InvalidParameter exception." << endl;
452  sflg = 1;
453  }
454  catch (NotAvailable na) {
455  cout << "NotAvailable exception." << endl;
456  sflg = 2;
457  }
458  catch (InternalError ip) {
459  cout << "InternalError exception." << endl;
460  sflg = 3;
461  }
462  catch (...) {
463  cout << "othrer exception." << endl;
464  sflg = 4;
465  }
466  CPPUNIT_ASSERT(sflg == 1);
467 
468  // 戻り値:true を確認
469  sflg = -1;
470  try {
471  ret = m_pOi->remove_organization_property("hoge");
472  if (!ret) {
473  cout << "Couldn't remove name: hoge" << endl;
474  }
475  CPPUNIT_ASSERT(ret);
476  sflg = 0;
477  }
478  catch (InvalidParameter ip) {
479  cout << "InvalidParameter exception." << endl;
480  sflg = 1;
481  }
482  catch (NotAvailable na) {
483  cout << "NotAvailable exception." << endl;
484  sflg = 2;
485  }
486  catch (InternalError ip) {
487  cout << "InternalError exception." << endl;
488  sflg = 3;
489  }
490  catch (...) {
491  cout << "othrer exception." << endl;
492  sflg = 4;
493  }
494  CPPUNIT_ASSERT(sflg == 0);
495 // std::cout << "test_remove_organization_property OUT" << std::endl;
496  }
497 
498 
503 // std::cout << "test_set_get_owner IN" << std::endl;
504  CORBA::Boolean ret;
505  SDOPackage::SDOSystemElement_var varOwner;
506  SDOPackage::SDOSystemElement_ptr ptrOwner;
507 
508  try {
509  // オーナー取得が行えるか?
510  varOwner = m_pOi->get_owner();
511  CPPUNIT_ASSERT(!::CORBA::is_nil(varOwner));
512 
513  // InvalidParameter exceptionを確認
514  short sflg = -1;
515  try {
516  // オーナー設定時、InvalidParameter が返されるか?
517  ptrOwner = SDOPackage::SDOSystemElement::_nil();
518  ret = m_pOi->set_owner(ptrOwner);
519  CPPUNIT_ASSERT(ret);
520  sflg = 0;
521  }
522  catch (InvalidParameter ip) {
523 // cout << "InvalidParameter exception." << endl;
524  sflg = 1;
525  }
526  catch (NotAvailable na) {
527  cout << "NotAvailable exception." << endl;
528  sflg = 2;
529  }
530  catch (InternalError ip) {
531  cout << "InternalError exception." << endl;
532  sflg = 3;
533  }
534  catch (...) {
535  cout << "othrer exception." << endl;
536  sflg = 4;
537  }
538  CPPUNIT_ASSERT(sflg == 1);
539 
540  // 戻り値:true を確認
541  sflg = -1;
542  try {
543  // オーナー設定時、true が返されるか?
544  ::RTC::RTObject_impl* rtobj2;
546  rtobj2 = new ::RTC::RTObject_impl(&mgr2);
547  ptrOwner = rtobj2->getObjRef();
548 
549  ret = m_pOi->set_owner(ptrOwner);
550  CPPUNIT_ASSERT(ret);
551  sflg = 0;
552  rtobj2->_remove_ref();
553  }
554  catch (InvalidParameter ip) {
555  cout << "InvalidParameter exception." << endl;
556  sflg = 1;
557  }
558  catch (NotAvailable na) {
559  cout << "NotAvailable exception." << endl;
560  sflg = 2;
561  }
562  catch (InternalError ip) {
563  cout << "InternalError exception." << endl;
564  sflg = 3;
565  }
566  catch (...) {
567  cout << "othrer exception." << endl;
568  sflg = 4;
569  }
570  CPPUNIT_ASSERT(sflg == 0);
571  }
572  catch (InvalidParameter ip) {
573  cout << "InvalidParameter exception." << endl;
574  }
575  catch (NotAvailable na) {
576  cout << "NotAvailable exception." << endl;
577  }
578  catch (InternalError ip) {
579  cout << "InternalError exception." << endl;
580  }
581  catch (...) {
582  cout << "othrer exception." << endl;
583  }
584 // std::cout << "test_set_get_owner OUT" << std::endl;
585  }
586 
587 
592 // std::cout << "test_set_get_members IN" << std::endl;
593  CORBA::Boolean ret;
594  SDOPackage::SDO_var sdo;
595  SDOPackage::SDOList slist;
596  SDOPackage::SDOList* rslist;
597 
598  // SDO のセット時、InvalidParameter を取得できるか?
599  // set_members()に、NULL や 空のリストを渡してもlength()=0となるため // InvalidParameterを返すケースはない。 // SDOList のセット時、空のリストを渡して取得できるか? short sflg = -1; try { slist = NULL; ret = m_pOi->set_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 0件のSDOList取得が行えるか? rslist = m_pOi->get_members(); CPPUNIT_ASSERT(rslist->length() == 0); // SDOList のセット時、リストをセットして true を取得できるか? sflg = -1; try { RTC::RTObject_impl* rtobj2; RTC::Manager& mgr2(RTC::Manager::instance()); rtobj2 = new ::RTC::RTObject_impl(&mgr2); sdo = SDOPackage::SDO::_duplicate(rtobj2->getObjRef()); CORBA_SeqUtil::push_back(slist, sdo); ret = m_pOi->set_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; rtobj2->_remove_ref(); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 1件のSDOList取得が行えるか? rslist = m_pOi->get_members(); CPPUNIT_ASSERT(rslist->length() == 1); // std::cout << "test_set_get_members OUT" << std::endl; } /*! * @brief add_members() and remove_member() */ void test_add_remove_members() { // std::cout << "test_add_remove_members IN" << std::endl; CORBA::Boolean ret; SDOPackage::SDO_var sdo; SDOPackage::SDOList slist; SDOPackage::SDOList* rslist; Organization_impl* m_pOi2; std::string str; CORBA::Any any; RTC::RTObject_impl* rtobj2; RTC::Manager& mgr2(RTC::Manager::instance()); mgr2.activateManager(); rtobj2 = new ::RTC::RTObject_impl(&mgr2); m_pOi2 = new Organization_impl(rtobj2->getObjRef()); // SDO のセット時、InvalidParameter を取得できるか? // add_members()に、NULL や 空のリストを渡してもlength()=0となるため // InvalidParameterを返すケースはない。 // SDOList のセット時、空のリストを渡して true を取得できるか? short sflg = -1; try { slist = NULL; ret = m_pOi->add_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // SDOList のセット時、リストをセットして true を取得できるか? sflg = -1; try { sdo = SDOPackage::SDO::_duplicate(rtobj2->getObjRef()); CORBA_SeqUtil::push_back(slist, sdo); rtobj2->setInstanceName("hoge1"); // SDOメンバーの追加が成功するか? ret = m_pOi2->add_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; str = m_pOi2->get_organization_id(); any <<= str.c_str(); ret = m_pOi2->set_organization_property_value("instance_name", any); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 1件のSDOList取得が行えるか? rslist = m_pOi2->get_members(); CPPUNIT_ASSERT(rslist->length() == 1); // SDOList削除時、引数未定義でInvalidParameterを取得できるか? sflg = -1; try { ret = m_pOi2->remove_member(""); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // SDOList削除時、引数不正でInvalidParameterを取得できるか? sflg = -1; try { ret = m_pOi2->remove_member("dummy"); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // SDOList削除時、正しい引数で削除できるか? sflg = -1; try { ret = m_pOi2->remove_member("hoge1"); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 0件のSDOList取得が行えるか? rslist = m_pOi2->get_members(); CPPUNIT_ASSERT(rslist->length() == 0); if ( !CORBA::is_nil( mgr2.getPOA()) ) { if ( !CORBA::is_nil(mgr2.getPOAManager()) ) { mgr2.getPOAManager()->deactivate(false, true); } } rtobj2->_remove_ref(); m_pOi2->_remove_ref(); // std::cout << "test_add_remove_members OUT" << std::endl; } /*! * @brief set_dependency() and get_dependency() */ void test_set_get_dependency() { // std::cout << "test_set_get_dependency IN" << std::endl; DependencyType depType; // Success case. // default return value is 0. depType = m_pOi->get_dependency(); // cout << "depType: " << depType << endl; CPPUNIT_ASSERT(depType == 0); m_pOi->set_dependency(NO_DEPENDENCY); // returned value is 2. depType = m_pOi->get_dependency(); CPPUNIT_ASSERT(depType == 2); // cout << "depType: " << depType << endl; // Failure case. // m_pOi->set_dependency(0); // コンパイルエラー // CPPUNIT_ASSERT(depType == 3); // cout << "depType: " << depType << endl; // std::cout << "test_set_get_dependency OUT" << std::endl; } }; }; // namespace SdoOrganization /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoOrganization::SdoOrganizationTests); #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 // SdoOrganization_cpp
600  // InvalidParameterを返すケースはない。
601  // SDOList のセット時、空のリストを渡して取得できるか?
602  short sflg = -1;
603  try {
604  slist = NULL;
605  ret = m_pOi->set_members(slist);
606  CPPUNIT_ASSERT(ret);
607  sflg = 0;
608  }
609  catch (InvalidParameter ip) {
610  cout << "InvalidParameter exception." << endl;
611  sflg = 1;
612  }
613  catch (NotAvailable na) {
614  cout << "NotAvailable exception." << endl;
615  sflg = 2;
616  }
617  catch (InternalError ip) {
618  cout << "InternalError exception." << endl;
619  sflg = 3;
620  }
621  catch (...) {
622  cout << "othrer exception." << endl;
623  sflg = 4;
624  }
625  CPPUNIT_ASSERT(sflg == 0);
626 
627  // 0件のSDOList取得が行えるか?
628  rslist = m_pOi->get_members();
629  CPPUNIT_ASSERT(rslist->length() == 0);
630 
631 
632  // SDOList のセット時、リストをセットして true を取得できるか?
633  sflg = -1;
634  try {
635  RTC::RTObject_impl* rtobj2;
637  rtobj2 = new ::RTC::RTObject_impl(&mgr2);
638  sdo = SDOPackage::SDO::_duplicate(rtobj2->getObjRef());
639  CORBA_SeqUtil::push_back(slist, sdo);
640  ret = m_pOi->set_members(slist);
641  CPPUNIT_ASSERT(ret);
642  sflg = 0;
643  rtobj2->_remove_ref();
644  }
645  catch (InvalidParameter ip) {
646  cout << "InvalidParameter exception." << endl;
647  sflg = 1;
648  }
649  catch (NotAvailable na) {
650  cout << "NotAvailable exception." << endl;
651  sflg = 2;
652  }
653  catch (InternalError ip) {
654  cout << "InternalError exception." << endl;
655  sflg = 3;
656  }
657  catch (...) {
658  cout << "othrer exception." << endl;
659  sflg = 4;
660  }
661  CPPUNIT_ASSERT(sflg == 0);
662 
663  // 1件のSDOList取得が行えるか?
664  rslist = m_pOi->get_members();
665  CPPUNIT_ASSERT(rslist->length() == 1);
666 // std::cout << "test_set_get_members OUT" << std::endl;
667  }
668 
669 
674 // std::cout << "test_add_remove_members IN" << std::endl;
675  CORBA::Boolean ret;
676  SDOPackage::SDO_var sdo;
677  SDOPackage::SDOList slist;
678  SDOPackage::SDOList* rslist;
679  Organization_impl* m_pOi2;
680  std::string str;
681  CORBA::Any any;
682 
683  RTC::RTObject_impl* rtobj2;
685  mgr2.activateManager();
686  rtobj2 = new ::RTC::RTObject_impl(&mgr2);
687  m_pOi2 = new Organization_impl(rtobj2->getObjRef());
688 
689  // SDO のセット時、InvalidParameter を取得できるか?
690  // add_members()に、NULL や 空のリストを渡してもlength()=0となるため // InvalidParameterを返すケースはない。 // SDOList のセット時、空のリストを渡して true を取得できるか? short sflg = -1; try { slist = NULL; ret = m_pOi->add_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // SDOList のセット時、リストをセットして true を取得できるか? sflg = -1; try { sdo = SDOPackage::SDO::_duplicate(rtobj2->getObjRef()); CORBA_SeqUtil::push_back(slist, sdo); rtobj2->setInstanceName("hoge1"); // SDOメンバーの追加が成功するか? ret = m_pOi2->add_members(slist); CPPUNIT_ASSERT(ret); sflg = 0; str = m_pOi2->get_organization_id(); any <<= str.c_str(); ret = m_pOi2->set_organization_property_value("instance_name", any); } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 1件のSDOList取得が行えるか? rslist = m_pOi2->get_members(); CPPUNIT_ASSERT(rslist->length() == 1); // SDOList削除時、引数未定義でInvalidParameterを取得できるか? sflg = -1; try { ret = m_pOi2->remove_member(""); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // SDOList削除時、引数不正でInvalidParameterを取得できるか? sflg = -1; try { ret = m_pOi2->remove_member("dummy"); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { // cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 1); // SDOList削除時、正しい引数で削除できるか? sflg = -1; try { ret = m_pOi2->remove_member("hoge1"); CPPUNIT_ASSERT(ret); sflg = 0; } catch (InvalidParameter ip) { cout << "InvalidParameter exception." << endl; sflg = 1; } catch (NotAvailable na) { cout << "NotAvailable exception." << endl; sflg = 2; } catch (InternalError ip) { cout << "InternalError exception." << endl; sflg = 3; } catch (...) { cout << "othrer exception." << endl; sflg = 4; } CPPUNIT_ASSERT(sflg == 0); // 0件のSDOList取得が行えるか? rslist = m_pOi2->get_members(); CPPUNIT_ASSERT(rslist->length() == 0); if ( !CORBA::is_nil( mgr2.getPOA()) ) { if ( !CORBA::is_nil(mgr2.getPOAManager()) ) { mgr2.getPOAManager()->deactivate(false, true); } } rtobj2->_remove_ref(); m_pOi2->_remove_ref(); // std::cout << "test_add_remove_members OUT" << std::endl; } /*! * @brief set_dependency() and get_dependency() */ void test_set_get_dependency() { // std::cout << "test_set_get_dependency IN" << std::endl; DependencyType depType; // Success case. // default return value is 0. depType = m_pOi->get_dependency(); // cout << "depType: " << depType << endl; CPPUNIT_ASSERT(depType == 0); m_pOi->set_dependency(NO_DEPENDENCY); // returned value is 2. depType = m_pOi->get_dependency(); CPPUNIT_ASSERT(depType == 2); // cout << "depType: " << depType << endl; // Failure case. // m_pOi->set_dependency(0); // コンパイルエラー // CPPUNIT_ASSERT(depType == 3); // cout << "depType: " << depType << endl; // std::cout << "test_set_get_dependency OUT" << std::endl; } }; }; // namespace SdoOrganization /* * Register test suite */ CPPUNIT_TEST_SUITE_REGISTRATION(SdoOrganization::SdoOrganizationTests); #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 // SdoOrganization_cpp
691  // InvalidParameterを返すケースはない。
692  // SDOList のセット時、空のリストを渡して true を取得できるか?
693 
694  short sflg = -1;
695  try {
696  slist = NULL;
697  ret = m_pOi->add_members(slist);
698  CPPUNIT_ASSERT(ret);
699  sflg = 0;
700  }
701  catch (InvalidParameter ip) {
702  cout << "InvalidParameter exception." << endl;
703  sflg = 1;
704  }
705  catch (NotAvailable na) {
706  cout << "NotAvailable exception." << endl;
707  sflg = 2;
708  }
709  catch (InternalError ip) {
710  cout << "InternalError exception." << endl;
711  sflg = 3;
712  }
713  catch (...) {
714  cout << "othrer exception." << endl;
715  sflg = 4;
716  }
717  CPPUNIT_ASSERT(sflg == 0);
718 
719  // SDOList のセット時、リストをセットして true を取得できるか?
720  sflg = -1;
721  try {
722  sdo = SDOPackage::SDO::_duplicate(rtobj2->getObjRef());
723  CORBA_SeqUtil::push_back(slist, sdo);
724  rtobj2->setInstanceName("hoge1");
725 
726  // SDOメンバーの追加が成功するか?
727  ret = m_pOi2->add_members(slist);
728  CPPUNIT_ASSERT(ret);
729  sflg = 0;
730 
731  str = m_pOi2->get_organization_id();
732  any <<= str.c_str();
733  ret = m_pOi2->set_organization_property_value("instance_name", any);
734  }
735  catch (InvalidParameter ip) {
736  cout << "InvalidParameter exception." << endl;
737  sflg = 1;
738  }
739  catch (NotAvailable na) {
740  cout << "NotAvailable exception." << endl;
741  sflg = 2;
742  }
743  catch (InternalError ip) {
744  cout << "InternalError exception." << endl;
745  sflg = 3;
746  }
747  catch (...) {
748  cout << "othrer exception." << endl;
749  sflg = 4;
750  }
751  CPPUNIT_ASSERT(sflg == 0);
752 
753  // 1件のSDOList取得が行えるか?
754  rslist = m_pOi2->get_members();
755  CPPUNIT_ASSERT(rslist->length() == 1);
756 
757  // SDOList削除時、引数未定義でInvalidParameterを取得できるか?
758  sflg = -1;
759  try {
760  ret = m_pOi2->remove_member("");
761  CPPUNIT_ASSERT(ret);
762  sflg = 0;
763  }
764  catch (InvalidParameter ip) {
765 // cout << "InvalidParameter exception." << endl;
766  sflg = 1;
767  }
768  catch (NotAvailable na) {
769  cout << "NotAvailable exception." << endl;
770  sflg = 2;
771  }
772  catch (InternalError ip) {
773  cout << "InternalError exception." << endl;
774  sflg = 3;
775  }
776  catch (...) {
777  cout << "othrer exception." << endl;
778  sflg = 4;
779  }
780  CPPUNIT_ASSERT(sflg == 1);
781 
782  // SDOList削除時、引数不正でInvalidParameterを取得できるか?
783  sflg = -1;
784  try {
785  ret = m_pOi2->remove_member("dummy");
786  CPPUNIT_ASSERT(ret);
787  sflg = 0;
788  }
789  catch (InvalidParameter ip) {
790 // cout << "InvalidParameter exception." << endl;
791  sflg = 1;
792  }
793  catch (NotAvailable na) {
794  cout << "NotAvailable exception." << endl;
795  sflg = 2;
796  }
797  catch (InternalError ip) {
798  cout << "InternalError exception." << endl;
799  sflg = 3;
800  }
801  catch (...) {
802  cout << "othrer exception." << endl;
803  sflg = 4;
804  }
805  CPPUNIT_ASSERT(sflg == 1);
806 
807  // SDOList削除時、正しい引数で削除できるか?
808  sflg = -1;
809  try {
810  ret = m_pOi2->remove_member("hoge1");
811  CPPUNIT_ASSERT(ret);
812  sflg = 0;
813  }
814  catch (InvalidParameter ip) {
815  cout << "InvalidParameter exception." << endl;
816  sflg = 1;
817  }
818  catch (NotAvailable na) {
819  cout << "NotAvailable exception." << endl;
820  sflg = 2;
821  }
822  catch (InternalError ip) {
823  cout << "InternalError exception." << endl;
824  sflg = 3;
825  }
826  catch (...) {
827  cout << "othrer exception." << endl;
828  sflg = 4;
829  }
830  CPPUNIT_ASSERT(sflg == 0);
831 
832  // 0件のSDOList取得が行えるか?
833  rslist = m_pOi2->get_members();
834  CPPUNIT_ASSERT(rslist->length() == 0);
835 
836  if ( !CORBA::is_nil( mgr2.getPOA()) ) {
837  if ( !CORBA::is_nil(mgr2.getPOAManager()) ) {
838  mgr2.getPOAManager()->deactivate(false, true);
839  }
840  }
841  rtobj2->_remove_ref();
842  m_pOi2->_remove_ref();
843 // std::cout << "test_add_remove_members OUT" << std::endl;
844  }
845 
846 
851 // std::cout << "test_set_get_dependency IN" << std::endl;
852  DependencyType depType;
853 
854  // Success case.
855  // default return value is 0.
856  depType = m_pOi->get_dependency();
857 // cout << "depType: " << depType << endl;
858  CPPUNIT_ASSERT(depType == 0);
859 
860  m_pOi->set_dependency(NO_DEPENDENCY);
861  // returned value is 2.
862  depType = m_pOi->get_dependency();
863  CPPUNIT_ASSERT(depType == 2);
864 // cout << "depType: " << depType << endl;
865 
866  // Failure case.
867  // m_pOi->set_dependency(0); // コンパイルエラー
868  // CPPUNIT_ASSERT(depType == 3);
869  // cout << "depType: " << depType << endl;
870 // std::cout << "test_set_get_dependency OUT" << std::endl;
871  }
872 
873  };
874 }; // namespace SdoOrganization
875 
876 /*
877  * Register test suite
878  */
880 
881 #ifdef LOCAL_MAIN
882 int main(int argc, char* argv[])
883 {
884 
885  FORMAT format = TEXT_OUT;
886  int target = 0;
887  std::string xsl;
888  std::string ns;
889  std::string fname;
890  std::ofstream ofs;
891 
892  int i(1);
893  while (i < argc)
894  {
895  std::string arg(argv[i]);
896  std::string next_arg;
897  if (i + 1 < argc) next_arg = argv[i + 1];
898  else next_arg = "";
899 
900  if (arg == "--text") { format = TEXT_OUT; break; }
901  if (arg == "--xml")
902  {
903  if (next_arg == "")
904  {
905  fname = argv[0];
906  fname += ".xml";
907  }
908  else
909  {
910  fname = next_arg;
911  }
912  format = XML_OUT;
913  ofs.open(fname.c_str());
914  }
915  if ( arg == "--compiler" ) { format = COMPILER_OUT; break; }
916  if ( arg == "--cerr" ) { target = 1; break; }
917  if ( arg == "--xsl" )
918  {
919  if (next_arg == "") xsl = "default.xsl";
920  else xsl = next_arg;
921  }
922  if ( arg == "--namespace" )
923  {
924  if (next_arg == "")
925  {
926  std::cerr << "no namespace specified" << std::endl;
927  exit(1);
928  }
929  else
930  {
931  xsl = next_arg;
932  }
933  }
934  ++i;
935  }
936  CppUnit::TextUi::TestRunner runner;
937  if ( ns.empty() )
938  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
939  else
940  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
941  CppUnit::Outputter* outputter = 0;
942  std::ostream* stream = target ? &std::cerr : &std::cout;
943  switch ( format )
944  {
945  case TEXT_OUT :
946  outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
947  break;
948  case XML_OUT :
949  std::cout << "XML_OUT" << std::endl;
950  outputter = new CppUnit::XmlOutputter(&runner.result(),
951  ofs, "shift_jis");
952  static_cast<CppUnit::XmlOutputter*>(outputter)->setStyleSheet(xsl);
953  break;
954  case COMPILER_OUT :
955  outputter = new CppUnit::CompilerOutputter(&runner.result(),*stream);
956  break;
957  }
958  runner.setOutputter(outputter);
959  runner.run();
960  return 0; // runner.run() ? 0 : 1;
961 }
962 #endif // MAIN
963 #endif // SdoOrganization_cpp
int main(int argc, char **argv)
PortableServer::POAManager_ptr getPOAManager()
Get POAManager that Manager has.
Definition: Manager.cpp:858
virtual CORBA::Boolean add_organization_property(const OrganizationProperty &org_property)
[CORBA interface] Set OrganizationProperty
virtual SDOList * get_members()
[CORBA interface] Get the member list of the Organization
PortableServer::POA_ptr getPOA()
Get a pointer to RootPOA held by Manager.
Definition: Manager.cpp:845
void test_set_get_owner()
set_owner() and get_owner()
virtual SDOSystemElement_ptr get_owner()
[CORBA interface] Get the owner of Organization
void test_set_get_organization_property_value()
set_organization_property_value() and get_organization_property_value()
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
RT-Component class.
Definition: RTObject.h:89
Manager class.
Definition: Manager.h:80
virtual char * get_organization_id()
[CORBA interface] Get Organization ID
SDO Organization implementation class.
static Manager & instance()
Get instance of the manager.
Definition: Manager.cpp:140
virtual CORBA::Boolean remove_organization_property(const char *name)
[CORBA interface] Remove specified OrganizationProperty
void test_set_get_dependency()
set_dependency() and get_dependency()
SDO Package.
virtual CORBA::Boolean set_organization_property_value(const char *name, const CORBA::Any &value)
[CORBA interface] Set specified value of OrganizationProperty
RTComponent manager class.
virtual DependencyType get_dependency()
[CORBA interface] Get the DependencyType of the Organization
virtual CORBA::Boolean set_members(const SDOList &sdos)
[CORBA interface] Set SDO
virtual void tearDown()
Test finalization.
Organization implementation class.
virtual CORBA::Boolean remove_member(const char *id)
[CORBA interface] Remove member SDO from Organization
void test_set_get_organization_property()
set_organization_property() and get_organization_property()
void test_set_get_members()
set_members() and get_members()
bool activateManager()
Activate the Manager.
Definition: Manager.cpp:244
void test_remove_organization_property()
add_organization_property() and remove_organization_property()
virtual CORBA::Boolean set_owner(SDOSystemElement_ptr sdo)
[CORBA interface] Set the owner to the Organization
void test_add_remove_members()
add_members() and remove_member()
virtual void setUp()
Test initialization.
virtual OrganizationProperty * get_organization_property()
[CORBA interface] Get OrganizationProperty
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
void setInstanceName(const char *instance_name)
[local interface] Set instance name
Definition: RTObject.cpp:1437
CPPUNIT_TEST_SUITE_REGISTRATION(SdoOrganization::SdoOrganizationTests)
virtual CORBA::Any * get_organization_property_value(const char *name)
[CORBA interface] Get specified value of OrganizationProperty
void test_get_organization_id()
get_organization_id()
RTObject_ptr getObjRef() const
[local interface] Get the object reference
Definition: RTObject.cpp:1483
virtual CORBA::Boolean add_members(const SDOList &sdo_list)
[CORBA interface] Add the member SDOs
virtual CORBA::Boolean set_dependency(DependencyType dependency)
[CORBA interface] Set the DependencyType of the Organization


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:56