summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Bug_2800_Regression
diff options
context:
space:
mode:
authorJohnny Willemsen <jwillemsen@remedy.nl>2007-02-08 18:01:58 +0000
committerJohnny Willemsen <jwillemsen@remedy.nl>2007-02-08 18:01:58 +0000
commita2ad1e9423192863cc9a4b1df23795c54d3265fd (patch)
treeb6c0f4d296a0dfac2bd0041f207672380a72ceaa /TAO/orbsvcs/tests/Bug_2800_Regression
parentac80b8ff96d0c2a2b8b8fcd89a82b306b97f20c5 (diff)
downloadATCD-a2ad1e9423192863cc9a4b1df23795c54d3265fd.tar.gz
Thu Feb 8 18:00:14 UTC 2007 Johnny Willemsen <jwillemsen@remedy.nl>
Diffstat (limited to 'TAO/orbsvcs/tests/Bug_2800_Regression')
-rw-r--r--TAO/orbsvcs/tests/Bug_2800_Regression/Bug_2800_Regression.mpc33
-rw-r--r--TAO/orbsvcs/tests/Bug_2800_Regression/Hello.cpp25
-rw-r--r--TAO/orbsvcs/tests/Bug_2800_Regression/Hello.h33
-rw-r--r--TAO/orbsvcs/tests/Bug_2800_Regression/NamingTask.cpp86
-rw-r--r--TAO/orbsvcs/tests/Bug_2800_Regression/NamingTask.h26
-rw-r--r--TAO/orbsvcs/tests/Bug_2800_Regression/Test.idl20
-rw-r--r--TAO/orbsvcs/tests/Bug_2800_Regression/client.cpp96
-rw-r--r--TAO/orbsvcs/tests/Bug_2800_Regression/nsmain.cpp164
-rwxr-xr-xTAO/orbsvcs/tests/Bug_2800_Regression/run_test.pl56
9 files changed, 539 insertions, 0 deletions
diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/Bug_2800_Regression.mpc b/TAO/orbsvcs/tests/Bug_2800_Regression/Bug_2800_Regression.mpc
new file mode 100644
index 00000000000..04fcfb3257f
--- /dev/null
+++ b/TAO/orbsvcs/tests/Bug_2800_Regression/Bug_2800_Regression.mpc
@@ -0,0 +1,33 @@
+// -*- MPC -*-
+// $Id$
+
+project(*idl): taoidldefaults {
+ IDL_Files {
+ Test.idl
+ }
+ custom_only = 1
+}
+
+project(*Server): namingexe, naming_serv {
+ after += *idl
+ Source_Files {
+ Hello.cpp
+ NamingTask.cpp
+ nsmain.cpp
+ }
+ Source_Files {
+ TestC.cpp
+ TestS.cpp
+ }
+}
+
+project(*Client): namingexe {
+ after += *idl
+ Source_Files {
+ client.cpp
+ }
+ Source_Files {
+ TestC.cpp
+ }
+}
+
diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/Hello.cpp b/TAO/orbsvcs/tests/Bug_2800_Regression/Hello.cpp
new file mode 100644
index 00000000000..3bb0a772b76
--- /dev/null
+++ b/TAO/orbsvcs/tests/Bug_2800_Regression/Hello.cpp
@@ -0,0 +1,25 @@
+//
+// $Id$
+//
+#include "Hello.h"
+
+ACE_RCSID(Hello, Hello, "$Id$")
+
+Hello::Hello (CORBA::ORB_ptr orb)
+ : orb_ (CORBA::ORB::_duplicate (orb))
+{
+}
+
+char *
+Hello::get_string (void)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ return CORBA::string_dup ("Hello there!");
+}
+
+void
+Hello::shutdown (void)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ this->orb_->shutdown (0);
+}
diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/Hello.h b/TAO/orbsvcs/tests/Bug_2800_Regression/Hello.h
new file mode 100644
index 00000000000..6131e1a3c88
--- /dev/null
+++ b/TAO/orbsvcs/tests/Bug_2800_Regression/Hello.h
@@ -0,0 +1,33 @@
+//
+// $Id$
+//
+
+#ifndef HELLO_H
+#define HELLO_H
+#include /**/ "ace/pre.h"
+
+#include "TestS.h"
+
+/// Implement the Test::Hello interface
+class Hello
+ : public virtual POA_Test::Hello
+{
+public:
+ /// Constructor
+ Hello (CORBA::ORB_ptr orb);
+
+ // = The skeleton methods
+ virtual char * get_string (void)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void shutdown (void)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+private:
+ /// Use an ORB reference to conver strings to objects and shutdown
+ /// the application.
+ CORBA::ORB_var orb_;
+};
+
+#include /**/ "ace/post.h"
+#endif /* HELLO_H */
diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/NamingTask.cpp b/TAO/orbsvcs/tests/Bug_2800_Regression/NamingTask.cpp
new file mode 100644
index 00000000000..a76b3e659db
--- /dev/null
+++ b/TAO/orbsvcs/tests/Bug_2800_Regression/NamingTask.cpp
@@ -0,0 +1,86 @@
+// $Id$
+
+#include "NamingTask.h"
+#include "orbsvcs/Naming/Naming_Server.h"
+#include "ace/OS_NS_unistd.h"
+#include "ace/Argv_Type_Converter.h"
+
+NamingTask::NamingTask (const char* orbname, int argc, char** argv, unsigned short port)
+ : initialized_(false)
+{
+ char** my_argv = new char*[argc + 2];
+ char buf[128];
+ int my_argc = 0;
+ for(; my_argc<argc ;++my_argc)
+ my_argv[my_argc] = argv[my_argc];
+ ACE_OS::sprintf (buf, "iiop://localhost:%d", port);
+ my_argv[my_argc++] = "-ORBEndpoint";
+ my_argv[my_argc++] = buf;
+
+ ACE_Argv_Type_Converter satc (my_argc, my_argv);
+ orb_ = CORBA::ORB_init(satc.get_argc (), satc.get_TCHAR_argv (), orbname);
+}
+
+void NamingTask::waitInit ()
+{
+ // Wait for Naming Service initialized.
+ while (! initialized_) {
+ ACE_OS::sleep(ACE_Time_Value(0, 100 * 1000));
+ }
+}
+
+void NamingTask::end()
+{
+ orb_->shutdown(0);
+ wait();
+}
+
+const char* NamingTask::ior()
+{
+ return ior_.in ();
+}
+
+int NamingTask::svc()
+{
+ try {
+ // Get reference to Root POA
+ CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA");
+ PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
+
+ // Activate POA Manager
+ PortableServer::POAManager_var poaManager = poa->the_POAManager();
+ poaManager->activate();
+
+ // Initialize the naming service
+ // We are not going to look for other naming servers
+ TAO_Naming_Server naming;
+ if (naming.init(orb_.in(),
+ poa.in(),
+ ACE_DEFAULT_MAP_SIZE,
+ 0,
+ 0,
+ 0,
+ TAO_NAMING_BASE_ADDR,
+ 0) == 0)
+ {
+ ACE_DEBUG ((LM_DEBUG, "The Naming Service Task is ready.\n"));
+ ior_ = CORBA::string_dup (naming.naming_service_ior ());
+ initialized_ = true;
+ // Accept requests
+ orb_->run();
+ orb_->destroy();
+ return 0;
+ }
+ else
+ {
+ ACE_ERROR ((LM_ERROR, "Unable to initialize the Naming Service.\n"));
+ }
+ }
+ catch (CORBA::Exception& ex)
+ {
+ ex._tao_print_exception ("NamingTask::svc() CORBA::Exception: ");
+ }
+
+ return -1;
+}
+
diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/NamingTask.h b/TAO/orbsvcs/tests/Bug_2800_Regression/NamingTask.h
new file mode 100644
index 00000000000..f9108a4ba45
--- /dev/null
+++ b/TAO/orbsvcs/tests/Bug_2800_Regression/NamingTask.h
@@ -0,0 +1,26 @@
+// $Id$
+
+#ifndef NAMINGTASK_H
+#define NAMINGTASK_H
+
+#include "tao/CORBA_String.h"
+#include "tao/ORB.h"
+#include "ace/Task.h"
+
+class NamingTask : public ACE_Task<ACE_MT_SYNCH>
+{
+public:
+ NamingTask (const char* orbname, int argc, char** argv, unsigned short port);
+ virtual int svc();
+ void waitInit ();
+ void end();
+
+ const char* ior ();
+
+private:
+ CORBA::ORB_var orb_;
+ bool initialized_;
+ CORBA::String_var ior_;
+};
+
+#endif
diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/Test.idl b/TAO/orbsvcs/tests/Bug_2800_Regression/Test.idl
new file mode 100644
index 00000000000..3c0976e106d
--- /dev/null
+++ b/TAO/orbsvcs/tests/Bug_2800_Regression/Test.idl
@@ -0,0 +1,20 @@
+//
+// $Id$
+//
+
+/// Put the interfaces in a module, to avoid global namespace pollution
+module Test
+{
+ /// A very simple interface
+ interface Hello
+ {
+ /// Return a simple string
+ string get_string ();
+
+ /// A method to shutdown the ORB
+ /**
+ * This method is used to simplify the test shutdown process
+ */
+ oneway void shutdown ();
+ };
+};
diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/client.cpp b/TAO/orbsvcs/tests/Bug_2800_Regression/client.cpp
new file mode 100644
index 00000000000..397f101215c
--- /dev/null
+++ b/TAO/orbsvcs/tests/Bug_2800_Regression/client.cpp
@@ -0,0 +1,96 @@
+// $Id$
+
+#include "TestC.h"
+#include "orbsvcs/CosNamingC.h"
+#include "ace/Get_Opt.h"
+
+ACE_RCSID(Hello, client, "$Id$")
+
+int
+parse_args (int argc, char *argv[])
+{
+ ACE_Get_Opt get_opts (argc, argv, "k:");
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case '?':
+ default:
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "usage: %s "
+ "\n",
+ argv [0]),
+ -1);
+ }
+ // Indicates sucessful parsing of the command line
+ return 0;
+}
+
+int
+main (int argc, char *argv[])
+{
+ try
+ {
+ CORBA::ORB_var orb =
+ CORBA::ORB_init (argc, argv);
+
+ if (parse_args (argc, argv) != 0)
+ return 1;
+
+ CORBA::Object_var tmp =
+ orb->string_to_object("corbaloc:iiop:1.2@localhost:9931/NameService");
+
+ CosNaming::NamingContext_var root =
+ CosNaming::NamingContext::_narrow(tmp.in());
+
+ if (CORBA::is_nil (root.in ()))
+ {
+ ACE_ERROR_RETURN ((LM_DEBUG,
+ "Nil NamingService reference\n"),
+ 1);
+ }
+
+ ACE_DEBUG ((LM_INFO, "**** Narrowed root NamingContext\n"));
+
+ CosNaming::Name name;
+ name.length(2);
+ name[0].id = CORBA::string_dup("example");
+ name[1].id = CORBA::string_dup("Hello");
+
+ tmp = root->resolve (name);
+
+ ACE_DEBUG ((LM_INFO, "**** Resolved #example/Hello\n"));
+
+ Test::Hello_var hello =
+ Test::Hello::_narrow(tmp.in ());
+
+ if (CORBA::is_nil (hello.in ()))
+ {
+ ACE_ERROR_RETURN ((LM_DEBUG,
+ "Nil Test::Hello reference\n"),
+ 1);
+ }
+
+ CORBA::String_var the_string =
+ hello->get_string ();
+
+ ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%s>\n",
+ the_string.in ()));
+
+ hello->shutdown ();
+
+ orb->destroy ();
+ }
+ catch (const CosNaming::NamingContext::CannotProceed&)
+ {
+ ACE_DEBUG ((LM_DEBUG, "Catched correct exception\n"));
+ }
+ catch (const CORBA::Exception& ex)
+ {
+ ex._tao_print_exception ("Exception caught:");
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/nsmain.cpp b/TAO/orbsvcs/tests/Bug_2800_Regression/nsmain.cpp
new file mode 100644
index 00000000000..e0e5f55acf3
--- /dev/null
+++ b/TAO/orbsvcs/tests/Bug_2800_Regression/nsmain.cpp
@@ -0,0 +1,164 @@
+
+#include "NamingTask.h"
+#include "Hello.h"
+#include "orbsvcs/CosNamingC.h"
+#include "ace/OS.h"
+#include "ace/Get_Opt.h"
+
+class TestTask : public ACE_Task_Base
+{
+public:
+ TestTask(int argc, char **argv);
+ virtual int svc();
+
+ int parse_args (int argc, char **argv);
+
+ void end();
+private:
+ NamingTask namingServiceA_;
+ NamingTask namingServiceB_;
+ CORBA::ORB_var orb_;
+ CORBA::Boolean shutdown_ns_;
+};
+
+TestTask::TestTask(int argc, char **argv)
+ : namingServiceA_("NamingORBA", argc, argv, 9931),
+ namingServiceB_("NamingORBB", argc, argv, 9932)
+{
+ orb_ = CORBA::ORB_init(argc, argv, "ServerORB");
+ shutdown_ns_ = false;
+ parse_args(argc, argv);
+}
+
+void TestTask::end()
+{
+ orb_->shutdown(0);
+ wait();
+}
+
+int
+TestTask::parse_args (int argc, char **argv)
+{
+ ACE_Get_Opt get_opts (argc, argv, "s");
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 's':
+ shutdown_ns_ = true;
+ break;
+ }
+ // Indicates sucessful parsing of the command line
+ return 0;
+}
+
+int TestTask::svc()
+{
+
+ try {
+ // Start the Naming Service tasks
+ namingServiceA_.activate();
+ // Wait for the Naming Service initialized.
+ namingServiceA_.waitInit();
+
+ namingServiceB_.activate();
+ // Wait for the Naming Service initialized.
+ namingServiceB_.waitInit();
+
+ FILE *output_file= ACE_OS::fopen ("ns.ior", "w");
+ if (output_file == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Cannot open output file for writing IOR: ns.ior\n"),
+ 1);
+ ACE_OS::fprintf (output_file, "%s", namingServiceA_.ior ());
+ ACE_OS::fclose (output_file);
+
+ // Get reference to Root POA
+ CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA");
+ PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
+
+ // Activate POA Manager
+ PortableServer::POAManager_var mgr = poa->the_POAManager();
+ mgr->activate();
+
+ // Find the Naming Service
+ obj = orb_->string_to_object (namingServiceB_.ior ());
+ CosNaming::NamingContext_var root =
+ CosNaming::NamingContext::_narrow(obj.in());
+
+ if (CORBA::is_nil(root.in())) {
+ ACE_ERROR ((LM_ERROR, "Error, Nil Naming Context reference\n"));
+ return 1;
+ }
+ // Bind the example Naming Context, if necessary
+ CosNaming::NamingContext_var example_nc;
+ CosNaming::Name name;
+ name.length(1);
+ name[0].id = CORBA::string_dup("example");
+ try {
+ obj = root->resolve(name);
+ example_nc =
+ CosNaming::NamingContext::_narrow(obj.in());
+ }
+ catch (CosNaming::NamingContext::NotFound&) {
+ example_nc = root->bind_new_context(name);
+ }
+
+ // Bind the Test object
+ name.length(2);
+ name[1].id = CORBA::string_dup("Hello");
+
+ // Create an object
+ Hello servant(orb_.in ());
+ PortableServer::ObjectId_var oid = poa->activate_object(&servant);
+ obj = poa->id_to_reference(oid.in());
+ root->rebind(name, obj.in());
+
+ ACE_DEBUG ((LM_INFO, "Hello object bound in Naming Service B\n"));
+
+ name.length(1);
+ obj = orb_->string_to_object (namingServiceA_.ior ());
+ root = CosNaming::NamingContext::_narrow(obj.in());
+ root->bind_context (name, example_nc.in ());
+
+ ACE_DEBUG ((LM_INFO, "'example' context of NS B bound in Naming Service A\n"));
+
+ if (shutdown_ns_)
+ {
+ namingServiceB_.end();
+
+ ACE_DEBUG ((LM_INFO, "Naming Service B shut down\n"));
+ }
+
+ // Normally we run the orb and the orb is shutdown by
+ // calling TestTask::end().
+ // Accept requests
+ orb_->run();
+ orb_->destroy();
+
+ // Shutdown the Naming Services.
+ namingServiceA_.end();
+ namingServiceB_.end();
+
+ return 0;
+ }
+ catch (CORBA::Exception& ex)
+ {
+ ex._tao_print_exception ("CORBA exception: ");
+ }
+
+ return -1;
+}
+
+int main(int argc, char* argv[])
+{
+ // Start the Test task
+ TestTask test_(argc, argv);
+ test_.activate();
+
+ // Wait the Test task finish.
+ test_.wait();
+
+ return 0;
+}
diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/run_test.pl b/TAO/orbsvcs/tests/Bug_2800_Regression/run_test.pl
new file mode 100755
index 00000000000..7148d2f8a49
--- /dev/null
+++ b/TAO/orbsvcs/tests/Bug_2800_Regression/run_test.pl
@@ -0,0 +1,56 @@
+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::Run_Test;
+
+$status = 0;
+$debug_level = '0';
+
+foreach $i (@ARGV) {
+ if ($i eq '-debug') {
+ $debug_level = '10';
+ }
+}
+
+$iorfile = PerlACE::LocalFile ("ns.ior");
+unlink $iorfile;
+
+$SV = new PerlACE::Process ("nsmain", "-s -ORBDebuglevel $debug_level");
+$CL = new PerlACE::Process ("client", "");
+
+$server = $SV->Spawn ();
+
+if ($server != 0) {
+ print STDERR "ERROR: server returned $server\n";
+ exit 1;
+}
+
+if (PerlACE::waitforfile_timed ($iorfile,
+ $PerlACE::wait_interval_for_process_creation) == -1) {
+ print STDERR "ERROR: cannot find file <$iorfile>\n";
+ $SV->Kill (); $SV->TimedWait (1);
+ exit 1;
+}
+
+$client = $CL->SpawnWaitKill (300);
+
+if ($client != 0) {
+ print STDERR "ERROR: client returned $client\n";
+ $status = 1;
+}
+
+$server = $SV->WaitKill (10);
+
+if ($server != 0) {
+ print STDERR "ERROR: server returned $server\n";
+ $status = 1;
+}
+
+unlink $iorfile;
+
+exit $status;