blob: 3f9158e09a1a58c5e1c09ace293e4900860e13b3 [file] [log] [blame]
Jens Geyerbd52f1a2014-07-28 01:25:30 +02001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20package;
21
22import haxe.Int32;
23import haxe.Int64;
24import haxe.Timer;
25import haxe.ds.IntMap;
26import haxe.ds.StringMap;
27import haxe.ds.ObjectMap;
28
29import org.apache.thrift.*;
30import org.apache.thrift.helper.*;
31import org.apache.thrift.protocol.*;
32import org.apache.thrift.transport.*;
33import org.apache.thrift.server.*;
34import org.apache.thrift.meta_data.*;
35
36#if cpp
37import cpp.vm.Thread;
38#else
39// no thread support (yet)
40#end
41
42import thrift.test.*; // generated code
43
44
45class TestResults {
Jens Geyerb5028322014-11-09 02:38:11 +010046 private var successCnt : Int = 0;
47 private var errorCnt : Int = 0;
48 private var failedTests : String = "";
49 private var print_direct : Bool = false;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020050
Jens Geyerb5028322014-11-09 02:38:11 +010051 public static var EXITCODE_SUCCESS = 0x00; // no errors bits set
52 //
53 public static var EXITCODE_FAILBIT_BASETYPES = 0x01;
54 public static var EXITCODE_FAILBIT_STRUCTS = 0x02;
55 public static var EXITCODE_FAILBIT_CONTAINERS = 0x04;
56 public static var EXITCODE_FAILBIT_EXCEPTIONS = 0x08;
57 //
58 public static var EXITCODE_ALL_FAILBITS = 0x0F;
59 //
60 private var testsExecuted : Int = 0;
61 private var testsFailed : Int = 0;
62 private var currentTest : Int = 0;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020063
64
Jens Geyerb5028322014-11-09 02:38:11 +010065 public function new(direct : Bool) {
66 print_direct = direct;
67 }
68
69 public function StartTestGroup( groupBit : Int) : Void {
70 currentTest = groupBit;
71 testsExecuted |= groupBit;
72 }
73
74 public function Expect( expr : Bool, msg : String) : Void {
75 if ( expr) {
76 ++successCnt;
77 } else {
78 ++errorCnt;
79 testsFailed |= currentTest;
80 failedTests += "\n " + msg;
81 if( print_direct) {
82 trace('FAIL: $msg');
83 }
84 }
85 }
86
87 public function CalculateExitCode() : Int {
88 var notExecuted : Int = EXITCODE_ALL_FAILBITS & (~testsExecuted);
89 return testsFailed | notExecuted;
90 }
91
92 public function PrintSummary() : Void {
93 var total = successCnt + errorCnt;
94 var sp = (100 * successCnt) / total;
95 var ep = (100 * errorCnt) / total;
96
97 trace('===========================');
98 trace('Tests executed $total');
99 trace('Tests succeeded $successCnt ($sp%)');
100 trace('Tests failed $errorCnt ($ep%)');
101 if ( errorCnt > 0)
102 {
103 trace('===========================');
104 trace('FAILED TESTS: $failedTests');
105 }
106 trace('===========================');
107 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200108}
109
110
111class TestClient {
112
Jens Geyerb5028322014-11-09 02:38:11 +0100113 public static function Execute(args : Arguments) : Void
114 {
115 var exitCode = 0xFF;
116 try
117 {
118 var difft = Timer.stamp();
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200119
Jens Geyerb5028322014-11-09 02:38:11 +0100120 if( args.numThreads > 1) {
121 var threads = new List<Thread>();
122 for( test in 0 ... args.numThreads) {
123 threads.add( StartThread( args));
124 }
125 exitCode = 0;
126 for( thread in threads) {
127 exitCode |= Thread.readMessage(true);
128 }
129 } else {
130 var rslt = new TestResults(true);
131 RunClient(args,rslt);
132 rslt.PrintSummary();
133 exitCode = rslt.CalculateExitCode();
134 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200135
Jens Geyerb5028322014-11-09 02:38:11 +0100136 difft = Timer.stamp() - difft;
137 trace('total test time: $difft seconds');
138 }
139 catch (e : TException)
140 {
141 trace('$e');
142 exitCode = 0xFF;
143 }
144 catch (e : Dynamic)
145 {
146 trace('$e');
147 exitCode = 0xFF;
148 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200149
Jens Geyerb5028322014-11-09 02:38:11 +0100150 #if sys
151 Sys.exit( exitCode);
152 #end
153 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200154
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200155
Jens Geyerb5028322014-11-09 02:38:11 +0100156 private static function StartThread(args : Arguments) : Thread {
157 var thread = Thread.create(
158 function() : Void {
159 var rslt = new TestResults(false);
160 var main : Thread = Thread.readMessage(true);
161 try
162 {
163 RunClient(args,rslt);
164 }
165 catch (e : TException)
166 {
167 rslt.Expect( false, '$e');
168 trace('$e');
169 }
170 catch (e : Dynamic)
171 {
172 rslt.Expect( false, '$e');
173 trace('$e');
174 }
175 main.sendMessage( rslt.CalculateExitCode());
176 });
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200177
Jens Geyerb5028322014-11-09 02:38:11 +0100178 thread.sendMessage(Thread.current());
179 return thread;
180 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200181
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200182
Jens Geyerb5028322014-11-09 02:38:11 +0100183 public static function RunClient(args : Arguments, rslt : TestResults)
184 {
185 var transport : TTransport = null;
186 switch (args.transport)
187 {
188 case socket:
189 transport = new TSocket(args.host, args.port);
190 case http:
191 transport = new THttpClient(args.host);
192 default:
193 throw "Unhandled transport";
194 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200195
Jens Geyerb5028322014-11-09 02:38:11 +0100196 // optional: layered transport
197 if ( args.framed) {
198 trace("- framed transport");
199 transport = new TFramedTransport(transport);
200 }
201 if ( args.buffered) {
202 trace("- buffered transport");
203 throw "TBufferedTransport not implemented yet";
204 //transport = new TBufferedTransport(transport);
205 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200206
Jens Geyerb5028322014-11-09 02:38:11 +0100207 // protocol
208 var protocol : TProtocol = null;
209 switch( args.protocol)
210 {
211 case binary:
212 trace("- binary protocol");
213 protocol = new TBinaryProtocol(transport);
214 case json:
215 trace("- json protocol");
216 protocol = new TJSONProtocol(transport);
217 default:
218 throw "Unhandled protocol";
219 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200220
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200221
Jens Geyerb5028322014-11-09 02:38:11 +0100222 // run the test code
223 HaxeBasicsTest( args, rslt);
224 for( i in 0 ... args.numIterations) {
225 ClientTest( transport, protocol, args, rslt);
226 }
227 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200228
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200229
Jens Geyerb5028322014-11-09 02:38:11 +0100230 public static function HaxeBasicsTest( args : Arguments, rslt : TestResults) : Void
231 {
232 // We need to test a few basic things used in the ClientTest
233 // Anything else beyond this scope should go into /lib/haxe/ instead
234 rslt.StartTestGroup( 0);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200235
Jens Geyerb5028322014-11-09 02:38:11 +0100236 var map32 = new IntMap<Int32>();
237 var map64 = new Int64Map<Int32>();
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200238
Jens Geyerb5028322014-11-09 02:38:11 +0100239 rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #1");
240 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #2");
241 rslt.Expect( map32.remove( 4711) == map64.remove( Int64.make(47,11)), "Int64Map<Int32> Test #3");
242 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #4");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200243
Jens Geyerb5028322014-11-09 02:38:11 +0100244 map32.set( 42, 815);
245 map64.set( Int64.make(0,42), 815);
246 map32.set( -517, 23);
247 map64.set( Int64.make(-5,17), 23);
248 map32.set( 0, -123);
249 map64.set( Int64.make(0,0), -123);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200250
Jens Geyerb5028322014-11-09 02:38:11 +0100251 rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #10");
252 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #11");
253 rslt.Expect( map32.exists( -517) == map64.exists( Int64.make(-5,17)), "Int64Map<Int32> Test #12");
254 rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #13");
255 rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #14");
256 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #15");
257 rslt.Expect( map32.get( -517) == map64.get( Int64.make(-5,17)), "Int64Map<Int32> Test #16");
258 rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #Int64.make(-5,17)");
259 rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #18");
260 rslt.Expect( map32.remove( 4711) == map64.remove( Int64.make(47,11)), "Int64Map<Int32> Test #19");
261 rslt.Expect( map32.remove( -517) == map64.remove( Int64.make(-5,17)), "Int64Map<Int32> Test #20");
262 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #21");
263 rslt.Expect( map32.exists( -517) == map64.exists( Int64.make(-5,17)), "Int64Map<Int32> Test #22");
264 rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #23");
265 rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #24");
266 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #25");
267 rslt.Expect( map32.get( -517) == map64.get( Int64.make(-5,17)), "Int64Map<Int32> Test #26");
268 rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #27");
269 rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #28");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200270
Jens Geyerb5028322014-11-09 02:38:11 +0100271 map32.set( 42, 1);
272 map64.set( Int64.make(0,42), 1);
273 map32.set( -517, -2);
274 map64.set( Int64.make(-5,17), -2);
275 map32.set( 0, 3);
276 map64.set( Int64.make(0,0), 3);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200277
Jens Geyerb5028322014-11-09 02:38:11 +0100278 var c32 = 0;
279 for (key in map32.keys()) {
280 ++c32;
281 }
282 var c64 = 0;
283 for (key in map64.keys()) {
284 ++c64;
285 }
286 rslt.Expect( c32 == c64, "Int64Map<Int32> Test #30");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200287
Jens Geyerb5028322014-11-09 02:38:11 +0100288 var s32 = map32.toString();
289 var s64 = map64.toString();
290 trace("Int64Map<Int32>.toString(): " + ' ("$s32" == "$s64")');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200291
Jens Geyerb5028322014-11-09 02:38:11 +0100292 map32.remove( 42);
293 map64.remove( Int64.make(0,42));
294 map32.remove( -517);
295 map64.remove( Int64.make(-5,17));
296 map32.remove( 0);
297 map64.remove( Int64.make(0,0));
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200298
Jens Geyerb5028322014-11-09 02:38:11 +0100299 rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #90");
300 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #91");
301 rslt.Expect( map32.exists( -517) == map64.exists( Int64.make(-5,17)), "Int64Map<Int32> Test #92");
302 rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #93");
303 rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #94");
304 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #95");
305 rslt.Expect( map32.get( -517) == map64.get( Int64.make(-5,17)), "Int64Map<Int32> Test #96");
306 rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #97");
307 rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #98");
308 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200309
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200310
Jens Geyerb5028322014-11-09 02:38:11 +0100311 public static function ClientTest( transport : TTransport, protocol : TProtocol,
312 args : Arguments, rslt : TestResults) : Void
313 {
314 var client = new ThriftTestImpl(protocol,protocol);
315 try
316 {
317 if (!transport.isOpen())
318 {
319 transport.open();
320 }
321 }
322 catch (e : TException)
323 {
324 trace('$e');
325 return;
326 }
327 catch (e : Dynamic)
328 {
329 trace('$e');
330 return;
331 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200332
Jens Geyerb5028322014-11-09 02:38:11 +0100333 var start = Date.now();
334
335 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_EXCEPTIONS);
336
337 // if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
338 trace('testException("Xception")');
339 try {
340 client.testException("Xception");
341 rslt.Expect( false, 'testException("Xception") should throw');
342 }
343 catch (e : Xception)
344 {
345 rslt.Expect( e.message == "Xception", 'testException("Xception") - e.message == "Xception"');
346 rslt.Expect( e.errorCode == 1001, 'testException("Xception") - e.errorCode == 1001');
347 }
348 catch (e : Dynamic)
349 {
350 rslt.Expect( false, 'testException("Xception") - $e');
351 }
352
353 // if arg == "TException" throw TException
354 trace('testException("TException")');
355 try {
356 client.testException("TException");
357 rslt.Expect( false, 'testException("TException") should throw');
358 }
359 catch (e : TException)
360 {
361 rslt.Expect( true, 'testException("TException") - $e');
362 }
363 catch (e : Dynamic)
364 {
365 rslt.Expect( false, 'testException("TException") - $e');
366 }
367
368 // else do not throw anything
369 trace('testException("bla")');
370 try {
371 client.testException("bla");
372 rslt.Expect( true, 'testException("bla") should not throw');
373 }
374 catch (e : Dynamic)
375 {
376 rslt.Expect( false, 'testException("bla") - $e');
377 }
378
379
380
381 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES);
382
383 trace('testVoid()');
384 client.testVoid();
385 trace(' = void');
386 rslt.Expect(true,"testVoid()"); // bump counter
387
388 trace('testString("Test")');
389 var s = client.testString("Test");
390 trace(' = "$s"');
391 rslt.Expect(s == "Test", '$s == "Test"');
392
393 trace('testByte(1)');
394 var i8 = client.testByte(1);
395 trace(' = $i8');
396 rslt.Expect(i8 == 1, '$i8 == 1');
397
398 trace('testI32(-1)');
399 var i32 = client.testI32(-1);
400 trace(' = $i32');
401 rslt.Expect(i32 == -1, '$i32 == -1');
402
403 trace('testI64(-34359738368)');
404 var i64 = client.testI64( Int64.make( 0xFFFFFFF8, 0x00000000)); // -34359738368
405 trace(' = $i64');
406 rslt.Expect( Int64.compare( i64, Int64.make( 0xFFFFFFF8, 0x00000000)) == 0,
407 Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0xFFFFFFF8, 0x00000000)));
408
409 // edge case: the largest negative Int64 has no positive Int64 equivalent
410 trace('testI64(-9223372036854775808)');
411 i64 = client.testI64( Int64.make( 0x80000000, 0x00000000)); // -9223372036854775808
412 trace(' = $i64');
413 rslt.Expect( Int64.compare( i64, Int64.make( 0x80000000, 0x00000000)) == 0,
414 Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0x80000000, 0x00000000)));
415
416 trace('testDouble(5.325098235)');
417 var dub = client.testDouble(5.325098235);
418 trace(' = $dub');
419 rslt.Expect(dub == 5.325098235, '$dub == 5.325098235');
420
421
422 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS);
423
424 trace('testStruct({"Zero", 1, -3, -5})');
425 var o = new Xtruct();
426 o.string_thing = "Zero";
427 o.byte_thing = 1;
428 o.i32_thing = -3;
429 o.i64_thing = Int64.make(0,-5);
430 var i = client.testStruct(o);
431 trace(' = {"' + i.string_thing + '", ' + i.byte_thing +', '
432 + i.i32_thing +', '+ Int64.toStr(i.i64_thing) + '}');
433 rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing");
434 rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing");
435 rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing");
436 rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing");
437
438 trace('testNest({1, {\"Zero\", 1, -3, -5}, 5})');
439 var o2 = new Xtruct2();
440 o2.byte_thing = 1;
441 o2.struct_thing = o;
442 o2.i32_thing = 5;
443 var i2 = client.testNest(o2);
444 i = i2.struct_thing;
445 trace(" = {" + i2.byte_thing + ", {\"" + i.string_thing + "\", "
446 + i.byte_thing + ", " + i.i32_thing + ", " + Int64.toStr(i.i64_thing) + "}, "
447 + i2.i32_thing + "}");
448 rslt.Expect( i2.byte_thing == o2.byte_thing, "i2.byte_thing == o2.byte_thing");
449 rslt.Expect( i2.i32_thing == o2.i32_thing, "i2.i32_thing == o2.i32_thing");
450 rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing");
451 rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing");
452 rslt.Expect( i.i32_thing == o.i32_thing, "i.i32_thing == o.i32_thing");
453 rslt.Expect( Int64.compare( i.i64_thing, o.i64_thing) == 0, "i.i64_thing == o.i64_thing");
454
455
456 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS);
457
458 var mapout = new IntMap< haxe.Int32>();
459 for ( j in 0 ... 5)
460 {
461 mapout.set(j, j - 10);
462 }
463 trace("testMap({");
464 var first : Bool = true;
465 for( key in mapout.keys())
466 {
467 if (first)
468 {
469 first = false;
470 }
471 else
472 {
473 trace(", ");
474 }
475 trace(key + " => " + mapout.get(key));
476 }
477 trace("})");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200478
Jens Geyerb5028322014-11-09 02:38:11 +0100479 var mapin = client.testMap(mapout);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200480
Jens Geyerb5028322014-11-09 02:38:11 +0100481 trace(" = {");
482 first = true;
483 for( key in mapin.keys())
484 {
485 if (first)
486 {
487 first = false;
488 }
489 else
490 {
491 trace(", ");
492 }
493 trace(key + " => " + mapin.get(key));
494 rslt.Expect( mapin.get(key) == mapout.get(key), ' mapin.get($key) == mapout.get($key)');
495 }
496 trace("}");
497 for( key in mapout.keys())
498 {
499 rslt.Expect(mapin.exists(key), 'mapin.exists($key)');
500 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200501
Jens Geyerb5028322014-11-09 02:38:11 +0100502 var listout = new List<Int>();
503 for (j in -2 ... 3)
504 {
505 listout.add(j);
506 }
507 trace("testList({");
508 first = true;
509 for( j in listout)
510 {
511 if (first)
512 {
513 first = false;
514 }
515 else
516 {
517 trace(", ");
518 }
519 trace(j);
520 }
521 trace("})");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200522
Jens Geyerb5028322014-11-09 02:38:11 +0100523 var listin = client.testList(listout);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200524
Jens Geyerb5028322014-11-09 02:38:11 +0100525 trace(" = {");
526 first = true;
527 for( j in listin)
528 {
529 if (first)
530 {
531 first = false;
532 }
533 else
534 {
535 trace(", ");
536 }
537 trace(j);
538 }
539 trace("}");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200540
Jens Geyerb5028322014-11-09 02:38:11 +0100541 rslt.Expect(listin.length == listout.length, "listin.length == listout.length");
542 var literout = listout.iterator();
543 var literin = listin.iterator();
544 while( literin.hasNext()) {
545 rslt.Expect(literin.next() == literout.next(), "literin[i] == literout[i]");
546 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200547
Jens Geyerb5028322014-11-09 02:38:11 +0100548 //set
549 var setout = new IntSet();
550 for (j in -2 ... 3)
551 {
552 setout.add(j);
553 }
554 trace("testSet({");
555 first = true;
556 for( j in setout)
557 {
558 if (first)
559 {
560 first = false;
561 }
562 else
563 {
564 trace(", ");
565 }
566 trace(j);
567 }
568 trace("})");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200569
Jens Geyerb5028322014-11-09 02:38:11 +0100570 var setin = client.testSet(setout);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200571
Jens Geyerb5028322014-11-09 02:38:11 +0100572 trace(" = {");
573 first = true;
574 for( j in setin)
575 {
576 if (first)
577 {
578 first = false;
579 }
580 else
581 {
582 trace(", ");
583 }
584 trace(j);
585 rslt.Expect(setout.contains(j), 'setout.contains($j)');
586 }
587 trace("}");
588 rslt.Expect(setin.size == setout.size, "setin.length == setout.length");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200589
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200590
Jens Geyerb5028322014-11-09 02:38:11 +0100591 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200592
Jens Geyerb5028322014-11-09 02:38:11 +0100593 trace("testEnum(ONE)");
594 var ret = client.testEnum(Numberz.ONE);
595 trace(" = " + ret);
596 rslt.Expect(ret == Numberz.ONE, '$ret == Numberz.ONE');
Jens Geyerfea00ac2014-10-01 02:22:48 +0200597
Jens Geyerb5028322014-11-09 02:38:11 +0100598 trace("testEnum(TWO)");
599 ret = client.testEnum(Numberz.TWO);
600 trace(" = " + ret);
601 rslt.Expect(ret == Numberz.TWO, '$ret == Numberz.TWO');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200602
Jens Geyerb5028322014-11-09 02:38:11 +0100603 trace("testEnum(THREE)");
604 ret = client.testEnum(Numberz.THREE);
605 trace(" = " + ret);
606 rslt.Expect(ret == Numberz.THREE, '$ret == Numberz.THREE');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200607
Jens Geyerb5028322014-11-09 02:38:11 +0100608 trace("testEnum(FIVE)");
609 ret = client.testEnum(Numberz.FIVE);
610 trace(" = " + ret);
611 rslt.Expect(ret == Numberz.FIVE, '$ret == Numberz.FIVE');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200612
Jens Geyerb5028322014-11-09 02:38:11 +0100613 trace("testEnum(EIGHT)");
614 ret = client.testEnum(Numberz.EIGHT);
615 trace(" = " + ret);
616 rslt.Expect(ret == Numberz.EIGHT, '$ret == Numberz.EIGHT');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200617
Jens Geyerb5028322014-11-09 02:38:11 +0100618 trace("testTypedef(309858235082523)");
619 var uid = client.testTypedef( Int64.make( 0x119D0, 0x7E08671B)); // 309858235082523
620 trace(" = " + uid);
621 rslt.Expect( Int64.compare( uid, Int64.make( 0x119D0, 0x7E08671B)) == 0,
622 Int64.toStr(uid)+" == "+Int64.toStr(Int64.make( 0x119D0, 0x7E08671B)));
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200623
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200624
Jens Geyerb5028322014-11-09 02:38:11 +0100625 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200626
Jens Geyerb5028322014-11-09 02:38:11 +0100627 trace("testMapMap(1)");
628 var mm = client.testMapMap(1);
629 trace(" = {");
630 for( key in mm.keys())
631 {
632 trace(key + " => {");
633 var m2 = mm.get(key);
634 for( k2 in m2.keys())
635 {
636 trace(k2 + " => " + m2.get(k2) + ", ");
637 }
638 trace("}, ");
639 }
640 trace("}");
Jens Geyerfea00ac2014-10-01 02:22:48 +0200641
Jens Geyerb5028322014-11-09 02:38:11 +0100642 var pos = mm.get(4);
643 var neg = mm.get(-4);
644 rslt.Expect( (pos != null) && (neg != null), "(pos != null) && (neg != null)");
645 for (i in 0 ... 5) {
646 rslt.Expect( pos.get(i) == i, 'pos.get($i) == $i');
647 rslt.Expect( neg.get(-i) == -i, 'neg.get(-$i) == -$i');
648 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200649
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200650
Jens Geyerb5028322014-11-09 02:38:11 +0100651 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200652
Jens Geyerb5028322014-11-09 02:38:11 +0100653 var insane = new Insanity();
654 insane.userMap = new IntMap< Int64>();
655 insane.userMap.set( Numberz.FIVE, Int64.make(0,5000));
656 var truck = new Xtruct();
657 truck.string_thing = "Truck";
658 truck.byte_thing = 8;
659 truck.i32_thing = 8;
660 truck.i64_thing = Int64.make(0,8);
661 insane.xtructs = new List<Xtruct>();
662 insane.xtructs.add(truck);
663 trace("testInsanity()");
664 var whoa = client.testInsanity(insane);
665 trace(" = {");
666 for( key in whoa.keys())
667 {
668 var val = whoa.get(key);
669 trace(key + " => {");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200670
Jens Geyerb5028322014-11-09 02:38:11 +0100671 for( k2 in val.keys())
672 {
673 var v2 = val.get(k2);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200674
Jens Geyerb5028322014-11-09 02:38:11 +0100675 trace(k2 + " => {");
676 var userMap = v2.userMap;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200677
Jens Geyerb5028322014-11-09 02:38:11 +0100678 trace("{");
679 if (userMap != null)
680 {
681 for( k3 in userMap.keys())
682 {
683 trace(k3 + " => " + userMap.get(k3) + ", ");
684 }
685 }
686 else
687 {
688 trace("null");
689 }
690 trace("}, ");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200691
Jens Geyerb5028322014-11-09 02:38:11 +0100692 var xtructs = v2.xtructs;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200693
Jens Geyerb5028322014-11-09 02:38:11 +0100694 trace("{");
695 if (xtructs != null)
696 {
697 for( x in xtructs)
698 {
699 trace("{\"" + x.string_thing + "\", "
700 + x.byte_thing + ", " + x.i32_thing + ", "
701 + x.i32_thing + "}, ");
702 }
703 }
704 else
705 {
706 trace("null");
707 }
708 trace("}");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200709
Jens Geyerb5028322014-11-09 02:38:11 +0100710 trace("}, ");
711 }
712 trace("}, ");
713 }
714 trace("}");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200715
Jens Geyerfea00ac2014-10-01 02:22:48 +0200716
Jens Geyerb5028322014-11-09 02:38:11 +0100717 var first_map = whoa.get(Int64.make(0,1));
718 var second_map = whoa.get(Int64.make(0,2));
719 rslt.Expect( (first_map != null) && (second_map != null), "(first_map != null) && (second_map != null)");
720 if ((first_map != null) && (second_map != null))
721 {
722 var crazy2 = first_map.get(Numberz.TWO);
723 var crazy3 = first_map.get(Numberz.THREE);
724 var looney = second_map.get(Numberz.SIX);
725 rslt.Expect( (crazy2 != null) && (crazy3 != null) && (looney != null),
726 "(crazy2 != null) && (crazy3 != null) && (looney != null)");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200727
Jens Geyerb5028322014-11-09 02:38:11 +0100728 rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0,
729 "crazy2.UserMap.get(Numberz.EIGHT) == 8");
730 rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0,
731 "crazy3.UserMap.get(Numberz.EIGHT) == 8");
732 rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0,
733 "crazy2.UserMap.get(Numberz.FIVE) == 5");
734 rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0,
735 "crazy3.UserMap.get(Numberz.FIVE) == 5");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200736
Jens Geyerb5028322014-11-09 02:38:11 +0100737 var crz2iter = crazy2.xtructs.iterator();
738 var crz3iter = crazy3.xtructs.iterator();
739 rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()");
740 var goodbye2 = crz2iter.next();
741 var goodbye3 = crz3iter.next();
742 rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()");
743 var hello2 = crz2iter.next();
744 var hello3 = crz3iter.next();
745 rslt.Expect( ! (crz2iter.hasNext() || crz3iter.hasNext()), "! (crz2iter.hasNext() || crz3iter.hasNext())");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200746
Jens Geyerb5028322014-11-09 02:38:11 +0100747 rslt.Expect( hello2.string_thing == "Hello2", 'hello2.String_thing == "Hello2"');
748 rslt.Expect( hello2.byte_thing == 2, 'hello2.Byte_thing == 2');
749 rslt.Expect( hello2.i32_thing == 2, 'hello2.I32_thing == 2');
750 rslt.Expect( Int64.compare( hello2.i64_thing, Int64.make(0,2)) == 0, 'hello2.I64_thing == 2');
751 rslt.Expect( hello3.string_thing == "Hello2", 'hello3.String_thing == "Hello2"');
752 rslt.Expect( hello3.byte_thing == 2, 'hello3.Byte_thing == 2');
753 rslt.Expect( hello3.i32_thing == 2, 'hello3.I32_thing == 2');
754 rslt.Expect( Int64.compare( hello3.i64_thing, Int64.make(0,2)) == 0, 'hello3.I64_thing == 2');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200755
Jens Geyerb5028322014-11-09 02:38:11 +0100756 rslt.Expect( goodbye2.string_thing == "Goodbye4", 'goodbye2.String_thing == "Goodbye4"');
757 rslt.Expect( goodbye2.byte_thing == 4, 'goodbye2.Byte_thing == 4');
758 rslt.Expect( goodbye2.i32_thing == 4, 'goodbye2.I32_thing == 4');
759 rslt.Expect( Int64.compare( goodbye2.i64_thing, Int64.make(0,4)) == 0, 'goodbye2.I64_thing == 4');
760 rslt.Expect( goodbye3.string_thing == "Goodbye4", 'goodbye3.String_thing == "Goodbye4"');
761 rslt.Expect( goodbye3.byte_thing == 4, 'goodbye3.Byte_thing == 4');
762 rslt.Expect( goodbye3.i32_thing == 4, 'goodbye3.I32_thing == 4');
763 rslt.Expect( Int64.compare( goodbye3.i64_thing, Int64.make(0,4)) == 0, 'goodbye3.I64_thing == 4');
764 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200765
Jens Geyerb5028322014-11-09 02:38:11 +0100766 var arg0 = 1;
767 var arg1 = 2;
768 var arg2 = Int64.make( 0x7FFFFFFF,0xFFFFFFFF);
769 var multiDict = new IntMap< String>();
770 multiDict.set(1, "one");
771 var arg4 = Numberz.FIVE;
772 var arg5 = Int64.make(0,5000000);
773 trace("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")");
774 var multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5);
775 trace(" = Xtruct(byte_thing:" + multiResponse.byte_thing + ",string_thing:" + multiResponse.string_thing
776 + ",i32_thing:" + multiResponse.i32_thing
777 + ",i64_thing:" + Int64.toStr(multiResponse.i64_thing) + ")");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200778
Jens Geyerb5028322014-11-09 02:38:11 +0100779 rslt.Expect( multiResponse.string_thing == "Hello2", 'multiResponse.String_thing == "Hello2"');
780 rslt.Expect( multiResponse.byte_thing == arg0, 'multiResponse.Byte_thing == arg0');
781 rslt.Expect( multiResponse.i32_thing == arg1, 'multiResponse.I32_thing == arg1');
782 rslt.Expect( Int64.compare( multiResponse.i64_thing, arg2) == 0, 'multiResponse.I64_thing == arg2');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200783
784
Jens Geyerb5028322014-11-09 02:38:11 +0100785 rslt.StartTestGroup( 0);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200786
Jens Geyerb5028322014-11-09 02:38:11 +0100787 trace("Test Oneway(1)");
788 client.testOneway(1);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200789
Jens Geyerb5028322014-11-09 02:38:11 +0100790 if( ! args.skipSpeedTest) {
791 trace("Test Calltime()");
792 var difft = Timer.stamp();
793 for ( k in 0 ... 1000) {
794 client.testVoid();
795 }
796 difft = Timer.stamp() - difft;
797 trace('$difft ms per testVoid() call');
798 }
799 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200800}