4
* Copyright Ericsson AB 2003-2011. All Rights Reserved.
6
* The contents of this file are subject to the Erlang Public License,
7
* Version 1.1, (the "License"); you may not use this file except in
8
* compliance with the License. You should have received a copy of the
9
* Erlang Public License along with this software. If not, it can be
10
* retrieved online at http://www.erlang.org/.
12
* Software distributed under the License is distributed on an "AS IS"
13
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
* the License for the specific language governing rights and limitations
20
public class JavaClient {
22
public static void main(String[] argv)
24
System.out.println("Hello World!");
25
if (argv.length < 4) {
26
System.out.println("Too few arguments!");
29
// for (int j = 0; j < argv.length; j++)
30
// System.out.println(argv[j]);
32
if (argv[3].equals("marshal_ll")) {
33
System.out.println("marshal_ll");
34
marshal_ll(argv[0], argv[1], argv[2], argv[3]);
36
else if (argv[3].equals("marshal_ull")) {
37
marshal_ull(argv[0], argv[1], argv[2], argv[3]);
39
else if (argv[3].equals("marshal_l")) {
40
marshal_l(argv[0], argv[1], argv[2], argv[3]);
42
else if (argv[3].equals("marshal_ul")) {
43
marshal_ul(argv[0], argv[1], argv[2], argv[3]);
45
else if (argv[3].equals("marshal_s")) {
46
marshal_s(argv[0], argv[1], argv[2], argv[3]);
48
else if (argv[3].equals("marshal_us")) {
49
marshal_us(argv[0], argv[1], argv[2], argv[3]);
51
else if (argv[3].equals("marshal_c")) {
52
marshal_c(argv[0], argv[1], argv[2], argv[3]);
54
else if (argv[3].equals("marshal_wc")) {
55
marshal_wc(argv[0], argv[1], argv[2], argv[3]);
57
else if (argv[3].equals("marshal_str")) {
58
marshal_str(argv[0], argv[1], argv[2], argv[3]);
60
else if (argv[3].equals("marshal_any_3")) {
61
marshal_any_3(argv[0], argv[1], argv[2], argv[3]);
63
else if (argv[3].equals("marshal_any_2")) {
64
marshal_any_2(argv[0], argv[1], argv[2], argv[3]);
67
System.out.println("Unknown test: "+argv[3]);
70
} catch (java.lang.Exception e) {
71
System.out.println("Exception!: "+e);
79
static void marshal_ll(String selfNode, String peerNode,
80
String cookie, String serverName)
81
throws java.lang.Exception
83
m._iStub i = new m._iStub(selfNode, peerNode, cookie, serverName);
85
System.out.println("Just warming up.."+i);
86
verify_ll(i, 3, 2, 1);
87
verify_ll(i, 5, 4, 3);
88
verify_ll(i, -128, 0, 1);
89
// The small integer border
90
verify_ll(i, 255, 0, 1);
91
verify_ll(i, 256, 0, 1);
93
verify_ll(i, (1L<<26)-1L, 0L, 1);
94
verify_ll(i, 1L<<26, 0L, 1);
95
verify_ll(i, -(1L<<26), 0L, 1);
96
verify_ll(i, (1L<<27)-1L, 0L, 1);
97
verify_ll(i, 1L<<27, 0L, 1);
98
verify_ll(i, -(1L<<27), 0L, 1);
99
// Bignum byte borders
100
verify_ll(i, (1L<<32)-1L, 0L, 1);
101
verify_ll(i, 1L<<32, 0L, 1);
102
verify_ll(i, -(1L<<32)+1L, 0L, 1);
103
verify_ll(i, -(1L<<32), 0L, 1);
104
verify_ll(i, (1L<<40)-1L, 0L, 1);
105
verify_ll(i, 1L<<40, 0L, 1);
106
verify_ll(i, -(1L<<40)+1L, 0L, 1);
107
verify_ll(i, -(1L<<40), 0L, 1);
108
verify_ll(i, (1L<<48)-1L, 0L, 1);
109
verify_ll(i, 1L<<48, 0L, 1);
110
verify_ll(i, -(1L<<48)+1L, 0L, 1);
111
verify_ll(i, -(1L<<48), 0L, 1);
113
verify_ll(i, java.lang.Long.MAX_VALUE, 0L, 1);
114
verify_ll(i, java.lang.Long.MIN_VALUE, 0L, 1);
115
verify_ll(i, -1L, 0L, 1);
116
// Impossible decodes
117
verify_ll_bad(i, java.lang.Long.MAX_VALUE, -1L, 1);
118
verify_ll_bad(i, java.lang.Long.MIN_VALUE, 1L, 1);
119
verify_ll_bad(i, java.lang.Long.MIN_VALUE, 0L, -1);
120
verify_ll_bad(i, java.lang.Long.MAX_VALUE, -1L, 2);
121
verify_ll_bad(i, java.lang.Long.MIN_VALUE, 0L, 2);
124
static void marshal_ull(String selfNode, String peerNode,
125
String cookie, String serverName)
126
throws java.lang.Exception
128
m._iStub i = new m._iStub(selfNode, peerNode, cookie, serverName);
130
verify_ull(i, 3, 2, 1);
131
verify_ull(i, 5, 4, 3);
132
// The small integer border
133
verify_ull(i, 255, 0, 1);
134
verify_ull(i, 256, 0, 1);
135
// The integer border
136
verify_ull(i, (1L<<26)-1L, 0L, 1);
137
verify_ull(i, 1L<<26, 0L, 1);
138
verify_ull(i, (1L<<27)-1L, 0L, 1);
139
verify_ull(i, 1L<<27, 0L, 1);
140
// Bignum byte borders
141
verify_ull(i, (1L<<32)-1L, 0L, 1);
142
verify_ull(i, 1L<<32, 0L, 1);
143
verify_ull(i, (1L<<40)-1L, 0L, 1);
144
verify_ull(i, 1L<<40, 0L, 1);
145
verify_ull(i, (1L<<48)-1L, 0L, 1);
146
verify_ull(i, 1L<<48, 0L, 1);
148
verify_ull(i, java.lang.Long.MAX_VALUE, 0L, 1);
149
verify_ull(i, java.lang.Long.MIN_VALUE, 0L, 1);
150
verify_ull(i, -1L, 0L, 1);
151
verify_ull(i, java.lang.Long.MAX_VALUE,
152
java.lang.Long.MIN_VALUE, 1);
153
// Impossible decodes
154
verify_ull_bad(i, -1L, -1L, 1);
155
verify_ull_bad(i, java.lang.Long.MAX_VALUE, -1L, 2);
158
static void marshal_l(String selfNode, String peerNode,
159
String cookie, String serverName)
160
throws java.lang.Exception
162
m._iStub i = new m._iStub(selfNode, peerNode, cookie, serverName);
164
verify_l(i, 3, 2, 1);
165
verify_l(i, 5, 4, 3);
166
verify_l(i, -128, 0, 1);
167
// The small integer border
168
verify_l(i, 255, 0, 1);
169
verify_l(i, 256, 0, 1);
170
// The integer border
171
verify_l(i, (1<<26)-1, 0, 1);
172
verify_l(i, 1<<26, 0, 1);
173
verify_l(i, -(1<<26), 0, 1);
174
verify_l(i, (1<<27)-1, 0, 1);
175
verify_l(i, 1<<27, 0, 1);
176
verify_l(i, -(1<<27), 0, 1);
178
verify_l(i, java.lang.Integer.MAX_VALUE, 0, 1);
179
verify_l(i, java.lang.Integer.MIN_VALUE, 0, 1);
180
// Impossible decodes
181
verify_l_bad(i, java.lang.Integer.MAX_VALUE, -1, 1);
182
verify_l_bad(i, java.lang.Integer.MIN_VALUE, 1, 1);
183
verify_l_bad(i, java.lang.Integer.MIN_VALUE, 0, -1);
186
static void marshal_ul(String selfNode, String peerNode,
187
String cookie, String serverName)
188
throws java.lang.Exception
190
m._iStub i = new m._iStub(selfNode, peerNode, cookie, serverName);
192
verify_ul(i, 3, 2, 1);
193
verify_ul(i, 5, 4, 3);
194
// The small integer border
195
verify_ul(i, 255, 0, 1);
196
verify_ul(i, 256, 0, 1);
197
// The integer border
198
verify_ul(i, (1<<26)-1, 0, 1);
199
verify_ul(i, 1<<26, 0, 1);
200
verify_ul(i, (1<<27)-1, 0, 1);
201
verify_ul(i, 1<<27, 0, 1);
203
verify_ul(i, java.lang.Integer.MAX_VALUE, 0, 1);
204
verify_ul(i, java.lang.Integer.MIN_VALUE, 0, 1);
205
verify_ul(i, -1, 0, 1);
206
verify_ul(i, java.lang.Integer.MAX_VALUE,
207
java.lang.Integer.MIN_VALUE, 1);
208
// Impossible decodes
209
verify_ul_bad(i, -1, -1, 1);
212
static void marshal_s(String selfNode, String peerNode,
213
String cookie, String serverName)
214
throws java.lang.Exception
216
m._iStub i = new m._iStub(selfNode, peerNode, cookie, serverName);
218
verify_s(i, 3, 2, 1);
219
verify_s(i, 5, 4, 3);
220
verify_s(i, -128, 0, 1);
221
// The small integer border
222
verify_s(i, 255, 0, 1);
223
verify_s(i, 256, 0, 1);
225
verify_s(i, java.lang.Short.MAX_VALUE, 0, 1);
226
verify_s(i, java.lang.Short.MIN_VALUE, 0, 1);
227
// Impossible decodes
228
verify_s_bad(i, java.lang.Short.MAX_VALUE, -1, 1);
229
verify_s_bad(i, java.lang.Short.MIN_VALUE, 1, 1);
230
verify_s_bad(i, java.lang.Short.MIN_VALUE, 0, -1);
233
static void marshal_us(String selfNode, String peerNode,
234
String cookie, String serverName)
235
throws java.lang.Exception
237
m._iStub i = new m._iStub(selfNode, peerNode, cookie, serverName);
239
verify_us(i, 3, 2, 1);
240
verify_us(i, 5, 4, 3);
241
// The small integer border
242
verify_us(i, 255, 0, 1);
243
verify_us(i, 256, 0, 1);
245
verify_us(i, java.lang.Short.MAX_VALUE, 0, 1);
246
verify_us(i, java.lang.Short.MIN_VALUE, 0, 1);
247
verify_us(i, -1, 0, 1);
248
verify_us(i, java.lang.Short.MAX_VALUE,
249
java.lang.Short.MIN_VALUE, 1);
250
// Impossible decodes
251
verify_us_bad(i, -1, -1, 1);
254
static void marshal_c(String selfNode, String peerNode,
255
String cookie, String serverName)
256
throws java.lang.Exception
258
m._iStub i = new m._iStub(selfNode, peerNode, cookie, serverName);
260
verify_c(i, '\3', '\2', 1);
261
verify_c(i, '\5', '\4', 3);
262
// The small integer border
263
verify_c(i, '\u00FF', '\0', 1);
264
verify_c(i, '\u0100', '\0', 1);
266
verify_c(i, java.lang.Character.MAX_VALUE, '\0', 1);
267
verify_c(i, java.lang.Character.MIN_VALUE, '\0', 1);
268
verify_c(i, java.lang.Character.MAX_VALUE,
269
java.lang.Character.MIN_VALUE, 1);
270
// Impossible decodes
271
verify_c_bad(i, '\u8000', '\0', 2);
274
static void marshal_wc(String selfNode, String peerNode,
275
String cookie, String serverName)
276
throws java.lang.Exception
278
m._iStub i = new m._iStub(selfNode, peerNode, cookie, serverName);
280
verify_wc(i, '\3', '\2', 1);
281
verify_wc(i, '\5', '\4', 3);
282
// The small integer border
283
verify_wc(i, '\u00FF', '\0', 1);
284
verify_wc(i, '\u0100', '\0', 1);
286
verify_wc(i, java.lang.Character.MAX_VALUE, '\0', 1);
287
verify_wc(i, java.lang.Character.MIN_VALUE, '\0', 1);
288
verify_wc(i, java.lang.Character.MAX_VALUE,
289
java.lang.Character.MIN_VALUE, 1);
290
// Impossible decodes
291
verify_c_bad(i, '\u8000', '\0', 2);
294
static void marshal_str(String selfNode, String peerNode,
295
String cookie, String serverName)
296
throws java.lang.Exception
298
m._iStub i = new m._iStub(selfNode, peerNode, cookie, serverName);
300
verify_str(i, 100, 100);
301
verify_str(i, 100, 1);
302
// Erlang string border
303
verify_str(i, 65535, 1);
304
verify_str(i, 2, 65535);
305
// Erlang string border out
306
verify_str(i, 65536, 1);
307
verify_str(i, 65536, 65536);
310
static void marshal_any_3(String selfNode, String peerNode,
311
String cookie, String serverName)
312
throws java.lang.Exception
314
m._iStub i = new m._iStub(selfNode, peerNode, cookie, serverName);
315
com.ericsson.otp.ic.Any x = new com.ericsson.otp.ic.Any();
316
com.ericsson.otp.ic.Any y = new com.ericsson.otp.ic.Any();
317
com.ericsson.otp.ic.Any z = new com.ericsson.otp.ic.Any();
319
x.insert_longlong(java.lang.Long.MAX_VALUE);
320
y.insert_longlong(1L);
321
z.insert_longlong(java.lang.Long.MAX_VALUE-1L);
322
System.out.println("verify_any_3 longlong max");
323
verify_any_3(i, x, y, 1, z);
325
x.insert_longlong(java.lang.Long.MIN_VALUE);
326
y.insert_longlong(-1L);
327
z.insert_longlong(java.lang.Long.MIN_VALUE+1L);
328
System.out.println("verify_any_3 longlong min");
329
verify_any_3(i, x, y, 1, z);
331
x.insert_ulonglong(-1L);
332
y.insert_longlong(1L);
333
z.insert_ulonglong(-2L);
334
System.out.println("verify_any_3 ulonglong max");
335
verify_any_3(i, x, y, 1, z);
337
x.insert_ulonglong(0L);
338
y.insert_longlong(-1L);
339
z.insert_ulonglong(1L);
340
System.out.println("verify_any_3 ulonglong min");
341
verify_any_3(i, x, y, 1, z);
343
x.insert_long(java.lang.Integer.MAX_VALUE);
345
z.insert_long(java.lang.Integer.MAX_VALUE-1);
346
System.out.println("verify_any_3 long max");
347
verify_any_3(i, x, y, 1, z);
349
x.insert_long(java.lang.Integer.MIN_VALUE);
351
z.insert_long(java.lang.Integer.MIN_VALUE+1);
352
System.out.println("verify_any_3 long min");
353
verify_any_3(i, x, y, 1, z);
358
System.out.println("verify_any_3 ulong max");
359
verify_any_3(i, x, y, 1, z);
364
System.out.println("verify_any_3 ulong min");
365
verify_any_3(i, x, y, 1, z);
367
x.insert_short(java.lang.Short.MAX_VALUE);
368
y.insert_short((short)1);
369
z.insert_short((short)(java.lang.Short.MAX_VALUE-1));
370
System.out.println("verify_any_3 short max");
371
verify_any_3(i, x, y, 1, z);
373
x.insert_short(java.lang.Short.MIN_VALUE);
374
y.insert_short((short)-1);
375
z.insert_short((short)(java.lang.Short.MIN_VALUE+1));
376
System.out.println("verify_any_3 short min");
377
verify_any_3(i, x, y, 1, z);
379
x.insert_ushort((short)-1);
380
y.insert_short((short)1);
381
z.insert_ushort((short)-2);
382
System.out.println("verify_any_3 ushort max");
383
verify_any_3(i, x, y, 1, z);
385
x.insert_ushort((short)0);
386
y.insert_short((short)-1);
387
z.insert_ushort((short)1);
388
System.out.println("verify_any_3 ushort min");
389
verify_any_3(i, x, y, 1, z);
391
x.insert_char('\377');
393
z.insert_char('\376');
394
System.out.println("verify_any_3 char max");
395
verify_any_3(i, x, y, 1, z);
397
x.insert_wchar('\uFFFF');
398
y.insert_wchar('\u0001');
399
z.insert_wchar('\uFFFE');
400
System.out.println("verify_any_3 char max");
401
verify_any_3(i, x, y, 1, z);
404
static void marshal_any_2(String selfNode, String peerNode,
405
String cookie, String serverName)
406
throws java.lang.Exception
408
m._iStub i = new m._iStub(selfNode, peerNode, cookie, serverName);
410
com.ericsson.otp.ic.Any a = new com.ericsson.otp.ic.Any();
413
s.ll_x = java.lang.Long.MAX_VALUE;
416
s.ll_z = java.lang.Long.MAX_VALUE-1L;
419
s.l_x = java.lang.Integer.MAX_VALUE;
422
s.l_z = java.lang.Integer.MAX_VALUE-1;
425
s.s_x = java.lang.Short.MAX_VALUE;
428
s.s_z = (short)(java.lang.Short.MAX_VALUE-1);
436
m.sHelper.insert(a, s);
437
verify_any_2(i, a, 1);
440
s.ll_x = java.lang.Long.MIN_VALUE;
443
s.ll_z = java.lang.Long.MIN_VALUE+1L;
446
s.l_x = java.lang.Integer.MIN_VALUE;
449
s.l_z = java.lang.Integer.MIN_VALUE+1;
452
s.s_x = java.lang.Short.MIN_VALUE;
455
s.s_z = (short)(java.lang.Short.MIN_VALUE+1);
463
m.sHelper.insert(a, s);
464
verify_any_2(i, a, 1);
468
static void verify_ll(m._iStub i, long x, long y, int b)
469
throws java.lang.Exception
472
System.out.println("verify_ll "+a);
475
long expected = (x - y)*(short)b;
476
long result = i.marshal_ll(a, (short)b);
477
if (result == expected) {
478
System.out.println("verify_ll("+x+", "+y+", "+b+") => "
481
System.out.println("verify_ll("+x+", "+y+", "+b+") => "
482
+result+" != "+expected);
487
static void verify_ull(m._iStub i, long x, long y, int b)
488
throws java.lang.Exception
493
long expected = (x - y)*(short)b;
494
long result = i.marshal_ull(a, (short)b);
495
if (result == expected) {
496
System.out.println("verify_ull("+x+", "+y+", "+b+") => "
499
System.out.println("verify_ull("+x+", "+y+", "+b+") => "
500
+result+" != "+expected);
505
static void verify_l(m._iStub i, int x, int y, int b)
506
throws java.lang.Exception
511
int expected = (x - y)*(short)b;
512
int result = i.marshal_l(a, (short)b);
513
if (result == expected) {
514
System.out.println("verify_l("+x+", "+y+", "+b+") => "
517
System.out.println("verify_l("+x+", "+y+", "+b+") => "
518
+result+" != "+expected);
523
static void verify_ul(m._iStub i, int x, int y, int b)
524
throws java.lang.Exception
529
int expected = (x - y)*(short)b;
530
int result = i.marshal_ul(a, (short)b);
531
if (result == expected) {
532
System.out.println("verify_ul("+x+", "+y+", "+b+") => "
535
System.out.println("verify_ul("+x+", "+y+", "+b+") => "
536
+result+" != "+expected);
541
static void verify_s(m._iStub i, int x, int y, int b)
542
throws java.lang.Exception
547
short expected = (short)((x - y)*(short)b);
548
short result = i.marshal_s(a, (short)b);
549
if (result == expected) {
550
System.out.println("verify_s("+x+", "+y+", "+b+") => "
553
System.out.println("verify_s("+x+", "+y+", "+b+") => "
554
+result+" != "+expected);
559
static void verify_us(m._iStub i, int x, int y, int b)
560
throws java.lang.Exception
565
short expected = (short)((x - y)*(short)b);
566
short result = i.marshal_us(a, (short)b);
567
if (result == expected) {
568
System.out.println("verify_us("+x+", "+y+", "+b+") => "
571
System.out.println("verify_us("+x+", "+y+", "+b+") => "
572
+result+" != "+expected);
577
static void verify_c(m._iStub i, char x, char y, int b)
578
throws java.lang.Exception
583
char expected = (char)(((int)x - (int)y)*(short)b);
584
char result = i.marshal_c(a, (short)b);
585
if (result == expected) {
586
System.out.println("verify_c("+x+", "+y+", "+b+") => "
589
System.out.println("verify_c("+x+", "+y+", "+b+") => "
590
+result+" != "+expected);
595
static void verify_wc(m._iStub i, char x, char y, int b)
596
throws java.lang.Exception
601
char expected = (char)(((int)x - (int)y)*(short)b);
602
char result = i.marshal_wc(a, (short)b);
603
if (result == expected) {
604
System.out.println("verify_wc("+x+", "+y+", "+b+") => "
607
System.out.println("verify_wc("+x+", "+y+", "+b+") => "
608
+result+" != "+expected);
613
static void verify_str(m._iStub i, int a_len, int b_len)
614
throws java.lang.Exception
616
String a = mk_str(a_len);
617
String b = mk_str(b_len);
618
String expected = a + b;
619
String result = i.strcat(a, b);
620
if (result.equals(expected)) {
621
System.out.println("verify_str(\""+a+"\", \""+b+"\") => \""
624
System.out.println("verify_str(\""+a+"\", \""+b+"\") => \""
625
+result+"\" != \""+expected.length()+"\"");
630
static String mk_str(int len)
631
throws StringIndexOutOfBoundsException
633
StringBuffer s = new StringBuffer();
634
// 17 characters is prime relative all bases of two - on purpose
635
do s.append("qwertyuiopasdfghj"); while (s.length() < len);
636
return s.substring(0, len);
639
static void verify_any_3(m._iStub i,
640
com.ericsson.otp.ic.Any x,
641
com.ericsson.otp.ic.Any y,
643
com.ericsson.otp.ic.Any expected)
644
throws java.lang.Exception
646
com.ericsson.otp.ic.Any result = i.marshal_any_3(x, y, (short)b);
647
if (! expected.equal(result)) {
652
static void verify_any_2(m._iStub i, com.ericsson.otp.ic.Any a, int b)
653
throws java.lang.Exception
655
com.ericsson.otp.ic.Any result = i.marshal_any_2(a, (short)b);
656
if (! a.equal(result)) {
663
static void verify_ll_bad(m._iStub i, long x, long y, int b)
664
throws java.lang.Exception
667
verify_ll(i, x, y, b);
668
System.out.println("Expected exception missing!");
670
} catch (com.ericsson.otp.erlang.OtpErlangDecodeException e) {
671
System.out.println("Expected exception: "+e);
675
static void verify_ull_bad(m._iStub i, long x, long y, int b)
676
throws java.lang.Exception
679
verify_ull(i, x, y, b);
680
System.out.println("Expected exception missing!");
682
} catch (com.ericsson.otp.erlang.OtpErlangDecodeException e) {
683
System.out.println("Expected exception: "+e);
687
static void verify_l_bad(m._iStub i, int x, int y, int b)
688
throws java.lang.Exception
691
verify_l(i, x, y, b);
692
System.out.println("Expected exception missing!");
694
} catch (com.ericsson.otp.erlang.OtpErlangDecodeException e) {
695
System.out.println("Expected exception: "+e);
699
static void verify_ul_bad(m._iStub i, int x, int y, int b)
700
throws java.lang.Exception
703
verify_ul(i, x, y, b);
704
System.out.println("Expected exception missing!");
706
} catch (com.ericsson.otp.erlang.OtpErlangDecodeException e) {
707
System.out.println("Expected exception: "+e);
711
static void verify_s_bad(m._iStub i, int x, int y, int b)
712
throws java.lang.Exception
715
verify_s(i, x, y, b);
716
System.out.println("Expected exception missing!");
718
} catch (com.ericsson.otp.erlang.OtpErlangDecodeException e) {
719
System.out.println("Expected exception: "+e);
723
static void verify_us_bad(m._iStub i, int x, int y, int b)
724
throws java.lang.Exception
727
verify_us(i, x, y, b);
728
System.out.println("Expected exception missing!");
730
} catch (com.ericsson.otp.erlang.OtpErlangDecodeException e) {
731
System.out.println("Expected exception: "+e);
735
static void verify_c_bad(m._iStub i, char x, char y, int b)
736
throws java.lang.Exception
739
verify_c(i, x, y, b);
740
System.out.println("Expected exception missing!");
742
} catch (com.ericsson.otp.erlang.OtpErlangDecodeException e) {
743
System.out.println("Expected exception: "+e);
747
static void verify_wc_bad(m._iStub i, char x, char y, int b)
748
throws java.lang.Exception
751
verify_wc(i, x, y, b);
752
System.out.println("Expected exception missing!");
754
} catch (com.ericsson.otp.erlang.OtpErlangDecodeException e) {
755
System.out.println("Expected exception: "+e);