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 |
| 38 | import cpp.vm.Thread; |
| 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 | } |
| 447 | catch (e : Dynamic) |
| 448 | { |
| 449 | rslt.Expect( false, 'testException("Xception") - $e'); |
| 450 | } |
| 451 | |
| 452 | // if arg == "TException" throw TException |
| 453 | trace('testException("TException")'); |
| 454 | try { |
| 455 | client.testException("TException"); |
| 456 | rslt.Expect( false, 'testException("TException") should throw'); |
| 457 | } |
| 458 | catch (e : TException) |
| 459 | { |
| 460 | rslt.Expect( true, 'testException("TException") - $e'); |
| 461 | } |
| 462 | catch (e : Dynamic) |
| 463 | { |
| 464 | rslt.Expect( false, 'testException("TException") - $e'); |
| 465 | } |
| 466 | |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 467 | // reopen the transport, just in case the server closed his end |
| 468 | if (transport.isOpen()) |
| 469 | transport.close(); |
| 470 | transport.open(); |
| 471 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 472 | // else do not throw anything |
| 473 | trace('testException("bla")'); |
| 474 | try { |
| 475 | client.testException("bla"); |
| 476 | rslt.Expect( true, 'testException("bla") should not throw'); |
| 477 | } |
| 478 | catch (e : Dynamic) |
| 479 | { |
| 480 | rslt.Expect( false, 'testException("bla") - $e'); |
| 481 | } |
| 482 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 483 | rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES); |
| 484 | |
| 485 | trace('testVoid()'); |
| 486 | client.testVoid(); |
| 487 | trace(' = void'); |
| 488 | rslt.Expect(true,"testVoid()"); // bump counter |
| 489 | |
Jens Geyer | fa2daef | 2015-09-22 00:11:01 +0200 | [diff] [blame] | 490 | trace('testBool(${true})'); |
| 491 | var b = client.testBool(true); |
| 492 | trace(' = $b'); |
Jens Geyer | 1d20a37 | 2016-03-15 23:04:27 +0200 | [diff] [blame] | 493 | rslt.Expect(b, '$b == "${true}"'); |
Jens Geyer | fa2daef | 2015-09-22 00:11:01 +0200 | [diff] [blame] | 494 | trace('testBool(${false})'); |
| 495 | b = client.testBool(false); |
| 496 | trace(' = $b'); |
Jens Geyer | 1d20a37 | 2016-03-15 23:04:27 +0200 | [diff] [blame] | 497 | rslt.Expect( ! b, '$b == "${false}"'); |
Jens Geyer | fa2daef | 2015-09-22 00:11:01 +0200 | [diff] [blame] | 498 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 499 | trace('testString("Test")'); |
| 500 | var s = client.testString("Test"); |
| 501 | trace(' = "$s"'); |
| 502 | rslt.Expect(s == "Test", '$s == "Test"'); |
| 503 | |
| 504 | trace('testByte(1)'); |
| 505 | var i8 = client.testByte(1); |
| 506 | trace(' = $i8'); |
| 507 | rslt.Expect(i8 == 1, '$i8 == 1'); |
| 508 | |
| 509 | trace('testI32(-1)'); |
| 510 | var i32 = client.testI32(-1); |
| 511 | trace(' = $i32'); |
| 512 | rslt.Expect(i32 == -1, '$i32 == -1'); |
| 513 | |
| 514 | trace('testI64(-34359738368)'); |
| 515 | var i64 = client.testI64( Int64.make( 0xFFFFFFF8, 0x00000000)); // -34359738368 |
| 516 | trace(' = $i64'); |
| 517 | rslt.Expect( Int64.compare( i64, Int64.make( 0xFFFFFFF8, 0x00000000)) == 0, |
| 518 | Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0xFFFFFFF8, 0x00000000))); |
| 519 | |
| 520 | // edge case: the largest negative Int64 has no positive Int64 equivalent |
| 521 | trace('testI64(-9223372036854775808)'); |
| 522 | i64 = client.testI64( Int64.make( 0x80000000, 0x00000000)); // -9223372036854775808 |
| 523 | trace(' = $i64'); |
| 524 | rslt.Expect( Int64.compare( i64, Int64.make( 0x80000000, 0x00000000)) == 0, |
| 525 | Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0x80000000, 0x00000000))); |
| 526 | |
| 527 | trace('testDouble(5.325098235)'); |
| 528 | var dub = client.testDouble(5.325098235); |
| 529 | trace(' = $dub'); |
| 530 | rslt.Expect(dub == 5.325098235, '$dub == 5.325098235'); |
| 531 | |
Jens Geyer | 43e195a | 2014-12-14 00:29:17 +0100 | [diff] [blame] | 532 | var binOut = PrepareTestData(true); |
| 533 | trace('testBinary('+BytesToHex(binOut)+')'); |
| 534 | try { |
| 535 | var binIn = client.testBinary(binOut); |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 536 | trace('testBinary() = '+BytesToHex(binIn)); |
| 537 | rslt.Expect( binIn.length == binOut.length, '${binIn.length} == ${binOut.length}'); |
| 538 | var len = ((binIn.length < binOut.length) ? binIn.length : binOut.length); |
Jens Geyer | 43e195a | 2014-12-14 00:29:17 +0100 | [diff] [blame] | 539 | for (ofs in 0 ... len) { |
| 540 | if (binIn.get(ofs) != binOut.get(ofs)) { |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 541 | rslt.Expect( false, 'testBinary('+BytesToHex(binOut)+'): content mismatch at offset $ofs'); |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | catch (e : TApplicationException) { |
Jens Geyer | 43e195a | 2014-12-14 00:29:17 +0100 | [diff] [blame] | 546 | trace('testBinary('+BytesToHex(binOut)+'): '+e.errorMsg); // may not be supported by the server |
| 547 | } |
| 548 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 549 | |
| 550 | rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS); |
| 551 | |
| 552 | trace('testStruct({"Zero", 1, -3, -5})'); |
| 553 | var o = new Xtruct(); |
| 554 | o.string_thing = "Zero"; |
| 555 | o.byte_thing = 1; |
| 556 | o.i32_thing = -3; |
| 557 | o.i64_thing = Int64.make(0,-5); |
| 558 | var i = client.testStruct(o); |
| 559 | trace(' = {"' + i.string_thing + '", ' + i.byte_thing +', ' |
| 560 | + i.i32_thing +', '+ Int64.toStr(i.i64_thing) + '}'); |
| 561 | rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing"); |
| 562 | rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing"); |
| 563 | rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing"); |
| 564 | rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing"); |
| 565 | |
| 566 | trace('testNest({1, {\"Zero\", 1, -3, -5}, 5})'); |
| 567 | var o2 = new Xtruct2(); |
| 568 | o2.byte_thing = 1; |
| 569 | o2.struct_thing = o; |
| 570 | o2.i32_thing = 5; |
| 571 | var i2 = client.testNest(o2); |
| 572 | i = i2.struct_thing; |
| 573 | trace(" = {" + i2.byte_thing + ", {\"" + i.string_thing + "\", " |
| 574 | + i.byte_thing + ", " + i.i32_thing + ", " + Int64.toStr(i.i64_thing) + "}, " |
| 575 | + i2.i32_thing + "}"); |
| 576 | rslt.Expect( i2.byte_thing == o2.byte_thing, "i2.byte_thing == o2.byte_thing"); |
| 577 | rslt.Expect( i2.i32_thing == o2.i32_thing, "i2.i32_thing == o2.i32_thing"); |
| 578 | rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing"); |
| 579 | rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing"); |
| 580 | rslt.Expect( i.i32_thing == o.i32_thing, "i.i32_thing == o.i32_thing"); |
| 581 | rslt.Expect( Int64.compare( i.i64_thing, o.i64_thing) == 0, "i.i64_thing == o.i64_thing"); |
| 582 | |
| 583 | |
| 584 | rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS); |
| 585 | |
| 586 | var mapout = new IntMap< haxe.Int32>(); |
| 587 | for ( j in 0 ... 5) |
| 588 | { |
| 589 | mapout.set(j, j - 10); |
| 590 | } |
| 591 | trace("testMap({"); |
| 592 | var first : Bool = true; |
| 593 | for( key in mapout.keys()) |
| 594 | { |
| 595 | if (first) |
| 596 | { |
| 597 | first = false; |
| 598 | } |
| 599 | else |
| 600 | { |
| 601 | trace(", "); |
| 602 | } |
| 603 | trace(key + " => " + mapout.get(key)); |
| 604 | } |
| 605 | trace("})"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 606 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 607 | var mapin = client.testMap(mapout); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 608 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 609 | trace(" = {"); |
| 610 | first = true; |
| 611 | for( key in mapin.keys()) |
| 612 | { |
| 613 | if (first) |
| 614 | { |
| 615 | first = false; |
| 616 | } |
| 617 | else |
| 618 | { |
| 619 | trace(", "); |
| 620 | } |
| 621 | trace(key + " => " + mapin.get(key)); |
| 622 | rslt.Expect( mapin.get(key) == mapout.get(key), ' mapin.get($key) == mapout.get($key)'); |
| 623 | } |
| 624 | trace("}"); |
| 625 | for( key in mapout.keys()) |
| 626 | { |
| 627 | rslt.Expect(mapin.exists(key), 'mapin.exists($key)'); |
| 628 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 629 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 630 | var listout = new List<Int>(); |
| 631 | for (j in -2 ... 3) |
| 632 | { |
| 633 | listout.add(j); |
| 634 | } |
| 635 | trace("testList({"); |
| 636 | first = true; |
| 637 | for( j in listout) |
| 638 | { |
| 639 | if (first) |
| 640 | { |
| 641 | first = false; |
| 642 | } |
| 643 | else |
| 644 | { |
| 645 | trace(", "); |
| 646 | } |
| 647 | trace(j); |
| 648 | } |
| 649 | trace("})"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 650 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 651 | var listin = client.testList(listout); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 652 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 653 | trace(" = {"); |
| 654 | first = true; |
| 655 | for( j in listin) |
| 656 | { |
| 657 | if (first) |
| 658 | { |
| 659 | first = false; |
| 660 | } |
| 661 | else |
| 662 | { |
| 663 | trace(", "); |
| 664 | } |
| 665 | trace(j); |
| 666 | } |
| 667 | trace("}"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 668 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 669 | rslt.Expect(listin.length == listout.length, "listin.length == listout.length"); |
| 670 | var literout = listout.iterator(); |
| 671 | var literin = listin.iterator(); |
| 672 | while( literin.hasNext()) { |
| 673 | rslt.Expect(literin.next() == literout.next(), "literin[i] == literout[i]"); |
| 674 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 675 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 676 | //set |
| 677 | var setout = new IntSet(); |
| 678 | for (j in -2 ... 3) |
| 679 | { |
| 680 | setout.add(j); |
| 681 | } |
| 682 | trace("testSet({"); |
| 683 | first = true; |
| 684 | for( j in setout) |
| 685 | { |
| 686 | if (first) |
| 687 | { |
| 688 | first = false; |
| 689 | } |
| 690 | else |
| 691 | { |
| 692 | trace(", "); |
| 693 | } |
| 694 | trace(j); |
| 695 | } |
| 696 | trace("})"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 697 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 698 | var setin = client.testSet(setout); |
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 | trace(" = {"); |
| 701 | first = true; |
| 702 | for( j in setin) |
| 703 | { |
| 704 | if (first) |
| 705 | { |
| 706 | first = false; |
| 707 | } |
| 708 | else |
| 709 | { |
| 710 | trace(", "); |
| 711 | } |
| 712 | trace(j); |
| 713 | rslt.Expect(setout.contains(j), 'setout.contains($j)'); |
| 714 | } |
| 715 | trace("}"); |
| 716 | rslt.Expect(setin.size == setout.size, "setin.length == setout.length"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 717 | |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 718 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 719 | rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 720 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 721 | trace("testEnum(ONE)"); |
| 722 | var ret = client.testEnum(Numberz.ONE); |
| 723 | trace(" = " + ret); |
| 724 | rslt.Expect(ret == Numberz.ONE, '$ret == Numberz.ONE'); |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 725 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 726 | trace("testEnum(TWO)"); |
| 727 | ret = client.testEnum(Numberz.TWO); |
| 728 | trace(" = " + ret); |
| 729 | rslt.Expect(ret == Numberz.TWO, '$ret == Numberz.TWO'); |
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("testEnum(THREE)"); |
| 732 | ret = client.testEnum(Numberz.THREE); |
| 733 | trace(" = " + ret); |
| 734 | rslt.Expect(ret == Numberz.THREE, '$ret == Numberz.THREE'); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 735 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 736 | trace("testEnum(FIVE)"); |
| 737 | ret = client.testEnum(Numberz.FIVE); |
| 738 | trace(" = " + ret); |
| 739 | rslt.Expect(ret == Numberz.FIVE, '$ret == Numberz.FIVE'); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 740 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 741 | trace("testEnum(EIGHT)"); |
| 742 | ret = client.testEnum(Numberz.EIGHT); |
| 743 | trace(" = " + ret); |
| 744 | rslt.Expect(ret == Numberz.EIGHT, '$ret == Numberz.EIGHT'); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 745 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 746 | trace("testTypedef(309858235082523)"); |
| 747 | var uid = client.testTypedef( Int64.make( 0x119D0, 0x7E08671B)); // 309858235082523 |
| 748 | trace(" = " + uid); |
| 749 | rslt.Expect( Int64.compare( uid, Int64.make( 0x119D0, 0x7E08671B)) == 0, |
| 750 | Int64.toStr(uid)+" == "+Int64.toStr(Int64.make( 0x119D0, 0x7E08671B))); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 751 | |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 752 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 753 | rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS); |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 754 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 755 | trace("testMapMap(1)"); |
| 756 | var mm = client.testMapMap(1); |
| 757 | trace(" = {"); |
| 758 | for( key in mm.keys()) |
| 759 | { |
| 760 | trace(key + " => {"); |
| 761 | var m2 = mm.get(key); |
| 762 | for( k2 in m2.keys()) |
| 763 | { |
| 764 | trace(k2 + " => " + m2.get(k2) + ", "); |
| 765 | } |
| 766 | trace("}, "); |
| 767 | } |
| 768 | trace("}"); |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 769 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 770 | var pos = mm.get(4); |
| 771 | var neg = mm.get(-4); |
| 772 | rslt.Expect( (pos != null) && (neg != null), "(pos != null) && (neg != null)"); |
Jens Geyer | bbd6fd7 | 2015-05-30 19:33:44 +0200 | [diff] [blame] | 773 | for (i in 1 ... 5) { |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 774 | rslt.Expect( pos.get(i) == i, 'pos.get($i) == $i'); |
| 775 | rslt.Expect( neg.get(-i) == -i, 'neg.get(-$i) == -$i'); |
Jens Geyer | bbd6fd7 | 2015-05-30 19:33:44 +0200 | [diff] [blame] | 776 | } |
| 777 | rslt.Expect( ! pos.exists(0), '!pos.exists(0)'); |
| 778 | rslt.Expect( ! neg.exists(-0), '!neg.exists(-0)'); |
| 779 | rslt.Expect( ! pos.exists(42), '!pos.exists(42)'); |
| 780 | rslt.Expect( ! neg.exists(-42), '!neg.exists(-42)'); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 781 | |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 782 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 783 | rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS); |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 784 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 785 | var insane = new Insanity(); |
| 786 | insane.userMap = new IntMap< Int64>(); |
| 787 | insane.userMap.set( Numberz.FIVE, Int64.make(0,5000)); |
| 788 | var truck = new Xtruct(); |
| 789 | truck.string_thing = "Truck"; |
| 790 | truck.byte_thing = 8; |
| 791 | truck.i32_thing = 8; |
| 792 | truck.i64_thing = Int64.make(0,8); |
| 793 | insane.xtructs = new List<Xtruct>(); |
| 794 | insane.xtructs.add(truck); |
| 795 | trace("testInsanity()"); |
| 796 | var whoa = client.testInsanity(insane); |
| 797 | trace(" = {"); |
| 798 | for( key in whoa.keys()) |
| 799 | { |
| 800 | var val = whoa.get(key); |
| 801 | trace(key + " => {"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 802 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 803 | for( k2 in val.keys()) |
| 804 | { |
| 805 | var v2 = val.get(k2); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 806 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 807 | trace(k2 + " => {"); |
| 808 | var userMap = v2.userMap; |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 809 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 810 | trace("{"); |
| 811 | if (userMap != null) |
| 812 | { |
| 813 | for( k3 in userMap.keys()) |
| 814 | { |
| 815 | trace(k3 + " => " + userMap.get(k3) + ", "); |
| 816 | } |
| 817 | } |
| 818 | else |
| 819 | { |
| 820 | trace("null"); |
| 821 | } |
| 822 | trace("}, "); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 823 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 824 | var xtructs = v2.xtructs; |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 825 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 826 | trace("{"); |
| 827 | if (xtructs != null) |
| 828 | { |
| 829 | for( x in xtructs) |
| 830 | { |
| 831 | trace("{\"" + x.string_thing + "\", " |
| 832 | + x.byte_thing + ", " + x.i32_thing + ", " |
| 833 | + x.i32_thing + "}, "); |
| 834 | } |
| 835 | } |
| 836 | else |
| 837 | { |
| 838 | trace("null"); |
| 839 | } |
| 840 | trace("}"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 841 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 842 | trace("}, "); |
| 843 | } |
| 844 | trace("}, "); |
| 845 | } |
| 846 | trace("}"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 847 | |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 848 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 849 | var first_map = whoa.get(Int64.make(0,1)); |
| 850 | var second_map = whoa.get(Int64.make(0,2)); |
| 851 | rslt.Expect( (first_map != null) && (second_map != null), "(first_map != null) && (second_map != null)"); |
| 852 | if ((first_map != null) && (second_map != null)) |
| 853 | { |
| 854 | var crazy2 = first_map.get(Numberz.TWO); |
| 855 | var crazy3 = first_map.get(Numberz.THREE); |
| 856 | var looney = second_map.get(Numberz.SIX); |
| 857 | rslt.Expect( (crazy2 != null) && (crazy3 != null) && (looney != null), |
| 858 | "(crazy2 != null) && (crazy3 != null) && (looney != null)"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 859 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 860 | rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0, |
| 861 | "crazy2.UserMap.get(Numberz.EIGHT) == 8"); |
| 862 | rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0, |
| 863 | "crazy3.UserMap.get(Numberz.EIGHT) == 8"); |
| 864 | rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0, |
| 865 | "crazy2.UserMap.get(Numberz.FIVE) == 5"); |
| 866 | rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0, |
| 867 | "crazy3.UserMap.get(Numberz.FIVE) == 5"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 868 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 869 | var crz2iter = crazy2.xtructs.iterator(); |
| 870 | var crz3iter = crazy3.xtructs.iterator(); |
| 871 | rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()"); |
| 872 | var goodbye2 = crz2iter.next(); |
| 873 | var goodbye3 = crz3iter.next(); |
| 874 | rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()"); |
| 875 | var hello2 = crz2iter.next(); |
| 876 | var hello3 = crz3iter.next(); |
| 877 | rslt.Expect( ! (crz2iter.hasNext() || crz3iter.hasNext()), "! (crz2iter.hasNext() || crz3iter.hasNext())"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 878 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 879 | rslt.Expect( hello2.string_thing == "Hello2", 'hello2.String_thing == "Hello2"'); |
| 880 | rslt.Expect( hello2.byte_thing == 2, 'hello2.Byte_thing == 2'); |
| 881 | rslt.Expect( hello2.i32_thing == 2, 'hello2.I32_thing == 2'); |
| 882 | rslt.Expect( Int64.compare( hello2.i64_thing, Int64.make(0,2)) == 0, 'hello2.I64_thing == 2'); |
| 883 | rslt.Expect( hello3.string_thing == "Hello2", 'hello3.String_thing == "Hello2"'); |
| 884 | rslt.Expect( hello3.byte_thing == 2, 'hello3.Byte_thing == 2'); |
| 885 | rslt.Expect( hello3.i32_thing == 2, 'hello3.I32_thing == 2'); |
| 886 | rslt.Expect( Int64.compare( hello3.i64_thing, Int64.make(0,2)) == 0, 'hello3.I64_thing == 2'); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 887 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 888 | rslt.Expect( goodbye2.string_thing == "Goodbye4", 'goodbye2.String_thing == "Goodbye4"'); |
| 889 | rslt.Expect( goodbye2.byte_thing == 4, 'goodbye2.Byte_thing == 4'); |
| 890 | rslt.Expect( goodbye2.i32_thing == 4, 'goodbye2.I32_thing == 4'); |
| 891 | rslt.Expect( Int64.compare( goodbye2.i64_thing, Int64.make(0,4)) == 0, 'goodbye2.I64_thing == 4'); |
| 892 | rslt.Expect( goodbye3.string_thing == "Goodbye4", 'goodbye3.String_thing == "Goodbye4"'); |
| 893 | rslt.Expect( goodbye3.byte_thing == 4, 'goodbye3.Byte_thing == 4'); |
| 894 | rslt.Expect( goodbye3.i32_thing == 4, 'goodbye3.I32_thing == 4'); |
| 895 | rslt.Expect( Int64.compare( goodbye3.i64_thing, Int64.make(0,4)) == 0, 'goodbye3.I64_thing == 4'); |
| 896 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 897 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 898 | var arg0 = 1; |
| 899 | var arg1 = 2; |
| 900 | var arg2 = Int64.make( 0x7FFFFFFF,0xFFFFFFFF); |
| 901 | var multiDict = new IntMap< String>(); |
| 902 | multiDict.set(1, "one"); |
| 903 | var arg4 = Numberz.FIVE; |
| 904 | var arg5 = Int64.make(0,5000000); |
| 905 | trace("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")"); |
| 906 | var multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5); |
| 907 | trace(" = Xtruct(byte_thing:" + multiResponse.byte_thing + ",string_thing:" + multiResponse.string_thing |
| 908 | + ",i32_thing:" + multiResponse.i32_thing |
| 909 | + ",i64_thing:" + Int64.toStr(multiResponse.i64_thing) + ")"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 910 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 911 | rslt.Expect( multiResponse.string_thing == "Hello2", 'multiResponse.String_thing == "Hello2"'); |
| 912 | rslt.Expect( multiResponse.byte_thing == arg0, 'multiResponse.Byte_thing == arg0'); |
| 913 | rslt.Expect( multiResponse.i32_thing == arg1, 'multiResponse.I32_thing == arg1'); |
| 914 | 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] | 915 | |
| 916 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 917 | rslt.StartTestGroup( 0); |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 918 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 919 | trace("Test Oneway(1)"); |
| 920 | client.testOneway(1); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 921 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 922 | if( ! args.skipSpeedTest) { |
| 923 | trace("Test Calltime()"); |
| 924 | var difft = Timer.stamp(); |
| 925 | for ( k in 0 ... 1000) { |
| 926 | client.testVoid(); |
| 927 | } |
Jens Geyer | bbd6fd7 | 2015-05-30 19:33:44 +0200 | [diff] [blame] | 928 | difft = Math.round( 1000 * (Timer.stamp() - difft)) / 1000; |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 929 | trace('$difft ms per testVoid() call'); |
| 930 | } |
| 931 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 932 | } |