diff options
Diffstat (limited to 'modules/CIAO/DAnCE/tests/NameServiceTest')
8 files changed, 322 insertions, 0 deletions
diff --git a/modules/CIAO/DAnCE/tests/NameServiceTest/Dummy.idl b/modules/CIAO/DAnCE/tests/NameServiceTest/Dummy.idl new file mode 100644 index 00000000000..1f0edee59cd --- /dev/null +++ b/modules/CIAO/DAnCE/tests/NameServiceTest/Dummy.idl @@ -0,0 +1,14 @@ +// $Id$ + +#ifndef DUMMY_IDL +#define DUMMY_IDL + +module NameServiceTest +{ + interface Dummy { + string sayHello(); + }; +}; + +#endif /* DUMMY_IDL */ + diff --git a/modules/CIAO/DAnCE/tests/NameServiceTest/DummyImpl.cpp b/modules/CIAO/DAnCE/tests/NameServiceTest/DummyImpl.cpp new file mode 100644 index 00000000000..4fe5dea9b16 --- /dev/null +++ b/modules/CIAO/DAnCE/tests/NameServiceTest/DummyImpl.cpp @@ -0,0 +1,14 @@ +// $Id$ +#include "DummyImpl.h" + +namespace NameServiceTest + { + + char * DummyImpl::sayHello ( + ) + { + return CORBA::string_dup (this->helloSentence); + } + + } // namespace ObjectLocatorTest + diff --git a/modules/CIAO/DAnCE/tests/NameServiceTest/DummyImpl.h b/modules/CIAO/DAnCE/tests/NameServiceTest/DummyImpl.h new file mode 100644 index 00000000000..7b54d8b1386 --- /dev/null +++ b/modules/CIAO/DAnCE/tests/NameServiceTest/DummyImpl.h @@ -0,0 +1,25 @@ +// $Id$ +#ifndef DUMMYIMPL_H_ +#define DUMMYIMPL_H_ + +#include "DummyS.h" + +namespace NameServiceTest + { + + class DummyImpl + : public virtual POA_NameServiceTest::Dummy + { + public: + DummyImpl() : helloSentence ("A dummy hello sentence.") {}; + + virtual char * sayHello ( + ); + + private: + const char * helloSentence; + }; + + } // namespace POA_ObjectLocatorTest + +#endif /*DUMMYIMPL_H_*/ diff --git a/modules/CIAO/DAnCE/tests/NameServiceTest/NameServiceTest.mpc b/modules/CIAO/DAnCE/tests/NameServiceTest/NameServiceTest.mpc new file mode 100644 index 00000000000..64068565ed3 --- /dev/null +++ b/modules/CIAO/DAnCE/tests/NameServiceTest/NameServiceTest.mpc @@ -0,0 +1,30 @@ +// $Id$ + +project(*idl): ciaoidldefaults { + IDL_Files { + Dummy.idl + } + custom_only = 1 +} + +project (*NameServiceTestServer): dance, taoserver, iortable, naming_serv, dance_logger { + after += *idl + IDL_Files { + } + Source_Files { + srv_main.cpp + DummyC.cpp + DummyS.cpp + DummyImpl.cpp + } +} + +project (NameServiceTestClient): dance, taoclient, naming, dance_logger { + after += *idl + IDL_Files { + } + Source_Files { + clt_main.cpp + DummyC.cpp + } +} diff --git a/modules/CIAO/DAnCE/tests/NameServiceTest/RegistrationPath.h b/modules/CIAO/DAnCE/tests/NameServiceTest/RegistrationPath.h new file mode 100644 index 00000000000..4a6ea64c651 --- /dev/null +++ b/modules/CIAO/DAnCE/tests/NameServiceTest/RegistrationPath.h @@ -0,0 +1,9 @@ +// $Id$ +#ifndef REGISTRATIONPATH_H_ +#define REGISTRATIONPATH_H_ + +const char * app_name = "app1"; +const char * inst_name = "inst1"; +const char * port_name = "port1"; + +#endif /*REGISTRATIONPATH_H_*/ diff --git a/modules/CIAO/DAnCE/tests/NameServiceTest/clt_main.cpp b/modules/CIAO/DAnCE/tests/NameServiceTest/clt_main.cpp new file mode 100644 index 00000000000..fdccfc5b337 --- /dev/null +++ b/modules/CIAO/DAnCE/tests/NameServiceTest/clt_main.cpp @@ -0,0 +1,85 @@ +// $Id$ +#include "ace/String_Base.h" +#include <orbsvcs/orbsvcs/CosNamingC.h> +#include "DAnCE/Logger/Log_Macros.h" +#include "RegistrationPath.h" +#include "DummyC.h" + +using namespace NameServiceTest; + + +int ACE_TMAIN (int argc, ACE_TCHAR * argv[]) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); + + CORBA::Object_var naming_obj = orb->resolve_initial_references ("NameService"); +// CosNaming::NamingContext_var naming = CosNaming::NamingContext::_narrow(naming_obj.in()); +// CosNaming::Name name(1); +// +// name.length(1); +// +// name[0].id = CORBA::string_dup("Dummy"); +// name[0].kind = CORBA::string_dup(""); +// +// CORBA::Object_ptr res_obj = naming->resolve(name); +// if ( CORBA::is_nil(res_obj) ) +// { +// DANCE_ERROR((LM_ERROR, "[%M] Failed to resolve object. The test failed.\n")); +// return 1; +// } +// DANCE_DEBUG((LM_DEBUG, "[%M] resolve object : ok.\n")); +// +// Dummy_var res_dummy_obj = Dummy::_narrow(res_obj); +// if ( CORBA::is_nil(res_dummy_obj) ) +// { +// DANCE_ERROR((LM_ERROR, "[%M] Failed to narrow the resolved object to custom type. The test failed.\n")); +// return 1; +// } +// DANCE_DEBUG((LM_DEBUG, "[%M] resolved object -> dummy : ok.\n")); +// +// DANCE_DEBUG((LM_DEBUG, "[%M] Dummy object returned : %s.", res_dummy_obj->sayHello())); +// DANCE_DEBUG((LM_DEBUG, "[%M] The test succeeded.")); + //glasgow.headquarters.eclipsesp.com:12345 + ACE_CString url = "corbaname:rir:#app1.DeploymentPlan/Dummy"; +// url += app_name; +// url += "/"; +// url += inst_name; +// url += "/"; +// url += port_name; + DANCE_DEBUG((LM_DEBUG, "[%M] URL : %s\n", url.c_str())); + + CORBA::Object_var obj = orb->string_to_object (url.c_str()); + if (CORBA::is_nil (obj)) + { + DANCE_ERROR((LM_ERROR, "[%M] Failed to convert url to object. The test failed.\n")); + return 1; + } + DANCE_DEBUG((LM_DEBUG, "[%M] URL -> object : ok.\n")); + + Dummy_var dummy_obj = Dummy::_narrow (obj); + if (CORBA::is_nil (dummy_obj)) + { + DANCE_ERROR((LM_ERROR, "[%M] Failed to narrow the object to custom type. The test failed.\n")); + return 1; + } + DANCE_DEBUG((LM_DEBUG, "[%M] object -> dummy : ok.\n")); + + DANCE_DEBUG((LM_DEBUG, "[%M] Dummy object returned : %C.", dummy_obj->sayHello())); + DANCE_DEBUG((LM_DEBUG, "[%M] The test succeeded.")); + return 0; + } + catch (const CORBA::Exception & e) + { + DANCE_ERROR((LM_ERROR, "[%M] A CORBA exception \"%C\" (%C) was thrown. The test failed." + , e._name(), e._info().c_str())); + return 1; + } + catch (...) + { + DANCE_ERROR((LM_ERROR, "[%M] An exception was thrown. The test failed.")); + return 1; + } +} + diff --git a/modules/CIAO/DAnCE/tests/NameServiceTest/run_test.pl b/modules/CIAO/DAnCE/tests/NameServiceTest/run_test.pl new file mode 100755 index 00000000000..719974e5c50 --- /dev/null +++ b/modules/CIAO/DAnCE/tests/NameServiceTest/run_test.pl @@ -0,0 +1,73 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +use lib "$ENV{ACE_ROOT}/bin"; +use PerlACE::TestTarget; + +$status = 0; +$debug_level = '0'; + +foreach $i (@ARGV) { + if ($i eq '-debug') { + $debug_level = '10'; + } +} + +my $server = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n"; +my $client = PerlACE::TestTarget::create_target (2) || die "Create target 2 failed\n"; + +my $iorbase = "server.ior"; +my $server_iorfile = $server->LocalFile ($iorbase); +my $client_iorfile = $client->LocalFile ($iorbase); +$server->DeleteFile($iorbase); +$client->DeleteFile($iorbase); + +$SV = $server->CreateProcess ("server", "-ORBdebuglevel $debug_level -o $server_iorfile"); +$CL = $client->CreateProcess ("client", "-k file://$client_iorfile"); +$server_status = $SV->Spawn (); + +if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + exit 1; +} + +if ($server->WaitForFileTimed ($iorbase, + $server->ProcessStartWaitInterval()) == -1) { + print STDERR "ERROR: cannot find file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} + +if ($server->GetFile ($iorbase) == -1) { + print STDERR "ERROR: cannot retrieve file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} +if ($client->PutFile ($iorbase) == -1) { + print STDERR "ERROR: cannot set file <$client_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} + +$client_status = $CL->SpawnWaitKill ($client->ProcessStartWaitInterval()); + +if ($client_status != 0) { + print STDERR "ERROR: client returned $client_status\n"; + $status = 1; +} + +$server_status = $SV->WaitKill ($server->ProcessStopWaitInterval()); + +if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + $status = 1; +} + +$server->DeleteFile($iorbase); +$client->DeleteFile($iorbase); + +exit $status; diff --git a/modules/CIAO/DAnCE/tests/NameServiceTest/srv_main.cpp b/modules/CIAO/DAnCE/tests/NameServiceTest/srv_main.cpp new file mode 100644 index 00000000000..46531143c85 --- /dev/null +++ b/modules/CIAO/DAnCE/tests/NameServiceTest/srv_main.cpp @@ -0,0 +1,72 @@ +// $Id$ +#include "ace/OS_NS_stdio.h" +#include <orbsvcs/orbsvcs/CosNamingC.h> +#include <orbsvcs/orbsvcs/Naming/Naming_Loader.h> +#include "DAnCE/Logger/Log_Macros.h" + +#include "DummyC.h" +#include "DummyImpl.h" +#include "RegistrationPath.h" + +using namespace NameServiceTest; + +int ACE_TMAIN (int argc, ACE_TCHAR * argv[]) +{ + try + { + int argcm = argc + 2; + ACE_TCHAR ** argvm = new ACE_TCHAR* [argcm+1]; + for (int i = 0; i < argc; ++i) + { + argvm[i] = argv[i]; + } + ACE_TCHAR buf1[32]; + ACE_OS::sprintf (buf1, ACE_TEXT("-ORBListenEndpoints")); + argvm[argcm-2] = buf1; + ACE_TCHAR buf2[32]; + ACE_OS::sprintf (buf2, ACE_TEXT("iiop://:12345")); + argvm[argcm-1] = buf2; + argvm[argcm] = 0; + + CORBA::ORB_var orb = CORBA::ORB_init (argcm, argvm); + + CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); + PortableServer::POA_var root_poa = PortableServer::POA::_narrow (obj.in ()); + + PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); + poa_manager->activate(); + + DummyImpl servant; + + PortableServer::ObjectId_var id = root_poa->activate_object (&servant); + + Dummy_var dummy_obj = Dummy::_narrow (root_poa->id_to_reference (id));//servant._this(); + + TAO_Naming_Loader loader; + + CORBA::Object_var obj_tmp = loader.create_object (orb.in(), argcm, argvm); + CORBA::Object_var naming_obj = orb->resolve_initial_references ("NameService"); + CosNaming::NamingContext_var naming = CosNaming::NamingContext::_narrow (naming_obj.in()); + + CosNaming::Name name (1); + + name.length (1); + + name[0].id = CORBA::string_dup (app_name); + name[0].kind = CORBA::string_dup ("DeploymentPlan"); + + CosNaming::NamingContext_var naming_app = naming->bind_new_context (name); + + name[0].id = CORBA::string_dup ("Dummy"); + name[0].kind = CORBA::string_dup (""); + naming_app->bind (name, dummy_obj.in()); + + orb->run(); + } + catch (...) + { + DANCE_ERROR((LM_ERROR, "[%M] An error has occured.")); + } + return 0; +} + |