Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Faults / client.cpp
blobe935a3990ef6e861205702d56dde28255e2770ed
1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_unistd.h"
4 #include "test_i.h"
6 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
7 int niterations = 10;
8 int do_shutdown = 0;
9 int do_suicide = 0;
10 int do_self_shutdown = 0;
11 int do_abort = 0;
12 int do_crash = 0;
14 int
15 parse_args (int argc, ACE_TCHAR *argv[])
17 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("acszxk:i:"));
18 int c;
20 while ((c = get_opts ()) != -1)
21 switch (c)
23 case 'a':
24 do_abort = 1;
25 break;
27 case 'c':
28 do_crash = 1;
29 break;
31 case 'x':
32 do_shutdown = 1;
33 break;
35 case 's':
36 do_suicide = 1;
37 break;
39 case 'z':
40 do_self_shutdown = 1;
41 break;
43 case 'k':
44 ior = get_opts.opt_arg ();
45 break;
47 case 'i':
48 niterations = ACE_OS::atoi (get_opts.opt_arg ());
49 break;
51 case '?':
52 default:
53 ACE_ERROR_RETURN ((LM_ERROR,
54 "usage: %s "
55 "[-a] [-c] [-x] [-s] [-z] "
56 "-k <ior> "
57 "-i <niterations> "
58 "\n",
59 argv [0]),
60 -1);
62 // Indicates successful parsing of the command line
63 return 0;
66 int
67 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
69 try
71 CORBA::ORB_var orb =
72 CORBA::ORB_init (argc, argv);
74 CORBA::Object_var poa_object =
75 orb->resolve_initial_references("RootPOA");
77 if (CORBA::is_nil (poa_object.in ()))
78 ACE_ERROR_RETURN ((LM_ERROR,
79 " (%P|%t) Unable to initialize the POA.\n"),
80 1);
82 PortableServer::POA_var root_poa =
83 PortableServer::POA::_narrow (poa_object.in ());
85 PortableServer::POAManager_var poa_manager =
86 root_poa->the_POAManager ();
88 poa_manager->activate ();
90 if (parse_args (argc, argv) != 0)
91 return 1;
93 CORBA::Object_var object =
94 orb->string_to_object (ior);
96 Simple_Server_var server =
97 Simple_Server::_narrow (object.in ());
99 if (CORBA::is_nil (server.in ()))
101 ACE_ERROR_RETURN ((LM_ERROR,
102 "Object reference <%s> is nil.\n",
103 ior),
107 Callback_i callback_impl (orb.in ());
109 PortableServer::ObjectId_var id =
110 root_poa->activate_object (&callback_impl);
112 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
114 Callback_var callback =
115 Callback::_narrow (object_act.in ());
117 for (int i = 0; i != niterations; ++i)
119 CORBA::Long r =
120 server->test_method (0, 0, callback.in ());
122 if (r != 0)
124 ACE_DEBUG ((LM_DEBUG,
125 "(%P|%t) unexpected result = %d for %d",
126 r, i));
130 if (do_abort)
134 server->shutdown_now (0);
136 catch (const CORBA::COMM_FAILURE&)
138 // Expected exception, continue....
141 else if (do_crash)
145 server->shutdown_now (1);
147 catch (const CORBA::COMM_FAILURE&)
149 // Expected exception, continue....
152 else if (do_suicide)
154 (void) server->test_method (1, 0, callback.in ());
155 // The shutdown callback could arrive after this twoway invocation
156 // returned. Wait for it shutdown callback and abort,
157 // otherwise it will timeout (in run_test.pl).
158 ACE_OS::sleep (120);
160 else if (do_self_shutdown)
162 (void) server->test_method (1, 1, callback.in ());
165 if (do_shutdown)
167 server->shutdown ();
170 root_poa->destroy (true, true);
172 catch (const CORBA::COMM_FAILURE& x)
174 // For other case this is expected.
175 if (do_self_shutdown == 0)
177 x._tao_print_exception ("ERROR: Unexpected exception\n");
180 catch (const CORBA::Exception& ex)
182 ex._tao_print_exception ("Exception caught in client:");
183 return -1;
186 return 0;