blob: 5c0de7c7650fa6935be1054d6cbd191e8e645719 [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;
Jens Geyer43e195a2014-12-14 00:29:17 +010024import haxe.io.Bytes;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020025import 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
46class TestResults {
Jens Geyerb5028322014-11-09 02:38:11 +010047 private var successCnt : Int = 0;
48 private var errorCnt : Int = 0;
49 private var failedTests : String = "";
50 private var print_direct : Bool = false;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020051
Jens Geyerb5028322014-11-09 02:38:11 +010052 public static var EXITCODE_SUCCESS = 0x00; // no errors bits set
53 //
54 public static var EXITCODE_FAILBIT_BASETYPES = 0x01;
55 public static var EXITCODE_FAILBIT_STRUCTS = 0x02;
56 public static var EXITCODE_FAILBIT_CONTAINERS = 0x04;
57 public static var EXITCODE_FAILBIT_EXCEPTIONS = 0x08;
58 //
59 public static var EXITCODE_ALL_FAILBITS = 0x0F;
60 //
61 private var testsExecuted : Int = 0;
62 private var testsFailed : Int = 0;
63 private var currentTest : Int = 0;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020064
65
Jens Geyerb5028322014-11-09 02:38:11 +010066 public function new(direct : Bool) {
67 print_direct = direct;
68 }
69
70 public function StartTestGroup( groupBit : Int) : Void {
71 currentTest = groupBit;
72 testsExecuted |= groupBit;
73 }
74
75 public function Expect( expr : Bool, msg : String) : Void {
76 if ( expr) {
77 ++successCnt;
78 } else {
79 ++errorCnt;
80 testsFailed |= currentTest;
81 failedTests += "\n " + msg;
82 if( print_direct) {
83 trace('FAIL: $msg');
84 }
85 }
86 }
87
88 public function CalculateExitCode() : Int {
89 var notExecuted : Int = EXITCODE_ALL_FAILBITS & (~testsExecuted);
90 return testsFailed | notExecuted;
91 }
92
93 public function PrintSummary() : Void {
94 var total = successCnt + errorCnt;
Jens Geyerbbd6fd72015-05-30 19:33:44 +020095 var sp = Math.round((1000 * successCnt) / total) / 10;
96 var ep = Math.round((1000 * errorCnt) / total) / 10;
Jens Geyerb5028322014-11-09 02:38:11 +010097
98 trace('===========================');
99 trace('Tests executed $total');
100 trace('Tests succeeded $successCnt ($sp%)');
101 trace('Tests failed $errorCnt ($ep%)');
102 if ( errorCnt > 0)
103 {
104 trace('===========================');
105 trace('FAILED TESTS: $failedTests');
106 }
107 trace('===========================');
108 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200109}
110
111
112class TestClient {
113
Jens Geyerb5028322014-11-09 02:38:11 +0100114 public static function Execute(args : Arguments) : Void
115 {
116 var exitCode = 0xFF;
117 try
118 {
119 var difft = Timer.stamp();
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200120
Jens Geyerb5028322014-11-09 02:38:11 +0100121 if( args.numThreads > 1) {
122 var threads = new List<Thread>();
123 for( test in 0 ... args.numThreads) {
124 threads.add( StartThread( args));
125 }
126 exitCode = 0;
127 for( thread in threads) {
128 exitCode |= Thread.readMessage(true);
129 }
130 } else {
131 var rslt = new TestResults(true);
132 RunClient(args,rslt);
133 rslt.PrintSummary();
134 exitCode = rslt.CalculateExitCode();
135 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200136
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200137 difft = Math.round( 1000 * (Timer.stamp() - difft)) / 1000;
Jens Geyerb5028322014-11-09 02:38:11 +0100138 trace('total test time: $difft seconds');
139 }
140 catch (e : TException)
141 {
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200142 trace('TException: $e');
Jens Geyerb5028322014-11-09 02:38:11 +0100143 exitCode = 0xFF;
144 }
145 catch (e : Dynamic)
146 {
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200147 trace('Exception: $e');
Jens Geyerb5028322014-11-09 02:38:11 +0100148 exitCode = 0xFF;
149 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200150
Jens Geyerb5028322014-11-09 02:38:11 +0100151 #if sys
152 Sys.exit( exitCode);
153 #end
154 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200155
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200156
Jens Geyerb5028322014-11-09 02:38:11 +0100157 private static function StartThread(args : Arguments) : Thread {
158 var thread = Thread.create(
159 function() : Void {
160 var rslt = new TestResults(false);
161 var main : Thread = Thread.readMessage(true);
162 try
163 {
164 RunClient(args,rslt);
165 }
166 catch (e : TException)
167 {
168 rslt.Expect( false, '$e');
169 trace('$e');
170 }
171 catch (e : Dynamic)
172 {
173 rslt.Expect( false, '$e');
174 trace('$e');
175 }
176 main.sendMessage( rslt.CalculateExitCode());
177 });
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200178
Jens Geyerb5028322014-11-09 02:38:11 +0100179 thread.sendMessage(Thread.current());
180 return thread;
181 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200182
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200183
Jens Geyerb5028322014-11-09 02:38:11 +0100184 public static function RunClient(args : Arguments, rslt : TestResults)
185 {
186 var transport : TTransport = null;
187 switch (args.transport)
188 {
189 case socket:
190 transport = new TSocket(args.host, args.port);
191 case http:
192 transport = new THttpClient(args.host);
193 default:
194 throw "Unhandled transport";
195 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200196
Jens Geyerb5028322014-11-09 02:38:11 +0100197 // optional: layered transport
198 if ( args.framed) {
199 trace("- framed transport");
200 transport = new TFramedTransport(transport);
201 }
202 if ( args.buffered) {
203 trace("- buffered transport");
Jens Geyerd35f6162014-11-29 19:23:03 +0100204 transport = new TBufferedTransport(transport);
Jens Geyerb5028322014-11-09 02:38:11 +0100205 }
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);
Jens Geyer426ab862015-03-02 23:37:15 +0100217 case compact:
218 trace("- compact protocol");
219 protocol = new TCompactProtocol(transport);
Jens Geyerb5028322014-11-09 02:38:11 +0100220 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200221
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200222 // some quick and basic unit tests
Jens Geyerb5028322014-11-09 02:38:11 +0100223 HaxeBasicsTest( args, rslt);
Jens Geyer426ab862015-03-02 23:37:15 +0100224 ModuleUnitTests( args, rslt);
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200225
226 // now run the test code
227 trace('- ${args.numIterations} iterations');
Jens Geyerb5028322014-11-09 02:38:11 +0100228 for( i in 0 ... args.numIterations) {
229 ClientTest( transport, protocol, args, rslt);
230 }
231 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200232
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200233
Jens Geyerb5028322014-11-09 02:38:11 +0100234 public static function HaxeBasicsTest( args : Arguments, rslt : TestResults) : Void
235 {
236 // We need to test a few basic things used in the ClientTest
237 // Anything else beyond this scope should go into /lib/haxe/ instead
238 rslt.StartTestGroup( 0);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200239
Jens Geyerb5028322014-11-09 02:38:11 +0100240 var map32 = new IntMap<Int32>();
241 var map64 = new Int64Map<Int32>();
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200242
Jens Geyerb5028322014-11-09 02:38:11 +0100243 rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #1");
244 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #2");
245 rslt.Expect( map32.remove( 4711) == map64.remove( Int64.make(47,11)), "Int64Map<Int32> Test #3");
246 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #4");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200247
Jens Geyerb5028322014-11-09 02:38:11 +0100248 map32.set( 42, 815);
249 map64.set( Int64.make(0,42), 815);
250 map32.set( -517, 23);
Jens Geyer426ab862015-03-02 23:37:15 +0100251 map64.set( Int64.neg(Int64.make(0,517)), 23);
Jens Geyerb5028322014-11-09 02:38:11 +0100252 map32.set( 0, -123);
253 map64.set( Int64.make(0,0), -123);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200254
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200255 //trace('map32 = $map32');
256 //trace('map64 = $map64');
257
Jens Geyerb5028322014-11-09 02:38:11 +0100258 rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #10");
259 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #11");
Jens Geyer426ab862015-03-02 23:37:15 +0100260 rslt.Expect( map32.exists( -517) == map64.exists( Int64.neg(Int64.make(0,517))), "Int64Map<Int32> Test #12");
Jens Geyerb5028322014-11-09 02:38:11 +0100261 rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #13");
262 rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #14");
263 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #15");
Jens Geyer426ab862015-03-02 23:37:15 +0100264 rslt.Expect( map32.get( -517) == map64.get( Int64.neg(Int64.make(0,517))), "Int64Map<Int32> Test #16");
Jens Geyerb5028322014-11-09 02:38:11 +0100265 rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #Int64.make(-5,17)");
266 rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #18");
267 rslt.Expect( map32.remove( 4711) == map64.remove( Int64.make(47,11)), "Int64Map<Int32> Test #19");
Jens Geyer426ab862015-03-02 23:37:15 +0100268 rslt.Expect( map32.remove( -517) == map64.remove( Int64.neg(Int64.make(0,517))), "Int64Map<Int32> Test #20");
Jens Geyerb5028322014-11-09 02:38:11 +0100269 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #21");
Jens Geyer426ab862015-03-02 23:37:15 +0100270 rslt.Expect( map32.exists( -517) == map64.exists( Int64.neg(Int64.make(0,517))), "Int64Map<Int32> Test #22");
Jens Geyerb5028322014-11-09 02:38:11 +0100271 rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #23");
272 rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #24");
273 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #25");
Jens Geyer426ab862015-03-02 23:37:15 +0100274 rslt.Expect( map32.get( -517) == map64.get( Int64.neg(Int64.make(0,517))), "Int64Map<Int32> Test #26");
Jens Geyerb5028322014-11-09 02:38:11 +0100275 rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #27");
276 rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #28");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200277
Jens Geyerb5028322014-11-09 02:38:11 +0100278 map32.set( 42, 1);
279 map64.set( Int64.make(0,42), 1);
280 map32.set( -517, -2);
Jens Geyer426ab862015-03-02 23:37:15 +0100281 map64.set( Int64.neg(Int64.make(0,517)), -2);
Jens Geyerb5028322014-11-09 02:38:11 +0100282 map32.set( 0, 3);
283 map64.set( Int64.make(0,0), 3);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200284
Jens Geyerb5028322014-11-09 02:38:11 +0100285 var c32 = 0;
Jens Geyer426ab862015-03-02 23:37:15 +0100286 var ksum32 = 0;
Jens Geyerb5028322014-11-09 02:38:11 +0100287 for (key in map32.keys()) {
288 ++c32;
Jens Geyer426ab862015-03-02 23:37:15 +0100289 ksum32 += key;
Jens Geyerb5028322014-11-09 02:38:11 +0100290 }
291 var c64 = 0;
Jens Geyer426ab862015-03-02 23:37:15 +0100292 var ksum64 = Int64.make(0,0);
Jens Geyerb5028322014-11-09 02:38:11 +0100293 for (key in map64.keys()) {
294 ++c64;
Jens Geyer426ab862015-03-02 23:37:15 +0100295 ksum64 = Int64.add( ksum64, key);
Jens Geyerb5028322014-11-09 02:38:11 +0100296 }
297 rslt.Expect( c32 == c64, "Int64Map<Int32> Test #30");
Jens Geyer426ab862015-03-02 23:37:15 +0100298 rslt.Expect( '$ksum64' == '$ksum32', '$ksum64 == $ksum32 Test #31');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200299
Jens Geyerb5028322014-11-09 02:38:11 +0100300 var s32 = map32.toString();
301 var s64 = map64.toString();
Jens Geyer426ab862015-03-02 23:37:15 +0100302 rslt.Expect( s32 == s64, "Int64Map<Int32>.toString(): " + ' ("$s32" == "$s64") Test #32');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200303
Jens Geyerb5028322014-11-09 02:38:11 +0100304 map32.remove( 42);
305 map64.remove( Int64.make(0,42));
306 map32.remove( -517);
Jens Geyer426ab862015-03-02 23:37:15 +0100307 map64.remove( Int64.neg(Int64.make(0,517)));
Jens Geyerb5028322014-11-09 02:38:11 +0100308 map32.remove( 0);
309 map64.remove( Int64.make(0,0));
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200310
Jens Geyerb5028322014-11-09 02:38:11 +0100311 rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #90");
312 rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #91");
Jens Geyer426ab862015-03-02 23:37:15 +0100313 rslt.Expect( map32.exists( -517) == map64.exists( Int64.neg(Int64.make(0,517))), "Int64Map<Int32> Test #92");
Jens Geyerb5028322014-11-09 02:38:11 +0100314 rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #93");
315 rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #94");
316 rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #95");
317 rslt.Expect( map32.get( -517) == map64.get( Int64.make(-5,17)), "Int64Map<Int32> Test #96");
318 rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #97");
Jens Geyer426ab862015-03-02 23:37:15 +0100319 rslt.Expect( map32.get( 0) == map64.get( Int64.make(0, 0)), "Int64Map<Int32> Test #98");
Jens Geyerb5028322014-11-09 02:38:11 +0100320 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200321
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200322
Jens Geyer426ab862015-03-02 23:37:15 +0100323 // core module unit tests
324 public static function ModuleUnitTests( args : Arguments, rslt : TestResults) : Void {
Jens Geyerfa2daef2015-09-22 00:11:01 +0200325 #if debug
326
Jens Geyer426ab862015-03-02 23:37:15 +0100327 try {
328 BitConverter.UnitTest();
329 rslt.Expect( true, 'BitConverter.UnitTest Test #100');
330 }
331 catch( e : Dynamic) {
332 rslt.Expect( false, 'BitConverter.UnitTest: $e Test #100');
333 }
Jens Geyer43e195a2014-12-14 00:29:17 +0100334
Jens Geyer426ab862015-03-02 23:37:15 +0100335 try {
336 ZigZag.UnitTest();
337 rslt.Expect( true, 'ZigZag.UnitTest Test #101');
338 }
339 catch( e : Dynamic) {
340 rslt.Expect( false, 'ZigZag.UnitTest: $e Test #101');
341 }
Jens Geyerfa2daef2015-09-22 00:11:01 +0200342
343 #end
Jens Geyer426ab862015-03-02 23:37:15 +0100344 }
Jens Geyer43e195a2014-12-14 00:29:17 +0100345
Jens Geyer43e195a2014-12-14 00:29:17 +0100346
Jens Geyer426ab862015-03-02 23:37:15 +0100347 public static function BytesToHex(data : Bytes) : String {
348 var hex = "";
349 for ( i in 0 ... data.length) {
350 hex += StringTools.hex( data.get(i), 2);
351 }
352 return hex;
353 }
Jens Geyer43e195a2014-12-14 00:29:17 +0100354
Jens Geyer426ab862015-03-02 23:37:15 +0100355 public static function PrepareTestData(randomDist : Bool) : Bytes {
356 var retval = Bytes.alloc(0x100);
357 var initLen : Int = (retval.length > 0x100 ? 0x100 : retval.length);
358
359 // linear distribution, unless random is requested
360 if (!randomDist) {
361 for (i in 0 ... initLen) {
362 retval.set(i, i % 0x100);
363 }
364 return retval;
365 }
366
367 // random distribution
368 for (i in 0 ... initLen) {
369 retval.set(i, 0);
370 }
371 for (i in 1 ... initLen) {
372 while( true) {
373 var nextPos = Std.random(initLen);
374 if (retval.get(nextPos) == 0) {
375 retval.set( nextPos, i % 0x100);
376 break;
377 }
378 }
379 }
380 return retval;
381 }
382
383
Jens Geyerb5028322014-11-09 02:38:11 +0100384 public static function ClientTest( transport : TTransport, protocol : TProtocol,
385 args : Arguments, rslt : TestResults) : Void
386 {
387 var client = new ThriftTestImpl(protocol,protocol);
388 try
389 {
390 if (!transport.isOpen())
391 {
392 transport.open();
393 }
394 }
395 catch (e : TException)
396 {
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200397 rslt.Expect( false, 'unable to open transport: $e');
Jens Geyerb5028322014-11-09 02:38:11 +0100398 return;
399 }
400 catch (e : Dynamic)
401 {
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200402 rslt.Expect( false, 'unable to open transport: $e');
Jens Geyerb5028322014-11-09 02:38:11 +0100403 return;
404 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200405
Jens Geyerb5028322014-11-09 02:38:11 +0100406 var start = Date.now();
407
408 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_EXCEPTIONS);
409
410 // if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
411 trace('testException("Xception")');
412 try {
413 client.testException("Xception");
414 rslt.Expect( false, 'testException("Xception") should throw');
415 }
416 catch (e : Xception)
417 {
418 rslt.Expect( e.message == "Xception", 'testException("Xception") - e.message == "Xception"');
419 rslt.Expect( e.errorCode == 1001, 'testException("Xception") - e.errorCode == 1001');
420 }
421 catch (e : Dynamic)
422 {
423 rslt.Expect( false, 'testException("Xception") - $e');
424 }
425
426 // if arg == "TException" throw TException
427 trace('testException("TException")');
428 try {
429 client.testException("TException");
430 rslt.Expect( false, 'testException("TException") should throw');
431 }
432 catch (e : TException)
433 {
434 rslt.Expect( true, 'testException("TException") - $e');
435 }
436 catch (e : Dynamic)
437 {
438 rslt.Expect( false, 'testException("TException") - $e');
439 }
440
Jens Geyer426ab862015-03-02 23:37:15 +0100441 // reopen the transport, just in case the server closed his end
442 if (transport.isOpen())
443 transport.close();
444 transport.open();
445
Jens Geyerb5028322014-11-09 02:38:11 +0100446 // else do not throw anything
447 trace('testException("bla")');
448 try {
449 client.testException("bla");
450 rslt.Expect( true, 'testException("bla") should not throw');
451 }
452 catch (e : Dynamic)
453 {
454 rslt.Expect( false, 'testException("bla") - $e');
455 }
456
Jens Geyerb5028322014-11-09 02:38:11 +0100457 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES);
458
459 trace('testVoid()');
460 client.testVoid();
461 trace(' = void');
462 rslt.Expect(true,"testVoid()"); // bump counter
463
Jens Geyerfa2daef2015-09-22 00:11:01 +0200464 trace('testBool(${true})');
465 var b = client.testBool(true);
466 trace(' = $b');
467 rslt.Expect(b, '$b == "${true}"');
468 trace('testBool(${false})');
469 b = client.testBool(false);
470 trace(' = $b');
471 rslt.Expect( ! b, '$b == "${false}"');
472
Jens Geyerb5028322014-11-09 02:38:11 +0100473 trace('testString("Test")');
474 var s = client.testString("Test");
475 trace(' = "$s"');
476 rslt.Expect(s == "Test", '$s == "Test"');
477
478 trace('testByte(1)');
479 var i8 = client.testByte(1);
480 trace(' = $i8');
481 rslt.Expect(i8 == 1, '$i8 == 1');
482
483 trace('testI32(-1)');
484 var i32 = client.testI32(-1);
485 trace(' = $i32');
486 rslt.Expect(i32 == -1, '$i32 == -1');
487
488 trace('testI64(-34359738368)');
489 var i64 = client.testI64( Int64.make( 0xFFFFFFF8, 0x00000000)); // -34359738368
490 trace(' = $i64');
491 rslt.Expect( Int64.compare( i64, Int64.make( 0xFFFFFFF8, 0x00000000)) == 0,
492 Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0xFFFFFFF8, 0x00000000)));
493
494 // edge case: the largest negative Int64 has no positive Int64 equivalent
495 trace('testI64(-9223372036854775808)');
496 i64 = client.testI64( Int64.make( 0x80000000, 0x00000000)); // -9223372036854775808
497 trace(' = $i64');
498 rslt.Expect( Int64.compare( i64, Int64.make( 0x80000000, 0x00000000)) == 0,
499 Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0x80000000, 0x00000000)));
500
501 trace('testDouble(5.325098235)');
502 var dub = client.testDouble(5.325098235);
503 trace(' = $dub');
504 rslt.Expect(dub == 5.325098235, '$dub == 5.325098235');
505
Jens Geyer43e195a2014-12-14 00:29:17 +0100506 var binOut = PrepareTestData(true);
507 trace('testBinary('+BytesToHex(binOut)+')');
508 try {
509 var binIn = client.testBinary(binOut);
Jens Geyer426ab862015-03-02 23:37:15 +0100510 trace('testBinary() = '+BytesToHex(binIn));
511 rslt.Expect( binIn.length == binOut.length, '${binIn.length} == ${binOut.length}');
512 var len = ((binIn.length < binOut.length) ? binIn.length : binOut.length);
Jens Geyer43e195a2014-12-14 00:29:17 +0100513 for (ofs in 0 ... len) {
514 if (binIn.get(ofs) != binOut.get(ofs)) {
Jens Geyer426ab862015-03-02 23:37:15 +0100515 rslt.Expect( false, 'testBinary('+BytesToHex(binOut)+'): content mismatch at offset $ofs');
516 }
517 }
518 }
519 catch (e : TApplicationException) {
Jens Geyer43e195a2014-12-14 00:29:17 +0100520 trace('testBinary('+BytesToHex(binOut)+'): '+e.errorMsg); // may not be supported by the server
521 }
522
Jens Geyerb5028322014-11-09 02:38:11 +0100523
524 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS);
525
526 trace('testStruct({"Zero", 1, -3, -5})');
527 var o = new Xtruct();
528 o.string_thing = "Zero";
529 o.byte_thing = 1;
530 o.i32_thing = -3;
531 o.i64_thing = Int64.make(0,-5);
532 var i = client.testStruct(o);
533 trace(' = {"' + i.string_thing + '", ' + i.byte_thing +', '
534 + i.i32_thing +', '+ Int64.toStr(i.i64_thing) + '}');
535 rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing");
536 rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing");
537 rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing");
538 rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing");
539
540 trace('testNest({1, {\"Zero\", 1, -3, -5}, 5})');
541 var o2 = new Xtruct2();
542 o2.byte_thing = 1;
543 o2.struct_thing = o;
544 o2.i32_thing = 5;
545 var i2 = client.testNest(o2);
546 i = i2.struct_thing;
547 trace(" = {" + i2.byte_thing + ", {\"" + i.string_thing + "\", "
548 + i.byte_thing + ", " + i.i32_thing + ", " + Int64.toStr(i.i64_thing) + "}, "
549 + i2.i32_thing + "}");
550 rslt.Expect( i2.byte_thing == o2.byte_thing, "i2.byte_thing == o2.byte_thing");
551 rslt.Expect( i2.i32_thing == o2.i32_thing, "i2.i32_thing == o2.i32_thing");
552 rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing");
553 rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing");
554 rslt.Expect( i.i32_thing == o.i32_thing, "i.i32_thing == o.i32_thing");
555 rslt.Expect( Int64.compare( i.i64_thing, o.i64_thing) == 0, "i.i64_thing == o.i64_thing");
556
557
558 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS);
559
560 var mapout = new IntMap< haxe.Int32>();
561 for ( j in 0 ... 5)
562 {
563 mapout.set(j, j - 10);
564 }
565 trace("testMap({");
566 var first : Bool = true;
567 for( key in mapout.keys())
568 {
569 if (first)
570 {
571 first = false;
572 }
573 else
574 {
575 trace(", ");
576 }
577 trace(key + " => " + mapout.get(key));
578 }
579 trace("})");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200580
Jens Geyerb5028322014-11-09 02:38:11 +0100581 var mapin = client.testMap(mapout);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200582
Jens Geyerb5028322014-11-09 02:38:11 +0100583 trace(" = {");
584 first = true;
585 for( key in mapin.keys())
586 {
587 if (first)
588 {
589 first = false;
590 }
591 else
592 {
593 trace(", ");
594 }
595 trace(key + " => " + mapin.get(key));
596 rslt.Expect( mapin.get(key) == mapout.get(key), ' mapin.get($key) == mapout.get($key)');
597 }
598 trace("}");
599 for( key in mapout.keys())
600 {
601 rslt.Expect(mapin.exists(key), 'mapin.exists($key)');
602 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200603
Jens Geyerb5028322014-11-09 02:38:11 +0100604 var listout = new List<Int>();
605 for (j in -2 ... 3)
606 {
607 listout.add(j);
608 }
609 trace("testList({");
610 first = true;
611 for( j in listout)
612 {
613 if (first)
614 {
615 first = false;
616 }
617 else
618 {
619 trace(", ");
620 }
621 trace(j);
622 }
623 trace("})");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200624
Jens Geyerb5028322014-11-09 02:38:11 +0100625 var listin = client.testList(listout);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200626
Jens Geyerb5028322014-11-09 02:38:11 +0100627 trace(" = {");
628 first = true;
629 for( j in listin)
630 {
631 if (first)
632 {
633 first = false;
634 }
635 else
636 {
637 trace(", ");
638 }
639 trace(j);
640 }
641 trace("}");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200642
Jens Geyerb5028322014-11-09 02:38:11 +0100643 rslt.Expect(listin.length == listout.length, "listin.length == listout.length");
644 var literout = listout.iterator();
645 var literin = listin.iterator();
646 while( literin.hasNext()) {
647 rslt.Expect(literin.next() == literout.next(), "literin[i] == literout[i]");
648 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200649
Jens Geyerb5028322014-11-09 02:38:11 +0100650 //set
651 var setout = new IntSet();
652 for (j in -2 ... 3)
653 {
654 setout.add(j);
655 }
656 trace("testSet({");
657 first = true;
658 for( j in setout)
659 {
660 if (first)
661 {
662 first = false;
663 }
664 else
665 {
666 trace(", ");
667 }
668 trace(j);
669 }
670 trace("})");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200671
Jens Geyerb5028322014-11-09 02:38:11 +0100672 var setin = client.testSet(setout);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200673
Jens Geyerb5028322014-11-09 02:38:11 +0100674 trace(" = {");
675 first = true;
676 for( j in setin)
677 {
678 if (first)
679 {
680 first = false;
681 }
682 else
683 {
684 trace(", ");
685 }
686 trace(j);
687 rslt.Expect(setout.contains(j), 'setout.contains($j)');
688 }
689 trace("}");
690 rslt.Expect(setin.size == setout.size, "setin.length == setout.length");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200691
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200692
Jens Geyerb5028322014-11-09 02:38:11 +0100693 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200694
Jens Geyerb5028322014-11-09 02:38:11 +0100695 trace("testEnum(ONE)");
696 var ret = client.testEnum(Numberz.ONE);
697 trace(" = " + ret);
698 rslt.Expect(ret == Numberz.ONE, '$ret == Numberz.ONE');
Jens Geyerfea00ac2014-10-01 02:22:48 +0200699
Jens Geyerb5028322014-11-09 02:38:11 +0100700 trace("testEnum(TWO)");
701 ret = client.testEnum(Numberz.TWO);
702 trace(" = " + ret);
703 rslt.Expect(ret == Numberz.TWO, '$ret == Numberz.TWO');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200704
Jens Geyerb5028322014-11-09 02:38:11 +0100705 trace("testEnum(THREE)");
706 ret = client.testEnum(Numberz.THREE);
707 trace(" = " + ret);
708 rslt.Expect(ret == Numberz.THREE, '$ret == Numberz.THREE');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200709
Jens Geyerb5028322014-11-09 02:38:11 +0100710 trace("testEnum(FIVE)");
711 ret = client.testEnum(Numberz.FIVE);
712 trace(" = " + ret);
713 rslt.Expect(ret == Numberz.FIVE, '$ret == Numberz.FIVE');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200714
Jens Geyerb5028322014-11-09 02:38:11 +0100715 trace("testEnum(EIGHT)");
716 ret = client.testEnum(Numberz.EIGHT);
717 trace(" = " + ret);
718 rslt.Expect(ret == Numberz.EIGHT, '$ret == Numberz.EIGHT');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200719
Jens Geyerb5028322014-11-09 02:38:11 +0100720 trace("testTypedef(309858235082523)");
721 var uid = client.testTypedef( Int64.make( 0x119D0, 0x7E08671B)); // 309858235082523
722 trace(" = " + uid);
723 rslt.Expect( Int64.compare( uid, Int64.make( 0x119D0, 0x7E08671B)) == 0,
724 Int64.toStr(uid)+" == "+Int64.toStr(Int64.make( 0x119D0, 0x7E08671B)));
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200725
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200726
Jens Geyerb5028322014-11-09 02:38:11 +0100727 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200728
Jens Geyerb5028322014-11-09 02:38:11 +0100729 trace("testMapMap(1)");
730 var mm = client.testMapMap(1);
731 trace(" = {");
732 for( key in mm.keys())
733 {
734 trace(key + " => {");
735 var m2 = mm.get(key);
736 for( k2 in m2.keys())
737 {
738 trace(k2 + " => " + m2.get(k2) + ", ");
739 }
740 trace("}, ");
741 }
742 trace("}");
Jens Geyerfea00ac2014-10-01 02:22:48 +0200743
Jens Geyerb5028322014-11-09 02:38:11 +0100744 var pos = mm.get(4);
745 var neg = mm.get(-4);
746 rslt.Expect( (pos != null) && (neg != null), "(pos != null) && (neg != null)");
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200747 for (i in 1 ... 5) {
Jens Geyerb5028322014-11-09 02:38:11 +0100748 rslt.Expect( pos.get(i) == i, 'pos.get($i) == $i');
749 rslt.Expect( neg.get(-i) == -i, 'neg.get(-$i) == -$i');
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200750 }
751 rslt.Expect( ! pos.exists(0), '!pos.exists(0)');
752 rslt.Expect( ! neg.exists(-0), '!neg.exists(-0)');
753 rslt.Expect( ! pos.exists(42), '!pos.exists(42)');
754 rslt.Expect( ! neg.exists(-42), '!neg.exists(-42)');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200755
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200756
Jens Geyerb5028322014-11-09 02:38:11 +0100757 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200758
Jens Geyerb5028322014-11-09 02:38:11 +0100759 var insane = new Insanity();
760 insane.userMap = new IntMap< Int64>();
761 insane.userMap.set( Numberz.FIVE, Int64.make(0,5000));
762 var truck = new Xtruct();
763 truck.string_thing = "Truck";
764 truck.byte_thing = 8;
765 truck.i32_thing = 8;
766 truck.i64_thing = Int64.make(0,8);
767 insane.xtructs = new List<Xtruct>();
768 insane.xtructs.add(truck);
769 trace("testInsanity()");
770 var whoa = client.testInsanity(insane);
771 trace(" = {");
772 for( key in whoa.keys())
773 {
774 var val = whoa.get(key);
775 trace(key + " => {");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200776
Jens Geyerb5028322014-11-09 02:38:11 +0100777 for( k2 in val.keys())
778 {
779 var v2 = val.get(k2);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200780
Jens Geyerb5028322014-11-09 02:38:11 +0100781 trace(k2 + " => {");
782 var userMap = v2.userMap;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200783
Jens Geyerb5028322014-11-09 02:38:11 +0100784 trace("{");
785 if (userMap != null)
786 {
787 for( k3 in userMap.keys())
788 {
789 trace(k3 + " => " + userMap.get(k3) + ", ");
790 }
791 }
792 else
793 {
794 trace("null");
795 }
796 trace("}, ");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200797
Jens Geyerb5028322014-11-09 02:38:11 +0100798 var xtructs = v2.xtructs;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200799
Jens Geyerb5028322014-11-09 02:38:11 +0100800 trace("{");
801 if (xtructs != null)
802 {
803 for( x in xtructs)
804 {
805 trace("{\"" + x.string_thing + "\", "
806 + x.byte_thing + ", " + x.i32_thing + ", "
807 + x.i32_thing + "}, ");
808 }
809 }
810 else
811 {
812 trace("null");
813 }
814 trace("}");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200815
Jens Geyerb5028322014-11-09 02:38:11 +0100816 trace("}, ");
817 }
818 trace("}, ");
819 }
820 trace("}");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200821
Jens Geyerfea00ac2014-10-01 02:22:48 +0200822
Jens Geyerb5028322014-11-09 02:38:11 +0100823 var first_map = whoa.get(Int64.make(0,1));
824 var second_map = whoa.get(Int64.make(0,2));
825 rslt.Expect( (first_map != null) && (second_map != null), "(first_map != null) && (second_map != null)");
826 if ((first_map != null) && (second_map != null))
827 {
828 var crazy2 = first_map.get(Numberz.TWO);
829 var crazy3 = first_map.get(Numberz.THREE);
830 var looney = second_map.get(Numberz.SIX);
831 rslt.Expect( (crazy2 != null) && (crazy3 != null) && (looney != null),
832 "(crazy2 != null) && (crazy3 != null) && (looney != null)");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200833
Jens Geyerb5028322014-11-09 02:38:11 +0100834 rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0,
835 "crazy2.UserMap.get(Numberz.EIGHT) == 8");
836 rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0,
837 "crazy3.UserMap.get(Numberz.EIGHT) == 8");
838 rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0,
839 "crazy2.UserMap.get(Numberz.FIVE) == 5");
840 rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0,
841 "crazy3.UserMap.get(Numberz.FIVE) == 5");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200842
Jens Geyerb5028322014-11-09 02:38:11 +0100843 var crz2iter = crazy2.xtructs.iterator();
844 var crz3iter = crazy3.xtructs.iterator();
845 rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()");
846 var goodbye2 = crz2iter.next();
847 var goodbye3 = crz3iter.next();
848 rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()");
849 var hello2 = crz2iter.next();
850 var hello3 = crz3iter.next();
851 rslt.Expect( ! (crz2iter.hasNext() || crz3iter.hasNext()), "! (crz2iter.hasNext() || crz3iter.hasNext())");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200852
Jens Geyerb5028322014-11-09 02:38:11 +0100853 rslt.Expect( hello2.string_thing == "Hello2", 'hello2.String_thing == "Hello2"');
854 rslt.Expect( hello2.byte_thing == 2, 'hello2.Byte_thing == 2');
855 rslt.Expect( hello2.i32_thing == 2, 'hello2.I32_thing == 2');
856 rslt.Expect( Int64.compare( hello2.i64_thing, Int64.make(0,2)) == 0, 'hello2.I64_thing == 2');
857 rslt.Expect( hello3.string_thing == "Hello2", 'hello3.String_thing == "Hello2"');
858 rslt.Expect( hello3.byte_thing == 2, 'hello3.Byte_thing == 2');
859 rslt.Expect( hello3.i32_thing == 2, 'hello3.I32_thing == 2');
860 rslt.Expect( Int64.compare( hello3.i64_thing, Int64.make(0,2)) == 0, 'hello3.I64_thing == 2');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200861
Jens Geyerb5028322014-11-09 02:38:11 +0100862 rslt.Expect( goodbye2.string_thing == "Goodbye4", 'goodbye2.String_thing == "Goodbye4"');
863 rslt.Expect( goodbye2.byte_thing == 4, 'goodbye2.Byte_thing == 4');
864 rslt.Expect( goodbye2.i32_thing == 4, 'goodbye2.I32_thing == 4');
865 rslt.Expect( Int64.compare( goodbye2.i64_thing, Int64.make(0,4)) == 0, 'goodbye2.I64_thing == 4');
866 rslt.Expect( goodbye3.string_thing == "Goodbye4", 'goodbye3.String_thing == "Goodbye4"');
867 rslt.Expect( goodbye3.byte_thing == 4, 'goodbye3.Byte_thing == 4');
868 rslt.Expect( goodbye3.i32_thing == 4, 'goodbye3.I32_thing == 4');
869 rslt.Expect( Int64.compare( goodbye3.i64_thing, Int64.make(0,4)) == 0, 'goodbye3.I64_thing == 4');
870 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200871
Jens Geyerb5028322014-11-09 02:38:11 +0100872 var arg0 = 1;
873 var arg1 = 2;
874 var arg2 = Int64.make( 0x7FFFFFFF,0xFFFFFFFF);
875 var multiDict = new IntMap< String>();
876 multiDict.set(1, "one");
877 var arg4 = Numberz.FIVE;
878 var arg5 = Int64.make(0,5000000);
879 trace("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")");
880 var multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5);
881 trace(" = Xtruct(byte_thing:" + multiResponse.byte_thing + ",string_thing:" + multiResponse.string_thing
882 + ",i32_thing:" + multiResponse.i32_thing
883 + ",i64_thing:" + Int64.toStr(multiResponse.i64_thing) + ")");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200884
Jens Geyerb5028322014-11-09 02:38:11 +0100885 rslt.Expect( multiResponse.string_thing == "Hello2", 'multiResponse.String_thing == "Hello2"');
886 rslt.Expect( multiResponse.byte_thing == arg0, 'multiResponse.Byte_thing == arg0');
887 rslt.Expect( multiResponse.i32_thing == arg1, 'multiResponse.I32_thing == arg1');
888 rslt.Expect( Int64.compare( multiResponse.i64_thing, arg2) == 0, 'multiResponse.I64_thing == arg2');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200889
890
Jens Geyerb5028322014-11-09 02:38:11 +0100891 rslt.StartTestGroup( 0);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200892
Jens Geyerb5028322014-11-09 02:38:11 +0100893 trace("Test Oneway(1)");
894 client.testOneway(1);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200895
Jens Geyerb5028322014-11-09 02:38:11 +0100896 if( ! args.skipSpeedTest) {
897 trace("Test Calltime()");
898 var difft = Timer.stamp();
899 for ( k in 0 ... 1000) {
900 client.testVoid();
901 }
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200902 difft = Math.round( 1000 * (Timer.stamp() - difft)) / 1000;
Jens Geyerb5028322014-11-09 02:38:11 +0100903 trace('$difft ms per testVoid() call');
904 }
905 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200906}