diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2010-09-10 14:44:16 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2010-09-10 14:44:16 +0000 |
commit | f22ab06d81dd1b633436135ac7c7edd126f69396 (patch) | |
tree | 1e6bf181c0b327f33af942c7bd3c7706e051759f /DAnCE/tests/NameServiceTest | |
parent | b4b85156a0191cf42263e31a336fa0134b63df9d (diff) | |
download | ATCD-f22ab06d81dd1b633436135ac7c7edd126f69396.tar.gz |
Fri Sep 10 14:43:35 UTC 2010 William Otte <wotte@zifnab>
* .:
Moved DAnCE to root of DOC Repository.
Diffstat (limited to 'DAnCE/tests/NameServiceTest')
-rw-r--r-- | DAnCE/tests/NameServiceTest/Dummy.idl | 14 | ||||
-rw-r--r-- | DAnCE/tests/NameServiceTest/DummyImpl.cpp | 14 | ||||
-rw-r--r-- | DAnCE/tests/NameServiceTest/DummyImpl.h | 25 | ||||
-rw-r--r-- | DAnCE/tests/NameServiceTest/NameServiceTest.mpc | 30 | ||||
-rw-r--r-- | DAnCE/tests/NameServiceTest/RegistrationPath.h | 9 | ||||
-rw-r--r-- | DAnCE/tests/NameServiceTest/clt_main.cpp | 85 | ||||
-rwxr-xr-x | DAnCE/tests/NameServiceTest/run_test.pl | 73 | ||||
-rw-r--r-- | DAnCE/tests/NameServiceTest/srv_main.cpp | 72 |
8 files changed, 322 insertions, 0 deletions
diff --git a/DAnCE/tests/NameServiceTest/Dummy.idl b/DAnCE/tests/NameServiceTest/Dummy.idl new file mode 100644 index 00000000000..1f0edee59cd --- /dev/null +++ b/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/DAnCE/tests/NameServiceTest/DummyImpl.cpp b/DAnCE/tests/NameServiceTest/DummyImpl.cpp new file mode 100644 index 00000000000..4fe5dea9b16 --- /dev/null +++ b/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/DAnCE/tests/NameServiceTest/DummyImpl.h b/DAnCE/tests/NameServiceTest/DummyImpl.h new file mode 100644 index 00000000000..7b54d8b1386 --- /dev/null +++ b/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/DAnCE/tests/NameServiceTest/NameServiceTest.mpc b/DAnCE/tests/NameServiceTest/NameServiceTest.mpc new file mode 100644 index 00000000000..64068565ed3 --- /dev/null +++ b/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/DAnCE/tests/NameServiceTest/RegistrationPath.h b/DAnCE/tests/NameServiceTest/RegistrationPath.h new file mode 100644 index 00000000000..4a6ea64c651 --- /dev/null +++ b/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/DAnCE/tests/NameServiceTest/clt_main.cpp b/DAnCE/tests/NameServiceTest/clt_main.cpp new file mode 100644 index 00000000000..02e2aa89ede --- /dev/null +++ b/DAnCE/tests/NameServiceTest/clt_main.cpp @@ -0,0 +1,85 @@ +// $Id$ +#include "ace/String_Base.h" +#include <orbsvcs/CosNamingC.h> +#include "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) ) +// { +// ACE_ERROR ((LM_ERROR, "Failed to resolve object. The test failed.\n")); +// return 1; +// } +// ACE_DEBUG ((LM_DEBUG, "resolve object : ok.\n")); +// +// Dummy_var res_dummy_obj = Dummy::_narrow(res_obj); +// if ( CORBA::is_nil(res_dummy_obj) ) +// { +// ACE_ERROR ((LM_ERROR, "Failed to narrow the resolved object to custom type. The test failed.\n")); +// return 1; +// } +// ACE_DEBUG ((LM_DEBUG, "resolved object -> dummy : ok.\n")); +// +// ACE_DEBUG ((LM_DEBUG, "Dummy object returned : %s.", res_dummy_obj->sayHello())); +// ACE_DEBUG ((LM_DEBUG, "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; + ACE_DEBUG ((LM_DEBUG, "URL : %C\n", url.c_str())); + + CORBA::Object_var obj = orb->string_to_object (url.c_str()); + if (CORBA::is_nil (obj)) + { + ACE_ERROR ((LM_ERROR, "Failed to convert url to object. The test failed.\n")); + return 1; + } + ACE_DEBUG ((LM_DEBUG, "URL -> object : ok.\n")); + + Dummy_var dummy_obj = Dummy::_narrow (obj); + if (CORBA::is_nil (dummy_obj)) + { + ACE_ERROR ((LM_ERROR, "Failed to narrow the object to custom type. The test failed.\n")); + return 1; + } + ACE_DEBUG ((LM_DEBUG, "object -> dummy : ok.\n")); + + ACE_DEBUG ((LM_DEBUG, "Dummy object returned : %C.", dummy_obj->sayHello())); + ACE_DEBUG ((LM_DEBUG, "The test succeeded.")); + return 0; + } + catch (const CORBA::Exception & e) + { + ACE_ERROR ((LM_ERROR, "A CORBA exception \"%C\" (%C) was thrown. The test failed." + , e._name(), e._info().c_str())); + return 1; + } + catch (...) + { + ACE_ERROR ((LM_ERROR, "An exception was thrown. The test failed.")); + return 1; + } +} + diff --git a/DAnCE/tests/NameServiceTest/run_test.pl b/DAnCE/tests/NameServiceTest/run_test.pl new file mode 100755 index 00000000000..719974e5c50 --- /dev/null +++ b/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/DAnCE/tests/NameServiceTest/srv_main.cpp b/DAnCE/tests/NameServiceTest/srv_main.cpp new file mode 100644 index 00000000000..227c6612c9c --- /dev/null +++ b/DAnCE/tests/NameServiceTest/srv_main.cpp @@ -0,0 +1,72 @@ +// $Id$ +#include "ace/OS_NS_stdio.h" +#include <orbsvcs/CosNamingC.h> +#include <orbsvcs/Naming/Naming_Loader.h> +#include "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 (...) + { + ACE_ERROR ((LM_ERROR, "An error has occured.")); + } + return 0; +} + |