summaryrefslogtreecommitdiff
path: root/TAO/tests
diff options
context:
space:
mode:
authorAngelo Corsaro <angelo@icorsaro.net>2000-08-28 22:40:51 +0000
committerAngelo Corsaro <angelo@icorsaro.net>2000-08-28 22:40:51 +0000
commit201d97463e6508407f06f32f684b351ea89e4652 (patch)
tree7036596e524e155bf59e27410f942af67cea9979 /TAO/tests
parentc687f69e2a649974fa6cefe9ea11bdb32cd41d86 (diff)
downloadATCD-201d97463e6508407f06f32f684b351ea89e4652.tar.gz
ChangeLogTag: Mon Aug 28 17:28:45 2000 Angelo Corsaro <corsaro@cs.wustl.edu>
Diffstat (limited to 'TAO/tests')
-rw-r--r--TAO/tests/Exposed_Policies/Client.dsp16
-rw-r--r--TAO/tests/Exposed_Policies/Counter.idl12
-rw-r--r--TAO/tests/Exposed_Policies/Policy_Tester.cpp303
-rw-r--r--TAO/tests/Exposed_Policies/Policy_Tester.h68
-rw-r--r--TAO/tests/Exposed_Policies/Policy_Verifier.cpp231
-rw-r--r--TAO/tests/Exposed_Policies/Policy_Verifier.h70
-rw-r--r--TAO/tests/Exposed_Policies/README10
-rw-r--r--TAO/tests/Exposed_Policies/RT_Properties.cpp2
-rw-r--r--TAO/tests/Exposed_Policies/Server.dsp18
-rw-r--r--TAO/tests/Exposed_Policies/client.cpp182
-rw-r--r--TAO/tests/Exposed_Policies/server.cpp226
11 files changed, 736 insertions, 402 deletions
diff --git a/TAO/tests/Exposed_Policies/Client.dsp b/TAO/tests/Exposed_Policies/Client.dsp
index 4feb08df095..b8551623b56 100644
--- a/TAO/tests/Exposed_Policies/Client.dsp
+++ b/TAO/tests/Exposed_Policies/Client.dsp
@@ -93,6 +93,18 @@ SOURCE=.\client.cpp
SOURCE=.\CounterC.cpp
# End Source File
+# Begin Source File
+
+SOURCE=.\Policy_Tester.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Policy_Verifier.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\RT_Properties.cpp
+# End Source File
# End Group
# Begin Group "Header Files"
@@ -101,6 +113,10 @@ SOURCE=.\CounterC.cpp
SOURCE=.\CounterC.h
# End Source File
+# Begin Source File
+
+SOURCE=.\Policy_Verifier.h
+# End Source File
# End Group
# Begin Group "Resource Files"
diff --git a/TAO/tests/Exposed_Policies/Counter.idl b/TAO/tests/Exposed_Policies/Counter.idl
index 0e1140573ef..60ac5162c8a 100644
--- a/TAO/tests/Exposed_Policies/Counter.idl
+++ b/TAO/tests/Exposed_Policies/Counter.idl
@@ -1,10 +1,18 @@
//$Id$
+// This interface abstracts a counter. It provides methods
+// for increasing and getting the value of the counter.
interface Counter
{
- // @@ Angelo: please add some comments explaining how does this work
- // or what it is supposed to do.
void increment ();
+ // Increases the counter value.
+
long get_count ();
+ // Decreases the counter value.
+
+ void reset ();
+ // Sets the counter value to zero.
+
oneway void shutdown ();
+ // Shuts down the ORB on which this obj is running.
};
diff --git a/TAO/tests/Exposed_Policies/Policy_Tester.cpp b/TAO/tests/Exposed_Policies/Policy_Tester.cpp
new file mode 100644
index 00000000000..ccf7ad8ed80
--- /dev/null
+++ b/TAO/tests/Exposed_Policies/Policy_Tester.cpp
@@ -0,0 +1,303 @@
+// $Id$
+
+// -- App. Specific Include --
+#include "Policy_Tester.h"
+#include "RT_Properties.h"
+#include "CounterC.h"
+
+// -- ACE Include --
+#include "ace/Arg_Shifter.h"
+
+// -- TAO Include --
+#include "tao/RT_ORB.h"
+#include "tao/RT_Policy_i.h"
+
+
+ACE_RCSID (tao, Policy_Tester, "$Id$");
+
+Policy_Tester::Policy_Tester (void)
+ : rt_object_properties_ (0),
+ rt_poa_properties_ (0)
+{
+ // No_Op
+}
+
+Policy_Tester::~Policy_Tester (void)
+{
+ this->shutdown ();
+}
+
+void
+Policy_Tester::run (CORBA::Environment &ACE_TRY_ENV)
+{
+ ACE_TRY
+ {
+ this->create_objects (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ PortableServer::POAManager_var poa_manager =
+ this->child_poa_->the_POAManager (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ poa_manager->activate (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ this->orb_->run (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+ }
+ ACE_CATCHANY
+ {
+ ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
+ ACE_TEXT ("CORBA Exception Raised."));
+ }
+ ACE_ENDTRY;
+}
+
+int
+Policy_Tester::init (int argc,
+ char *argv[],
+ CORBA::Environment &ACE_TRY_ENV)
+{
+ ACE_TRY
+ {
+ // ORB Initialization.
+ this->orb_ = CORBA::ORB_init (argc, argv, "", ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ // Get a reference to the RT-ORB.
+ CORBA::Object_var object =
+ this->orb_->resolve_initial_references ("RTORB", ACE_TRY_ENV);
+
+ ACE_TRY_CHECK;
+
+ this->rt_orb_ = RTCORBA::RTORB::_narrow (object.in (),
+ ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+ // Here we parse the command line paramether passed
+ // to the application.
+
+ ACE_Arg_Shifter arg_shifter (argc, argv);
+
+ while (arg_shifter.is_anything_left ())
+ {
+ char *arg;
+ // IOR File Name Option.
+ if ((arg = arg_shifter.get_the_parameter ("-POAConfigFile")))
+ {
+ this->rt_poa_properties_ =
+ RT_Properties::read_from (arg, ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+ }
+ else if ((arg = arg_shifter.get_the_parameter ("-ObjectConfigFile")))
+ {
+ this->rt_object_properties_ =
+ RT_Properties::read_from (arg, ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+ }
+ else
+ arg_shifter.consume_arg ();
+
+ }
+
+ if ((this->rt_poa_properties_ == 0) || (this->rt_object_properties_ == 0))
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Configuration file missing!")));
+ return 0;
+ }
+
+ }
+ ACE_CATCHANY
+ {
+ ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
+ ACE_TEXT ("CORBA Exception Raised."));
+ return 0;
+ }
+ ACE_ENDTRY;
+ return 1;
+}
+
+CORBA::Boolean
+Policy_Tester::check_reference (CORBA::Object_ptr object,
+ const char *msg)
+{
+ if (CORBA::is_nil (object))
+ {
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT (msg)));
+ return 0;
+ }
+ return 1;
+}
+
+
+int
+Policy_Tester::create_objects (CORBA::Environment &ACE_TRY_ENV)
+{
+ ACE_TRY
+ {
+ CORBA::PolicyList poa_policy_list;
+ poa_policy_list.length (3);
+
+ // Create the priority policy using the RT-ORB.
+ RTCORBA::Priority priority = this->rt_poa_properties_->priority ();
+ poa_policy_list[0] =
+ this->rt_orb_->create_priority_model_policy (RTCORBA::SERVER_DECLARED,
+ priority,
+ ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ // Create priority Banded Connection Policy.
+ RTCORBA::PriorityBands poa_priority_bands =
+ this->rt_poa_properties_->priority_bands ();
+
+ poa_policy_list[1] =
+ this->rt_orb_->create_priority_banded_connection_policy (poa_priority_bands,
+ ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ // Client Protocol Policy.
+ RTCORBA::ProtocolList protocol_list;
+ protocol_list.length (1);
+
+ protocol_list[0].protocol_type = IOP::TAG_INTERNET_IOP;
+ protocol_list[0].orb_protocol_properties =
+ TAO_Protocol_Properties_Factory::create_orb_protocol_property (IOP::TAG_INTERNET_IOP);
+
+ protocol_list[0].transport_protocol_properties =
+ TAO_Protocol_Properties_Factory::create_transport_protocol_property (IOP::TAG_INTERNET_IOP);
+
+ poa_policy_list[2] =
+ this->rt_orb_->create_client_protocol_policy (protocol_list);
+
+ CORBA::Object_var object =
+ this->orb_->resolve_initial_references ("RootPOA", ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ this->poa_ =
+ PortableServer::POA::_narrow (object.in (), ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ PortableServer::POAManager_var poa_mgr =
+ PortableServer::POAManager::_nil ();
+
+ this->child_poa_ =
+ this->poa_->create_POA ("Child_POA",
+ poa_mgr ,
+ poa_policy_list);
+
+ // Create a Corba Object reference, using the policies
+ // set at the POA level.
+ object =
+ this->child_poa_->create_reference ("IDL:Counter:1.0",
+ ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Reference Created!\n")));
+
+ if (!check_reference (object,
+ "Unable to create Object!\n"))
+ return 0;
+
+ Counter_var base_object = Counter::_narrow (object.in (), ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ if (!check_reference (base_object.in(),
+ "Unable to create a Object!\n"))
+ return 0;
+
+ CORBA::String_var ior =
+ this->orb_->object_to_string (base_object.in (), ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Activated as <%s>\n"), ior.in ()));
+
+ FILE *output_file = ACE_OS::fopen (this->rt_poa_properties_->ior_source (), "w");
+ if (output_file == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("Cannot open output file for writing IOR: %s"),
+ this->rt_poa_properties_->ior_source ()),
+ 0);
+ ACE_OS::fprintf (output_file, "%s", ior.in ());
+ ACE_OS::fclose (output_file);
+
+ // Now we create an object that overrides some of the policies
+ // set at the POA level.
+
+
+ // Create a Corba Object reference, using the policies
+ // set at the POA level.
+
+ // @@ Shortcut - The following code is not definitive, and
+ // the cast is only used to access a RTPortableServer::POA
+ // method that isn't currently accessible otherwise.
+
+ object =
+ ((TAO_POA*)this->child_poa_.ptr ())->create_reference_with_priority
+ ("IDL:Counter:1.0",
+ this->rt_object_properties_->priority (),
+ ACE_TRY_ENV);
+
+ ACE_TRY_CHECK;
+
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Reference Created!\n")));
+
+ if (!check_reference (object,
+ "Unable to create a Counter Object!\n"))
+ return 0;
+
+ Counter_var over_object = Counter::_narrow (object.in (), ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ if (!check_reference (over_object.in(),
+ "Unable to create Object!\n"))
+ return 0;
+
+
+ CORBA::String_var o_ior = this->orb_->object_to_string (over_object.in (), ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Activated as <%s>\n"), o_ior.in ()));
+
+ output_file = ACE_OS::fopen (this->rt_object_properties_->ior_source (), "w");
+
+ if (output_file == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("Cannot open output file for writing IOR: %s"),
+ this->rt_object_properties_->ior_source ()),
+ 0);
+ ACE_OS::fprintf (output_file, "%s", o_ior.in ());
+ ACE_OS::fclose (output_file);
+ }
+ ACE_CATCHANY
+ {
+ ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
+ ACE_TEXT ("CORBA Exception Raised."));
+ return 0;
+ }
+ ACE_ENDTRY;
+ return 1;
+}
+
+void
+Policy_Tester::shutdown (CORBA::Environment &ACE_TRY_ENV)
+{
+ this->orb_->shutdown (0, ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ this->child_poa_->destroy (1, 1, ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ this->poa_->destroy (1, 1, ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+}
+
+
+
+
+
+
+
diff --git a/TAO/tests/Exposed_Policies/Policy_Tester.h b/TAO/tests/Exposed_Policies/Policy_Tester.h
new file mode 100644
index 00000000000..540b61f890b
--- /dev/null
+++ b/TAO/tests/Exposed_Policies/Policy_Tester.h
@@ -0,0 +1,68 @@
+// $Id$
+//
+// ============================================================================
+//
+// = LIBRARY
+// TAO/tests/Exposed_Policies
+//
+// = FILENAME
+// Policy_Verifier.h
+//
+// = DESCRIPTION
+// This class verifies that the policy are correctly embedded
+// in the IOR.
+//
+// = AUTHOR
+// Angelo Corsaro <corsaro@cs.wustl.edu>
+//
+// ============================================================================
+
+#ifndef POLICY_TESTER_H_
+#define POLICY_TESTER_H_
+
+// -- App. Specific Include --
+#include "RT_Properties.h"
+
+// -- TAO Include --
+#include "tao/corba.h"
+
+class Policy_Tester
+{
+public:
+ // Ctor/Dtor.
+ Policy_Tester (void);
+ ~Policy_Tester (void);
+
+ void run (CORBA::Environment &ACE_TRY_ENV
+ = TAO_default_environment ());
+ // Runs the test.
+
+ int init (int argc,
+ char *argv[],
+ CORBA::Environment &ACE_TRY_ENV
+ = TAO_default_environment ());
+
+ void shutdown (CORBA::Environment &ACE_TRY_ENV
+ = TAO_default_environment ());
+private:
+ // Helper method used internally.
+ int create_objects (CORBA::Environment &ACE_TRY_ENV
+ = TAO_default_environment ());
+public:
+
+ static CORBA::Boolean check_reference (CORBA::Object_ptr object,
+ const char *msg);
+
+private:
+
+ int is_initialized_;
+
+ RTCORBA::RTORB_var rt_orb_;
+ CORBA::ORB_var orb_;
+ PortableServer::POA_var poa_;
+ PortableServer::POA_var child_poa_;
+ RT_Properties *rt_object_properties_;
+ RT_Properties *rt_poa_properties_;
+};
+
+#endif
diff --git a/TAO/tests/Exposed_Policies/Policy_Verifier.cpp b/TAO/tests/Exposed_Policies/Policy_Verifier.cpp
new file mode 100644
index 00000000000..185b529d409
--- /dev/null
+++ b/TAO/tests/Exposed_Policies/Policy_Verifier.cpp
@@ -0,0 +1,231 @@
+#include "Policy_Verifier.h"
+
+ACE_RCSID (tao, Policy_Verifier, "$Id$");
+
+
+Policy_Verifier::Policy_Verifier (void)
+{
+ ACE_OS_String::strcpy (this->base_object_ref_,
+ "file://");
+ ACE_OS_String::strcpy (this->overridden_object_ref_,
+ "file://");
+}
+
+Policy_Verifier::~Policy_Verifier (void)
+{
+ // No Op.
+}
+
+void
+Policy_Verifier::init (int argc,
+ char *argv[],
+ CORBA::Environment &ACE_TRY_ENV)
+{
+ ACE_TRY
+ {
+ this->orb_ =
+ CORBA::ORB_init (argc, argv, "", ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ ACE_Arg_Shifter arg_shifter (argc, argv);
+
+ while (arg_shifter.is_anything_left ())
+ {
+ char *arg;
+ // IOR File Name Option.
+ if ((arg = arg_shifter.get_the_parameter ("-POAConfigFile")))
+ {
+ this->rt_poa_properties_ =
+ RT_Properties::read_from (arg, ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ ACE_OS_String::strcat (this->base_object_ref_,
+ this->rt_poa_properties_->ior_source ());
+ }
+ else if ((arg = arg_shifter.get_the_parameter ("-ObjectConfigFile")))
+ {
+ this->rt_object_properties_ =
+ RT_Properties::read_from (arg, ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ ACE_OS_String::strcat (this->overridden_object_ref_,
+ this->rt_object_properties_->ior_source ());
+
+ }
+ else
+ arg_shifter.consume_arg ();
+
+ }
+
+ if ((this->rt_poa_properties_ == 0) || (this->rt_object_properties_ == 0))
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Configuration file missing!\n")));
+ return;
+ }
+
+ // Get the Object references.
+ CORBA::Object_var object = this->orb_->string_to_object (this->base_object_ref_,
+ ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ if (!Policy_Tester::check_reference (object.in (), "Invalid IOR file!\n"))
+ return;
+
+ this->base_object_ = Counter::_narrow (object.in (), ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ if (!Policy_Tester::check_reference (this->base_object_,
+ "Unable to convert the IOR to the proper object reference.\n"))
+ return;
+
+ object = this->orb_->string_to_object (this->overridden_object_ref_, ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ if (!Policy_Tester::check_reference (object.in (), "Invalid IOR file!\n"))
+ return;
+
+ this->overridden_object_ = Counter::_narrow (object.in (), ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ if (!Policy_Tester::check_reference (this->overridden_object_,
+ "Unable to convert the IOR to the proper object reference.\n"))
+ return;
+
+ }
+ ACE_CATCHANY
+ {
+ ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "CORBA Excaption Raised");
+ }
+ ACE_ENDTRY;
+}
+
+void
+Policy_Verifier::run (CORBA::Environment &ACE_TRY_ENV )
+{
+ this->verify_reference (this->base_object_,
+ this->rt_poa_properties_,
+ ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ this->verify_reference (this->overridden_object_,
+ this->rt_object_properties_,
+ ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+}
+
+void
+Policy_Verifier::verify_reference (Counter_ptr object,
+ RT_Properties *rt_properties,
+ CORBA::Environment &ACE_TRY_ENV)
+{
+
+ ACE_TRY
+ {
+ CORBA::Policy_var policy_ptr =
+ object->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE,
+ ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ if (Policy_Tester::check_reference (policy_ptr, "Unable to get Priority Policy.\n"))
+ {
+ RTCORBA::PriorityModelPolicy_var priority_policy =
+ RTCORBA::PriorityModelPolicy::_narrow (policy_ptr);
+
+ RTCORBA::PriorityModel priority_model =
+ priority_policy->priority_model (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ RTCORBA::Priority priority =
+ priority_policy->server_priority (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ if (priority_model == RTCORBA::SERVER_DECLARED)
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("\n\nPriority Model: RTCORBA::SERVER_DECLARED\n")
+ ));
+
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Priority Model: %d\nCORBA Priority: %d\n\n"),
+ priority_model,
+ priority
+ ));
+
+
+ if (priority != rt_properties->priority ())
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Priority Value Mismatch.\n")));
+ }
+
+ policy_ptr = object->_get_policy (RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE,
+ ACE_TRY_ENV);
+ if (Policy_Tester::check_reference (policy_ptr,
+ "Unable to get Priority Banded Policy\n"))
+ {
+
+ RTCORBA::PriorityBandedConnectionPolicy_var priority_banded_policy =
+ RTCORBA::PriorityBandedConnectionPolicy::_narrow (policy_ptr,
+ ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+
+ if (Policy_Tester::check_reference (priority_banded_policy,
+ "Unable to get Priority Banded Policy\n"))
+ {
+
+ // Here we have a priority banded connection policy.
+
+ RTCORBA::PriorityBands_var pb =
+ priority_banded_policy->priority_bands ();
+ unsigned int band_num = pb->length ();
+ if (band_num != rt_properties->priority_bands ().length ())
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Mismatching Number of Priority Bands!\n")));
+
+ for (unsigned int i = 0; i < band_num; ++i)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Priority Band <%d>: (%d, %d)\n"),
+ i,
+ pb[i].low,
+ pb[i].high
+ ));
+
+
+ if ((band_num == rt_properties->priority_bands ().length ()) &&
+ ((pb[i].low != rt_properties->priority_bands ()[i].low) ||
+ (pb[i].high != rt_properties->priority_bands ()[i].high)))
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Mismatching Priority Band Range!\n")));
+
+ }
+ }
+ }
+ policy_ptr = object->_get_policy (RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE,
+ ACE_TRY_ENV);
+ if (Policy_Tester::check_reference (policy_ptr, "Unable Client Protocol Policy\n"))
+ {
+ RTCORBA::ClientProtocolPolicy_var client_protocol_policy =
+ RTCORBA::ClientProtocolPolicy::_narrow (policy_ptr, ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ RTCORBA::ProtocolList_var protocol_list =
+ client_protocol_policy->protocols (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ for (unsigned int i = 0; i < protocol_list->length (); i++)
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("\nThe Client Protocol Type: %d\n"),
+ protocol_list[i].protocol_type));
+
+ }
+
+ }
+ ACE_CATCHANY
+ {
+ ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "CORBA Excaption Raised");
+ }
+
+ ACE_ENDTRY;
+}
+
diff --git a/TAO/tests/Exposed_Policies/Policy_Verifier.h b/TAO/tests/Exposed_Policies/Policy_Verifier.h
new file mode 100644
index 00000000000..f8251b43f6a
--- /dev/null
+++ b/TAO/tests/Exposed_Policies/Policy_Verifier.h
@@ -0,0 +1,70 @@
+// $Id$
+//
+// ============================================================================
+//
+// = LIBRARY
+// TAO/tests/Exposed_Policies
+//
+// = FILENAME
+// Policy_Verifier.h
+//
+// = DESCRIPTION
+// This class verifies that the policy are correctly embedded
+// in the IOR.
+//
+// = AUTHOR
+// Angelo Corsaro <corsaro@cs.wustl.edu>
+//
+// ============================================================================
+
+#ifndef POLICY_VERIFIER_H_
+#define POLICY_VERIFIER_H_
+
+// -- App. Specific Include --
+#include "CounterC.h"
+#include "RT_Properties.h"
+#include "Policy_Tester.h"
+// -- ACE Include --
+#include "ace/Arg_Shifter.h"
+
+// -- TAO Include --
+#include "tao/corba.h"
+
+class Policy_Verifier
+{
+public:
+
+ // -- Ctor/Dtor --
+ Policy_Verifier (void);
+ ~Policy_Verifier (void);
+
+ void init (int argc,
+ char *argv[],
+ CORBA::Environment &ACE_TRY_ENV
+ = TAO_default_environment ());
+
+ void run (CORBA::Environment &ACE_TRY_ENV
+ = TAO_default_environment ());
+
+private:
+ // -- Helper methods --
+ void verify_reference (Counter_ptr counter,
+ RT_Properties *rt_properties,
+ CORBA::Environment &ACE_TRY_ENV
+ = TAO_default_environment ());
+
+private:
+
+ CORBA::ORB_var orb_;
+
+ RT_Properties *rt_object_properties_;
+ RT_Properties *rt_poa_properties_;
+
+ Counter_var base_object_;
+ Counter_var overridden_object_;
+
+ char base_object_ref_[256];
+ char overridden_object_ref_[256];
+};
+
+#endif /* POLICY_VERIFIER_H_ */
diff --git a/TAO/tests/Exposed_Policies/README b/TAO/tests/Exposed_Policies/README
index c09c90f8857..b33abbff283 100644
--- a/TAO/tests/Exposed_Policies/README
+++ b/TAO/tests/Exposed_Policies/README
@@ -58,21 +58,25 @@ the same priority that where specified when the POA was created, while
the other ovverride some of them as prescribed in the config file
specified with the option "-ObjectConfigFile".
+The config file are used by the client side to verify that what is
+embedded in the IOR is correct.
+
USAGE:
server -POAConfigFile <config_file_name>
-ObjectConfigFile <config_file_name>
- client -IORSource <ior_source>
+ client -POAConfigFile <config_file_name>
+ -ObjectConfigFile <config_file_name>
EXAMPLE:
$ server -POAConfigFile POA.cfg -ObjectConfigFile Object.cfg
- $ client -IORSource file://default.ior
+ $ client -POAConfigFile POA.cfg -ObjectConfigFile Object.cfg
- $ client -IORSource file://overridden.ior
+ $ client -POAConfigFile POA.cfg -ObjectConfigFile Object.cfg
diff --git a/TAO/tests/Exposed_Policies/RT_Properties.cpp b/TAO/tests/Exposed_Policies/RT_Properties.cpp
index 9dcfc156cab..fff46b828f6 100644
--- a/TAO/tests/Exposed_Policies/RT_Properties.cpp
+++ b/TAO/tests/Exposed_Policies/RT_Properties.cpp
@@ -1,4 +1,4 @@
->//$Id$
+//$Id$
#include "RT_Properties.h"
diff --git a/TAO/tests/Exposed_Policies/Server.dsp b/TAO/tests/Exposed_Policies/Server.dsp
index edd817c05e1..008618dc980 100644
--- a/TAO/tests/Exposed_Policies/Server.dsp
+++ b/TAO/tests/Exposed_Policies/Server.dsp
@@ -99,6 +99,10 @@ SOURCE=.\CounterS.cpp
# End Source File
# Begin Source File
+SOURCE=.\Policy_Tester.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\RT_Properties.cpp
# End Source File
# Begin Source File
@@ -123,6 +127,10 @@ SOURCE=.\CounterS.h
# End Source File
# Begin Source File
+SOURCE=.\Policy_Tester.h
+# End Source File
+# Begin Source File
+
SOURCE=.\RT_Properties.h
# End Source File
# End Group
@@ -146,13 +154,16 @@ InputName=Counter
BuildCmds= \
..\..\..\bin\tao_idl -Ge 1 $(InputName).idl
+"$(InputName)C.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
"$(InputName)C.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
$(BuildCmds)
"$(InputName)C.i" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
$(BuildCmds)
-"$(InputName)C.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+"$(InputName)S.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
$(BuildCmds)
"$(InputName)S.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
@@ -161,7 +172,7 @@ BuildCmds= \
"$(InputName)S.i" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
$(BuildCmds)
-"$(InputName)S.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+"$(InputName)S_T.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
$(BuildCmds)
"$(InputName)S_T.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
@@ -169,9 +180,6 @@ BuildCmds= \
"$(InputName)S_T.i" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
$(BuildCmds)
-
-"$(InputName)S_T.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- $(BuildCmds)
# End Custom Build
!ELSEIF "$(CFG)" == "Server - Win32 Debug"
diff --git a/TAO/tests/Exposed_Policies/client.cpp b/TAO/tests/Exposed_Policies/client.cpp
index 5de236695c5..bc71bb285d2 100644
--- a/TAO/tests/Exposed_Policies/client.cpp
+++ b/TAO/tests/Exposed_Policies/client.cpp
@@ -1,26 +1,14 @@
// $Id$
-#include "ace/Arg_Shifter.h"
+// -- App. Specific Include --
#include "CounterC.h"
+#include "util.h"
-char object_ref[256];
+// -- App. Specific Include --
+#include "Policy_Verifier.h"
ACE_RCSID(tao, client, "$Id$")
-
-CORBA::Boolean
-check_reference (CORBA::Object_ptr object,
- const char *msg)
-{
- if (CORBA::is_nil (object))
- {
- ACE_DEBUG ((LM_DEBUG, ACE_TEXT (msg)));
- return 0;
- }
- return 1;
-}
-
-
int
main (int argc, char *argv[])
{
@@ -28,169 +16,17 @@ main (int argc, char *argv[])
ACE_TRY
{
- // ORB Initialization
- CORBA::ORB_var orb =
- CORBA::ORB_init (argc, argv, "TAO", ACE_TRY_ENV);
- // @@ Angelo: there is no need to name the ORB, don't do it
- // unless you have a good reason to, because it confuses the
- // users that see this stuff.
- ACE_TRY_CHECK;
-
- // @@ Angelo: we have been using -k IOR for this same kind of
- // option forever, please try to make your examples consistent,
- // it is easier to understand them that way.
- ACE_Arg_Shifter arg_shifter (argc, argv);
+ Policy_Verifier policy_verifier;
- int file_set = 0;
- while (arg_shifter.is_anything_left ())
- {
- char *arg;
- if ((arg = arg_shifter.get_the_parameter ("-IORSource")))
- {
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("IOR File Name: %s\n"),
- arg));
- ACE_OS_String::strcpy (object_ref, arg);
- file_set = 1;
- }
- else
- arg_shifter.consume_arg ();
- }
-
- if (file_set == 0)
- ACE_OS_String::strcpy (object_ref, "file://poa_default.ior");
-
- // @@ Angelo: it is better style just to initialize the
- // variables as soon as you declare them, in this case:
- //
- // CORBA::Object_var object = orb->string_to_object_....
- //
- CORBA::Object_var object;
-
- // @@ Angelo: you may want to repeat the test multiple times in
- // a loop, this is useful when running with Purify or similar
- // tools because the leaks are more visible when you do that.
-
- // @@ Angelo: I'm not sure if you really need a client and a
- // server, it may be enough to have a single program that does
- // object_to_string() and then string_to_object() to verify that
- // all the policies are preserved and parsed correctly. Those
- // programs are usually much easier to debug and purify.
-
- // Get the IOR from a file.
- object = orb->string_to_object (object_ref, ACE_TRY_ENV);
+ policy_verifier.init (argc, argv, ACE_TRY_ENV);
ACE_TRY_CHECK;
-
- // @@ Angelo: cool use of a helper routine, but you may want to
- // declare the helper at the top of the file and put its
- // definition at the bottom, to avoid distractions when looking
- // for the core of the test.
- if (!check_reference (object, "Invalid IOR file!\n"))
- return 1;
-
- Counter_var counter = Counter::_narrow (object.in (), ACE_TRY_ENV);
+
+ policy_verifier.run (ACE_TRY_ENV);
ACE_TRY_CHECK;
-
- if (!check_reference (object,
- "Unable to convert the IOR to the proper object reference.\n"))
- return 1;
-
- // @@ Angelo: more initialization stuff.
- CORBA::Policy_var policy_ptr;
- policy_ptr = counter->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- if (check_reference (policy_ptr, "Unable to get Priority Policy.\n"))
- {
- RTCORBA::PriorityModelPolicy_var priority_policy =
- RTCORBA::PriorityModelPolicy::_narrow (policy_ptr);
-
- RTCORBA::PriorityModel priority_model =
- priority_policy->priority_model (ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- RTCORBA::Priority priority =
- priority_policy->server_priority (ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- if (priority_model == RTCORBA::SERVER_DECLARED)
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("\n\nPriority Model: RTCORBA::SERVER_DECLARED\n")
- ));
-
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("Priority Model: %d\nCORBA Priority: %d\n\n"),
- priority_model,
- priority
- ));
- }
-
- policy_ptr = object->_get_policy (RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE,
- ACE_TRY_ENV);
- if (check_reference (policy_ptr, "Unable to get Priority Banded Policy\n"))
- {
-
- RTCORBA::PriorityBandedConnectionPolicy_var priority_banded_policy =
- RTCORBA::PriorityBandedConnectionPolicy::_narrow (policy_ptr,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
-
- if (check_reference (priority_banded_policy, "Unable to get Priority Banded Policy\n"))
- {
-
- // Here we have a priority banded connection policy.
-
- RTCORBA::PriorityBands_var pb =
- priority_banded_policy->priority_bands ();
- unsigned int band_num = pb->length ();
- for (unsigned int i = 0; i < band_num; ++i)
- {
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("Priority Band <%d>: (%d, %d)\n"),
- i,
- pb[i].low,
- pb[i].high
- ));
- }
- }
- }
- policy_ptr = object->_get_policy (RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE,
- ACE_TRY_ENV);
- if (check_reference (policy_ptr, "Unable Client Protocol Policy\n"))
- {
- RTCORBA::ClientProtocolPolicy_var client_protocol_policy =
- RTCORBA::ClientProtocolPolicy::_narrow (policy_ptr, ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- RTCORBA::ProtocolList_var protocol_list =
- client_protocol_policy->protocols (ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- for (unsigned int i = 0; i < protocol_list->length (); i++)
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("\nThe Client Protocol Type: %d\n"),
- protocol_list[i].protocol_type));
-
- }
-
- // @@ Angelo: cleanup the ORB at the end!
-
- // @@ Angelo: in general this is a good test, but it does not
- // check if:
- // + The values obtained are the expected values,
- // could you compare against well known values somehow?
- // + Can
- // you check that things that should fail indeed do? For
- // example: what if the user queries or tries to set a policy
- // that makes no sense on the client, like ServerProtocolPolicy?
- // Certain values should be returned and maybe exceptions raised
- // (I don't know), we need to check for that too!
}
ACE_CATCHANY
{
- ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "CORBA Excaption Raised");
+ ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "CORBA Exception Raised");
return 1;
}
diff --git a/TAO/tests/Exposed_Policies/server.cpp b/TAO/tests/Exposed_Policies/server.cpp
index 94931085a88..971d4bf927c 100644
--- a/TAO/tests/Exposed_Policies/server.cpp
+++ b/TAO/tests/Exposed_Policies/server.cpp
@@ -10,38 +10,12 @@
// them into the IOR.
//
//
-#include "Counter_i.h"
-// @@ Angelo, we don't use angle brackets in our tests or examples
-// because that disables dependencies, we need to have the code
-// automatically compile if something fails.
-#include <tao/RT_ORB.h>
-#include <tao/RT_Policy_i.h>
-#include <ace/Arg_Shifter.h>
-
-// @@ Angelo: any reason to have an inconsistent order of declaration?
-#include "RT_Properties.h"
+// -- App. Specific Include --
+#include "Policy_Tester.h"
ACE_RCSID(tao, server, "$Id$");
-// @@ Angelo: please move this routine to some common place (but *NOT*
-// in the TAO library).
-CORBA::Boolean check_reference (CORBA::Object_ptr object,
- const char *msg = 0)
-{
- if (CORBA::is_nil (object))
- {
- if (msg == 0)
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("The Object reference is nil.\n")));
- else
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT (msg)));
- return 0;
- }
- return 1;
-}
-
int
main (int argc, char *argv[])
@@ -50,197 +24,12 @@ main (int argc, char *argv[])
ACE_TRY
{
- // ORB Initialization.
- CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "TAO", ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- // Here we parse the command line paramether passed
- // to the application.
-
- ACE_Arg_Shifter arg_shifter (argc, argv);
-
- RT_Properties *rt_object_properties = 0;
- RT_Properties *rt_poa_properties = 0;
-
- while (arg_shifter.is_anything_left ())
- {
- char *arg;
- // IOR File Name Option.
- if ((arg = arg_shifter.get_the_parameter ("-POAConfigFile")))
- {
- rt_poa_properties = RT_Properties::read_from (arg, ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- else if ((arg = arg_shifter.get_the_parameter ("-ObjectConfigFile")))
- {
- rt_object_properties = RT_Properties::read_from (arg, ACE_TRY_ENV);
- ACE_TRY_CHECK;
- }
- else
- arg_shifter.consume_arg ();
-
- }
-
- CORBA::Object_var object;
-
- // Get a reference to the RT-ORB.
- object = orb->resolve_initial_references ("RTORB", ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow (object.in (),
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- CORBA::PolicyList poa_policy_list;
- poa_policy_list.length (3);
-
-
- // Create the priority policy using the RT-ORB.
- RTCORBA::Priority priority = rt_poa_properties->priority ();
- poa_policy_list[0] =
- rt_orb->create_priority_model_policy (RTCORBA::SERVER_DECLARED,
- priority,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- // Create priority Banded Connection Policy.
- RTCORBA::PriorityBands poa_priority_bands = rt_poa_properties->priority_bands ();
-
- poa_policy_list[1] =
- rt_orb->create_priority_banded_connection_policy (poa_priority_bands,
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- // Client Protocol Policy.
- RTCORBA::ProtocolList protocol_list;
- protocol_list.length (1);
-
- protocol_list[0].protocol_type = IOP::TAG_INTERNET_IOP;
- protocol_list[0].orb_protocol_properties =
- TAO_Protocol_Properties_Factory::create_orb_protocol_property (IOP::TAG_INTERNET_IOP);
-
- protocol_list[0].transport_protocol_properties =
- TAO_Protocol_Properties_Factory::create_transport_protocol_property (IOP::TAG_INTERNET_IOP);
-
- poa_policy_list[2] =
- rt_orb->create_client_protocol_policy (protocol_list);
-
- object = orb->resolve_initial_references ("RootPOA", ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- PortableServer::POA_var poa =
- PortableServer::POA::_narrow (object.in (), ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- PortableServer::POAManager_var poa_mgr =
- PortableServer::POAManager::_nil ();
-
- PortableServer::POA_var child_poa =
- poa->create_POA ("Child_POA",
- poa_mgr ,
- poa_policy_list);
-
- // Create a Corba Object reference, using the policies
- // set at the POA level.
- object =
- child_poa->create_reference ("IDL:Counter:1.0",
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("Reference Created!\n")));
-
- if (!check_reference (object,
- "Unable to create a Counter Object!\n"))
- return 1;
-
- Counter_var counter = Counter::_narrow (object.in (), ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- if (!check_reference (counter.in(),
- "Unable to create a Counter Object!\n"))
- return 1;
-
- Counter_Servant servant (orb.in ());
-
- // TODO: Incarnate the CORBA Object with servant.
-
- CORBA::String_var ior =
- orb->object_to_string (counter.in (), ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("Activated as <%s>\n"), ior.in ()));
-
- FILE *output_file = ACE_OS::fopen (rt_poa_properties->ior_source (), "w");
- if (output_file == 0)
- ACE_ERROR_RETURN ((LM_ERROR,
- ACE_TEXT ("Cannot open output file for writing IOR: %s"),
- rt_poa_properties->ior_source ()),
- 1);
- ACE_OS::fprintf (output_file, "%s", ior.in ());
- ACE_OS::fclose (output_file);
-
- // Now we create an object that overrides some of the policies
- // set at the POA level.
-
-
- // Create a Corba Object reference, using the policies
- // set at the POA level.
-
- // @@ Shortcut - The following code is not definitive, and
- // the cast is only used to access a RTPortableServer::POA
- // method that isn't currently accessible otherwise.
-
- object =
- ((TAO_POA*)child_poa.ptr ())->create_reference_with_priority ("IDL:Counter:1.0",
- rt_object_properties->priority (),
- ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("Reference Created!\n")));
-
- if (!check_reference (object,
- "Unable to create a Counter Object!\n"))
- return 1;
-
- Counter_var counter_over = Counter::_narrow (object.in (), ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- if (!check_reference (counter_over.in(),
- "Unable to create a Counter Object!\n"))
- return 1;
-
-
- CORBA::String_var o_ior = orb->object_to_string (counter_over.in (), ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("Activated as <%s>\n"), o_ior.in ()));
-
- output_file = ACE_OS::fopen (rt_object_properties->ior_source (), "w");
-
- if (output_file == 0)
- ACE_ERROR_RETURN ((LM_ERROR,
- ACE_TEXT ("Cannot open output file for writing IOR: %s"),
- rt_object_properties->ior_source ()),
- 1);
- ACE_OS::fprintf (output_file, "%s", o_ior.in ());
- ACE_OS::fclose (output_file);
-
-
- PortableServer::POAManager_var poa_manager =
- child_poa->the_POAManager (ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- poa_manager->activate (ACE_TRY_ENV);
+ Policy_Tester policy_tester;
+
+ policy_tester.init (argc, argv, ACE_TRY_ENV);
ACE_TRY_CHECK;
- orb->run (ACE_TRY_ENV);
- ACE_TRY_CHECK;
-
- poa->destroy (1, 1, ACE_TRY_ENV);
+ policy_tester.run (ACE_TRY_ENV);
ACE_TRY_CHECK;
}
@@ -249,7 +38,8 @@ main (int argc, char *argv[])
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
ACE_TEXT ("CORBA Exception Raised."));
return 1;
- }
+ } return 1;
+
ACE_ENDTRY;
return 0;