#include <fstream>
#include <string>
#include <cstdlib>
+#include <cstdio>
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
// --- 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();
+
}
// ============================================================================
// ============================================================================
/*!
- *
+ * Test default constructor: must be followed by a call to init_orb(ORB)
*/
// ============================================================================
// ============================================================================
/*!
- *
+ * Test constructor with ORB parameter
*/
// ============================================================================
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]);
+}
#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:
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