Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Abstract_Interface / client.cpp
blobc0de312983e201a6d6196240f87debe458666537
1 // -*- C++ -*-
2 #include "testC.h"
3 #include "ace/Get_Opt.h"
5 const ACE_TCHAR *ior_input_file = ACE_TEXT ("file://test.ior");
6 int debug = 0;
8 enum test_select
10 TEST_STATE,
11 TEST_OPERATION,
12 TEST_EXCEPTION,
13 TEST_ALL
16 test_select which_test = TEST_ALL;
18 int
19 parse_args (int argc, ACE_TCHAR *argv[])
21 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:dsoe"));
22 int c;
24 while ((c = get_opts ()) != -1)
25 switch (c)
27 case 'k':
28 ior_input_file = get_opts.optarg;
29 break;
30 case 'd':
31 debug = 1;
32 break;
33 case 's':
34 which_test = TEST_STATE;
35 break;
36 case 'o':
37 which_test = TEST_OPERATION;
38 break;
39 case 'e':
40 which_test = TEST_EXCEPTION;
41 break;
42 case '?':
43 default:
44 ACE_ERROR_RETURN ((LM_ERROR,
45 "usage: %s "
46 "-k <iorfile>",
47 argv [0]),
48 -1);
51 // Indicates successful parsing of the command line
52 return 0;
55 void
56 dump_node (BaseNode* bn, int indent)
58 if (bn == 0)
60 return;
63 StringNode* sn = StringNode::_downcast (bn);
65 if (debug)
67 // This is ugly I know
68 int i = indent;
69 for (; i != 0; --i) ACE_DEBUG ((LM_DEBUG, " "));
71 if (sn != 0)
73 ACE_DEBUG ((LM_DEBUG, "%x <StringNode> %C\n",
74 bn,
75 sn->name ()));
77 else
79 ACE_DEBUG ((LM_DEBUG,
80 "%x <BaseNode>\n",
81 bn));
85 dump_node (bn->left (),
86 indent + 1);
87 dump_node (bn->right (),
88 indent + 1);
91 void
92 dump_tree (TreeController *tc)
94 if (debug)
96 ACE_DEBUG ((LM_DEBUG,
97 "(%P|%t) start tree dump <%x>\n",
98 tc));
101 dump_node (tc->root (),
104 if (debug)
106 ACE_DEBUG ((LM_DEBUG,
107 "(%P|%t) end tree dump <%x>\n",
108 tc));
112 void
113 test_state (base_ptr abs)
115 CORBA::ValueBase_var vbase = abs->_to_value ();
116 TreeController *tc = TreeController::_downcast (vbase.in ());
117 dump_tree (tc);
120 void
121 test_operation (base_ptr abs)
123 CORBA::String_var retval = abs->base_op ("base_op");
125 if (debug)
127 ACE_DEBUG ((LM_DEBUG,
128 "%C\n",
129 retval.in ()));
132 CORBA::Object_var obj = abs->_to_object ();
134 foo_var concrete = foo::_narrow (obj.in ());
136 retval = concrete->foo_op ("foo_op");
138 if (debug)
140 ACE_DEBUG ((LM_DEBUG,
141 "%C\n",
142 retval.in ()));
145 retval = concrete->base_op ("base_op");
147 if (debug)
149 ACE_DEBUG ((LM_DEBUG,
150 "%C\n",
151 retval.in ()));
155 void
156 test_exception (base_ptr abs)
160 CORBA::String_var retval = abs->base_op ("bad_name");
162 if (debug)
164 ACE_DEBUG ((LM_DEBUG,
165 "%C\n",
166 retval.in ()));
169 catch (const BadInput& ex)
171 if (debug)
173 ACE_DEBUG ((LM_DEBUG,
174 "%C\n",
175 ex.message.in ()));
181 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
183 CORBA::String_var retval;
187 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
189 if (parse_args (argc, argv) != 0)
191 return 1;
194 CORBA::Object_var obj =
195 orb->string_to_object (ior_input_file);
197 if (CORBA::is_nil (obj.in ()))
199 ACE_ERROR_RETURN ((LM_ERROR,
200 "string_to_object failed.\n"),
201 -1);
204 passer_var objref = passer::_narrow (obj.in ());
206 if (CORBA::is_nil (objref.in ()))
208 ACE_ERROR_RETURN ((LM_ERROR,
209 "_narrow failed.\n"),
210 -1);
213 base_var package = base::_nil ();
215 if (which_test == TEST_STATE || which_test == TEST_ALL)
217 // Create and register factory for BaseNode.
218 BaseNode_init *bn_factory = 0;
219 ACE_NEW_RETURN (bn_factory,
220 BaseNode_init,
223 orb->register_value_factory (bn_factory->tao_repository_id (),
224 bn_factory);
225 bn_factory->_remove_ref (); // release ownership
227 // Create and register factory for TreeController.
228 TreeController_init *tc_factory = 0;
229 ACE_NEW_RETURN (tc_factory,
230 TreeController_init,
233 orb->register_value_factory (tc_factory->tao_repository_id (),
234 tc_factory);
235 tc_factory->_remove_ref (); // release ownership
237 // Create and register factory for StringNode.
238 StringNode_init *sn_factory = 0;
239 ACE_NEW_RETURN (sn_factory,
240 StringNode_init,
243 orb->register_value_factory (sn_factory->tao_repository_id (),
244 sn_factory);
245 sn_factory->_remove_ref (); // release ownership
247 objref->pass_state (package.out ());
249 if (CORBA::is_nil (package.in ()))
251 ACE_ERROR_RETURN ((LM_ERROR,
252 "pass_state() returned null OUT arg\n"),
253 -1);
256 test_state (package.in ());
259 if (which_test != TEST_STATE)
261 objref->pass_ops (package.out ());
263 if (CORBA::is_nil (package.in ()))
265 ACE_ERROR_RETURN ((LM_ERROR,
266 "pass_ops() returned null OUT arg\n"),
267 -1);
271 if (which_test == TEST_OPERATION || which_test == TEST_ALL)
273 test_operation (package.in ());
276 if (which_test == TEST_EXCEPTION || which_test == TEST_ALL)
278 test_exception (package.in ());
281 if (which_test == TEST_ALL)
283 objref->pass_nil (package.out ());
285 if (!CORBA::is_nil (package.in ()))
287 ACE_ERROR_RETURN ((LM_ERROR,
288 "pass_nil() did NOT return null OUT arg\n"),
289 -1);
293 objref->shutdown ();
295 orb->destroy ();
297 catch (const CORBA::Exception& ex)
299 ex._tao_print_exception ("Client: exception caught - ");
301 return 1;
304 return 0;