diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:21 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:21 +0000 |
commit | 3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c (patch) | |
tree | 197c810e5f5bce17b1233a7cb8d7b50c0bcd25e2 /TAO/tests/Abstract_Interface | |
parent | 6b846cf03c0bcbd8c276cb0af61a181e5f98eaae (diff) | |
download | ATCD-3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c.tar.gz |
Repo restructuring
Diffstat (limited to 'TAO/tests/Abstract_Interface')
-rw-r--r-- | TAO/tests/Abstract_Interface/.cvsignore | 2 | ||||
-rw-r--r-- | TAO/tests/Abstract_Interface/Abstract_Interface.mpc | 41 | ||||
-rw-r--r-- | TAO/tests/Abstract_Interface/README | 49 | ||||
-rw-r--r-- | TAO/tests/Abstract_Interface/client.cpp | 340 | ||||
-rwxr-xr-x | TAO/tests/Abstract_Interface/run_test.pl | 54 | ||||
-rw-r--r-- | TAO/tests/Abstract_Interface/server.cpp | 171 | ||||
-rw-r--r-- | TAO/tests/Abstract_Interface/test.idl | 42 | ||||
-rw-r--r-- | TAO/tests/Abstract_Interface/test_i.cpp | 106 | ||||
-rw-r--r-- | TAO/tests/Abstract_Interface/test_i.h | 40 |
9 files changed, 845 insertions, 0 deletions
diff --git a/TAO/tests/Abstract_Interface/.cvsignore b/TAO/tests/Abstract_Interface/.cvsignore new file mode 100644 index 00000000000..f2ad85300eb --- /dev/null +++ b/TAO/tests/Abstract_Interface/.cvsignore @@ -0,0 +1,2 @@ +client +server diff --git a/TAO/tests/Abstract_Interface/Abstract_Interface.mpc b/TAO/tests/Abstract_Interface/Abstract_Interface.mpc new file mode 100644 index 00000000000..cc0059d58c7 --- /dev/null +++ b/TAO/tests/Abstract_Interface/Abstract_Interface.mpc @@ -0,0 +1,41 @@ +// -*- MPC -*- +// $Id$ + +project(*client) : taoclient, valuetype { + idlflags += -Sc + + IDL_Files { + test.idl + } + + Source_Files { + client.cpp + testC.cpp + } + + Header_Files { + testC.h + } +} + +project(*server) : taoserver, valuetype { + after += *client + idlflags += -Sc + + IDL_Files { + test.idl + } + + Source_Files { + server.cpp + test_i.cpp + testC.cpp + testS.cpp + } + + Header_Files { + test_i.h + testC.h + testS.h + } +} diff --git a/TAO/tests/Abstract_Interface/README b/TAO/tests/Abstract_Interface/README new file mode 100644 index 00000000000..f4607cafe2a --- /dev/null +++ b/TAO/tests/Abstract_Interface/README @@ -0,0 +1,49 @@ +# $Id$ + +Description: + +This code contains some simple tests of abstract interfaces. + +Note: + +The test for passing state with a valuetype is based on the code +in TAO/tests/OBV/Forward. A simple valuetype tree is constructed +by defining valuetypes that can contain other valuetypes as a root +or as left and right branches. All nodes also contain a string name. +The tree is constructed on the server side and the root is passed back to the +client in an OUT argument as an abstract interface. The valuetype +is extracted, and the contents of the tree are displayed. + +The other two tests are for operations of an interface passed as an +abstract interface. A derived interface is passed to the client in +an OUT argument as an abstract interface which is the parent of the +derived interface's base class. The base class operation is called +directly on the abstract interface by the client. Then the interface +itself is extracted and cast to the derived type. Finally, both the +base class and the derived class operations are called by the client. + +In the final test, an operation called on the abstract interface +is made to throw a user exception deliberately to test exception +handling. + +Usage: + +The server will put the passer object's IOR into a file with a default +name known to the client. However, the filename may be changed with: + +$ server -o <filename> + +in which case the client should be run as follows: + +$ client -k file://<filename> + +Other client command line options: + +-d Enable test output for debugging +-s Test the passing of state only +-o Test operations only +-e Test exception handling only + +The last three options are mutually exclusive and will override +any previous test selection options. The default behavior is to run +all three tests.
\ No newline at end of file diff --git a/TAO/tests/Abstract_Interface/client.cpp b/TAO/tests/Abstract_Interface/client.cpp new file mode 100644 index 00000000000..0a26fb84775 --- /dev/null +++ b/TAO/tests/Abstract_Interface/client.cpp @@ -0,0 +1,340 @@ +// $Id$ + +#include "testC.h" +#include "ace/Get_Opt.h" + +ACE_RCSID (Abstract_Interface, + client, + "$Id$") + +const char *ior_input_file = "file://test.ior"; +int debug = 0; + +enum test_select +{ + TEST_STATE, + TEST_OPERATION, + TEST_EXCEPTION, + TEST_ALL +}; + +test_select which_test = TEST_ALL; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "k:dsoe"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'k': + ior_input_file = get_opts.optarg; + break; + case 'd': + debug = 1; + break; + case 's': + which_test = TEST_STATE; + break; + case 'o': + which_test = TEST_OPERATION; + break; + case 'e': + which_test = TEST_EXCEPTION; + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-k <iorfile>", + argv [0]), + -1); + } + + // Indicates sucessful parsing of the command line + return 0; +} + +void +dump_node (BaseNode* bn, + int indent) +{ + if (bn == 0) + { + return; + } + + // This is ugly I know + int i = indent; + for (; i != 0; --i) ACE_DEBUG ((LM_DEBUG, " ")); + + StringNode* sn = StringNode::_downcast (bn); + + if (debug) + { + if (sn != 0) + { + ACE_DEBUG ((LM_DEBUG, "%x <StringNode> %s\n", + bn, + sn->name ())); + } + else + { + ACE_DEBUG ((LM_DEBUG, + "%x <BaseNode> \n", + bn)); + } + } + + dump_node (bn->left (), + indent + 1); + dump_node (bn->right (), + indent + 1); +} + +void +dump_tree (TreeController *tc) +{ + if (debug) + { + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) start tree dump <%x>\n", + tc)); + } + + dump_node (tc->root (), + 1); + + if (debug) + { + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) end tree dump <%x>\n", + tc)); + } +} + +void +test_state (base_ptr abs) +{ + CORBA::ValueBase_var vbase = abs->_to_value (); + TreeController *tc = TreeController::_downcast (vbase.in ()); + dump_tree (tc); +} + +void +test_operation (base_ptr abs + ACE_ENV_ARG_DECL) +{ + CORBA::String_var retval = abs->base_op ("base_op" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + if (debug) + { + ACE_DEBUG ((LM_DEBUG, + "%s\n", + retval.in ())); + } + + CORBA::Object_var obj = abs->_to_object (); + + foo_var concrete = foo::_narrow (obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + retval = concrete->foo_op ("foo_op" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + if (debug) + { + ACE_DEBUG ((LM_DEBUG, + "%s\n", + retval.in ())); + } + + retval = concrete->base_op ("base_op" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + if (debug) + { + ACE_DEBUG ((LM_DEBUG, + "%s\n", + retval.in ())); + } +} + +void +test_exception (base_ptr abs + ACE_ENV_ARG_DECL) +{ + CORBA::String_var retval = abs->base_op ("bad_name" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + if (debug) + { + ACE_DEBUG ((LM_DEBUG, + "%s\n", + retval.in ())); + } +} + +int +main (int argc, char *argv[]) +{ + CORBA::String_var retval; + + ACE_TRY_NEW_ENV + { + CORBA::ORB_var orb = CORBA::ORB_init (argc, + argv, + "" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (parse_args (argc, argv) != 0) + { + return 1; + } + + CORBA::Object_var obj = + orb->string_to_object (ior_input_file + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (obj.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR, + "string_to_object failed.\n"), + -1); + } + + passer_var objref = passer::_narrow (obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (objref.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR, + "_narrow failed.\n"), + -1); + } + + base_var package = base::_nil (); + + if (which_test == TEST_STATE || which_test == TEST_ALL) + { + // Create and register factory for BaseNode. + BaseNode_init *bn_factory = 0; + ACE_NEW_RETURN (bn_factory, + BaseNode_init, + 1); + + orb->register_value_factory (bn_factory->tao_repository_id (), + bn_factory + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + bn_factory->_remove_ref (); // release ownership + + // Create and register factory for TreeController. + TreeController_init *tc_factory = 0; + ACE_NEW_RETURN (tc_factory, + TreeController_init, + 1); + + orb->register_value_factory (tc_factory->tao_repository_id (), + tc_factory + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + tc_factory->_remove_ref (); // release ownership + + // Create and register factory for StringNode. + StringNode_init *sn_factory = 0; + ACE_NEW_RETURN (sn_factory, + StringNode_init, + 1); + + orb->register_value_factory (sn_factory->tao_repository_id (), + sn_factory + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + sn_factory->_remove_ref (); // release ownership + + objref->pass_state (package.out () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (package.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR, + "pass_state() returned null OUT arg\n"), + -1); + } + + test_state (package.in ()); + } + + if (which_test != TEST_STATE) + { + objref->pass_ops (package.out () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (package.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR, + "pass_ops() returned null OUT arg\n"), + -1); + } + } + + if (which_test == TEST_OPERATION || which_test == TEST_ALL) + { + test_operation (package.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + } + + if (which_test == TEST_EXCEPTION || which_test == TEST_ALL) + { + which_test = TEST_EXCEPTION; + test_exception (package.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + } + + orb->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCH (BadInput, ex) + { + if (which_test != TEST_EXCEPTION) + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Client: exception caught - "); + + return 1; + } + + if (debug) + { + ACE_DEBUG ((LM_DEBUG, + "%s\n", + ex.message.in ())); + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Client: exception caught - "); + + return 1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/tests/Abstract_Interface/run_test.pl b/TAO/tests/Abstract_Interface/run_test.pl new file mode 100755 index 00000000000..2c44e9a4c2f --- /dev/null +++ b/TAO/tests/Abstract_Interface/run_test.pl @@ -0,0 +1,54 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +use lib '../../../bin'; +use PerlACE::Run_Test; + +$debug = ""; +$which_test = ""; + +foreach $i (@ARGV) { + if ($i eq "-d") { + $debug = $i; + } + else { + $which_test = $i; + } +} + +$iorfile = PerlACE::LocalFile ("test.ior"); + +unlink $iorfile; + +$SV = new PerlACE::Process ("server", + "-ORBDottedDecimalAddresses 1 " + . " -o $iorfile"); + +$SV->Spawn (); + +if (PerlACE::waitforfile_timed ($iorfile, 15) == -1) { + print STDERR "ERROR: cannot find file <$iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} + +$CL = new PerlACE::Process ("client", + " -k file://$iorfile " + . " $debug " + . " $which_test"); + +$client = $CL->SpawnWaitKill (20); +$server = $SV->WaitKill (20); + +unlink $iorfile; + +if ($server != 0 || $client != 0) { + exit 1; +} + +exit 0; + diff --git a/TAO/tests/Abstract_Interface/server.cpp b/TAO/tests/Abstract_Interface/server.cpp new file mode 100644 index 00000000000..6a3c9034587 --- /dev/null +++ b/TAO/tests/Abstract_Interface/server.cpp @@ -0,0 +1,171 @@ +// $Id$ + +#include "test_i.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" + +ACE_RCSID (Abstract_Interface, + server, + "$Id$") + +const char *ior_output_file = "test.ior"; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "o:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + ior_output_file = get_opts.optarg; + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-o <iorfile>" + "\n", + argv [0]), + -1); + } + + // Indicates sucessful parsing of the command line + return 0; +} + +int +main (int argc, char *argv[]) +{ + ACE_TRY_NEW_ENV + { + CORBA::ORB_var orb = CORBA::ORB_init (argc, + argv, + "" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Create and register factory for BaseNode. + BaseNode_init *bn_factory = 0; + ACE_NEW_RETURN (bn_factory, + BaseNode_init, + 1); + + orb->register_value_factory (bn_factory->tao_repository_id (), + bn_factory + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + bn_factory->_remove_ref (); // release ownership + + // Create and register factory for TreeController. + TreeController_init *tc_factory = 0; + ACE_NEW_RETURN (tc_factory, + TreeController_init, + 1); + + orb->register_value_factory (tc_factory->tao_repository_id (), + tc_factory + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + tc_factory->_remove_ref (); // release ownership + + // Create and register factory for StringNode. + StringNode_init *sn_factory = 0; + ACE_NEW_RETURN (sn_factory, + StringNode_init, + 1); + + orb->register_value_factory (sn_factory->tao_repository_id (), + sn_factory + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + sn_factory->_remove_ref (); // release ownership + + CORBA::Object_var poa_object = + orb->resolve_initial_references ("RootPOA" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (poa_object.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Unable to initialize the POA.\n"), + 1); + } + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (parse_args (argc, argv) != 0) + { + return 1; + } + + passer_i servant; + passer_var server = + servant._this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::String_var ior = + orb->object_to_string (server.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_DEBUG ((LM_DEBUG, + "Activated as <%s>\n", + ior.in ())); + + // If the ior_output_file exists, output the ior to it + if (ior_output_file != 0) + { + FILE *output_file = ACE_OS::fopen (ior_output_file, "w"); + + if (output_file == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "Can't open output file for writing IOR: %s", + ior_output_file), + 1); + } + + ACE_OS::fprintf (output_file, + "%s", + ior.in ()); + ACE_OS::fclose (output_file); + } + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_Time_Value tv (10); + orb->run (tv + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Destroy the POA, waiting until the destruction terminates + root_poa->destroy (1, + 1 + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + orb->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Server: exception caught - "); + return 1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/tests/Abstract_Interface/test.idl b/TAO/tests/Abstract_Interface/test.idl new file mode 100644 index 00000000000..0b7bf4f636f --- /dev/null +++ b/TAO/tests/Abstract_Interface/test.idl @@ -0,0 +1,42 @@ +// $Id$ + +exception BadInput +{ + string message; +}; + +abstract interface base +{ + string base_op (in string inarg) + raises (BadInput); +}; + +interface foo : base +{ + string foo_op (in string inarg) + raises (BadInput); +}; + +interface passer +{ + void pass_ops (out base outarg); + void pass_state (out base outarg); +}; + +valuetype BaseNode +{ + public BaseNode left; + public BaseNode right; +}; + +valuetype StringNode : BaseNode +{ + public string name; +}; + +valuetype TreeController supports base +{ + public BaseNode root; +}; + + diff --git a/TAO/tests/Abstract_Interface/test_i.cpp b/TAO/tests/Abstract_Interface/test_i.cpp new file mode 100644 index 00000000000..a3e9072788b --- /dev/null +++ b/TAO/tests/Abstract_Interface/test_i.cpp @@ -0,0 +1,106 @@ +// $Id$ + +#include "test_i.h" +#include "ace/OS_NS_string.h" + + +ACE_RCSID (Abstract_Interface, + test_i, + "$Id$") + + +char * +foo_i::foo_op (const char * inarg + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC (( + CORBA::SystemException, + BadInput + )) +{ + CORBA::String_var retval = CORBA::string_dup ("bad"); + + if (ACE_OS::strcmp (inarg, "foo_op") == 0) + { + retval = CORBA::string_dup ("good"); + } + else + { + ACE_THROW_RETURN (BadInput ("expected \"foo_op\"\n"), + retval._retn ()); + } + + return retval._retn (); +} + +char * +foo_i::base_op (const char * inarg + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC (( + CORBA::SystemException, + BadInput + )) +{ + CORBA::String_var retval = CORBA::string_dup ("bad"); + + if (ACE_OS::strcmp (inarg, "base_op") == 0) + { + retval = CORBA::string_dup ("good"); + } + else + { + ACE_THROW_RETURN (BadInput ("expected \"base_op\"\n"), + retval._retn ()); + } + + return retval._retn (); +} + +void +passer_i::pass_ops (base_out outarg + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC (( + CORBA::SystemException + )) +{ + foo_i *servant = 0; + ACE_NEW (servant, + foo_i); + PortableServer::ServantBase_var safety (servant); + outarg = servant->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; +} + +void +passer_i::pass_state (base_out outarg + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC (( + CORBA::SystemException + )) +{ + TreeController_var tc; + ACE_NEW (tc.inout (), + OBV_TreeController); + + // Create the root node. + StringNode_var sn; + ACE_NEW (sn.inout (), + OBV_StringNode); + sn->name ((const char *) "RootNode"); + tc->root (sn.in ()); + + // Create the left leaf. + StringNode_var l_dummy; + ACE_NEW (l_dummy.inout (), + OBV_StringNode); + l_dummy->name ((const char *) "LeftNode"); + sn->left (l_dummy.in ()); + + // Create the right leaf. + StringNode_var r_dummy; + ACE_NEW (r_dummy.inout (), + OBV_StringNode); + r_dummy->name ((const char *) "RightNode"); + sn->right (r_dummy.in ()); + + outarg = tc._retn (); +} diff --git a/TAO/tests/Abstract_Interface/test_i.h b/TAO/tests/Abstract_Interface/test_i.h new file mode 100644 index 00000000000..b9af23803aa --- /dev/null +++ b/TAO/tests/Abstract_Interface/test_i.h @@ -0,0 +1,40 @@ +// $Id$ + +#ifndef TAO_TEST_I_H +#define TAO_TEST_I_H + +#include "testS.h" + +class foo_i : public virtual POA_foo +{ + virtual char * foo_op (const char * inarg + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC (( + CORBA::SystemException, + BadInput + )); + + virtual char * base_op (const char * inarg + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC (( + CORBA::SystemException, + BadInput + )); +}; + +class passer_i : public virtual POA_passer +{ + virtual void pass_ops (base_out outarg + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC (( + CORBA::SystemException + )); + + virtual void pass_state (base_out outarg + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC (( + CORBA::SystemException + )); +}; + +#endif /* TAO_TEST_I_H */ |