Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / DSI_Gateway / client.cpp
blobaac67ece8cfdd3a5508c4004868dc452b6bf1a9f
1 #include "testC.h"
2 #include "tao/debug.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/Task.h"
6 const ACE_TCHAR *ior = ACE_TEXT("file://gateway.ior");
7 int niterations = 5;
8 int do_shutdown = 0;
9 int test_user_exception = 0;
10 int test_system_exception = 0;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("xusk:i:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'x':
22 do_shutdown = 1;
23 break;
25 case 'u':
26 test_user_exception = 1;
27 break;
29 case 's':
30 test_system_exception = 1;
31 break;
33 case 'k':
34 ior = get_opts.opt_arg ();
35 break;
37 case 'i':
38 niterations = ACE_OS::atoi (get_opts.opt_arg ());
39 break;
41 case '?':
42 default:
43 ACE_ERROR_RETURN ((LM_ERROR,
44 "usage: %s "
45 "-x "
46 "-u "
47 "-s "
48 "-k <ior> "
49 "-i <niterations> "
50 "\n",
51 argv [0]),
52 -1);
55 // Indicates successful parsing of the command line
56 return 0;
59 int
60 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
62 try
64 CORBA::ORB_var orb =
65 CORBA::ORB_init (argc, argv);
67 if (parse_args (argc, argv) != 0)
69 return 1;
72 CORBA::Object_var object =
73 orb->string_to_object (ior);
75 Simple_Server_var server =
76 Simple_Server::_narrow (object.in ());
78 if (CORBA::is_nil (server.in ()))
80 ACE_ERROR_RETURN ((LM_ERROR,
81 "Object reference <%s> is nil.\n",
82 ior),
83 1);
86 Structure the_in_structure;
87 the_in_structure.seq.length (10);
89 if (test_user_exception == 1)
91 server->raise_user_exception ();
93 else if (test_system_exception == 1)
95 server->raise_system_exception ();
97 else
99 for (int i = 0; i != niterations; ++i)
101 CORBA::Long const tv = i + 100;
102 server->test_val(tv);
103 CORBA::Long const rtv = server->test_val ();
105 if (TAO_debug_level > 0)
107 ACE_DEBUG ((LM_DEBUG,
108 "DSI_Simpler_Server ==== Expected result = %d for %d\n",
109 rtv, tv));
112 if (rtv != tv)
114 ACE_ERROR ((LM_ERROR,
115 "(%P|%t) ERROR: unexpected result = %d for %d\n",
116 rtv, tv));
119 the_in_structure.i = i;
120 CORBA::String_var name = CORBA::string_dup ("the name");
122 Structure_var the_out_structure;
124 CORBA::Long const r =
125 server->test_method (i,
126 the_in_structure,
127 the_out_structure.out (),
128 name.inout ());
130 if (TAO_debug_level > 0)
132 ACE_DEBUG ((LM_DEBUG,
133 "DSI_Simpler_Server ====\n"
134 " x = %d\n"
135 " i = %d\n"
136 " length = %d\n"
137 " name = <%C>\n",
139 the_out_structure->i,
140 the_out_structure->seq.length (),
141 name.in ()));
144 if (r != i)
146 ACE_ERROR ((LM_ERROR,
147 "(%P|%t) ERROR: unexpected result = %d for %d",
148 r, i));
153 if (do_shutdown)
155 server->shutdown ();
158 catch (const test_exception& ex)
160 if (test_user_exception == 1)
161 ACE_DEBUG ((LM_DEBUG,
162 "Client: caught expected user exception: %C\n",
163 ex._name()));
164 else
165 ex._tao_print_exception ("Client: exception caught - ");
167 ACE_DEBUG ((LM_DEBUG,
168 "error code: %d\n"
169 "error info: %C\n"
170 "status: %C\n",
171 ex.error_code,
172 ex.error_message.in (),
173 ex.status_message.in ()));
175 return test_user_exception == 1 ? 0 : 1;
177 catch (const CORBA::NO_PERMISSION& ex)
179 if (test_system_exception == 1)
180 ACE_DEBUG ((LM_DEBUG,
181 "Client: caught expected system exception: %C\n",
182 ex._name()));
183 else
184 ex._tao_print_exception ("Client: exception caught - ");
185 return test_system_exception == 1 ? 0 : 1;
187 catch (const CORBA::Exception& ex)
189 ex._tao_print_exception ("Client: exception caught - ");
190 return 1;
193 return 0;