blob: 3c98e6aba3eae18646ab19bcff6f653f3c8abca1 [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 {
46 private var successCnt : Int = 0;
47 private var errorCnt : Int = 0;
48 private var failedTests : String = "";
49 private var print_direct : Bool = false;
Jens Geyerfea00ac2014-10-01 02:22:48 +020050
51 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
Jens Geyerfea00ac2014-10-01 02:22:48 +020064
Jens Geyerbd52f1a2014-07-28 01:25:30 +020065 public function new(direct : Bool) {
66 print_direct = direct;
67 }
68
Jens Geyerfea00ac2014-10-01 02:22:48 +020069 public function StartTestGroup( groupBit : Int) : Void {
70 currentTest = groupBit;
71 testsExecuted |= groupBit;
72 }
73
Jens Geyerbd52f1a2014-07-28 01:25:30 +020074 public function Expect( expr : Bool, msg : String) : Void {
75 if ( expr) {
76 ++successCnt;
77 } else {
78 ++errorCnt;
Jens Geyerfea00ac2014-10-01 02:22:48 +020079 testsFailed |= currentTest;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020080 failedTests += "\n " + msg;
81 if( print_direct) {
82 trace('FAIL: $msg');
83 }
84 }
85 }
86
Jens Geyerfea00ac2014-10-01 02:22:48 +020087 public function CalculateExitCode() : Int {
88 var notExecuted : Int = EXITCODE_ALL_FAILBITS & (~testsExecuted);
89 return testsFailed | notExecuted;
90 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020091
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 }
108}
109
110
111class TestClient {
112
113 public static function Execute(args : Arguments) : Void
114 {
Jens Geyerfea00ac2014-10-01 02:22:48 +0200115 var exitCode = 0xFF;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200116 try
117 {
118 var difft = Timer.stamp();
Jens Geyerfea00ac2014-10-01 02:22:48 +0200119
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200120 if( args.numThreads > 1) {
121 var threads = new List<Thread>();
122 for( test in 0 ... args.numThreads) {
123 threads.add( StartThread( args));
124 }
Jens Geyerfea00ac2014-10-01 02:22:48 +0200125 exitCode = 0;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200126 for( thread in threads) {
Jens Geyerfea00ac2014-10-01 02:22:48 +0200127 exitCode |= Thread.readMessage(true);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200128 }
129 } else {
130 var rslt = new TestResults(true);
131 RunClient(args,rslt);
132 rslt.PrintSummary();
Jens Geyerfea00ac2014-10-01 02:22:48 +0200133 exitCode = rslt.CalculateExitCode();
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200134 }
135
Jens Geyerfea00ac2014-10-01 02:22:48 +0200136 difft = Timer.stamp() - difft;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200137 trace('total test time: $difft seconds');
138 }
139 catch (e : TException)
140 {
141 trace('$e');
Jens Geyerfea00ac2014-10-01 02:22:48 +0200142 exitCode = 0xFF;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200143 }
144 catch (e : Dynamic)
145 {
146 trace('$e');
Jens Geyerfea00ac2014-10-01 02:22:48 +0200147 exitCode = 0xFF;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200148 }
Jens Geyerfea00ac2014-10-01 02:22:48 +0200149
150 #if sys
151 Sys.exit( exitCode);
152 #end
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200153 }
154
155
156 private static function StartThread(args : Arguments) : Thread {
157 var thread = Thread.create(
158 function() : Void {
Jens Geyerfea00ac2014-10-01 02:22:48 +0200159 var rslt = new TestResults(false);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200160 var main : Thread = Thread.readMessage(true);
161 try
162 {
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200163 RunClient(args,rslt);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200164 }
165 catch (e : TException)
166 {
Jens Geyerfea00ac2014-10-01 02:22:48 +0200167 rslt.Expect( false, '$e');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200168 trace('$e');
169 }
170 catch (e : Dynamic)
171 {
Jens Geyerfea00ac2014-10-01 02:22:48 +0200172 rslt.Expect( false, '$e');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200173 trace('$e');
174 }
Jens Geyerfea00ac2014-10-01 02:22:48 +0200175 main.sendMessage( rslt.CalculateExitCode());
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200176 });
177
178 thread.sendMessage(Thread.current());
179 return thread;
180 }
181
182
183 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:
Jens Geyerfea00ac2014-10-01 02:22:48 +0200191 transport = new THttpClient(args.host);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200192 default:
193 throw "Unhandled transport";
194 }
195
196 // optional: layered transport
197 if ( args.framed) {
198 trace("- framed transport");
199 transport = new TFramedTransport(transport);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200200 }
201 if ( args.buffered) {
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200202 trace("- buffered transport");
203 throw "TBufferedTransport not implemented yet";
204 //transport = new TBufferedTransport(transport);
205 }
206
207 // 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 }
220
221
222 // run the test code
Jens Geyerfea00ac2014-10-01 02:22:48 +0200223 HaxeBasicsTest( args, rslt);
224 for( i in 0 ... args.numIterations) {
225 ClientTest( transport, protocol, args, rslt);
226 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200227 }
228
229
Jens Geyerfea00ac2014-10-01 02:22:48 +0200230 public static function HaxeBasicsTest( args : Arguments, rslt : TestResults) : Void
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200231 {
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
Jens Geyerfea00ac2014-10-01 02:22:48 +0200234 rslt.StartTestGroup( 0);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200235
236 var map32 = new IntMap<Int32>();
237 var map64 = new Int64Map<Int32>();
238
239 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");
243
244 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);
250
251 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");
270
271 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);
277
278 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");
287
288 var s32 = map32.toString();
289 var s64 = map64.toString();
290 trace("Int64Map<Int32>.toString(): " + ' ("$s32" == "$s64")');
291
292 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));
298
299 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 }
309
310
Jens Geyerfea00ac2014-10-01 02:22:48 +0200311 public static function ClientTest( transport : TTransport, protocol : TProtocol,
312 args : Arguments, rslt : TestResults) : Void
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200313 {
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 }
332
333 var start = Date.now();
334
Jens Geyerfea00ac2014-10-01 02:22:48 +0200335 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
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200383 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
Jens Geyerfea00ac2014-10-01 02:22:48 +0200421
422 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS);
423
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200424 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 +', '
Jens Geyerfea00ac2014-10-01 02:22:48 +0200432 + i.i32_thing +', '+ Int64.toStr(i.i64_thing) + '}');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200433 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
Jens Geyerfea00ac2014-10-01 02:22:48 +0200455
456 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS);
457
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200458 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("})");
478
479 var mapin = client.testMap(mapout);
480
481 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 }
501
502 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("})");
522
523 var listin = client.testList(listout);
524
525 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("}");
540
541 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 }
547
548 //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("})");
569
570 var setin = client.testSet(setout);
571
572 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");
589
590
Jens Geyerfea00ac2014-10-01 02:22:48 +0200591 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES);
592
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200593 trace("testEnum(ONE)");
594 var ret = client.testEnum(Numberz.ONE);
595 trace(" = " + ret);
596 rslt.Expect(ret == Numberz.ONE, '$ret == Numberz.ONE');
597
598 trace("testEnum(TWO)");
599 ret = client.testEnum(Numberz.TWO);
600 trace(" = " + ret);
601 rslt.Expect(ret == Numberz.TWO, '$ret == Numberz.TWO');
602
603 trace("testEnum(THREE)");
604 ret = client.testEnum(Numberz.THREE);
605 trace(" = " + ret);
606 rslt.Expect(ret == Numberz.THREE, '$ret == Numberz.THREE');
607
608 trace("testEnum(FIVE)");
609 ret = client.testEnum(Numberz.FIVE);
610 trace(" = " + ret);
611 rslt.Expect(ret == Numberz.FIVE, '$ret == Numberz.FIVE');
612
613 trace("testEnum(EIGHT)");
614 ret = client.testEnum(Numberz.EIGHT);
615 trace(" = " + ret);
616 rslt.Expect(ret == Numberz.EIGHT, '$ret == Numberz.EIGHT');
617
618 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)));
623
Jens Geyerfea00ac2014-10-01 02:22:48 +0200624
625 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS);
626
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200627 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("}");
641
642 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 }
649
Jens Geyerfea00ac2014-10-01 02:22:48 +0200650
651 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS);
652
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200653 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 + " => {");
670
671 for( k2 in val.keys())
672 {
673 var v2 = val.get(k2);
674
675 trace(k2 + " => {");
676 var userMap = v2.userMap;
677
678 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("}, ");
691
692 var xtructs = v2.xtructs;
693
694 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("}");
709
710 trace("}, ");
711 }
712 trace("}, ");
713 }
714 trace("}");
715
Jens Geyerfea00ac2014-10-01 02:22:48 +0200716
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200717 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)");
727
728 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");
736
737 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())");
746
747 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');
755
756 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 }
765
766 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) + ")");
778
779 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');
783
784
Jens Geyerfea00ac2014-10-01 02:22:48 +0200785 rslt.StartTestGroup( 0);
786
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200787 trace("Test Oneway(1)");
788 client.testOneway(1);
789
Jens Geyerfea00ac2014-10-01 02:22:48 +0200790 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');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200798 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200799 }
800}