blob: 8e43c76df5ca0c78210dc2e733401f22be6bd17b [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 {
325 try {
326 BitConverter.UnitTest();
327 rslt.Expect( true, 'BitConverter.UnitTest Test #100');
328 }
329 catch( e : Dynamic) {
330 rslt.Expect( false, 'BitConverter.UnitTest: $e Test #100');
331 }
Jens Geyer43e195a2014-12-14 00:29:17 +0100332
Jens Geyer426ab862015-03-02 23:37:15 +0100333 try {
334 ZigZag.UnitTest();
335 rslt.Expect( true, 'ZigZag.UnitTest Test #101');
336 }
337 catch( e : Dynamic) {
338 rslt.Expect( false, 'ZigZag.UnitTest: $e Test #101');
339 }
340 }
Jens Geyer43e195a2014-12-14 00:29:17 +0100341
Jens Geyer43e195a2014-12-14 00:29:17 +0100342
Jens Geyer426ab862015-03-02 23:37:15 +0100343 public static function BytesToHex(data : Bytes) : String {
344 var hex = "";
345 for ( i in 0 ... data.length) {
346 hex += StringTools.hex( data.get(i), 2);
347 }
348 return hex;
349 }
Jens Geyer43e195a2014-12-14 00:29:17 +0100350
Jens Geyer426ab862015-03-02 23:37:15 +0100351 public static function PrepareTestData(randomDist : Bool) : Bytes {
352 var retval = Bytes.alloc(0x100);
353 var initLen : Int = (retval.length > 0x100 ? 0x100 : retval.length);
354
355 // linear distribution, unless random is requested
356 if (!randomDist) {
357 for (i in 0 ... initLen) {
358 retval.set(i, i % 0x100);
359 }
360 return retval;
361 }
362
363 // random distribution
364 for (i in 0 ... initLen) {
365 retval.set(i, 0);
366 }
367 for (i in 1 ... initLen) {
368 while( true) {
369 var nextPos = Std.random(initLen);
370 if (retval.get(nextPos) == 0) {
371 retval.set( nextPos, i % 0x100);
372 break;
373 }
374 }
375 }
376 return retval;
377 }
378
379
Jens Geyerb5028322014-11-09 02:38:11 +0100380 public static function ClientTest( transport : TTransport, protocol : TProtocol,
381 args : Arguments, rslt : TestResults) : Void
382 {
383 var client = new ThriftTestImpl(protocol,protocol);
384 try
385 {
386 if (!transport.isOpen())
387 {
388 transport.open();
389 }
390 }
391 catch (e : TException)
392 {
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200393 rslt.Expect( false, 'unable to open transport: $e');
Jens Geyerb5028322014-11-09 02:38:11 +0100394 return;
395 }
396 catch (e : Dynamic)
397 {
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200398 rslt.Expect( false, 'unable to open transport: $e');
Jens Geyerb5028322014-11-09 02:38:11 +0100399 return;
400 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200401
Jens Geyerb5028322014-11-09 02:38:11 +0100402 var start = Date.now();
403
404 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_EXCEPTIONS);
405
406 // if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
407 trace('testException("Xception")');
408 try {
409 client.testException("Xception");
410 rslt.Expect( false, 'testException("Xception") should throw');
411 }
412 catch (e : Xception)
413 {
414 rslt.Expect( e.message == "Xception", 'testException("Xception") - e.message == "Xception"');
415 rslt.Expect( e.errorCode == 1001, 'testException("Xception") - e.errorCode == 1001');
416 }
417 catch (e : Dynamic)
418 {
419 rslt.Expect( false, 'testException("Xception") - $e');
420 }
421
422 // if arg == "TException" throw TException
423 trace('testException("TException")');
424 try {
425 client.testException("TException");
426 rslt.Expect( false, 'testException("TException") should throw');
427 }
428 catch (e : TException)
429 {
430 rslt.Expect( true, 'testException("TException") - $e');
431 }
432 catch (e : Dynamic)
433 {
434 rslt.Expect( false, 'testException("TException") - $e');
435 }
436
Jens Geyer426ab862015-03-02 23:37:15 +0100437 // reopen the transport, just in case the server closed his end
438 if (transport.isOpen())
439 transport.close();
440 transport.open();
441
Jens Geyerb5028322014-11-09 02:38:11 +0100442 // else do not throw anything
443 trace('testException("bla")');
444 try {
445 client.testException("bla");
446 rslt.Expect( true, 'testException("bla") should not throw');
447 }
448 catch (e : Dynamic)
449 {
450 rslt.Expect( false, 'testException("bla") - $e');
451 }
452
Jens Geyerb5028322014-11-09 02:38:11 +0100453 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES);
454
455 trace('testVoid()');
456 client.testVoid();
457 trace(' = void');
458 rslt.Expect(true,"testVoid()"); // bump counter
459
460 trace('testString("Test")');
461 var s = client.testString("Test");
462 trace(' = "$s"');
463 rslt.Expect(s == "Test", '$s == "Test"');
464
465 trace('testByte(1)');
466 var i8 = client.testByte(1);
467 trace(' = $i8');
468 rslt.Expect(i8 == 1, '$i8 == 1');
469
470 trace('testI32(-1)');
471 var i32 = client.testI32(-1);
472 trace(' = $i32');
473 rslt.Expect(i32 == -1, '$i32 == -1');
474
475 trace('testI64(-34359738368)');
476 var i64 = client.testI64( Int64.make( 0xFFFFFFF8, 0x00000000)); // -34359738368
477 trace(' = $i64');
478 rslt.Expect( Int64.compare( i64, Int64.make( 0xFFFFFFF8, 0x00000000)) == 0,
479 Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0xFFFFFFF8, 0x00000000)));
480
481 // edge case: the largest negative Int64 has no positive Int64 equivalent
482 trace('testI64(-9223372036854775808)');
483 i64 = client.testI64( Int64.make( 0x80000000, 0x00000000)); // -9223372036854775808
484 trace(' = $i64');
485 rslt.Expect( Int64.compare( i64, Int64.make( 0x80000000, 0x00000000)) == 0,
486 Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0x80000000, 0x00000000)));
487
488 trace('testDouble(5.325098235)');
489 var dub = client.testDouble(5.325098235);
490 trace(' = $dub');
491 rslt.Expect(dub == 5.325098235, '$dub == 5.325098235');
492
Jens Geyer43e195a2014-12-14 00:29:17 +0100493 var binOut = PrepareTestData(true);
494 trace('testBinary('+BytesToHex(binOut)+')');
495 try {
496 var binIn = client.testBinary(binOut);
Jens Geyer426ab862015-03-02 23:37:15 +0100497 trace('testBinary() = '+BytesToHex(binIn));
498 rslt.Expect( binIn.length == binOut.length, '${binIn.length} == ${binOut.length}');
499 var len = ((binIn.length < binOut.length) ? binIn.length : binOut.length);
Jens Geyer43e195a2014-12-14 00:29:17 +0100500 for (ofs in 0 ... len) {
501 if (binIn.get(ofs) != binOut.get(ofs)) {
Jens Geyer426ab862015-03-02 23:37:15 +0100502 rslt.Expect( false, 'testBinary('+BytesToHex(binOut)+'): content mismatch at offset $ofs');
503 }
504 }
505 }
506 catch (e : TApplicationException) {
Jens Geyer43e195a2014-12-14 00:29:17 +0100507 trace('testBinary('+BytesToHex(binOut)+'): '+e.errorMsg); // may not be supported by the server
508 }
509
Jens Geyerb5028322014-11-09 02:38:11 +0100510
511 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS);
512
513 trace('testStruct({"Zero", 1, -3, -5})');
514 var o = new Xtruct();
515 o.string_thing = "Zero";
516 o.byte_thing = 1;
517 o.i32_thing = -3;
518 o.i64_thing = Int64.make(0,-5);
519 var i = client.testStruct(o);
520 trace(' = {"' + i.string_thing + '", ' + i.byte_thing +', '
521 + i.i32_thing +', '+ Int64.toStr(i.i64_thing) + '}');
522 rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing");
523 rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing");
524 rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing");
525 rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing");
526
527 trace('testNest({1, {\"Zero\", 1, -3, -5}, 5})');
528 var o2 = new Xtruct2();
529 o2.byte_thing = 1;
530 o2.struct_thing = o;
531 o2.i32_thing = 5;
532 var i2 = client.testNest(o2);
533 i = i2.struct_thing;
534 trace(" = {" + i2.byte_thing + ", {\"" + i.string_thing + "\", "
535 + i.byte_thing + ", " + i.i32_thing + ", " + Int64.toStr(i.i64_thing) + "}, "
536 + i2.i32_thing + "}");
537 rslt.Expect( i2.byte_thing == o2.byte_thing, "i2.byte_thing == o2.byte_thing");
538 rslt.Expect( i2.i32_thing == o2.i32_thing, "i2.i32_thing == o2.i32_thing");
539 rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing");
540 rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing");
541 rslt.Expect( i.i32_thing == o.i32_thing, "i.i32_thing == o.i32_thing");
542 rslt.Expect( Int64.compare( i.i64_thing, o.i64_thing) == 0, "i.i64_thing == o.i64_thing");
543
544
545 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS);
546
547 var mapout = new IntMap< haxe.Int32>();
548 for ( j in 0 ... 5)
549 {
550 mapout.set(j, j - 10);
551 }
552 trace("testMap({");
553 var first : Bool = true;
554 for( key in mapout.keys())
555 {
556 if (first)
557 {
558 first = false;
559 }
560 else
561 {
562 trace(", ");
563 }
564 trace(key + " => " + mapout.get(key));
565 }
566 trace("})");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200567
Jens Geyerb5028322014-11-09 02:38:11 +0100568 var mapin = client.testMap(mapout);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200569
Jens Geyerb5028322014-11-09 02:38:11 +0100570 trace(" = {");
571 first = true;
572 for( key in mapin.keys())
573 {
574 if (first)
575 {
576 first = false;
577 }
578 else
579 {
580 trace(", ");
581 }
582 trace(key + " => " + mapin.get(key));
583 rslt.Expect( mapin.get(key) == mapout.get(key), ' mapin.get($key) == mapout.get($key)');
584 }
585 trace("}");
586 for( key in mapout.keys())
587 {
588 rslt.Expect(mapin.exists(key), 'mapin.exists($key)');
589 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200590
Jens Geyerb5028322014-11-09 02:38:11 +0100591 var listout = new List<Int>();
592 for (j in -2 ... 3)
593 {
594 listout.add(j);
595 }
596 trace("testList({");
597 first = true;
598 for( j in listout)
599 {
600 if (first)
601 {
602 first = false;
603 }
604 else
605 {
606 trace(", ");
607 }
608 trace(j);
609 }
610 trace("})");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200611
Jens Geyerb5028322014-11-09 02:38:11 +0100612 var listin = client.testList(listout);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200613
Jens Geyerb5028322014-11-09 02:38:11 +0100614 trace(" = {");
615 first = true;
616 for( j in listin)
617 {
618 if (first)
619 {
620 first = false;
621 }
622 else
623 {
624 trace(", ");
625 }
626 trace(j);
627 }
628 trace("}");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200629
Jens Geyerb5028322014-11-09 02:38:11 +0100630 rslt.Expect(listin.length == listout.length, "listin.length == listout.length");
631 var literout = listout.iterator();
632 var literin = listin.iterator();
633 while( literin.hasNext()) {
634 rslt.Expect(literin.next() == literout.next(), "literin[i] == literout[i]");
635 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200636
Jens Geyerb5028322014-11-09 02:38:11 +0100637 //set
638 var setout = new IntSet();
639 for (j in -2 ... 3)
640 {
641 setout.add(j);
642 }
643 trace("testSet({");
644 first = true;
645 for( j in setout)
646 {
647 if (first)
648 {
649 first = false;
650 }
651 else
652 {
653 trace(", ");
654 }
655 trace(j);
656 }
657 trace("})");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200658
Jens Geyerb5028322014-11-09 02:38:11 +0100659 var setin = client.testSet(setout);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200660
Jens Geyerb5028322014-11-09 02:38:11 +0100661 trace(" = {");
662 first = true;
663 for( j in setin)
664 {
665 if (first)
666 {
667 first = false;
668 }
669 else
670 {
671 trace(", ");
672 }
673 trace(j);
674 rslt.Expect(setout.contains(j), 'setout.contains($j)');
675 }
676 trace("}");
677 rslt.Expect(setin.size == setout.size, "setin.length == setout.length");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200678
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200679
Jens Geyerb5028322014-11-09 02:38:11 +0100680 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200681
Jens Geyerb5028322014-11-09 02:38:11 +0100682 trace("testEnum(ONE)");
683 var ret = client.testEnum(Numberz.ONE);
684 trace(" = " + ret);
685 rslt.Expect(ret == Numberz.ONE, '$ret == Numberz.ONE');
Jens Geyerfea00ac2014-10-01 02:22:48 +0200686
Jens Geyerb5028322014-11-09 02:38:11 +0100687 trace("testEnum(TWO)");
688 ret = client.testEnum(Numberz.TWO);
689 trace(" = " + ret);
690 rslt.Expect(ret == Numberz.TWO, '$ret == Numberz.TWO');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200691
Jens Geyerb5028322014-11-09 02:38:11 +0100692 trace("testEnum(THREE)");
693 ret = client.testEnum(Numberz.THREE);
694 trace(" = " + ret);
695 rslt.Expect(ret == Numberz.THREE, '$ret == Numberz.THREE');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200696
Jens Geyerb5028322014-11-09 02:38:11 +0100697 trace("testEnum(FIVE)");
698 ret = client.testEnum(Numberz.FIVE);
699 trace(" = " + ret);
700 rslt.Expect(ret == Numberz.FIVE, '$ret == Numberz.FIVE');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200701
Jens Geyerb5028322014-11-09 02:38:11 +0100702 trace("testEnum(EIGHT)");
703 ret = client.testEnum(Numberz.EIGHT);
704 trace(" = " + ret);
705 rslt.Expect(ret == Numberz.EIGHT, '$ret == Numberz.EIGHT');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200706
Jens Geyerb5028322014-11-09 02:38:11 +0100707 trace("testTypedef(309858235082523)");
708 var uid = client.testTypedef( Int64.make( 0x119D0, 0x7E08671B)); // 309858235082523
709 trace(" = " + uid);
710 rslt.Expect( Int64.compare( uid, Int64.make( 0x119D0, 0x7E08671B)) == 0,
711 Int64.toStr(uid)+" == "+Int64.toStr(Int64.make( 0x119D0, 0x7E08671B)));
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200712
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200713
Jens Geyerb5028322014-11-09 02:38:11 +0100714 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200715
Jens Geyerb5028322014-11-09 02:38:11 +0100716 trace("testMapMap(1)");
717 var mm = client.testMapMap(1);
718 trace(" = {");
719 for( key in mm.keys())
720 {
721 trace(key + " => {");
722 var m2 = mm.get(key);
723 for( k2 in m2.keys())
724 {
725 trace(k2 + " => " + m2.get(k2) + ", ");
726 }
727 trace("}, ");
728 }
729 trace("}");
Jens Geyerfea00ac2014-10-01 02:22:48 +0200730
Jens Geyerb5028322014-11-09 02:38:11 +0100731 var pos = mm.get(4);
732 var neg = mm.get(-4);
733 rslt.Expect( (pos != null) && (neg != null), "(pos != null) && (neg != null)");
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200734 for (i in 1 ... 5) {
Jens Geyerb5028322014-11-09 02:38:11 +0100735 rslt.Expect( pos.get(i) == i, 'pos.get($i) == $i');
736 rslt.Expect( neg.get(-i) == -i, 'neg.get(-$i) == -$i');
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200737 }
738 rslt.Expect( ! pos.exists(0), '!pos.exists(0)');
739 rslt.Expect( ! neg.exists(-0), '!neg.exists(-0)');
740 rslt.Expect( ! pos.exists(42), '!pos.exists(42)');
741 rslt.Expect( ! neg.exists(-42), '!neg.exists(-42)');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200742
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200743
Jens Geyerb5028322014-11-09 02:38:11 +0100744 rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200745
Jens Geyerb5028322014-11-09 02:38:11 +0100746 var insane = new Insanity();
747 insane.userMap = new IntMap< Int64>();
748 insane.userMap.set( Numberz.FIVE, Int64.make(0,5000));
749 var truck = new Xtruct();
750 truck.string_thing = "Truck";
751 truck.byte_thing = 8;
752 truck.i32_thing = 8;
753 truck.i64_thing = Int64.make(0,8);
754 insane.xtructs = new List<Xtruct>();
755 insane.xtructs.add(truck);
756 trace("testInsanity()");
757 var whoa = client.testInsanity(insane);
758 trace(" = {");
759 for( key in whoa.keys())
760 {
761 var val = whoa.get(key);
762 trace(key + " => {");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200763
Jens Geyerb5028322014-11-09 02:38:11 +0100764 for( k2 in val.keys())
765 {
766 var v2 = val.get(k2);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200767
Jens Geyerb5028322014-11-09 02:38:11 +0100768 trace(k2 + " => {");
769 var userMap = v2.userMap;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200770
Jens Geyerb5028322014-11-09 02:38:11 +0100771 trace("{");
772 if (userMap != null)
773 {
774 for( k3 in userMap.keys())
775 {
776 trace(k3 + " => " + userMap.get(k3) + ", ");
777 }
778 }
779 else
780 {
781 trace("null");
782 }
783 trace("}, ");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200784
Jens Geyerb5028322014-11-09 02:38:11 +0100785 var xtructs = v2.xtructs;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200786
Jens Geyerb5028322014-11-09 02:38:11 +0100787 trace("{");
788 if (xtructs != null)
789 {
790 for( x in xtructs)
791 {
792 trace("{\"" + x.string_thing + "\", "
793 + x.byte_thing + ", " + x.i32_thing + ", "
794 + x.i32_thing + "}, ");
795 }
796 }
797 else
798 {
799 trace("null");
800 }
801 trace("}");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200802
Jens Geyerb5028322014-11-09 02:38:11 +0100803 trace("}, ");
804 }
805 trace("}, ");
806 }
807 trace("}");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200808
Jens Geyerfea00ac2014-10-01 02:22:48 +0200809
Jens Geyerb5028322014-11-09 02:38:11 +0100810 var first_map = whoa.get(Int64.make(0,1));
811 var second_map = whoa.get(Int64.make(0,2));
812 rslt.Expect( (first_map != null) && (second_map != null), "(first_map != null) && (second_map != null)");
813 if ((first_map != null) && (second_map != null))
814 {
815 var crazy2 = first_map.get(Numberz.TWO);
816 var crazy3 = first_map.get(Numberz.THREE);
817 var looney = second_map.get(Numberz.SIX);
818 rslt.Expect( (crazy2 != null) && (crazy3 != null) && (looney != null),
819 "(crazy2 != null) && (crazy3 != null) && (looney != null)");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200820
Jens Geyerb5028322014-11-09 02:38:11 +0100821 rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0,
822 "crazy2.UserMap.get(Numberz.EIGHT) == 8");
823 rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0,
824 "crazy3.UserMap.get(Numberz.EIGHT) == 8");
825 rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0,
826 "crazy2.UserMap.get(Numberz.FIVE) == 5");
827 rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0,
828 "crazy3.UserMap.get(Numberz.FIVE) == 5");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200829
Jens Geyerb5028322014-11-09 02:38:11 +0100830 var crz2iter = crazy2.xtructs.iterator();
831 var crz3iter = crazy3.xtructs.iterator();
832 rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()");
833 var goodbye2 = crz2iter.next();
834 var goodbye3 = crz3iter.next();
835 rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()");
836 var hello2 = crz2iter.next();
837 var hello3 = crz3iter.next();
838 rslt.Expect( ! (crz2iter.hasNext() || crz3iter.hasNext()), "! (crz2iter.hasNext() || crz3iter.hasNext())");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200839
Jens Geyerb5028322014-11-09 02:38:11 +0100840 rslt.Expect( hello2.string_thing == "Hello2", 'hello2.String_thing == "Hello2"');
841 rslt.Expect( hello2.byte_thing == 2, 'hello2.Byte_thing == 2');
842 rslt.Expect( hello2.i32_thing == 2, 'hello2.I32_thing == 2');
843 rslt.Expect( Int64.compare( hello2.i64_thing, Int64.make(0,2)) == 0, 'hello2.I64_thing == 2');
844 rslt.Expect( hello3.string_thing == "Hello2", 'hello3.String_thing == "Hello2"');
845 rslt.Expect( hello3.byte_thing == 2, 'hello3.Byte_thing == 2');
846 rslt.Expect( hello3.i32_thing == 2, 'hello3.I32_thing == 2');
847 rslt.Expect( Int64.compare( hello3.i64_thing, Int64.make(0,2)) == 0, 'hello3.I64_thing == 2');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200848
Jens Geyerb5028322014-11-09 02:38:11 +0100849 rslt.Expect( goodbye2.string_thing == "Goodbye4", 'goodbye2.String_thing == "Goodbye4"');
850 rslt.Expect( goodbye2.byte_thing == 4, 'goodbye2.Byte_thing == 4');
851 rslt.Expect( goodbye2.i32_thing == 4, 'goodbye2.I32_thing == 4');
852 rslt.Expect( Int64.compare( goodbye2.i64_thing, Int64.make(0,4)) == 0, 'goodbye2.I64_thing == 4');
853 rslt.Expect( goodbye3.string_thing == "Goodbye4", 'goodbye3.String_thing == "Goodbye4"');
854 rslt.Expect( goodbye3.byte_thing == 4, 'goodbye3.Byte_thing == 4');
855 rslt.Expect( goodbye3.i32_thing == 4, 'goodbye3.I32_thing == 4');
856 rslt.Expect( Int64.compare( goodbye3.i64_thing, Int64.make(0,4)) == 0, 'goodbye3.I64_thing == 4');
857 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200858
Jens Geyerb5028322014-11-09 02:38:11 +0100859 var arg0 = 1;
860 var arg1 = 2;
861 var arg2 = Int64.make( 0x7FFFFFFF,0xFFFFFFFF);
862 var multiDict = new IntMap< String>();
863 multiDict.set(1, "one");
864 var arg4 = Numberz.FIVE;
865 var arg5 = Int64.make(0,5000000);
866 trace("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")");
867 var multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5);
868 trace(" = Xtruct(byte_thing:" + multiResponse.byte_thing + ",string_thing:" + multiResponse.string_thing
869 + ",i32_thing:" + multiResponse.i32_thing
870 + ",i64_thing:" + Int64.toStr(multiResponse.i64_thing) + ")");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200871
Jens Geyerb5028322014-11-09 02:38:11 +0100872 rslt.Expect( multiResponse.string_thing == "Hello2", 'multiResponse.String_thing == "Hello2"');
873 rslt.Expect( multiResponse.byte_thing == arg0, 'multiResponse.Byte_thing == arg0');
874 rslt.Expect( multiResponse.i32_thing == arg1, 'multiResponse.I32_thing == arg1');
875 rslt.Expect( Int64.compare( multiResponse.i64_thing, arg2) == 0, 'multiResponse.I64_thing == arg2');
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200876
877
Jens Geyerb5028322014-11-09 02:38:11 +0100878 rslt.StartTestGroup( 0);
Jens Geyerfea00ac2014-10-01 02:22:48 +0200879
Jens Geyerb5028322014-11-09 02:38:11 +0100880 trace("Test Oneway(1)");
881 client.testOneway(1);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200882
Jens Geyerb5028322014-11-09 02:38:11 +0100883 if( ! args.skipSpeedTest) {
884 trace("Test Calltime()");
885 var difft = Timer.stamp();
886 for ( k in 0 ... 1000) {
887 client.testVoid();
888 }
Jens Geyerbbd6fd72015-05-30 19:33:44 +0200889 difft = Math.round( 1000 * (Timer.stamp() - difft)) / 1000;
Jens Geyerb5028322014-11-09 02:38:11 +0100890 trace('$difft ms per testVoid() call');
891 }
892 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200893}