Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_2134_Regression / Hello.cpp
blob8ffa2778c9c29cd662e8ea5756d3ef1b43c02258
1 #include "tao/corba.h"
2 #include "tao/IORTable/IORTable.h"
3 #include "tao/Messaging/Messaging.h"
4 #include "tao/AnyTypeCode/Any.h"
5 #include "ace/OS_NS_string.h"
6 #include "ace/SString.h"
8 #include "HelloS.h"
10 namespace Test
12 class Hello_impl: virtual public POA_Test::Hello
14 public:
15 void say_hello()
21 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
23 int status = 0;
24 CORBA::ORB_var orb = CORBA::ORB::_nil();
26 try
28 // Initialize the ORB
29 orb = CORBA::ORB_init (argc, argv);
31 // create Hello object
32 Test::Hello_impl hello_i;
34 // Get the root POA
35 CORBA::Object_var obj_root = orb->resolve_initial_references ("RootPOA");
37 PortableServer::POA_var rootPOA = PortableServer::POA::_narrow (obj_root.in ());
39 PortableServer::ObjectId_var id =
40 rootPOA->activate_object (&hello_i);
42 CORBA::Object_var object = rootPOA->id_to_reference (id.in ());
44 Test::Hello_var hello = Test::Hello::_narrow (object.in ());
46 // give our object a friendly name
47 CORBA::Object_var iorTableObj =
48 orb->resolve_initial_references ("IORTable");
50 IORTable::Table_var iorTable
51 = IORTable::Table::_narrow (iorTableObj.in ());
53 CORBA::String_var ior_string = orb->object_to_string (hello.in ());
55 iorTable->bind("hello", ior_string.in ());
57 ACE_DEBUG ((LM_DEBUG, "Created binding of name 'hello' in IOR table for IOR:\n%C\n", ior_string.in ()));
59 // Activate the POA manager
60 PortableServer::POAManager_var poaManager = rootPOA->the_POAManager ();
62 poaManager->activate ();
64 // try and access the object with its friendly name
65 ACE_CString full_corbaloc (ior_string.in (), 0, 1);
67 CORBA::ULong first_slash = full_corbaloc.find ("/", 0);
69 ACE_CString friendly_corbaloc =
70 full_corbaloc.substring (0,
71 first_slash);
73 friendly_corbaloc += "/hello";
75 ACE_DEBUG ((LM_DEBUG, "Trying to access object with object ref:\n%C\n", friendly_corbaloc.c_str ()));
77 CORBA::Object_var obj = orb->string_to_object (friendly_corbaloc.c_str ());
79 TimeBase::TimeT timeout = 10000000;
81 CORBA::Any timeout_any;
82 timeout_any <<= timeout;
84 CORBA::PolicyList policy_list (1);
85 policy_list.length (1);
87 policy_list[0] = orb->create_policy (
88 Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
89 timeout_any);
91 CORBA::Object_var rtt_obj = obj->_set_policy_overrides (
92 policy_list,
93 CORBA::SET_OVERRIDE);
95 policy_list[0]->destroy();
97 Test::Hello_var hello2 = Test::Hello::_narrow (rtt_obj.in ());
99 if (CORBA::is_nil (hello2.in ()))
101 ACE_ERROR ((LM_ERROR,
102 "Unable to narrow from "
103 "corbaloc with policy override\n"));
104 status = 1;
106 else
108 hello2->say_hello ();
110 ACE_DEBUG ((LM_DEBUG, "Test succeeded !!!\n"));
113 orb->destroy();
115 catch (const CORBA::Exception& ex)
117 ex._tao_print_exception ("Error - test failed - exception caught:");
118 status = 1;
121 return status;