]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/test/haxe/src/TestClient.hx
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / test / haxe / src / TestClient.hx
CommitLineData
f67539c2
TL
1/*
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.io.Bytes;
25import haxe.Timer;
26import haxe.ds.IntMap;
27import haxe.ds.StringMap;
28import haxe.ds.ObjectMap;
29
30import org.apache.thrift.*;
31import org.apache.thrift.helper.*;
32import org.apache.thrift.protocol.*;
33import org.apache.thrift.transport.*;
34import org.apache.thrift.server.*;
35import org.apache.thrift.meta_data.*;
36
37#if cpp
38import cpp.vm.Thread;
39#else
40// no thread support (yet)
41#end
42
43import thrift.test.*; // generated code
44
45
46using StringTools;
47
48class TestResults {
49 private var successCnt : Int = 0;
50 private var errorCnt : Int = 0;
51 private var failedTests : String = "";
52 private var print_direct : Bool = false;
53
54 public static var EXITCODE_SUCCESS = 0x00; // no errors bits set
55 //
56 public static var EXITCODE_FAILBIT_BASETYPES = 0x01;
57 public static var EXITCODE_FAILBIT_STRUCTS = 0x02;
58 public static var EXITCODE_FAILBIT_CONTAINERS = 0x04;
59 public static var EXITCODE_FAILBIT_EXCEPTIONS = 0x08;
60 //
61 public static var EXITCODE_ALL_FAILBITS = 0x0F;
62 //
63 private var testsExecuted : Int = 0;
64 private var testsFailed : Int = 0;
65 private var currentTest : Int = 0;
66
67
68 public function new(direct : Bool) {
69 print_direct = direct;
70 }
71
72 public function StartTestGroup( groupBit : Int) : Void {
73 currentTest = groupBit;
74 testsExecuted |= groupBit;
75 }
76
77 public function Expect( expr : Bool, msg : String) : Void {
78 if ( expr) {
79 ++successCnt;
80 } else {
81 ++errorCnt;
82 testsFailed |= currentTest;
83 failedTests += "\n " + msg;
84 if( print_direct) {
85 trace('FAIL: $msg');
86 }
87 }
88 }
89
90 public function CalculateExitCode() : Int {
91 var notExecuted : Int = EXITCODE_ALL_FAILBITS & (~testsExecuted);
92 return testsFailed | notExecuted;
93 }
94
95 public function PrintSummary() : Void {
96 var total = successCnt + errorCnt;
97 var sp = Math.round((1000 * successCnt) / total) / 10;
98 var ep = Math.round((1000 * errorCnt) / total) / 10;
99
100 trace('===========================');
101 trace('Tests executed $total');
102 trace('Tests succeeded $successCnt ($sp%)');
103 trace('Tests failed $errorCnt ($ep%)');
104 if ( errorCnt > 0)
105 {
106 trace('===========================');
107 trace('FAILED TESTS: $failedTests');
108 }
109 trace('===========================');
110 }
111}
112
113
114class TestClient {
115
116 public static function Execute(args : Arguments) : Void
117 {
118 var exitCode = 0xFF;
119 try
120 {
121 var difft = Timer.stamp();
122
123 if ( args.numThreads > 1) {
124 #if cpp
125 exitCode = MultiThreadClient(args);
126 #else
127 trace('Threads not supported/implemented for this platform.');
128 exitCode = SingleThreadClient(args);
129 #end
130 } else {
131 exitCode = SingleThreadClient(args);
132 }
133
134 difft = Math.round( 1000 * (Timer.stamp() - difft)) / 1000;
135 trace('total test time: $difft seconds');
136 }
137 catch (e : TException)
138 {
139 trace('TException: $e');
140 exitCode = 0xFF;
141 }
142 catch (e : Dynamic)
143 {
144 trace('Exception: $e');
145 exitCode = 0xFF;
146 }
147
148 #if sys
149 Sys.exit( exitCode);
150 #end
151 }
152
153
154 public static function SingleThreadClient(args : Arguments) : Int
155 {
156 var rslt = new TestResults(true);
157 RunClient(args,rslt);
158 rslt.PrintSummary();
159 return rslt.CalculateExitCode();
160 }
161
162
163 #if cpp
164 public static function MultiThreadClient(args : Arguments) : Int
165 {
166 var threads = new List<Thread>();
167 for( test in 0 ... args.numThreads) {
168 threads.add( StartThread( args));
169 }
170 var exitCode : Int = 0;
171 for( thread in threads) {
172 exitCode |= Thread.readMessage(true);
173 }
174 return exitCode;
175 }
176 #end
177
178 #if cpp
179 private static function StartThread(args : Arguments) : Thread {
180 var thread = Thread.create(
181 function() : Void {
182 var rslt = new TestResults(false);
183 var main : Thread = Thread.readMessage(true);
184 try
185 {
186 RunClient(args,rslt);
187 }
188 catch (e : TException)
189 {
190 rslt.Expect( false, '$e');
191 trace('$e');
192 }
193 catch (e : Dynamic)
194 {
195 rslt.Expect( false, '$e');
196 trace('$e');
197 }
198 main.sendMessage( rslt.CalculateExitCode());
199 });
200
201 thread.sendMessage(Thread.current());
202 return thread;
203 }
204 #end
205
206
207 public static function RunClient(args : Arguments, rslt : TestResults)
208 {
209 var transport : TTransport = null;
210 switch (args.transport)
211 {
212 case socket:
213 transport = new TSocket(args.host, args.port);
214 case http:
215 var uri = 'http://${args.host}:${args.port}';
216 trace('- http client : ${uri}');
217 transport = new THttpClient(uri);
218 default:
219 throw "Unhandled transport";
220 }
221
222 // optional: layered transport
223 if ( args.framed) {
224 trace("- framed transport");
225 transport = new TFramedTransport(transport);
226 }
227 if ( args.buffered) {
228 trace("- buffered transport");
229 transport = new TBufferedTransport(transport);
230 }
231
232 // protocol
233 var protocol : TProtocol = null;
234 switch( args.protocol)
235 {
236 case binary:
237 trace("- binary protocol");
238 protocol = new TBinaryProtocol(transport);
239 case json:
240 trace("- json protocol");
241 protocol = new TJSONProtocol(transport);
242 case compact:
243 trace("- compact protocol");
244 protocol = new TCompactProtocol(transport);
245 }
246
247 // some quick and basic unit tests
248 HaxeBasicsTest( args, rslt);
249 ModuleUnitTests( args, rslt);
250
251 // now run the test code
252 trace('- ${args.numIterations} iterations');
253 for( i in 0 ... args.numIterations) {
254 ClientTest( transport, protocol, args, rslt);
255 }
256 }
257
258
259 public static function HaxeBasicsTest( args : Arguments, rslt : TestResults) : Void
260 {
261 // We need to test a few basic things used in the ClientTest
262 // Anything else beyond this scope should go into /lib/haxe/ instead
263 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES);
264
265 var map32 = new IntMap<Int32>();
266 var map64 = new Int64Map<Int32>();
267
268 rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #1");
269 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #2");
270 rslt.Expect( map32.remove( 4711) == map64.remove( Int64.make(47,11)), "Int64Map<Int32> Test #3");
271 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #4");
272
273 map32.set( 42, 815);
274 map64.set( Int64.make(0,42), 815);
275 map32.set( -517, 23);
276 map64.set( Int64.neg(Int64.make(0,517)), 23);
277 map32.set( 0, -123);
278 map64.set( Int64.make(0,0), -123);
279
280 //trace('map32 = $map32');
281 //trace('map64 = $map64');
282
283 rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #10");
284 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #11");
285 rslt.Expect( map32.exists( -517) == map64.exists( Int64.neg(Int64.make(0,517))), "Int64Map<Int32> Test #12");
286 rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #13");
287 rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #14");
288 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #15");
289 rslt.Expect( map32.get( -517) == map64.get( Int64.neg(Int64.make(0,517))), "Int64Map<Int32> Test #16");
290 rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #Int64.make(-5,17)");
291 rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #18");
292 rslt.Expect( map32.remove( 4711) == map64.remove( Int64.make(47,11)), "Int64Map<Int32> Test #19");
293 rslt.Expect( map32.remove( -517) == map64.remove( Int64.neg(Int64.make(0,517))), "Int64Map<Int32> Test #20");
294 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #21");
295 rslt.Expect( map32.exists( -517) == map64.exists( Int64.neg(Int64.make(0,517))), "Int64Map<Int32> Test #22");
296 rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #23");
297 rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #24");
298 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #25");
299 rslt.Expect( map32.get( -517) == map64.get( Int64.neg(Int64.make(0,517))), "Int64Map<Int32> Test #26");
300 rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #27");
301 rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #28");
302
303 map32.set( 42, 1);
304 map64.set( Int64.make(0,42), 1);
305 map32.set( -517, -2);
306 map64.set( Int64.neg(Int64.make(0,517)), -2);
307 map32.set( 0, 3);
308 map64.set( Int64.make(0,0), 3);
309
310 var c32 = 0;
311 var ksum32 = 0;
312 for (key in map32.keys()) {
313 ++c32;
314 ksum32 += key;
315 }
316 var c64 = 0;
317 var ksum64 = Int64.make(0,0);
318 for (key in map64.keys()) {
319 ++c64;
320 ksum64 = Int64.add( ksum64, key);
321 }
322 rslt.Expect( c32 == c64, "Int64Map<Int32> Test #30");
323 rslt.Expect( '$ksum64' == '$ksum32', '$ksum64 == $ksum32 Test #31');
324
325 //compare without spaces because differ in php and cpp
326 var s32 = map32.toString().replace(' ', '');
327 var s64 = map64.toString().replace(' ', '');
328 rslt.Expect( s32 == s64, "Int64Map<Int32>.toString(): " + ' ("$s32" == "$s64") Test #32');
329
330 map32.remove( 42);
331 map64.remove( Int64.make(0,42));
332 map32.remove( -517);
333 map64.remove( Int64.neg(Int64.make(0,517)));
334 map32.remove( 0);
335 map64.remove( Int64.make(0,0));
336
337 rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #90");
338 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #91");
339 rslt.Expect( map32.exists( -517) == map64.exists( Int64.neg(Int64.make(0,517))), "Int64Map<Int32> Test #92");
340 rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #93");
341 rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #94");
342 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #95");
343 rslt.Expect( map32.get( -517) == map64.get( Int64.make(-5,17)), "Int64Map<Int32> Test #96");
344 rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #97");
345 rslt.Expect( map32.get( 0) == map64.get( Int64.make(0, 0)), "Int64Map<Int32> Test #98");
346 }
347
348
349 // core module unit tests
350 public static function ModuleUnitTests( args : Arguments, rslt : TestResults) : Void {
351 #if debug
352
353 try {
354 BitConverter.UnitTest();
355 rslt.Expect( true, 'BitConverter.UnitTest Test #100');
356 }
357 catch( e : Dynamic) {
358 rslt.Expect( false, 'BitConverter.UnitTest: $e Test #100');
359 }
360
361 try {
362 ZigZag.UnitTest();
363 rslt.Expect( true, 'ZigZag.UnitTest Test #101');
364 }
365 catch( e : Dynamic) {
366 rslt.Expect( false, 'ZigZag.UnitTest: $e Test #101');
367 }
368
369 #end
370 }
371
372
373 public static function BytesToHex(data : Bytes) : String {
374 var hex = "";
375 for ( i in 0 ... data.length) {
376 hex += StringTools.hex( data.get(i), 2);
377 }
378 return hex;
379 }
380
381 public static function PrepareTestData(randomDist : Bool) : Bytes {
382 var retval = Bytes.alloc(0x100);
383 var initLen : Int = (retval.length > 0x100 ? 0x100 : retval.length);
384
385 // linear distribution, unless random is requested
386 if (!randomDist) {
387 for (i in 0 ... initLen) {
388 retval.set(i, i % 0x100);
389 }
390 return retval;
391 }
392
393 // random distribution
394 for (i in 0 ... initLen) {
395 retval.set(i, 0);
396 }
397 for (i in 1 ... initLen) {
398 while( true) {
399 var nextPos = Std.random(initLen);
400 if (retval.get(nextPos) == 0) {
401 retval.set( nextPos, i % 0x100);
402 break;
403 }
404 }
405 }
406 return retval;
407 }
408
409
410 public static function ClientTest( transport : TTransport, protocol : TProtocol,
411 args : Arguments, rslt : TestResults) : Void
412 {
413 var client = new ThriftTestImpl(protocol,protocol);
414 try
415 {
416 if (!transport.isOpen())
417 {
418 transport.open();
419 }
420 }
421 catch (e : TException)
422 {
423 rslt.Expect( false, 'unable to open transport: $e');
424 return;
425 }
426 catch (e : Dynamic)
427 {
428 rslt.Expect( false, 'unable to open transport: $e');
429 return;
430 }
431
432 var start = Date.now();
433
434 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_EXCEPTIONS);
435
436 // if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
437 trace('testException("Xception")');
438 try {
439 client.testException("Xception");
440 rslt.Expect( false, 'testException("Xception") should throw');
441 }
442 catch (e : Xception)
443 {
444 rslt.Expect( e.message == "Xception", 'testException("Xception") - e.message == "Xception"');
445 rslt.Expect( e.errorCode == 1001, 'testException("Xception") - e.errorCode == 1001');
446 }
447 catch (e : TException)
448 {
449 rslt.Expect( false, 'testException("Xception") - ${e} : ${e.errorMsg}');
450 }
451 catch (e : Dynamic)
452 {
453 rslt.Expect( false, 'testException("Xception") - $e');
454 }
455
456 // if arg == "TException" throw TException
457 trace('testException("TException")');
458 try {
459 client.testException("TException");
460 rslt.Expect( false, 'testException("TException") should throw');
461 }
462 catch (e : TException)
463 {
464 rslt.Expect( true, 'testException("TException") - $e : ${e.errorMsg}');
465 }
466 catch (e : Dynamic)
467 {
468 rslt.Expect( false, 'testException("TException") - $e');
469 }
470
471 // reopen the transport, just in case the server closed his end
472 if (transport.isOpen())
473 transport.close();
474 transport.open();
475
476 // else do not throw anything
477 trace('testException("bla")');
478 try {
479 client.testException("bla");
480 rslt.Expect( true, 'testException("bla") should not throw');
481 }
482 catch (e : TException)
483 {
484 rslt.Expect( false, 'testException("bla") - ${e} : ${e.errorMsg}');
485 }
486 catch (e : Dynamic)
487 {
488 rslt.Expect( false, 'testException("bla") - $e');
489 }
490
491 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES);
492
493 trace('testVoid()');
494 client.testVoid();
495 trace(' = void');
496 rslt.Expect(true,"testVoid()"); // bump counter
497
498 trace('testBool(${true})');
499 var b = client.testBool(true);
500 trace(' = $b');
501 rslt.Expect(b, '$b == "${true}"');
502 trace('testBool(${false})');
503 b = client.testBool(false);
504 trace(' = $b');
505 rslt.Expect( ! b, '$b == "${false}"');
506
507 trace('testString("Test")');
508 var s = client.testString("Test");
509 trace(' = "$s"');
510 rslt.Expect(s == "Test", '$s == "Test"');
511
512 trace('testByte(1)');
513 var i8 = client.testByte(1);
514 trace(' = $i8');
515 rslt.Expect(i8 == 1, '$i8 == 1');
516
517 trace('testI32(-1)');
518 var i32 = client.testI32(-1);
519 trace(' = $i32');
520 rslt.Expect(i32 == -1, '$i32 == -1');
521
522 trace('testI64(-34359738368)');
523 var i64 = client.testI64( Int64.make( 0xFFFFFFF8, 0x00000000)); // -34359738368
524 trace(' = $i64');
525 rslt.Expect( Int64.compare( i64, Int64.make( 0xFFFFFFF8, 0x00000000)) == 0,
526 Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0xFFFFFFF8, 0x00000000)));
527
528 // edge case: the largest negative Int64 has no positive Int64 equivalent
529 trace('testI64(-9223372036854775808)');
530 i64 = client.testI64( Int64.make( 0x80000000, 0x00000000)); // -9223372036854775808
531 trace(' = $i64');
532 rslt.Expect( Int64.compare( i64, Int64.make( 0x80000000, 0x00000000)) == 0,
533 Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0x80000000, 0x00000000)));
534
535 trace('testDouble(5.325098235)');
536 var dub = client.testDouble(5.325098235);
537 trace(' = $dub');
538 rslt.Expect(dub == 5.325098235, '$dub == 5.325098235');
539
540 var binOut = PrepareTestData(true);
541 trace('testBinary('+BytesToHex(binOut)+')');
542 try {
543 var binIn = client.testBinary(binOut);
544 trace('testBinary() = '+BytesToHex(binIn));
545 rslt.Expect( binIn.length == binOut.length, '${binIn.length} == ${binOut.length}');
546 var len = ((binIn.length < binOut.length) ? binIn.length : binOut.length);
547 for (ofs in 0 ... len) {
548 if (binIn.get(ofs) != binOut.get(ofs)) {
549 rslt.Expect( false, 'testBinary('+BytesToHex(binOut)+'): content mismatch at offset $ofs');
550 }
551 }
552 }
553 catch (e : TApplicationException) {
554 trace('testBinary('+BytesToHex(binOut)+'): '+e.errorMsg); // may not be supported by the server
555 }
556
557
558 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS);
559
560 trace('testStruct({"Zero", 1, -3, -5})');
561 var o = new Xtruct();
562 o.string_thing = "Zero";
563 o.byte_thing = 1;
564 o.i32_thing = -3;
565 o.i64_thing = Int64.make(0,-5);
566 var i = client.testStruct(o);
567 trace(' = {"' + i.string_thing + '", ' + i.byte_thing +', '
568 + i.i32_thing +', '+ Int64.toStr(i.i64_thing) + '}');
569 rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing");
570 rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing");
571 rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing");
572 rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing");
573
574 trace('testNest({1, {\"Zero\", 1, -3, -5}, 5})');
575 var o2 = new Xtruct2();
576 o2.byte_thing = 1;
577 o2.struct_thing = o;
578 o2.i32_thing = 5;
579 var i2 = client.testNest(o2);
580 i = i2.struct_thing;
581 trace(" = {" + i2.byte_thing + ", {\"" + i.string_thing + "\", "
582 + i.byte_thing + ", " + i.i32_thing + ", " + Int64.toStr(i.i64_thing) + "}, "
583 + i2.i32_thing + "}");
584 rslt.Expect( i2.byte_thing == o2.byte_thing, "i2.byte_thing == o2.byte_thing");
585 rslt.Expect( i2.i32_thing == o2.i32_thing, "i2.i32_thing == o2.i32_thing");
586 rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing");
587 rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing");
588 rslt.Expect( i.i32_thing == o.i32_thing, "i.i32_thing == o.i32_thing");
589 rslt.Expect( Int64.compare( i.i64_thing, o.i64_thing) == 0, "i.i64_thing == o.i64_thing");
590
591
592 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS);
593
594 var mapout = new IntMap< haxe.Int32>();
595 for ( j in 0 ... 5)
596 {
597 mapout.set(j, j - 10);
598 }
599 trace("testMap({");
600 var first : Bool = true;
601 for( key in mapout.keys())
602 {
603 if (first)
604 {
605 first = false;
606 }
607 else
608 {
609 trace(", ");
610 }
611 trace(key + " => " + mapout.get(key));
612 }
613 trace("})");
614
615 var mapin = client.testMap(mapout);
616
617 trace(" = {");
618 first = true;
619 for( key in mapin.keys())
620 {
621 if (first)
622 {
623 first = false;
624 }
625 else
626 {
627 trace(", ");
628 }
629 trace(key + " => " + mapin.get(key));
630 rslt.Expect( mapin.get(key) == mapout.get(key), ' mapin.get($key) == mapout.get($key)');
631 }
632 trace("}");
633 for( key in mapout.keys())
634 {
635 rslt.Expect(mapin.exists(key), 'mapin.exists($key)');
636 }
637
638 var listout = new List<Int>();
639 for (j in -2 ... 3)
640 {
641 listout.add(j);
642 }
643 trace("testList({");
644 first = true;
645 for( j in listout)
646 {
647 if (first)
648 {
649 first = false;
650 }
651 else
652 {
653 trace(", ");
654 }
655 trace(j);
656 }
657 trace("})");
658
659 var listin = client.testList(listout);
660
661 trace(" = {");
662 first = true;
663 for( j in listin)
664 {
665 if (first)
666 {
667 first = false;
668 }
669 else
670 {
671 trace(", ");
672 }
673 trace(j);
674 }
675 trace("}");
676
677 rslt.Expect(listin.length == listout.length, "listin.length == listout.length");
678 var literout = listout.iterator();
679 var literin = listin.iterator();
680 while( literin.hasNext()) {
681 rslt.Expect(literin.next() == literout.next(), "literin[i] == literout[i]");
682 }
683
684 //set
685 var setout = new IntSet();
686 for (j in -2 ... 3)
687 {
688 setout.add(j);
689 }
690 trace("testSet({");
691 first = true;
692 for( j in setout)
693 {
694 if (first)
695 {
696 first = false;
697 }
698 else
699 {
700 trace(", ");
701 }
702 trace(j);
703 }
704 trace("})");
705
706 var setin = client.testSet(setout);
707
708 trace(" = {");
709 first = true;
710 for( j in setin)
711 {
712 if (first)
713 {
714 first = false;
715 }
716 else
717 {
718 trace(", ");
719 }
720 trace(j);
721 rslt.Expect(setout.contains(j), 'setout.contains($j)');
722 }
723 trace("}");
724 rslt.Expect(setin.size == setout.size, "setin.length == setout.length");
725
726
727 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES);
728
729 trace("testEnum(ONE)");
730 var ret = client.testEnum(Numberz.ONE);
731 trace(" = " + ret);
732 rslt.Expect(ret == Numberz.ONE, '$ret == Numberz.ONE');
733
734 trace("testEnum(TWO)");
735 ret = client.testEnum(Numberz.TWO);
736 trace(" = " + ret);
737 rslt.Expect(ret == Numberz.TWO, '$ret == Numberz.TWO');
738
739 trace("testEnum(THREE)");
740 ret = client.testEnum(Numberz.THREE);
741 trace(" = " + ret);
742 rslt.Expect(ret == Numberz.THREE, '$ret == Numberz.THREE');
743
744 trace("testEnum(FIVE)");
745 ret = client.testEnum(Numberz.FIVE);
746 trace(" = " + ret);
747 rslt.Expect(ret == Numberz.FIVE, '$ret == Numberz.FIVE');
748
749 trace("testEnum(EIGHT)");
750 ret = client.testEnum(Numberz.EIGHT);
751 trace(" = " + ret);
752 rslt.Expect(ret == Numberz.EIGHT, '$ret == Numberz.EIGHT');
753
754 trace("testTypedef(309858235082523)");
755 var uid = client.testTypedef( Int64.make( 0x119D0, 0x7E08671B)); // 309858235082523
756 trace(" = " + uid);
757 rslt.Expect( Int64.compare( uid, Int64.make( 0x119D0, 0x7E08671B)) == 0,
758 Int64.toStr(uid)+" == "+Int64.toStr(Int64.make( 0x119D0, 0x7E08671B)));
759
760
761 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS);
762
763 trace("testMapMap(1)");
764 var mm = client.testMapMap(1);
765 trace(" = {");
766 for( key in mm.keys())
767 {
768 trace(key + " => {");
769 var m2 = mm.get(key);
770 for( k2 in m2.keys())
771 {
772 trace(k2 + " => " + m2.get(k2) + ", ");
773 }
774 trace("}, ");
775 }
776 trace("}");
777
778 var pos = mm.get(4);
779 var neg = mm.get(-4);
780 rslt.Expect( (pos != null) && (neg != null), "(pos != null) && (neg != null)");
781 for (i in 1 ... 5) {
782 rslt.Expect( pos.get(i) == i, 'pos.get($i) == $i');
783 rslt.Expect( neg.get(-i) == -i, 'neg.get(-$i) == -$i');
784 }
785 rslt.Expect( ! pos.exists(0), '!pos.exists(0)');
786 rslt.Expect( ! neg.exists(-0), '!neg.exists(-0)');
787 rslt.Expect( ! pos.exists(42), '!pos.exists(42)');
788 rslt.Expect( ! neg.exists(-42), '!neg.exists(-42)');
789
790
791 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS);
792
793 var insane = new Insanity();
794 insane.userMap = new IntMap< Int64>();
795 insane.userMap.set( Numberz.FIVE, Int64.make(0,5000));
796 var truck = new Xtruct();
797 truck.string_thing = "Truck";
798 truck.byte_thing = 8;
799 truck.i32_thing = 8;
800 truck.i64_thing = Int64.make(0,8);
801 insane.xtructs = new List<Xtruct>();
802 insane.xtructs.add(truck);
803 trace("testInsanity()");
804 var whoa = client.testInsanity(insane);
805 trace(" = {");
806 for( key in whoa.keys())
807 {
808 var val = whoa.get(key);
809 trace(key + " => {");
810
811 for( k2 in val.keys())
812 {
813 var v2 = val.get(k2);
814
815 trace(k2 + " => {");
816 var userMap = v2.userMap;
817
818 trace("{");
819 if (userMap != null)
820 {
821 for( k3 in userMap.keys())
822 {
823 trace(k3 + " => " + userMap.get(k3) + ", ");
824 }
825 }
826 else
827 {
828 trace("null");
829 }
830 trace("}, ");
831
832 var xtructs = v2.xtructs;
833
834 trace("{");
835 if (xtructs != null)
836 {
837 for( x in xtructs)
838 {
839 trace("{\"" + x.string_thing + "\", "
840 + x.byte_thing + ", " + x.i32_thing + ", "
841 + x.i32_thing + "}, ");
842 }
843 }
844 else
845 {
846 trace("null");
847 }
848 trace("}");
849
850 trace("}, ");
851 }
852 trace("}, ");
853 }
854 trace("}");
855
856
857 /**
858 * So you think you've got this all worked, out eh?
859 *
860 * Creates a the returned map with these values and prints it out:
861 * { 1 => { 2 => argument,
862 * 3 => argument,
863 * },
864 * 2 => { 6 => <empty Insanity struct>, },
865 * }
866 * @return map<UserId, map<Numberz,Insanity>> - a map with the above values
867 */
868
869 var first_map = whoa.get(Int64.make(0,1));
870 var second_map = whoa.get(Int64.make(0,2));
871 rslt.Expect( (first_map != null) && (second_map != null), "(first_map != null) && (second_map != null)");
872 if ((first_map != null) && (second_map != null))
873 {
874 var crazy2 = first_map.get(Numberz.TWO);
875 var crazy3 = first_map.get(Numberz.THREE);
876 var looney = second_map.get(Numberz.SIX);
877 rslt.Expect( (crazy2 != null) && (crazy3 != null) && (looney != null),
878 "(crazy2 != null) && (crazy3 != null) && (looney != null)");
879
880 var crz2iter = crazy2.xtructs.iterator();
881 var crz3iter = crazy3.xtructs.iterator();
882 rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()");
883 var goodbye2 = crz2iter.next();
884 var goodbye3 = crz3iter.next();
885 rslt.Expect( ! (crz2iter.hasNext() || crz3iter.hasNext()), "! (crz2iter.hasNext() || crz3iter.hasNext())");
886
887 rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.FIVE), insane.userMap.get(Numberz.FIVE)) == 0, "crazy2.userMap[5] == insane.userMap[5]");
888 rslt.Expect( truck.string_thing == goodbye2.string_thing, "truck.string_thing == goodbye2.string_thing");
889 rslt.Expect( truck.byte_thing == goodbye2.byte_thing, "truck.byte_thing == goodbye2.byte_thing");
890 rslt.Expect( truck.i32_thing == goodbye2.i32_thing, "truck.i32_thing == goodbye2.i32_thing");
891 rslt.Expect( Int64.compare( truck.i64_thing, goodbye2.i64_thing) == 0, "truck.i64_thing == goodbye2.i64_thing");
892
893 rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.FIVE), insane.userMap.get(Numberz.FIVE)) == 0, "crazy3.userMap[5] == insane.userMap[5]");
894 rslt.Expect( truck.string_thing == goodbye3.string_thing, "truck.string_thing == goodbye3.string_thing");
895 rslt.Expect( truck.byte_thing == goodbye3.byte_thing, "truck.byte_thing == goodbye3.byte_thing");
896 rslt.Expect( truck.i32_thing == goodbye3.i32_thing, "truck.i32_thing == goodbye3.i32_thing");
897 rslt.Expect( Int64.compare( truck.i64_thing, goodbye3.i64_thing) == 0, "truck.i64_thing == goodbye3.i64_thing");
898
899 rslt.Expect( ! looney.isSet(1), "! looney.isSet(1)");
900 rslt.Expect( ! looney.isSet(2), "! looney.isSet(2)");
901 }
902
903 var arg0 = 1;
904 var arg1 = 2;
905 var arg2 = Int64.make( 0x7FFFFFFF,0xFFFFFFFF);
906 var multiDict = new IntMap< String>();
907 multiDict.set(1, "one");
908 var arg4 = Numberz.FIVE;
909 var arg5 = Int64.make(0,5000000);
910 trace("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")");
911 var multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5);
912 trace(" = Xtruct(byte_thing:" + multiResponse.byte_thing + ",string_thing:" + multiResponse.string_thing
913 + ",i32_thing:" + multiResponse.i32_thing
914 + ",i64_thing:" + Int64.toStr(multiResponse.i64_thing) + ")");
915
916 rslt.Expect( multiResponse.string_thing == "Hello2", 'multiResponse.String_thing == "Hello2"');
917 rslt.Expect( multiResponse.byte_thing == arg0, 'multiResponse.Byte_thing == arg0');
918 rslt.Expect( multiResponse.i32_thing == arg1, 'multiResponse.I32_thing == arg1');
919 rslt.Expect( Int64.compare( multiResponse.i64_thing, arg2) == 0, 'multiResponse.I64_thing == arg2');
920
921
922 rslt.StartTestGroup( 0);
923
924 trace("Test Oneway(1)");
925 client.testOneway(1);
926
927 if( ! args.skipSpeedTest) {
928 trace("Test Calltime()");
929 var difft = Timer.stamp();
930 for ( k in 0 ... 1000) {
931 client.testVoid();
932 }
933 difft = Math.round( 1000 * (Timer.stamp() - difft)) / 1000;
934 trace('$difft ms per testVoid() call');
935 }
936 }
937}