Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / PICurrent / client.cpp
blob50e5b30603f5858a54af7d2db8f654fc455510d7
1 // -*- C++ -*-
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_unistd.h"
5 #include "testC.h"
6 #include "ClientORBInitializer.h"
8 #include "tao/ORBInitializer_Registry.h"
9 #include "tao/PI/PI.h"
11 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
13 int
14 parse_args (int argc, ACE_TCHAR *argv[])
16 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
17 int c;
19 while ((c = get_opts ()) != -1)
20 switch (c)
22 case 'k':
23 ior = get_opts.opt_arg ();
24 break;
25 default:
26 ACE_ERROR_RETURN ((LM_ERROR,
27 "Usage: %s "
28 "-k IOR "
29 "\n",
30 argv[0]),
31 -1);
33 return 0;
36 int
37 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
39 try
41 PortableInterceptor::ORBInitializer_ptr temp_initializer =
42 PortableInterceptor::ORBInitializer::_nil ();
44 ACE_NEW_RETURN (temp_initializer,
45 ClientORBInitializer,
46 -1); // No exceptions yet!
47 PortableInterceptor::ORBInitializer_var orb_initializer =
48 temp_initializer;
50 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
52 CORBA::ORB_var orb =
53 CORBA::ORB_init (argc,
54 argv,
55 "client_orb");
57 if (parse_args (argc, argv) != 0)
58 return 1;
60 // Get the PICurrent object.
61 CORBA::Object_var obj =
62 orb->resolve_initial_references ("PICurrent");
64 PortableInterceptor::Current_var pi_current =
65 PortableInterceptor::Current::_narrow (obj.in ());
67 if (CORBA::is_nil (pi_current.in ()))
69 ACE_ERROR_RETURN ((LM_ERROR,
70 "(%P|%t) ERROR: Could not resolve "
71 "PICurrent object.\n"),
72 -1);
75 // Insert some data into the allocated PICurrent slot.
76 CORBA::Any data;
77 CORBA::Long number = 46;
79 data <<= number;
81 // Now reset the contents of our slot in the thread-scope
82 // current (TSC).
83 pi_current->set_slot (::slot_id,
84 data);
86 // Resolve the target object, and perform the invocation.
87 obj =
88 orb->string_to_object (ior);
90 PICurrentTest::test_var server =
91 PICurrentTest::test::_narrow (obj.in ());
93 if (CORBA::is_nil (server.in ()))
95 ACE_ERROR_RETURN ((LM_ERROR,
96 "Object reference <%s> is nil.\n",
97 ior),
98 1);
101 // BUG 2656 testing - _get_policy_overrides() should return an empty
102 // sequence rather than nill.
103 CORBA::PolicyTypeSeq types;
104 CORBA::PolicyList_var policies = server->_get_policy_overrides(types);
106 if (policies.ptr () == 0)
108 ACE_ERROR ((LM_ERROR,
109 "(%P|%t) _get_policy_overrides returned nill pointer\n"));
110 throw CORBA::INTERNAL ();
112 else
114 CORBA::ULong const list_size = policies->length();
115 if (list_size != 0)
117 ACE_ERROR ((LM_ERROR,
118 "(%P|%t) _get_policy_overrides returned list with size not equal 0\n"));
119 throw CORBA::INTERNAL ();
123 server->invoke_me ();
125 CORBA::Any_var new_data =
126 pi_current->get_slot (::slot_id);
128 // The original data in the TSC was of type CORBA::Long. If the
129 // following extraction from the CORBA::Any fails, then the
130 // original data in the TSC was not replaced within the client
131 // request interceptor, as this test should do.
132 const char *str = 0;
133 if (new_data.in () >>= str)
135 ACE_DEBUG ((LM_DEBUG,
136 "(%P|%t) Retrieved \"%C\" from the TSC.\n",
137 str));
139 else
141 ACE_ERROR ((LM_ERROR,
142 "(%P|%t) Unable to extract data (a string) "
143 "from the TSC.\n"));
145 throw CORBA::INTERNAL ();
148 server->invoke_we ();
150 server->shutdown ();
152 ACE_OS::sleep(1);
153 orb->destroy ();
155 catch (const CORBA::Exception& ex)
157 ex._tao_print_exception ("PICurrent test (client-side):");
158 return -1;
161 return 0;