3 //=============================================================================
7 * C++ client side for testing interoperability with wchar data.
9 * @author Phil Mesnier <mesnier_p@ociweb.com>
11 //=============================================================================
14 #include "interop_wcharC.h"
15 #include "wchar_reference.h"
17 #include "ace/Get_Opt.h"
18 #include "ace/Argv_Type_Converter.h"
20 const int WCHAR_TO_SERVER
= 0x00000001;
21 const int WSTRING_TO_SERVER
= 0x00000002;
22 const int WARRAY_TO_SERVER
= 0x00000004;
23 const int ANY_WCHAR_TO_SERVER
= 0x00000008;
24 const int WSTRING_EXCEPTION
= 0x00000010;
25 const int WCHAR_FROM_SERVER
= 0x00000020;
26 const int WSTRING_FROM_SERVER
= 0x00000040;
27 const int WARRAY_FROM_SERVER
= 0x00000080;
28 const int ANY_WCHAR_FROM_SERVER
= 0x00000100;
29 const int ANY_WSTRING_TO_SERVER
= 0x00000200;
30 const int ANY_WSTRING_FROM_SERVER
= 0x00000400;
31 const int ANY_WSTRING_ECHO
= 0x00000800;
32 const int WSTRUCTSEQ_FROM_SERVER
= 0x00001000;
33 const int WSTRUCTSEQ_TO_SERVER
= 0x00002000;
34 const int NUL_WSTRING_TO_SERVER
= 0x00004000;
35 const int TBD_16
= 0x00008000; // update ALL_TESTS if this is defined
36 const int TBD_15
= 0x00010000; // update ALL_TESTS if this is defined
37 const int TBD_14
= 0x00020000; // update ALL_TESTS if this is defined
38 const int TBD_13
= 0x00040000; // update ALL_TESTS if this is defined
39 const int TBD_12
= 0x00080000; // update ALL_TESTS if this is defined
40 const int TBD_11
= 0x00100000; // update ALL_TESTS if this is defined
41 const int TBD_10
= 0x00200000; // update ALL_TESTS if this is defined
42 const int TBD_9
= 0x00400000; // update ALL_TESTS if this is defined
43 const int TBD_8
= 0x00800000; // update ALL_TESTS if this is defined
44 const int TBD_7
= 0x01000000; // update ALL_TESTS if this is defined
45 const int TBD_6
= 0x02000000; // update ALL_TESTS if this is defined
46 const int TBD_5
= 0x04000000; // update ALL_TESTS if this is defined
47 const int TBD_4
= 0x08000000; // update ALL_TESTS if this is defined
48 const int TBD_3
= 0x10000000; // update ALL_TESTS if this is defined
49 const int TBD_2
= 0x20000000; // update ALL_TESTS if this is defined
50 const int TBD_1
= 0x40000000; // update ALL_TESTS if this is defined
51 const int TBD_0
= 0x80000000; // update ALL_TESTS if this is defined
53 const int ALL_TESTS
= 0x00007FFF;
55 // The length of this array determines which tests are run for "all tests"
56 const char * test_name
[] =
61 "any(wchar)_to_server",
64 "wstring_from_server",
66 "any(wchar)_from_server",
67 "any(wstring)_to_server",
68 "any(wstring)_from_server",
70 "wstructseq_from_server",
71 "wstructseq_to_server",
72 "nul_wstring_to_server"
75 const int LAST_TEST
= sizeof (test_name
) / sizeof (test_name
[0]);
76 const ACE_TCHAR
*ior
= ACE_TEXT("file://IOR");
82 #if defined (ACE_HAS_WCHAR) || defined (ACE_HAS_XPG4_MULTIBYTE_CHAR)
87 assign_wstruct (short key
, interop::wstruct
& ws
)
89 ws
.st_char
= ref
.get_wchar(key
);
90 ws
.st_string
= CORBA::wstring_dup(ref
.get_wstring(key
));
91 ref
.assign_warray(key
, ws
.st_array
);
92 ws
.st_any
<<= CORBA::wstring_dup(ref
.get_wstring(key
));
97 run_one_test (interop::WChar_Passer_ptr server
,
102 case WCHAR_TO_SERVER
:
103 return server
->wchar_to_server (ref
.get_wchar(data_set
), data_set
);
104 case WSTRING_TO_SERVER
:
105 return server
->wstring_to_server (ref
.get_wstring(data_set
), data_set
);
106 case WARRAY_TO_SERVER
:
107 return server
->warray_to_server (ref
.get_warray(data_set
), data_set
);
108 case ANY_WCHAR_TO_SERVER
:
111 a
<<= CORBA::Any::from_wchar(ref
.get_wchar(data_set
));
112 return server
->any_to_server (a
,data_set
);
114 case WSTRING_EXCEPTION
:
118 server
->exception_test(data_set
);
120 catch (const interop::WChar_Passer::WStringException
& e
)
122 return ref
.match_except (data_set
,e
.why
.in());
126 case WCHAR_FROM_SERVER
:
128 CORBA::WChar wc
= server
->wchar_from_server (data_set
);
129 return ref
.match_wchar (data_set
,wc
);
131 case WSTRING_FROM_SERVER
:
133 CORBA::WString_var ws
=
134 server
->wstring_from_server (data_set
);
135 return ref
.match_wstring (data_set
,ws
.in());
137 case WARRAY_FROM_SERVER
:
139 interop::warray_var wa
=
140 server
->warray_from_server (data_set
);
141 return ref
.match_warray (data_set
,wa
.in());
143 case ANY_WCHAR_FROM_SERVER
:
146 CORBA::Any_var test
= server
->any_from_server (data_set
,
148 if (test
>>= CORBA::Any::to_wchar(wc
))
150 return ref
.match_wchar (data_set
,wc
);
154 case ANY_WSTRING_TO_SERVER
:
157 a
<<= ref
.get_wstring(data_set
);
158 return server
->any_to_server (a
,data_set
);
160 case ANY_WSTRING_FROM_SERVER
:
162 const CORBA::WChar
*ws
;
163 CORBA::Any_var test
= server
->any_from_server (data_set
,
164 interop::is_wstring
);
167 return ref
.match_wstring (data_set
,ws
);
171 case ANY_WSTRING_ECHO
:
174 a
<<= ref
.get_wstring(data_set
);
175 const CORBA::WChar
*ws
;
176 CORBA::Any_var test
= server
->any_echo (a
);
179 return ref
.match_wstring (data_set
,ws
);
183 case WSTRUCTSEQ_FROM_SERVER
:
185 interop::wstructseq_var wsList
=
186 server
->wstructseq_from_server(data_set
);
189 for (CORBA::ULong i
= 0; i
< wsList
->length(); i
++)
190 result
&= ref
.match_wstring (data_set
,
191 wsList
[i
].st_string
.in());
195 case WSTRUCTSEQ_TO_SERVER
:
197 interop::wstructseq_var wsList
= new interop::wstructseq
;
199 for (CORBA::ULong i
= 0; i
< wsList
->length(); ++i
)
201 assign_wstruct(data_set
, (*wsList
)[i
]);
203 return server
->wstructseq_to_server(wsList
.in(), data_set
);
205 case NUL_WSTRING_TO_SERVER
:
206 return server
->wstring_to_server (L
"", -1);
214 run_tests (interop::WChar_Passer_ptr server
)
218 ref
.set_verbose (verbose
);
220 for (int i
= 0; i
< LAST_TEST
; i
++, t
<<= 1)
221 if ((tests_to_run
& t
) == t
)
223 CORBA::Boolean result
= run_one_test (server
,t
);
225 if (result
) ++successes
;
227 ACE_DEBUG ((LM_DEBUG
, "%s[%d] %s\n",
228 test_name
[i
],data_set
,
229 (result
? "passed" : "failed")));
232 ACE_DEBUG ((LM_DEBUG
, "Total of %d successes out of %d tests\n",
233 successes
, numtests
));
234 return successes
== numtests
;
236 #endif // ACE_HAS_WCHAR || ACE_HAS_XPG4_MULTIBYTE_CHAR
239 parse_args (int argc
, ACE_TCHAR
*argv
[])
241 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:t:vx"));
243 while ((c
= get_opts ()) != -1)
247 ior
= get_opts
.opt_arg ();
251 int tnum
= ACE_OS::atoi(get_opts
.opt_arg());
252 if (tnum
>= 0 && tnum
< LAST_TEST
)
253 tests_to_run
|= (1 << tnum
);
255 ACE_ERROR_RETURN ((LM_ERROR
,"test %d is out of range\n",tnum
),-1);
267 ACE_ERROR ((LM_ERROR
,
270 "[-t <0 <= test_num < %d>][ -t ...] "
274 argv
[0], LAST_TEST
));
275 ACE_ERROR ((LM_ERROR
, "Available tests:\n"));
276 for (int i
= 0; i
< LAST_TEST
; i
++)
277 ACE_ERROR ((LM_ERROR
, " %d - %s\n",i
, test_name
[i
]));
282 if (tests_to_run
== 0)
283 tests_to_run
= ALL_TESTS
;
284 // Indicates successful parsing of the command line
289 ACE_TMAIN( int argc
, ACE_TCHAR
*argv
[] )
291 #if (!defined ACE_HAS_WCHAR) && (!defined ACE_HAS_XPG4_MULTIBYTE_CHAR)
292 ACE_UNUSED_ARG (argc
);
293 ACE_UNUSED_ARG (argv
);
294 ACE_ERROR_RETURN ((LM_ERROR
,ACE_TEXT ("This test requires wchar support\n")),0);
299 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
300 if (parse_args(argc
, argv
) == -1)
304 CORBA::Object_var obj
= orb
->string_to_object(ior
);
305 if( CORBA::is_nil( obj
.in() ) )
306 ACE_ERROR_RETURN ((LM_ERROR
,
307 "arg is not a valid ior sting"),
311 interop::WChar_Passer_var server
=
312 interop::WChar_Passer::_narrow( obj
.in());
314 if( CORBA::is_nil( server
.in() ))
315 ACE_ERROR_RETURN ((LM_ERROR
,
316 "arg is not a interop::WChar_Passer reference\n"),
319 short result
= run_tests (server
.in());
320 CORBA::String_var server_orb
=
322 ACE_ERROR ((LM_ERROR
,
323 "wchar_interop test (TAO client, %C server) %C\n",
325 (result
? "passed" : "failed")));
331 catch (const CORBA::Exception
& ex
)
333 ex
._tao_print_exception ("Uncaught CORBA exception: ");