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