OrganizationProxyTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
12 /*
13  * $Log$
14  *
15  */
16 
17 #ifndef OrganizationProxy_cpp
18 #define OrganizationProxy_cpp
19 
20 #include <cppunit/ui/text/TestRunner.h>
21 #include <cppunit/TextOutputter.h>
22 #include <cppunit/extensions/TestFactoryRegistry.h>
23 #include <cppunit/extensions/HelperMacros.h>
24 #include <cppunit/TestAssert.h>
25 #include <string>
26 #include <iostream>
27 #include <idl/SDOPackageSkel.h>
28 #include <OrganizationProxy.h>
29 #include <ISDOSystemElement.h>
31 #include <doil/corba/CORBAProxyBase.h>
32 
38 {
44  class Logger
45  {
46  public:
47  void log(const std::string& msg)
48  {
49  m_log.push_back(msg);
50  }
51 
52  int countLog(const std::string& msg)
53  {
54  int count = 0;
55  for (int i = 0; i < (int) m_log.size(); ++i)
56  {
57  if (m_log[i] == msg) ++count;
58  }
59  return count;
60  }
61 
62  private:
63  std::vector<std::string> m_log;
64  };
65 
72  : public virtual ::POA_SDOPackage::SDOSystemElement,
73  public virtual ::doil::CORBA::CORBAServantBase
74  {
75  public:
77  : ::doil::CORBA::CORBAServantBase(impl)
78  {
79  }
81  {
82  }
83 
84  virtual ::SDOPackage::OrganizationList* get_owned_organizations()
85  {
86  }
87  private:
88  ::SDOPackage::Local::ISDOSystemElement* m_impl;
89  };
96  : public virtual ::SDOPackage::Local::ISDOSystemElement
97  {
98  public:
100  : m_refcount(0)
101  {}
103  const char* id() {return "ISDOSystemElementMock";}
104  const char* name() {return "ISDOSystemElementMock";}
105  void incRef()
106  {
107  ++m_refcount;
108  }
109  void decRef()
110  {
111  --m_refcount;
112  if (m_refcount == 0)
113  delete this;
114  }
115  virtual ::SDOPackage::Local::OrganizationList get_owned_organizations()
116  throw (::SDOPackage::Local::NotAvailable)
117  {
118  ::SDOPackage::Local::OrganizationList list;
119  return list;
120  }
121  private:
122  std::string m_name;
124  };
131  : public virtual ::POA_SDOPackage::Organization
132  {
133  protected:
134  std::vector<std::string> m_log;
135  public :
138 
143  {
144  m_logger = logger;
145  }
149  virtual char* get_organization_id()
150  {
151  return "get_organization_id";
152  }
156  virtual SDOPackage::OrganizationProperty* get_organization_property()
157  {
158  return NULL;
159  }
160 
164  virtual CORBA::Any* get_organization_property_value(const char* name)
165  {
166  return NULL;
167  }
168 
172  virtual CORBA::Boolean set_organization_property(const SDOPackage::OrganizationProperty& organization_property)
173  {
174  return false;
175  }
176 
180  virtual CORBA::Boolean set_organization_property_value(const char* name, const CORBA::Any& value)
181  {
182  return false;
183  }
184 
188  virtual CORBA::Boolean remove_organization_property(const char* name)
189  {
190  return false;
191  }
192 
196  virtual SDOPackage::SDOSystemElement_ptr get_owner()
197  {
198  return NULL;
199  }
200 
204  virtual CORBA::Boolean set_owner(SDOPackage::SDOSystemElement_ptr sdo)
205  {
206  if (m_logger != NULL)
207  {
208  m_logger->log("set_owner");
209  }
210  return false;
211  }
212 
216  virtual SDOPackage::SDOList* get_members()
217  {
218  return NULL;
219  }
220 
224  virtual CORBA::Boolean set_members(const SDOPackage::SDOList& sdos)
225  {
226  return false;
227  }
228 
232  virtual CORBA::Boolean add_members(const SDOPackage::SDOList& sdo_list)
233  {
234  return false;
235  }
236 
240  virtual CORBA::Boolean remove_member(const char* id)
241  {
242  return false;
243  }
244 
248  virtual SDOPackage::DependencyType get_dependency()
249  {
250  return SDOPackage::NO_DEPENDENCY;
251  }
252 
256  virtual CORBA::Boolean set_dependency(SDOPackage::DependencyType dependency)
257  {
258  return false;
259  }
260  private:
262 
263  };
264 
266  : public CppUnit::TestFixture
267  {
268  CPPUNIT_TEST_SUITE(OrganizationProxyTests);
269  CPPUNIT_TEST(test_set_owner);
270 // CPPUNIT_TEST(test_case0);
271  CPPUNIT_TEST_SUITE_END();
272 
273  private:
274  CORBA::ORB_ptr m_pORB;
275  PortableServer::POA_ptr m_pPOA;
276 
277  public:
278 
283  {
284  int argc = 0;
285  char** argv = NULL;
286  m_pORB = CORBA::ORB_init(argc, argv);
287  m_pPOA = PortableServer::POA::_narrow(
288  m_pORB->resolve_initial_references("RootPOA"));
289  m_pPOA->the_POAManager()->activate();
290  }
291 
296  {
297  }
298 
302  virtual void setUp()
303  {
304  }
305 
309  virtual void tearDown()
310  {
311  }
318  {
321  std::cout <<"Manager Name==>"<< mgr.name() << std::endl;
322 
324  ::CORBA::Object_ptr ref = obj->_this();
325  if(::CORBA::is_nil(ref))
326  {
327  std::cout<<"ref is nil.Abort test."<<std::endl;
328  return;
329  }
330  ::SDOPackage::CORBA::OrganizationProxy* ap
331  = new ::SDOPackage::CORBA::OrganizationProxy(ref);
332 
333  Logger logger;
334  obj->setLogger(&logger);
335 
336 
337  bool ret;
339  mgr.registerFactory(sdo->id(),
340  doil::New<SDOSystemElementServantMock>,
341  doil::Delete<SDOSystemElementServantMock>);
342  mgr.activateObject(sdo);
343  CPPUNIT_ASSERT_EQUAL(0, logger.countLog("set_owner"));
344  ret = ap->set_owner(sdo);
345  CPPUNIT_ASSERT_EQUAL(1, logger.countLog("set_owner"));
346  CPPUNIT_ASSERT_EQUAL(false, ret);
347 
348  delete ap;
349  CORBA::release(ref);
350 
351  }
352 
353  /* test case */
354  void test_case0()
355  {
356  }
357  };
358 }; // namespace OrganizationProxy
359 
360 /*
361  * Register test suite
362  */
364 
365 #ifdef LOCAL_MAIN
366 int main(int argc, char* argv[])
367 {
368  CppUnit::TextUi::TestRunner runner;
369  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
370  CppUnit::Outputter* outputter =
371  new CppUnit::TextOutputter(&runner.result(), std::cout);
372  runner.setOutputter(outputter);
373  bool retcode = runner.run();
374  return !retcode;
375 }
376 #endif // MAIN
377 #endif // OrganizationProxy_cpp
int main(int argc, char **argv)
virtual const char * name()
Getting ORB&#39;s name.
virtual CORBA::Any * get_organization_property_value(const char *name)
CPPUNIT_TEST_SUITE_REGISTRATION(OrganizationProxy::OrganizationProxyTests)
virtual ReturnCode_t registerFactory(const char *id, doil::ServantNewFunc new_func, doil::ServantDeleteFunc delete_func)
Register servant&#39;s factory.
virtual CORBA::Boolean set_owner(SDOPackage::SDOSystemElement_ptr sdo)
static CORBAManager & instance()
getting instance
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
virtual CORBA::Boolean set_organization_property(const SDOPackage::OrganizationProperty &organization_property)
::SDOPackage::Local::ISDOSystemElement * m_impl
virtual CORBA::Boolean set_dependency(SDOPackage::DependencyType dependency)
SDO Package.
virtual CORBA::Boolean remove_organization_property(const char *name)
int countLog(const std::string &msg)
virtual CORBA::Boolean set_organization_property_value(const char *name, const CORBA::Any &value)
std::vector< std::string > m_log
virtual SDOPackage::DependencyType get_dependency()
virtual SDOPackage::SDOSystemElement_ptr get_owner()
CORBA manager for doil.
virtual void setUp()
Test initialization.
virtual CORBA::Boolean remove_member(const char *id)
virtual ::SDOPackage::Local::OrganizationList get_owned_organizations()
virtual void tearDown()
Test finalization.
void log(const std::string &msg)
virtual CORBA::Boolean add_members(const SDOPackage::SDOList &sdo_list)
::OutPortBase::Logger logger
virtual ::SDOPackage::OrganizationList * get_owned_organizations()
virtual CORBA::Boolean set_members(const SDOPackage::SDOList &sdos)
virtual ReturnCode_t activateObject(doil::ImplBase *impl)
Activate object.
virtual SDOPackage::SDOList * get_members()
virtual SDOPackage::OrganizationProperty * get_organization_property()


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:43