3 import org
.omg
.CORBA
.*;
10 * Java implemention of the interoperability tests for wchars.
12 * @author Phil Mesnier
18 private WCharReference ref
;
19 private org
.omg
.CORBA
.ORB orb
;
21 final private static int WCHAR_TO_SERVER
= 0x00000001;
22 final private static int WSTRING_TO_SERVER
= 0x00000002;
23 final private static int WARRAY_TO_SERVER
= 0x00000004;
24 final private static int ANY_WCHAR_TO_SERVER
= 0x00000008;
25 final private static int WSTRING_EXCEPTION
= 0x00000010;
26 final private static int WCHAR_FROM_SERVER
= 0x00000020;
27 final private static int WSTRING_FROM_SERVER
= 0x00000040;
28 final private static int WARRAY_FROM_SERVER
= 0x00000080;
29 final private static int ANY_WCHAR_FROM_SERVER
= 0x00000100;
30 final private static int ANY_WSTRING_TO_SERVER
= 0x00000200;
31 final private static int ANY_WSTRING_FROM_SERVER
= 0x00000400;
32 final private static int ANY_WSTRING_ECHO
= 0x00000800;
33 final private static int WSTRUCTSEQ_FROM_SERVER
= 0x00001000;
34 final private static int WSTRUCTSEQ_TO_SERVER
= 0x00002000;
35 final private static int NUL_WSTRING_TO_SERVER
= 0x00004000;
36 final private static int TBD_16
= 0x00008000; // update ALL_TESTS if this is defined
37 final private static int TBD_15
= 0x00010000; // update ALL_TESTS if this is defined
38 final private static int TBD_14
= 0x00020000; // update ALL_TESTS if this is defined
39 final private static int TBD_13
= 0x00040000; // update ALL_TESTS if this is defined
40 final private static int TBD_12
= 0x00080000; // update ALL_TESTS if this is defined
41 final private static int TBD_11
= 0x00100000; // update ALL_TESTS if this is defined
42 final private static int TBD_10
= 0x00200000; // update ALL_TESTS if this is defined
43 final private static int TBD_9
= 0x00400000; // update ALL_TESTS if this is defined
44 final private static int TBD_8
= 0x00800000; // update ALL_TESTS if this is defined
45 final private static int TBD_7
= 0x01000000; // update ALL_TESTS if this is defined
46 final private static int TBD_6
= 0x02000000; // update ALL_TESTS if this is defined
47 final private static int TBD_5
= 0x04000000; // update ALL_TESTS if this is defined
48 final private static int TBD_4
= 0x08000000; // update ALL_TESTS if this is defined
49 final private static int TBD_3
= 0x10000000; // update ALL_TESTS if this is defined
50 final private static int TBD_2
= 0x20000000; // update ALL_TESTS if this is defined
51 final private static int TBD_1
= 0x40000000; // update ALL_TESTS if this is defined
52 final private static int TBD_0
= 0x80000000; // update ALL_TESTS if this is defined
54 final private static int ALL_TESTS
= 0x00007FFF;
56 // for all tests, run each test named in this array
57 final private static String 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 private int tests_to_run
= 0;
76 private short data_set
= 0;
77 private boolean verbose
= false;
79 private boolean runOneTest (WChar_Passer server
, int test_num
)
81 if (test_num
> ALL_TESTS
)
86 case 0x00000001: //WCHAR_TO_SERVER:
88 return server
.wchar_to_server (ref
.get_wchar(data_set
),
91 case 0x00000002: //WSTRING_TO_SERVER:
93 return server
.wstring_to_server (ref
.get_wstring(data_set
),
96 case 0x00000004: //WARRAY_TO_SERVER:
98 return server
.warray_to_server (ref
.get_warray(data_set
),
101 case 0x00000008: //ANY_WCHAR_TO_SERVER:
103 Any a
= orb
.create_any();
104 a
.insert_wchar (ref
.get_wchar(data_set
));
105 return server
.any_to_server (a
,data_set
);
107 case 0x00000010: //WSTRING_EXCEPTION:
111 server
.exception_test(data_set
);
113 catch (interop
.WChar_PasserPackage
.WStringException ex
)
115 return ref
.match_except (data_set
,ex
.why
);
119 case 0x00000020: // WCHAR_FROM_SERVER:
121 char wc
= server
.wchar_from_server (data_set
);
122 return ref
.match_wchar (data_set
,wc
);
124 case 0x00000040: //WSTRING_FROM_SERVER:
126 String ws
= server
.wstring_from_server (data_set
);
127 return ref
.match_wstring (data_set
,ws
);
129 case 0x00000080: //WARRAY_FROM_SERVER:
131 char wa
[] = server
.warray_from_server (data_set
);
132 return ref
.match_warray (data_set
,wa
);
134 case 0x00000100: // ANY_WCHAR_FROM_SERVER:
137 System
.out
.println (" not yet implemented");
140 case 0x00000200: // ANY_WSTRING_TO_SERVER:
143 System
.out
.println (" not yet implemented");
146 case 0x00000400: // ANY_WSTRING_FROM_SERVER:
149 System
.out
.println (" not yet implemented");
152 case 0x00000800: // ANY_WSTRING_ECHO:
154 char[] h
= {'\u05D1', '\u05D2', '\u05D3'};
155 String test
= "\u05D1\u05D2\u05D3";
157 System
.out
.println ("Test string = " + test
);
158 Any a
= orb
.create_any();
159 a
.insert_string (test
);
160 a
= server
.any_echo (a
);
161 String echo
= a
.extract_string ();
163 System
.out
.println ("Echo string = " + echo
);
164 return test
.equals(echo
);
166 case 0x00001000: // WSTRUCTSEQ_FROM_SERVER
169 server
.wstructseq_from_server(data_set
);
170 boolean result
= true;
171 for (int i
= 0; i
< wsList
.length
; i
++)
173 ref
.match_wstring (data_set
,
174 wsList
[i
].st_string
);
177 case 0x00002000: // WSTRUCTSEQ_TO_SERVER
179 wstruct wsList
[] = new wstruct
[5];
180 for (int i
= 0; i
< wsList
.length
; ++i
)
182 wsList
[i
] = get_wstruct(data_set
);
184 System
.out
.println ("initialized wsList[" + i
+ "] : " + wsList
[i
]);
186 return server
.wstructseq_to_server(wsList
, data_set
);
189 case 0x00004000: // NUL_WSTRING_TO_SERVER
191 return server
.wstring_to_server ("", (short)-1);
196 System
.out
.println (" not yet implemented");
204 public boolean runTests (WChar_Passer server
)
208 ref
.set_verbose (verbose
);
210 for (int i
= 0; i
< test_name
.length
; i
++, t
<<= 1)
211 if ((tests_to_run
& t
) == t
)
214 System
.out
.println ("test " + test_name
[i
]);
215 boolean result
= runOneTest (server
,t
);
217 if (result
) ++successes
;
219 System
.out
.println (test_name
[i
] +
220 "[" + data_set
+ "] " +
221 (result ?
"passed" : "failed"));
224 System
.out
.println ("Total of " + successes
+
225 " successes out of " + numtests
+ " tests");
226 return successes
== numtests
;
229 // TODO: this should have a home where it's accessable to both
230 // client & server, but it doesn't belong in WCharReference
231 public wstruct
get_wstruct (short key
)
233 wstruct result
= new wstruct();
235 result
.st_char
= ref
.get_wchar(key
);
236 result
.st_string
= ref
.get_wstring(key
);
237 result
.st_array
= ref
.get_warray(key
);
238 result
.st_any
= orb
.create_any();
239 result
.st_any
.insert_wstring(ref
.get_wstring(key
));
244 // TODO: this should have a home where it's accessable to both
245 // client & server, but it doesn't belong in WCharReference
246 public boolean match_wstruct (short key
, wstruct test
)
248 boolean result
= ref
.match_wchar(key
, test
.st_char
);
249 result
&= ref
.match_wstring(key
, test
.st_string
);
250 result
&= ref
.match_warray(key
, test
.st_array
);
251 // @@ todo result &= ref.match_wstring (key, test.st_any.extract_wstring());
256 public void run(String
[] args
)
259 String iorfile
= "IOR";
260 boolean kill_server
= false;
262 for (int i
= 0; i
< args
.length
; i
++)
264 if (args
[i
].equals ("-i"))
266 else if (args
[i
].equals ("-v"))
268 else if (args
[i
].equals ("-x"))
270 else if (args
[i
].equals ("-t"))
272 int tnum
= Integer
.decode(args
[++i
]).intValue();
273 if (tnum
>= 0 && tnum
< test_name
.length
)
274 tests_to_run
|= (1 << tnum
);
278 System
.out
.println( "Usage: jaco interop.wchar.Client " +
280 "-t <0 <= num < " + test_name
.length
+ "> " +
283 System
.out
.println ("Available tests:");
284 for (int j
= 0; i
< test_name
.length
; i
++)
285 System
.out
.println (j
+ " - " + test_name
[i
]);
289 if (tests_to_run
== 0)
290 tests_to_run
= ALL_TESTS
;
292 File f
= new File(iorfile
);
294 //check if file exists
297 System
.out
.println("File " + iorfile
+
302 //check if args[0] points to a directory
303 if( f
.isDirectory() )
305 System
.out
.println("File " + iorfile
+
310 // initialize the ORB.
311 orb
= org
.omg
.CORBA
.ORB
.init( args
, null );
312 ref
= new WCharReference(verbose
);
315 new BufferedReader( new FileReader( f
));
317 // get object reference from command-line argument file
318 org
.omg
.CORBA
.Object obj
=
319 orb
.string_to_object( br
.readLine() );
323 WChar_Passer wp
= WChar_PasserHelper
.narrow( obj
);
325 boolean result
= runTests (wp
);
326 System
.out
.println ("wchar_interop test (Java client, " +
327 wp
.orb_name() + " server) " +
328 (result ?
"passed" : "failed"));
332 public static void main( String
[] args
)
335 Client client
= new Client();