OrganizationProxyTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00012 /*
00013  * $Log$
00014  *
00015  */
00016 
00017 #ifndef OrganizationProxy_cpp
00018 #define OrganizationProxy_cpp
00019 
00020 #include <cppunit/ui/text/TestRunner.h>
00021 #include <cppunit/TextOutputter.h>
00022 #include <cppunit/extensions/TestFactoryRegistry.h>
00023 #include <cppunit/extensions/HelperMacros.h>
00024 #include <cppunit/TestAssert.h>
00025 #include <string>
00026 #include <iostream>
00027 #include <idl/SDOPackageSkel.h>
00028 #include <OrganizationProxy.h>
00029 #include <ISDOSystemElement.h>
00030 #include <doil/corba/CORBAManager.h>
00031 #include <doil/corba/CORBAProxyBase.h>
00032 
00037 namespace OrganizationProxy
00038 {
00044   class Logger
00045   {
00046   public:
00047     void log(const std::string& msg)
00048     {
00049       m_log.push_back(msg);
00050     }
00051 
00052     int countLog(const std::string& msg)
00053     {
00054       int count = 0;
00055       for (int i = 0; i < (int) m_log.size(); ++i)
00056         {
00057           if (m_log[i] == msg) ++count;
00058         }
00059      return count;
00060     }
00061                 
00062   private:
00063     std::vector<std::string> m_log;
00064   };
00065 
00071   class SDOSystemElementServantMock
00072    : public virtual ::POA_SDOPackage::SDOSystemElement,
00073      public virtual ::doil::CORBA::CORBAServantBase
00074   {
00075   public:
00076     SDOSystemElementServantMock(doil::ImplBase* impl)
00077      : ::doil::CORBA::CORBAServantBase(impl) 
00078     {
00079     }
00080     virtual ~SDOSystemElementServantMock()
00081     {
00082     }
00083 
00084     virtual ::SDOPackage::OrganizationList* get_owned_organizations()
00085     {
00086     }
00087   private:
00088     ::SDOPackage::Local::ISDOSystemElement* m_impl;
00089   };
00095   class ISDOSystemElementMock
00096     : public virtual ::SDOPackage::Local::ISDOSystemElement
00097   {
00098   public:
00099     ISDOSystemElementMock()
00100       : m_refcount(0)
00101     {}
00102     virtual ~ISDOSystemElementMock(){}
00103     const char* id() {return "ISDOSystemElementMock";}
00104     const char* name() {return "ISDOSystemElementMock";}
00105     void incRef()
00106     {
00107       ++m_refcount;
00108     }
00109     void decRef()
00110     {
00111       --m_refcount;
00112       if (m_refcount == 0)
00113         delete this;
00114     }
00115     virtual ::SDOPackage::Local::OrganizationList get_owned_organizations()
00116       throw (::SDOPackage::Local::NotAvailable)
00117     {
00118         ::SDOPackage::Local::OrganizationList  list;
00119         return list;
00120     }
00121   private:
00122     std::string m_name;
00123     int m_refcount;
00124   };
00130   class OrganizationRtmMock
00131     : public virtual ::POA_SDOPackage::Organization
00132   {
00133   protected:
00134       std::vector<std::string> m_log;
00135   public :
00136       OrganizationRtmMock(){}
00137       virtual ~OrganizationRtmMock(){}
00138 
00142       void setLogger(Logger* logger)
00143       {
00144         m_logger = logger;
00145       }
00149     virtual char* get_organization_id()
00150     {
00151       return "get_organization_id";
00152     }
00156     virtual SDOPackage::OrganizationProperty* get_organization_property()
00157     {
00158       return NULL;
00159     }
00160                 
00164     virtual CORBA::Any* get_organization_property_value(const char* name)
00165     {
00166       return NULL;
00167     }
00168                 
00172     virtual CORBA::Boolean set_organization_property(const SDOPackage::OrganizationProperty& organization_property)
00173     {
00174       return false;
00175     }
00176                 
00180     virtual CORBA::Boolean set_organization_property_value(const char* name, const CORBA::Any& value)
00181     {
00182       return false;
00183     }
00184                 
00188     virtual CORBA::Boolean remove_organization_property(const char* name)
00189     {
00190       return false;
00191     }
00192                 
00196     virtual SDOPackage::SDOSystemElement_ptr get_owner()
00197     {
00198       return NULL;
00199     }
00200                 
00204     virtual CORBA::Boolean set_owner(SDOPackage::SDOSystemElement_ptr sdo)
00205     {
00206         if (m_logger != NULL)
00207         {
00208             m_logger->log("set_owner");
00209         }
00210         return false;
00211     }
00212                 
00216     virtual SDOPackage::SDOList* get_members()
00217     {
00218       return NULL;
00219     }
00220                 
00224     virtual CORBA::Boolean set_members(const SDOPackage::SDOList& sdos)
00225     {
00226       return false;
00227     }
00228                 
00232     virtual CORBA::Boolean add_members(const SDOPackage::SDOList& sdo_list)
00233     {
00234       return false;
00235     }
00236                 
00240     virtual CORBA::Boolean remove_member(const char* id)
00241     {
00242       return false;
00243     }
00244                 
00248     virtual SDOPackage::DependencyType get_dependency()
00249     {
00250       return SDOPackage::NO_DEPENDENCY;
00251     }
00252                 
00256     virtual CORBA::Boolean set_dependency(SDOPackage::DependencyType dependency)
00257     {
00258       return false;
00259     }
00260   private:
00261     Logger* m_logger;
00262 
00263   };
00264 
00265   class OrganizationProxyTests
00266    : public CppUnit::TestFixture
00267   {
00268     CPPUNIT_TEST_SUITE(OrganizationProxyTests);
00269     CPPUNIT_TEST(test_set_owner);
00270 //    CPPUNIT_TEST(test_case0);
00271     CPPUNIT_TEST_SUITE_END();
00272   
00273   private:
00274     CORBA::ORB_ptr m_pORB;
00275     PortableServer::POA_ptr m_pPOA;
00276   
00277   public:
00278   
00282     OrganizationProxyTests()
00283     {
00284       int argc = 0;
00285       char** argv = NULL;
00286       m_pORB = CORBA::ORB_init(argc, argv);
00287       m_pPOA = PortableServer::POA::_narrow(
00288                        m_pORB->resolve_initial_references("RootPOA"));
00289       m_pPOA->the_POAManager()->activate();
00290     }
00291     
00295     ~OrganizationProxyTests()
00296     {
00297     }
00298   
00302     virtual void setUp()
00303     {
00304     }
00305     
00309     virtual void tearDown()
00310     { 
00311     }
00317     void test_set_owner()
00318     {
00319       doil::CORBA::CORBAManager& 
00320                             mgr(doil::CORBA::CORBAManager::instance());
00321       std::cout <<"Manager Name==>"<< mgr.name() << std::endl;
00322 
00323       OrganizationRtmMock* obj = new OrganizationRtmMock();
00324       ::CORBA::Object_ptr ref = obj->_this();
00325       if(::CORBA::is_nil(ref))
00326       {
00327          std::cout<<"ref is nil.Abort test."<<std::endl;
00328          return;
00329       }
00330       ::SDOPackage::CORBA::OrganizationProxy* ap 
00331                  = new ::SDOPackage::CORBA::OrganizationProxy(ref);
00332 
00333       Logger logger;
00334       obj->setLogger(&logger);
00335 
00336        
00337       bool ret; 
00338       ISDOSystemElementMock* sdo = new ISDOSystemElementMock();
00339       mgr.registerFactory(sdo->id(), 
00340                           doil::New<SDOSystemElementServantMock>,
00341                           doil::Delete<SDOSystemElementServantMock>);
00342       mgr.activateObject(sdo);
00343       CPPUNIT_ASSERT_EQUAL(0, logger.countLog("set_owner"));
00344       ret = ap->set_owner(sdo);
00345       CPPUNIT_ASSERT_EQUAL(1, logger.countLog("set_owner"));
00346       CPPUNIT_ASSERT_EQUAL(false, ret);
00347 
00348       delete ap;
00349       CORBA::release(ref);
00350 
00351     }
00352   
00353     /* test case */
00354     void test_case0()
00355     {
00356     }
00357   };
00358 }; // namespace OrganizationProxy
00359 
00360 /*
00361  * Register test suite
00362  */
00363 CPPUNIT_TEST_SUITE_REGISTRATION(OrganizationProxy::OrganizationProxyTests);
00364 
00365 #ifdef LOCAL_MAIN
00366 int main(int argc, char* argv[])
00367 {
00368     CppUnit::TextUi::TestRunner runner;
00369     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00370     CppUnit::Outputter* outputter = 
00371       new CppUnit::TextOutputter(&runner.result(), std::cout);
00372     runner.setOutputter(outputter);
00373     bool retcode = runner.run();
00374     return !retcode;
00375 }
00376 #endif // MAIN
00377 #endif // OrganizationProxy_cpp


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