Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Dynamic / client.cpp
blob0917bb12eaf4f5fb1585a60d379fdc99695f2ebf
1 #include "ace/Get_Opt.h"
3 #include "testC.h"
4 #include "Echo_Client_ORBInitializer.h"
6 #include "tao/ORBInitializer_Registry.h"
8 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("ef:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'e':
20 break;
21 case 'f':
22 ior = get_opts.opt_arg ();
23 break;
24 case '?':
25 default:
26 ACE_ERROR_RETURN ((LM_ERROR,
27 "usage: %s "
28 "-v "
29 "\n",
30 argv [0]),
31 -1);
33 return 0;
36 void
37 run_test (Test_Interceptors::Visual_ptr server)
39 CORBA::String_var msg;
41 server->normal (10, msg.out ());
43 CORBA::Long one = 1, two = 1, result = 0;
44 result = server->calculate (one, two);
46 ACE_DEBUG ((LM_DEBUG,
47 "calculate() result = %d\n",
48 result));
50 Test_Interceptors::Visual::VarLenStruct_var v =
51 server->the_structure ();
53 ACE_DEBUG ((LM_DEBUG,
54 "the_structure() result is:\n"
55 " flag = %d\n"
56 " message = %C\n",
57 v->flag,
58 v->message.in ()));
60 try
62 server->user ();
64 catch (const Test_Interceptors::Silly&)
66 ACE_DEBUG ((LM_DEBUG, "Caught Silly\n"));
69 try
71 server->system ();
73 catch (const CORBA::INV_OBJREF&)
75 ACE_DEBUG ((LM_DEBUG, "Caught CORBA::INV_OBJREF\n"));
79 int
80 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
82 int result = 0;
84 try
86 #if TAO_HAS_INTERCEPTORS == 1
87 PortableInterceptor::ORBInitializer_ptr temp_initializer =
88 PortableInterceptor::ORBInitializer::_nil ();
90 ACE_NEW_RETURN (temp_initializer,
91 Echo_Client_ORBInitializer (result),
92 -1); // No exceptions yet!
93 PortableInterceptor::ORBInitializer_var orb_initializer =
94 temp_initializer;
96 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
97 #endif /* TAO_HAS_INTERCEPTORS == 1 */
99 CORBA::ORB_var orb =
100 CORBA::ORB_init (argc, argv);
102 if (parse_args (argc, argv) != 0)
103 return 1;
105 CORBA::Object_var object =
106 orb->string_to_object (ior);
108 Test_Interceptors::Visual_var server =
109 Test_Interceptors::Visual::_narrow (object.in ());
111 if (CORBA::is_nil (server.in ()))
113 ACE_ERROR_RETURN ((LM_ERROR,
114 "Object reference <%s> is nil.\n",
115 ior),
119 run_test (server.in ());
121 server->shutdown ();
123 orb->destroy ();
125 catch (const CORBA::Exception& ex)
127 ex._tao_print_exception ("Caught exception:");
128 return 1;
131 return result;