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