diff options
author | Johnny Willemsen <jwillemsen@remedy.nl> | 2018-10-30 09:51:53 +0100 |
---|---|---|
committer | Johnny Willemsen <jwillemsen@remedy.nl> | 2018-10-30 09:51:53 +0100 |
commit | 7d6b33e807e9d75a2d28248d0f69b143a18bddc3 (patch) | |
tree | 69dfcdc5e90a46cc04dab2fe93816687df791cdf | |
parent | e56a460c00e39f00c63b4b1192a68cda35f8893f (diff) | |
download | ATCD-7d6b33e807e9d75a2d28248d0f69b143a18bddc3.tar.gz |
New unit test for bugzilla 4213
-rw-r--r-- | TAO/tests/Bug_4213_Regression/Bug_4213_Regression.mpc | 35 | ||||
-rw-r--r-- | TAO/tests/Bug_4213_Regression/Hello.cpp | 18 | ||||
-rw-r--r-- | TAO/tests/Bug_4213_Regression/Hello.h | 28 | ||||
-rw-r--r-- | TAO/tests/Bug_4213_Regression/Test.idl | 17 | ||||
-rw-r--r-- | TAO/tests/Bug_4213_Regression/client.cpp | 71 | ||||
-rwxr-xr-x | TAO/tests/Bug_4213_Regression/run_test.pl | 84 | ||||
-rw-r--r-- | TAO/tests/Bug_4213_Regression/server.cpp | 113 |
7 files changed, 366 insertions, 0 deletions
diff --git a/TAO/tests/Bug_4213_Regression/Bug_4213_Regression.mpc b/TAO/tests/Bug_4213_Regression/Bug_4213_Regression.mpc new file mode 100644 index 00000000000..370086e5f73 --- /dev/null +++ b/TAO/tests/Bug_4213_Regression/Bug_4213_Regression.mpc @@ -0,0 +1,35 @@ +// -*- MPC -*- +project(*idl): taoidldefaults { + idlflags += -Sp + IDL_Files { + Test.idl + } + custom_only = 1 +} + +project(*Server): strategies, taoserver, iortable { + after += *idl + Source_Files { + Hello.cpp + server.cpp + } + Source_Files { + TestC.cpp + TestS.cpp + } + IDL_Files { + } +} + +project(*Client): strategies, taoclient { + after += *idl + Source_Files { + client.cpp + } + Source_Files { + TestC.cpp + } + IDL_Files { + } +} + diff --git a/TAO/tests/Bug_4213_Regression/Hello.cpp b/TAO/tests/Bug_4213_Regression/Hello.cpp new file mode 100644 index 00000000000..733fe2bfcaf --- /dev/null +++ b/TAO/tests/Bug_4213_Regression/Hello.cpp @@ -0,0 +1,18 @@ +#include "Hello.h" + +Hello::Hello (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) +{ +} + +char * +Hello::get_string (void) +{ + return CORBA::string_dup ("Hello there!"); +} + +void +Hello::shutdown (void) +{ + this->orb_->shutdown (0); +} diff --git a/TAO/tests/Bug_4213_Regression/Hello.h b/TAO/tests/Bug_4213_Regression/Hello.h new file mode 100644 index 00000000000..8b2124d9fe5 --- /dev/null +++ b/TAO/tests/Bug_4213_Regression/Hello.h @@ -0,0 +1,28 @@ + +#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); + + virtual void shutdown (void); + +private: + /// Use an ORB reference to convert strings to objects and shutdown + /// the application. + CORBA::ORB_var orb_; +}; + +#include /**/ "ace/post.h" +#endif /* HELLO_H */ diff --git a/TAO/tests/Bug_4213_Regression/Test.idl b/TAO/tests/Bug_4213_Regression/Test.idl new file mode 100644 index 00000000000..6cd2805ea74 --- /dev/null +++ b/TAO/tests/Bug_4213_Regression/Test.idl @@ -0,0 +1,17 @@ + +/// 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/tests/Bug_4213_Regression/client.cpp b/TAO/tests/Bug_4213_Regression/client.cpp new file mode 100644 index 00000000000..0c84ecddb37 --- /dev/null +++ b/TAO/tests/Bug_4213_Regression/client.cpp @@ -0,0 +1,71 @@ +#include "TestC.h" +#include "ace/Get_Opt.h" +#include "tao/Strategies/advanced_resource.h" + +const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior"); + +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'k': + ior = get_opts.opt_arg (); + break; + + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-k <ior> " + "\n", + argv [0]), + -1); + } + // Indicates successful parsing of the command line + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *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(ior); + + Test::Hello_var hello = Test::Hello::_narrow(tmp.in ()); + + if (CORBA::is_nil (hello.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::Hello reference <%s>\n", + ior), + 1); + } + + CORBA::String_var the_string = hello->get_string (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n", + the_string.in ())); + + hello->shutdown (); + + orb->destroy (); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/Bug_4213_Regression/run_test.pl b/TAO/tests/Bug_4213_Regression/run_test.pl new file mode 100755 index 00000000000..2ab705ae6b3 --- /dev/null +++ b/TAO/tests/Bug_4213_Regression/run_test.pl @@ -0,0 +1,84 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# -*- perl -*- + +use lib "$ENV{ACE_ROOT}/bin"; +use PerlACE::TestTarget; + +$status = 0; +$debug_level = '0'; +$cdebug_level = '0'; +foreach $i (@ARGV) { + if ($i eq '-debug') { + $debug_level = '10'; + } + if ($i eq '-cdebug') { + $cdebug_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 $socket_name = "/tmp/endpoint"; +my $server_iorfile = $server->LocalFile ($iorbase); +my $server_socket = $server->LocalFile ($socket_name); +my $client_iorfile = $client->LocalFile ($iorbase); +my $client_socket = $client->LocalFile ($socket_name); + +$server->DeleteFile($iorbase); +$server->DeleteFile($socket_name); +$client->DeleteFile($iorbase); +$client->DeleteFile($socket_name); + +$SV = $server->CreateProcess ("server", "-ORBdebuglevel $debug_level -o $server_iorfile -ORBEndpoint uiop://$server_socket"); +#$CL = $client->CreateProcess ("client", "-ORBdebuglevel $cdebug_level -k uioploc:///tmp/endpoint|Hello"); +$CL = $client->CreateProcess ("client", "-ORBdebuglevel $cdebug_level -k 'corbaloc:uiop:/tmp/endpoint|Hello'"); +$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); +$server->DeleteFile($socket_name); +$client->DeleteFile($iorbase); +$client->DeleteFile($socket_name); + +exit $status; diff --git a/TAO/tests/Bug_4213_Regression/server.cpp b/TAO/tests/Bug_4213_Regression/server.cpp new file mode 100644 index 00000000000..302f1e898c9 --- /dev/null +++ b/TAO/tests/Bug_4213_Regression/server.cpp @@ -0,0 +1,113 @@ +#include "Hello.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "tao/Strategies/advanced_resource.h" +#include "tao/IORTable/IORTable.h" + +const ACE_TCHAR *ior_output_file = ACE_TEXT ("test.ior"); + +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + ior_output_file = get_opts.opt_arg (); + break; + + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-o <iorfile>" + "\n", + argv [0]), + -1); + } + // Indicates successful parsing of the command line + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ + try + { + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv); + + CORBA::Object_var poa_object = + orb->resolve_initial_references("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + if (CORBA::is_nil (root_poa.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Panic: nil RootPOA\n"), + 1); + + PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); + + if (parse_args (argc, argv) != 0) + return 1; + + Hello *hello_impl = 0; + ACE_NEW_RETURN (hello_impl, + Hello (orb.in ()), + 1); + PortableServer::ServantBase_var owner_transfer(hello_impl); + + PortableServer::ObjectId_var id = + root_poa->activate_object (hello_impl); + + CORBA::Object_var object = root_poa->id_to_reference (id.in ()); + + Test::Hello_var hello = Test::Hello::_narrow (object.in ()); + + CORBA::String_var ior = orb->object_to_string (hello.in ()); + + CORBA::Object_var table_object = orb->resolve_initial_references ("IORTable"); + + IORTable::Table_var adapter = IORTable::Table::_narrow (table_object.in ()); + if (CORBA::is_nil (adapter.in ())) + { + ACE_ERROR ((LM_ERROR, "Nil IORTable\n")); + } + else + { + adapter->bind ("Hello", ior.in ()); + } + + // Output the IOR to the <ior_output_file> + FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: <%s>\n", + ior_output_file), + 1); + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + poa_manager->activate (); + + orb->run (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + + root_poa->destroy (1, 1); + + orb->destroy (); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} |