blob: 276cd0f7ed389326879e91c3392e8439f6ae9a47 [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");
Jens Geyerd35f6162014-11-29 19:23:03 +0100203 transport = new TBufferedTransport(transport);
Jens Geyerb5028322014-11-09 02:38:11 +0100204 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200205
Jens Geyerb5028322014-11-09 02:38:11 +0100206 // protocol
207 var protocol : TProtocol = null;
208 switch( args.protocol)
209 {
210 case binary:
211 trace("- binary protocol");
212 protocol = new TBinaryProtocol(transport);
213 case json:
214 trace("- json protocol");
215 protocol = new TJSONProtocol(transport);
216 default:
217 throw "Unhandled protocol";
218 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200219
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200220
Jens Geyerb5028322014-11-09 02:38:11 +0100221 // run the test code
222 HaxeBasicsTest( args, rslt);
223 for( i in 0 ... args.numIterations) {
224 ClientTest( transport, protocol, args, rslt);
225 }
226 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200227
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200228
Jens Geyerb5028322014-11-09 02:38:11 +0100229 public static function HaxeBasicsTest( args : Arguments, rslt : TestResults) : Void
230 {
231 // We need to test a few basic things used in the ClientTest
232 // Anything else beyond this scope should go into /lib/haxe/ instead
233 rslt.StartTestGroup( 0);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200234
Jens Geyerb5028322014-11-09 02:38:11 +0100235 var map32 = new IntMap<Int32>();
236 var map64 = new Int64Map<Int32>();
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200237
Jens Geyerb5028322014-11-09 02:38:11 +0100238 rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #1");
239 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #2");
240 rslt.Expect( map32.remove( 4711) == map64.remove( Int64.make(47,11)), "Int64Map<Int32> Test #3");
241 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #4");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200242
Jens Geyerb5028322014-11-09 02:38:11 +0100243 map32.set( 42, 815);
244 map64.set( Int64.make(0,42), 815);
245 map32.set( -517, 23);
246 map64.set( Int64.make(-5,17), 23);
247 map32.set( 0, -123);
248 map64.set( Int64.make(0,0), -123);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200249
Jens Geyerb5028322014-11-09 02:38:11 +0100250 rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #10");
251 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #11");
252 rslt.Expect( map32.exists( -517) == map64.exists( Int64.make(-5,17)), "Int64Map<Int32> Test #12");
253 rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #13");
254 rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #14");
255 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #15");
256 rslt.Expect( map32.get( -517) == map64.get( Int64.make(-5,17)), "Int64Map<Int32> Test #16");
257 rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #Int64.make(-5,17)");
258 rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #18");
259 rslt.Expect( map32.remove( 4711) == map64.remove( Int64.make(47,11)), "Int64Map<Int32> Test #19");
260 rslt.Expect( map32.remove( -517) == map64.remove( Int64.make(-5,17)), "Int64Map<Int32> Test #20");
261 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #21");
262 rslt.Expect( map32.exists( -517) == map64.exists( Int64.make(-5,17)), "Int64Map<Int32> Test #22");
263 rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #23");
264 rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #24");
265 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #25");
266 rslt.Expect( map32.get( -517) == map64.get( Int64.make(-5,17)), "Int64Map<Int32> Test #26");
267 rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #27");
268 rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #28");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200269
Jens Geyerb5028322014-11-09 02:38:11 +0100270 map32.set( 42, 1);
271 map64.set( Int64.make(0,42), 1);
272 map32.set( -517, -2);
273 map64.set( Int64.make(-5,17), -2);
274 map32.set( 0, 3);
275 map64.set( Int64.make(0,0), 3);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200276
Jens Geyerb5028322014-11-09 02:38:11 +0100277 var c32 = 0;
278 for (key in map32.keys()) {
279 ++c32;
280 }
281 var c64 = 0;
282 for (key in map64.keys()) {
283 ++c64;
284 }
285 rslt.Expect( c32 == c64, "Int64Map<Int32> Test #30");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200286
Jens Geyerb5028322014-11-09 02:38:11 +0100287 var s32 = map32.toString();
288 var s64 = map64.toString();
289 trace("Int64Map<Int32>.toString(): " + ' ("$s32" == "$s64")');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200290
Jens Geyerb5028322014-11-09 02:38:11 +0100291 map32.remove( 42);
292 map64.remove( Int64.make(0,42));
293 map32.remove( -517);
294 map64.remove( Int64.make(-5,17));
295 map32.remove( 0);
296 map64.remove( Int64.make(0,0));
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200297
Jens Geyerb5028322014-11-09 02:38:11 +0100298 rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #90");
299 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #91");
300 rslt.Expect( map32.exists( -517) == map64.exists( Int64.make(-5,17)), "Int64Map<Int32> Test #92");
301 rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #93");
302 rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #94");
303 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #95");
304 rslt.Expect( map32.get( -517) == map64.get( Int64.make(-5,17)), "Int64Map<Int32> Test #96");
305 rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #97");
306 rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #98");
307 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200308
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200309
Jens Geyerb5028322014-11-09 02:38:11 +0100310 public static function ClientTest( transport : TTransport, protocol : TProtocol,
311 args : Arguments, rslt : TestResults) : Void
312 {
313 var client = new ThriftTestImpl(protocol,protocol);
314 try
315 {
316 if (!transport.isOpen())
317 {
318 transport.open();
319 }
320 }
321 catch (e : TException)
322 {
323 trace('$e');
324 return;
325 }
326 catch (e : Dynamic)
327 {
328 trace('$e');
329 return;
330 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200331
Jens Geyerb5028322014-11-09 02:38:11 +0100332 var start = Date.now();
333
334 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_EXCEPTIONS);
335
336 // if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
337 trace('testException("Xception")');
338 try {
339 client.testException("Xception");
340 rslt.Expect( false, 'testException("Xception") should throw');
341 }
342 catch (e : Xception)
343 {
344 rslt.Expect( e.message == "Xception", 'testException("Xception") - e.message == "Xception"');
345 rslt.Expect( e.errorCode == 1001, 'testException("Xception") - e.errorCode == 1001');
346 }
347 catch (e : Dynamic)
348 {
349 rslt.Expect( false, 'testException("Xception") - $e');
350 }
351
352 // if arg == "TException" throw TException
353 trace('testException("TException")');
354 try {
355 client.testException("TException");
356 rslt.Expect( false, 'testException("TException") should throw');
357 }
358 catch (e : TException)
359 {
360 rslt.Expect( true, 'testException("TException") - $e');
361 }
362 catch (e : Dynamic)
363 {
364 rslt.Expect( false, 'testException("TException") - $e');
365 }
366
367 // else do not throw anything
368 trace('testException("bla")');
369 try {
370 client.testException("bla");
371 rslt.Expect( true, 'testException("bla") should not throw');
372 }
373 catch (e : Dynamic)
374 {
375 rslt.Expect( false, 'testException("bla") - $e');
376 }
377
378
379
380 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES);
381
382 trace('testVoid()');
383 client.testVoid();
384 trace(' = void');
385 rslt.Expect(true,"testVoid()"); // bump counter
386
387 trace('testString("Test")');
388 var s = client.testString("Test");
389 trace(' = "$s"');
390 rslt.Expect(s == "Test", '$s == "Test"');
391
392 trace('testByte(1)');
393 var i8 = client.testByte(1);
394 trace(' = $i8');
395 rslt.Expect(i8 == 1, '$i8 == 1');
396
397 trace('testI32(-1)');
398 var i32 = client.testI32(-1);
399 trace(' = $i32');
400 rslt.Expect(i32 == -1, '$i32 == -1');
401
402 trace('testI64(-34359738368)');
403 var i64 = client.testI64( Int64.make( 0xFFFFFFF8, 0x00000000)); // -34359738368
404 trace(' = $i64');
405 rslt.Expect( Int64.compare( i64, Int64.make( 0xFFFFFFF8, 0x00000000)) == 0,
406 Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0xFFFFFFF8, 0x00000000)));
407
408 // edge case: the largest negative Int64 has no positive Int64 equivalent
409 trace('testI64(-9223372036854775808)');
410 i64 = client.testI64( Int64.make( 0x80000000, 0x00000000)); // -9223372036854775808
411 trace(' = $i64');
412 rslt.Expect( Int64.compare( i64, Int64.make( 0x80000000, 0x00000000)) == 0,
413 Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0x80000000, 0x00000000)));
414
415 trace('testDouble(5.325098235)');
416 var dub = client.testDouble(5.325098235);
417 trace(' = $dub');
418 rslt.Expect(dub == 5.325098235, '$dub == 5.325098235');
419
420
421 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS);
422
423 trace('testStruct({"Zero", 1, -3, -5})');
424 var o = new Xtruct();
425 o.string_thing = "Zero";
426 o.byte_thing = 1;
427 o.i32_thing = -3;
428 o.i64_thing = Int64.make(0,-5);
429 var i = client.testStruct(o);
430 trace(' = {"' + i.string_thing + '", ' + i.byte_thing +', '
431 + i.i32_thing +', '+ Int64.toStr(i.i64_thing) + '}');
432 rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing");
433 rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing");
434 rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing");
435 rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing");
436
437 trace('testNest({1, {\"Zero\", 1, -3, -5}, 5})');
438 var o2 = new Xtruct2();
439 o2.byte_thing = 1;
440 o2.struct_thing = o;
441 o2.i32_thing = 5;
442 var i2 = client.testNest(o2);
443 i = i2.struct_thing;
444 trace(" = {" + i2.byte_thing + ", {\"" + i.string_thing + "\", "
445 + i.byte_thing + ", " + i.i32_thing + ", " + Int64.toStr(i.i64_thing) + "}, "
446 + i2.i32_thing + "}");
447 rslt.Expect( i2.byte_thing == o2.byte_thing, "i2.byte_thing == o2.byte_thing");
448 rslt.Expect( i2.i32_thing == o2.i32_thing, "i2.i32_thing == o2.i32_thing");
449 rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing");
450 rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing");
451 rslt.Expect( i.i32_thing == o.i32_thing, "i.i32_thing == o.i32_thing");
452 rslt.Expect( Int64.compare( i.i64_thing, o.i64_thing) == 0, "i.i64_thing == o.i64_thing");
453
454
455 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS);
456
457 var mapout = new IntMap< haxe.Int32>();
458 for ( j in 0 ... 5)
459 {
460 mapout.set(j, j - 10);
461 }
462 trace("testMap({");
463 var first : Bool = true;
464 for( key in mapout.keys())
465 {
466 if (first)
467 {
468 first = false;
469 }
470 else
471 {
472 trace(", ");
473 }
474 trace(key + " => " + mapout.get(key));
475 }
476 trace("})");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200477
Jens Geyerb5028322014-11-09 02:38:11 +0100478 var mapin = client.testMap(mapout);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200479
Jens Geyerb5028322014-11-09 02:38:11 +0100480 trace(" = {");
481 first = true;
482 for( key in mapin.keys())
483 {
484 if (first)
485 {
486 first = false;
487 }
488 else
489 {
490 trace(", ");
491 }
492 trace(key + " => " + mapin.get(key));
493 rslt.Expect( mapin.get(key) == mapout.get(key), ' mapin.get($key) == mapout.get($key)');
494 }
495 trace("}");
496 for( key in mapout.keys())
497 {
498 rslt.Expect(mapin.exists(key), 'mapin.exists($key)');
499 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200500
Jens Geyerb5028322014-11-09 02:38:11 +0100501 var listout = new List<Int>();
502 for (j in -2 ... 3)
503 {
504 listout.add(j);
505 }
506 trace("testList({");
507 first = true;
508 for( j in listout)
509 {
510 if (first)
511 {
512 first = false;
513 }
514 else
515 {
516 trace(", ");
517 }
518 trace(j);
519 }
520 trace("})");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200521
Jens Geyerb5028322014-11-09 02:38:11 +0100522 var listin = client.testList(listout);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200523
Jens Geyerb5028322014-11-09 02:38:11 +0100524 trace(" = {");
525 first = true;
526 for( j in listin)
527 {
528 if (first)
529 {
530 first = false;
531 }
532 else
533 {
534 trace(", ");
535 }
536 trace(j);
537 }
538 trace("}");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200539
Jens Geyerb5028322014-11-09 02:38:11 +0100540 rslt.Expect(listin.length == listout.length, "listin.length == listout.length");
541 var literout = listout.iterator();
542 var literin = listin.iterator();
543 while( literin.hasNext()) {
544 rslt.Expect(literin.next() == literout.next(), "literin[i] == literout[i]");
545 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200546
Jens Geyerb5028322014-11-09 02:38:11 +0100547 //set
548 var setout = new IntSet();
549 for (j in -2 ... 3)
550 {
551 setout.add(j);
552 }
553 trace("testSet({");
554 first = true;
555 for( j in setout)
556 {
557 if (first)
558 {
559 first = false;
560 }
561 else
562 {
563 trace(", ");
564 }
565 trace(j);
566 }
567 trace("})");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200568
Jens Geyerb5028322014-11-09 02:38:11 +0100569 var setin = client.testSet(setout);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200570
Jens Geyerb5028322014-11-09 02:38:11 +0100571 trace(" = {");
572 first = true;
573 for( j in setin)
574 {
575 if (first)
576 {
577 first = false;
578 }
579 else
580 {
581 trace(", ");
582 }
583 trace(j);
584 rslt.Expect(setout.contains(j), 'setout.contains($j)');
585 }
586 trace("}");
587 rslt.Expect(setin.size == setout.size, "setin.length == setout.length");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200588
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200589
Jens Geyerb5028322014-11-09 02:38:11 +0100590 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200591
Jens Geyerb5028322014-11-09 02:38:11 +0100592 trace("testEnum(ONE)");
593 var ret = client.testEnum(Numberz.ONE);
594 trace(" = " + ret);
595 rslt.Expect(ret == Numberz.ONE, '$ret == Numberz.ONE');
Jens Geyerfea00ac2014-10-01 02:22:48 +0200596
Jens Geyerb5028322014-11-09 02:38:11 +0100597 trace("testEnum(TWO)");
598 ret = client.testEnum(Numberz.TWO);
599 trace(" = " + ret);
600 rslt.Expect(ret == Numberz.TWO, '$ret == Numberz.TWO');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200601
Jens Geyerb5028322014-11-09 02:38:11 +0100602 trace("testEnum(THREE)");
603 ret = client.testEnum(Numberz.THREE);
604 trace(" = " + ret);
605 rslt.Expect(ret == Numberz.THREE, '$ret == Numberz.THREE');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200606
Jens Geyerb5028322014-11-09 02:38:11 +0100607 trace("testEnum(FIVE)");
608 ret = client.testEnum(Numberz.FIVE);
609 trace(" = " + ret);
610 rslt.Expect(ret == Numberz.FIVE, '$ret == Numberz.FIVE');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200611
Jens Geyerb5028322014-11-09 02:38:11 +0100612 trace("testEnum(EIGHT)");
613 ret = client.testEnum(Numberz.EIGHT);
614 trace(" = " + ret);
615 rslt.Expect(ret == Numberz.EIGHT, '$ret == Numberz.EIGHT');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200616
Jens Geyerb5028322014-11-09 02:38:11 +0100617 trace("testTypedef(309858235082523)");
618 var uid = client.testTypedef( Int64.make( 0x119D0, 0x7E08671B)); // 309858235082523
619 trace(" = " + uid);
620 rslt.Expect( Int64.compare( uid, Int64.make( 0x119D0, 0x7E08671B)) == 0,
621 Int64.toStr(uid)+" == "+Int64.toStr(Int64.make( 0x119D0, 0x7E08671B)));
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200622
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200623
Jens Geyerb5028322014-11-09 02:38:11 +0100624 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200625
Jens Geyerb5028322014-11-09 02:38:11 +0100626 trace("testMapMap(1)");
627 var mm = client.testMapMap(1);
628 trace(" = {");
629 for( key in mm.keys())
630 {
631 trace(key + " => {");
632 var m2 = mm.get(key);
633 for( k2 in m2.keys())
634 {
635 trace(k2 + " => " + m2.get(k2) + ", ");
636 }
637 trace("}, ");
638 }
639 trace("}");
Jens Geyerfea00ac2014-10-01 02:22:48 +0200640
Jens Geyerb5028322014-11-09 02:38:11 +0100641 var pos = mm.get(4);
642 var neg = mm.get(-4);
643 rslt.Expect( (pos != null) && (neg != null), "(pos != null) && (neg != null)");
644 for (i in 0 ... 5) {
645 rslt.Expect( pos.get(i) == i, 'pos.get($i) == $i');
646 rslt.Expect( neg.get(-i) == -i, 'neg.get(-$i) == -$i');
647 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200648
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200649
Jens Geyerb5028322014-11-09 02:38:11 +0100650 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200651
Jens Geyerb5028322014-11-09 02:38:11 +0100652 var insane = new Insanity();
653 insane.userMap = new IntMap< Int64>();
654 insane.userMap.set( Numberz.FIVE, Int64.make(0,5000));
655 var truck = new Xtruct();
656 truck.string_thing = "Truck";
657 truck.byte_thing = 8;
658 truck.i32_thing = 8;
659 truck.i64_thing = Int64.make(0,8);
660 insane.xtructs = new List<Xtruct>();
661 insane.xtructs.add(truck);
662 trace("testInsanity()");
663 var whoa = client.testInsanity(insane);
664 trace(" = {");
665 for( key in whoa.keys())
666 {
667 var val = whoa.get(key);
668 trace(key + " => {");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200669
Jens Geyerb5028322014-11-09 02:38:11 +0100670 for( k2 in val.keys())
671 {
672 var v2 = val.get(k2);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200673
Jens Geyerb5028322014-11-09 02:38:11 +0100674 trace(k2 + " => {");
675 var userMap = v2.userMap;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200676
Jens Geyerb5028322014-11-09 02:38:11 +0100677 trace("{");
678 if (userMap != null)
679 {
680 for( k3 in userMap.keys())
681 {
682 trace(k3 + " => " + userMap.get(k3) + ", ");
683 }
684 }
685 else
686 {
687 trace("null");
688 }
689 trace("}, ");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200690
Jens Geyerb5028322014-11-09 02:38:11 +0100691 var xtructs = v2.xtructs;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200692
Jens Geyerb5028322014-11-09 02:38:11 +0100693 trace("{");
694 if (xtructs != null)
695 {
696 for( x in xtructs)
697 {
698 trace("{\"" + x.string_thing + "\", "
699 + x.byte_thing + ", " + x.i32_thing + ", "
700 + x.i32_thing + "}, ");
701 }
702 }
703 else
704 {
705 trace("null");
706 }
707 trace("}");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200708
Jens Geyerb5028322014-11-09 02:38:11 +0100709 trace("}, ");
710 }
711 trace("}, ");
712 }
713 trace("}");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200714
Jens Geyerfea00ac2014-10-01 02:22:48 +0200715
Jens Geyerb5028322014-11-09 02:38:11 +0100716 var first_map = whoa.get(Int64.make(0,1));
717 var second_map = whoa.get(Int64.make(0,2));
718 rslt.Expect( (first_map != null) && (second_map != null), "(first_map != null) && (second_map != null)");
719 if ((first_map != null) && (second_map != null))
720 {
721 var crazy2 = first_map.get(Numberz.TWO);
722 var crazy3 = first_map.get(Numberz.THREE);
723 var looney = second_map.get(Numberz.SIX);
724 rslt.Expect( (crazy2 != null) && (crazy3 != null) && (looney != null),
725 "(crazy2 != null) && (crazy3 != null) && (looney != null)");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200726
Jens Geyerb5028322014-11-09 02:38:11 +0100727 rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0,
728 "crazy2.UserMap.get(Numberz.EIGHT) == 8");
729 rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0,
730 "crazy3.UserMap.get(Numberz.EIGHT) == 8");
731 rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0,
732 "crazy2.UserMap.get(Numberz.FIVE) == 5");
733 rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0,
734 "crazy3.UserMap.get(Numberz.FIVE) == 5");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200735
Jens Geyerb5028322014-11-09 02:38:11 +0100736 var crz2iter = crazy2.xtructs.iterator();
737 var crz3iter = crazy3.xtructs.iterator();
738 rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()");
739 var goodbye2 = crz2iter.next();
740 var goodbye3 = crz3iter.next();
741 rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()");
742 var hello2 = crz2iter.next();
743 var hello3 = crz3iter.next();
744 rslt.Expect( ! (crz2iter.hasNext() || crz3iter.hasNext()), "! (crz2iter.hasNext() || crz3iter.hasNext())");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200745
Jens Geyerb5028322014-11-09 02:38:11 +0100746 rslt.Expect( hello2.string_thing == "Hello2", 'hello2.String_thing == "Hello2"');
747 rslt.Expect( hello2.byte_thing == 2, 'hello2.Byte_thing == 2');
748 rslt.Expect( hello2.i32_thing == 2, 'hello2.I32_thing == 2');
749 rslt.Expect( Int64.compare( hello2.i64_thing, Int64.make(0,2)) == 0, 'hello2.I64_thing == 2');
750 rslt.Expect( hello3.string_thing == "Hello2", 'hello3.String_thing == "Hello2"');
751 rslt.Expect( hello3.byte_thing == 2, 'hello3.Byte_thing == 2');
752 rslt.Expect( hello3.i32_thing == 2, 'hello3.I32_thing == 2');
753 rslt.Expect( Int64.compare( hello3.i64_thing, Int64.make(0,2)) == 0, 'hello3.I64_thing == 2');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200754
Jens Geyerb5028322014-11-09 02:38:11 +0100755 rslt.Expect( goodbye2.string_thing == "Goodbye4", 'goodbye2.String_thing == "Goodbye4"');
756 rslt.Expect( goodbye2.byte_thing == 4, 'goodbye2.Byte_thing == 4');
757 rslt.Expect( goodbye2.i32_thing == 4, 'goodbye2.I32_thing == 4');
758 rslt.Expect( Int64.compare( goodbye2.i64_thing, Int64.make(0,4)) == 0, 'goodbye2.I64_thing == 4');
759 rslt.Expect( goodbye3.string_thing == "Goodbye4", 'goodbye3.String_thing == "Goodbye4"');
760 rslt.Expect( goodbye3.byte_thing == 4, 'goodbye3.Byte_thing == 4');
761 rslt.Expect( goodbye3.i32_thing == 4, 'goodbye3.I32_thing == 4');
762 rslt.Expect( Int64.compare( goodbye3.i64_thing, Int64.make(0,4)) == 0, 'goodbye3.I64_thing == 4');
763 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200764
Jens Geyerb5028322014-11-09 02:38:11 +0100765 var arg0 = 1;
766 var arg1 = 2;
767 var arg2 = Int64.make( 0x7FFFFFFF,0xFFFFFFFF);
768 var multiDict = new IntMap< String>();
769 multiDict.set(1, "one");
770 var arg4 = Numberz.FIVE;
771 var arg5 = Int64.make(0,5000000);
772 trace("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")");
773 var multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5);
774 trace(" = Xtruct(byte_thing:" + multiResponse.byte_thing + ",string_thing:" + multiResponse.string_thing
775 + ",i32_thing:" + multiResponse.i32_thing
776 + ",i64_thing:" + Int64.toStr(multiResponse.i64_thing) + ")");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200777
Jens Geyerb5028322014-11-09 02:38:11 +0100778 rslt.Expect( multiResponse.string_thing == "Hello2", 'multiResponse.String_thing == "Hello2"');
779 rslt.Expect( multiResponse.byte_thing == arg0, 'multiResponse.Byte_thing == arg0');
780 rslt.Expect( multiResponse.i32_thing == arg1, 'multiResponse.I32_thing == arg1');
781 rslt.Expect( Int64.compare( multiResponse.i64_thing, arg2) == 0, 'multiResponse.I64_thing == arg2');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200782
783
Jens Geyerb5028322014-11-09 02:38:11 +0100784 rslt.StartTestGroup( 0);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200785
Jens Geyerb5028322014-11-09 02:38:11 +0100786 trace("Test Oneway(1)");
787 client.testOneway(1);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200788
Jens Geyerb5028322014-11-09 02:38:11 +0100789 if( ! args.skipSpeedTest) {
790 trace("Test Calltime()");
791 var difft = Timer.stamp();
792 for ( k in 0 ... 1000) {
793 client.testVoid();
794 }
795 difft = Timer.stamp() - difft;
796 trace('$difft ms per testVoid() call');
797 }
798 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200799}