summaryrefslogtreecommitdiff
path: root/trunk/TAO/tests/Bug_1476_Test/client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'trunk/TAO/tests/Bug_1476_Test/client.cpp')
-rw-r--r--trunk/TAO/tests/Bug_1476_Test/client.cpp212
1 files changed, 212 insertions, 0 deletions
diff --git a/trunk/TAO/tests/Bug_1476_Test/client.cpp b/trunk/TAO/tests/Bug_1476_Test/client.cpp
new file mode 100644
index 00000000000..19f5115824d
--- /dev/null
+++ b/trunk/TAO/tests/Bug_1476_Test/client.cpp
@@ -0,0 +1,212 @@
+// $Id$
+
+#include "HelloC.h"
+
+#include "tao/Messaging/Messaging.h"
+
+#include "tao/Transport_Cache_Manager.h"
+#include "tao/ORB_Core.h"
+#include "tao/Thread_Lane_Resources.h"
+#include "tao/Base_Transport_Property.h"
+#include "tao/Stub.h"
+#include "tao/Profile.h"
+#include "tao/Transport.h"
+
+#include "ace/Get_Opt.h"
+
+ACE_RCSID(Hello, client, "$Id$")
+
+const char *ior = "file://test.ior";
+bool level_obj = false;
+bool level_thread = false;
+bool level_orb = false;
+
+bool synch_none = false;
+bool synch_delayed = false;
+
+int
+parse_args (int argc, char *argv[])
+{
+ ACE_Get_Opt get_opts (argc, argv, "k:l:s:");
+ int c;
+ level_obj = true; //default
+ synch_none = true; //default
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 'k':
+ ior = get_opts.opt_arg ();
+ break;
+ case 'l':
+ {
+ char *level = get_opts.opt_arg ();
+ level_obj = false;
+
+ if (ACE_OS::strcmp (level, "orb") == 0) {
+ level_orb = true;
+ }
+ else if (ACE_OS::strcmp (level, "thread") == 0) {
+ level_thread = true;
+ }
+ else {
+ level_obj = true;
+ }
+ break;
+ }
+ case 's':
+ {
+ char *synch = get_opts.opt_arg ();
+ synch_none = false;
+
+ if (ACE_OS::strcmp (synch, "delayed") == 0) {
+ synch_delayed = true;
+ }
+ else {
+ synch_none = true;
+ }
+ break;
+ }
+
+ case '?':
+ default:
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "usage: %s "
+ "-k <ior> "
+ "-l <obj|orb|thread> "
+ "-s <none|delayed> "
+ "\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, "test");
+
+ if (parse_args (argc, argv) != 0)
+ return 1;
+
+ CORBA::Object_var tmp = orb->string_to_object(ior);
+
+ if (CORBA::is_nil (tmp.in ())) {
+ ACE_ERROR_RETURN ((LM_ERROR, "Invalid IOR.\n")
+ ,1);
+ }
+
+ {
+ // Set the Synch Scopes
+
+ CORBA::Any scope_as_any;
+
+ if (synch_none == true)
+ {
+ ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Applying SYNC_NONE.\n"));
+ scope_as_any <<= Messaging::SYNC_NONE;
+ }
+ else if (synch_delayed == true)
+ {
+ ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Applying SYNC_DELAYED_BUFFERING.\n"));
+ scope_as_any <<= TAO::SYNC_DELAYED_BUFFERING;
+ }
+
+ CORBA::PolicyList policies (1);
+ policies.length (1);
+ policies[0] =
+ orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
+ scope_as_any);
+
+ if (level_thread == true)
+ {
+ ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Applying Synch Scope at thread level.\n"));
+
+ CORBA::Object_var object =
+ orb->resolve_initial_references ("PolicyCurrent");
+ CORBA::PolicyCurrent_var policy_current =
+ CORBA::PolicyCurrent::_narrow (object.in ());
+
+ policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
+ }
+ else if (level_orb == true)
+ {
+ ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Applying Synch Scope at orb level.\n"));
+
+ CORBA::Object_var obj =
+ orb->resolve_initial_references("ORBPolicyManager");
+ CORBA::PolicyManager_var policy_manager =
+ CORBA::PolicyManager::_narrow(obj.in());
+
+ policy_manager->set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
+ }
+ else if (level_obj == true)
+ {
+ ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Applying Synch Scope at Object level.\n"));
+
+ tmp = tmp->_set_policy_overrides (policies, CORBA::SET_OVERRIDE);
+ }
+
+ policies[0]->destroy ();
+ }
+
+ Test::Hello_var hello =
+ Test::Hello::_narrow(tmp.in ());
+
+ if (CORBA::is_nil (hello.in ())) {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Nil Test::Hello reference <%s>\n",
+ ior),
+ 1);
+ }
+
+ // If a blocking connection is initiated in the next step
+ // the test will get an exception indicating test failure.
+ // Be sure you IOR is for the localhost endpoint, else
+ // grab a book and wait around for timeout.
+ hello->get_string ();
+
+ TAO::Transport_Cache_Manager &tcm =
+ hello->orb_core ()->lane_resources ().transport_cache ();
+
+ TAO_Transport *transport = NULL;
+ TAO_Base_Transport_Property desc (hello->_stubobj ()->profile_in_use()->endpoint ());
+
+ if (tcm.current_size() == 0) {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "The Transport Cache shouldn't be empty here.\n"),
+ 1);
+ }
+
+ if (tcm.find_transport (&desc, transport) != 0) {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "The cache should have returned the just created transport.\n"),
+ 1);
+ }
+
+ if (transport->is_connected()) {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "This cannot happen. No server to connect to."),
+ 1);
+ }
+
+ if (transport != NULL) {
+ ACE_DEBUG ((LM_DEBUG, "Transport is %s\n", (transport->is_connected()?"connected":"not connected")));
+ }
+
+ orb->destroy ();
+ }
+ catch (CORBA::Exception &ex)
+ {
+ ACE_ERROR ((LM_ERROR, "Exception caught: %s\"%s\"\n"
+ , ex._name(), ex._rep_id ()));
+ return 1;
+ }
+
+ return 0;
+}