]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
PR: some unit tests on Naming service
authorprascle <prascle>
Mon, 7 Nov 2005 18:28:08 +0000 (18:28 +0000)
committerprascle <prascle>
Mon, 7 Nov 2005 18:28:08 +0000 (18:28 +0000)
idl/nstest.idl [new file with mode: 0644]
src/LifeCycleCORBA/Test/Makefile.in
src/NamingService/Test/Makefile.in
src/NamingService/Test/NamingServiceTest.cxx
src/NamingService/Test/NamingServiceTest.hxx
src/UnitTests/Makefile.in

diff --git a/idl/nstest.idl b/idl/nstest.idl
new file mode 100644 (file)
index 0000000..9d36923
--- /dev/null
@@ -0,0 +1,18 @@
+
+#ifndef NSTEST_IDL
+#define NSTEST_IDL
+
+module NSTEST
+{
+  interface echo
+  {
+    long getId();
+  };
+
+  interface aFactory
+  {
+    echo createInstance();
+  };
+};
+
+#endif
\ No newline at end of file
index 50253ddf596b3c6ff6110f9309737636f15e285b..cf8d73628edcc23f969c98f565800be55423777e 100644 (file)
@@ -44,7 +44,7 @@ EXPORT_PYSCRIPTS = TestLifeCycleCORBA.py
 LIB = libLifeCycleCORBATest.la 
 LIB_SRC = LifeCycleCORBATest.cxx
 LIB_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \
-                SALOME_Exception.idl
+                SALOME_Exception.idl nstest.idl
 
 # Executables targets
 
index e95d9f56b050cd7e7977be003eb8430d21cd57cc..36d8bcd179ea8401748b0bde1f50426112577222 100644 (file)
@@ -43,6 +43,9 @@ EXPORT_PYSCRIPTS = TestNamingService.py
 
 LIB = libNamingServiceTest.la 
 LIB_SRC = NamingServiceTest.cxx
+
+LIB_SERVER_IDL = nstest.idl
+
 LIB_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \
                 SALOME_Exception.idl
 
index fcac909c18bb7a4d57ed9b7c0087333c7636f278..dd5dbdf76bac245b6557ebbfde44f562762bc76d 100644 (file)
@@ -7,6 +7,7 @@
 #include <fstream>
 #include <string>
 #include <cstdlib>
+#include <cstdio>
 
 using namespace std;
 
@@ -24,6 +25,48 @@ using namespace std;
 
 #define TRACEFILE "/tmp/traceUnitTest.log"
 
+// ============================================================================
+/*!
+ *
+ */
+// ============================================================================
+
+NSTEST_echo_i::NSTEST_echo_i()
+{
+  _num=-1;
+}
+
+NSTEST_echo_i::NSTEST_echo_i(CORBA::Long num)
+{
+  _num=num;
+}
+
+NSTEST_echo_i::~NSTEST_echo_i()
+{
+}
+
+CORBA::Long NSTEST_echo_i::getId()
+{
+  return _num;
+}
+
+NSTEST_aFactory_i::NSTEST_aFactory_i()
+{
+  _num=0;
+}
+
+NSTEST_aFactory_i::~NSTEST_aFactory_i()
+{
+}
+
+NSTEST::echo_ptr NSTEST_aFactory_i::createInstance()
+{
+  NSTEST_echo_i * anEcho = new NSTEST_echo_i(_num);
+  _num++;
+  NSTEST::echo_var anEchoRef = anEcho->_this();
+  return anEchoRef._retn();
+}
+
 // ============================================================================
 /*!
  * Set Trace mecanism
@@ -70,6 +113,18 @@ NamingServiceTest::setUp()
   // --- Create a SALOME_NamingService instance
 
   _NS.init_orb(_orb) ;
+
+  // --- Create an NSTEST::factory
+
+  CORBA::Object_var obj = _orb->resolve_initial_references("RootPOA");
+  ASSERT(!CORBA::is_nil(obj));
+  _root_poa = PortableServer::POA::_narrow(obj);
+  _pman = _root_poa->the_POAManager();
+  _myFactory  = new NSTEST_aFactory_i();
+  _myFactoryId = _root_poa->activate_object(_myFactory);
+  _factoryRef = _myFactory->_this();
+  _pman->activate();
+  
 }
 
 // ============================================================================
@@ -89,7 +144,7 @@ NamingServiceTest::tearDown()
 
 // ============================================================================
 /*!
- *
+ *  Test default constructor: must be followed by a call to init_orb(ORB)
  */
 // ============================================================================
 
@@ -109,7 +164,7 @@ NamingServiceTest::testConstructorDefault()
 
 // ============================================================================
 /*!
- *
+ *  Test constructor with ORB parameter
  */
 // ============================================================================
 
@@ -125,5 +180,106 @@ NamingServiceTest::testConstructorOrb()
   CPPUNIT_ASSERT(!CORBA::is_nil(rootContext));
 }
 
+// ============================================================================
+/*!
+ * Test Register and resolve of a single CORBA object with absolute pathname,
+ * without subdirectories
+ */
+// ============================================================================
 
+void
+NamingServiceTest::testRegisterResolveAbsNoPath()
+{
+  _NS.Register(_factoryRef,"/nstest_factory");
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+}
+
+// ============================================================================
+/*!
+ * Test Register and resolve of a single CORBA object with absolute pathname,
+ * in a subdirectory
+ */
+// ============================================================================
+
+void
+NamingServiceTest::testRegisterResolveAbsWithPath()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+  NSTEST::echo_var anEchoRef = myFactory->createInstance();
+  _NS.Register(anEchoRef,"/nstest/echo_0");
+  obj = _NS.Resolve("/nstest/echo_0");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::echo_var anEchoRef2 = NSTEST::echo::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef2));
+}
+
+// ============================================================================
+/*!
+ * Test resolve with a name not known
+ */
+// ============================================================================
 
+void
+NamingServiceTest::testResolveBadName()
+{
+  CORBA::Object_var obj = _NS.Resolve("/notRegisteredName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+  obj = _NS.Resolve("/nstest/notRegisteredName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+  obj = _NS.Resolve("/unknownPath/notRegisteredName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+  obj = _NS.Resolve("/anUnknown/ComplicatedPath/notRegisteredName");
+  CPPUNIT_ASSERT(CORBA::is_nil(obj));
+}
+
+// ============================================================================
+/*!
+ * Test register and resolve multiple objects, test resolveFirst
+ */
+// ============================================================================
+
+#define NB_OBJS 10
+
+void
+NamingServiceTest::testResolveFirst()
+{
+  CORBA::Object_var obj = _NS.Resolve("/nstest_factory");
+  CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+  NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
+  CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
+  int ref[NB_OBJS];
+    for (int i=0; i<NB_OBJS; i++)
+      {
+       NSTEST::echo_var anEchoRef = myFactory->createInstance();
+       ref[i] = anEchoRef->getId();
+       string name = "/nstestfirst/echo_";
+       char anum[10];
+       sprintf(anum,"%d",ref[i]);
+       name += anum;
+       _NS.Register(anEchoRef,name.c_str());
+      }
+    for (int i=0; i<NB_OBJS; i++)
+      {
+       string name = "/nstestfirst/echo_";
+       char anum[10];
+       sprintf(anum,"%d",ref[i]);
+       name += anum;
+       CORBA::Object_var obj = _NS.Resolve(name.c_str());
+       CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+       NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
+       CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
+       CPPUNIT_ASSERT(anEchoRef->getId() == ref[i]);
+      }
+    string name = "/nstestfirst/echo";
+    obj = _NS.ResolveFirst(name.c_str());
+    CPPUNIT_ASSERT(!CORBA::is_nil(obj));
+    NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
+    CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRef));
+    CPPUNIT_ASSERT(anEchoRef->getId() == ref[0]);
+}
index d82af640a071a8eedd50d02e69aeb17f92b53ff8..e44ed8ea5276af5ccc6f070e1cd5d2c9470f4182 100644 (file)
@@ -5,12 +5,41 @@
 #include <cppunit/extensions/HelperMacros.h>
 #include "SALOME_NamingService.hxx"
 
+#include <SALOMEconfig.h>
+#include CORBA_SERVER_HEADER(nstest)
+
+class NSTEST_echo_i : public virtual POA_NSTEST::echo,
+                     public virtual PortableServer::RefCountServantBase
+{
+public:
+  NSTEST_echo_i();
+  NSTEST_echo_i(CORBA::Long num);
+  ~NSTEST_echo_i();
+  CORBA::Long getId();
+private:
+  int _num;
+};
+
+class NSTEST_aFactory_i : public virtual POA_NSTEST::aFactory,
+                         public virtual PortableServer::RefCountServantBase
+{
+public:
+  NSTEST_aFactory_i();
+  ~NSTEST_aFactory_i();
+  NSTEST::echo_ptr createInstance();
+private:
+  int _num;
+};
+
 class NamingServiceTest : public CppUnit::TestFixture
 {
   CPPUNIT_TEST_SUITE( NamingServiceTest );
   CPPUNIT_TEST( testConstructorDefault );
   CPPUNIT_TEST( testConstructorOrb );
-//   CPPUNIT_TEST(  );
+  CPPUNIT_TEST( testRegisterResolveAbsNoPath );
+  CPPUNIT_TEST( testRegisterResolveAbsWithPath );
+  CPPUNIT_TEST( testResolveBadName );
+  CPPUNIT_TEST( testResolveFirst );
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -20,11 +49,20 @@ public:
 
   void testConstructorDefault();
   void testConstructorOrb();
-//   void testFindOrLoad_Component_();
+  void testRegisterResolveAbsNoPath();
+  void testRegisterResolveAbsWithPath();
+  void testResolveBadName();
+  void testResolveFirst();
 
 protected:
   CORBA::ORB_var _orb;
   SALOME_NamingService _NS;
+
+  PortableServer::POA_var _root_poa;
+  PortableServer::POAManager_var _pman;
+  PortableServer::ObjectId_var _myFactoryId;
+  NSTEST_aFactory_i * _myFactory;
+  CORBA::Object_var _factoryRef;
 };
 
 #endif
index bdc46c93ebdaf353082b7440b30dbcb37056658f..f7651111f0b65b2bb9d7d2c5eb01a9c6f1f6cf28 100644 (file)
@@ -48,7 +48,7 @@ LIB_SRC =
 BIN = UnitTests
 BIN_SRC = 
 BIN_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \
-                SALOME_Exception.idl
+                SALOME_Exception.idl nstest.idl
 
 CXXFLAGS += @CPPUNIT_INCLUDES@
 CPPFLAGS += @CPPUNIT_INCLUDES@