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: |
| 215 | transport = new THttpClient(args.host); |
| 216 | default: |
| 217 | throw "Unhandled transport"; |
| 218 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 219 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 220 | // optional: layered transport |
| 221 | if ( args.framed) { |
| 222 | trace("- framed transport"); |
| 223 | transport = new TFramedTransport(transport); |
| 224 | } |
| 225 | if ( args.buffered) { |
| 226 | trace("- buffered transport"); |
Jens Geyer | d35f616 | 2014-11-29 19:23:03 +0100 | [diff] [blame] | 227 | transport = new TBufferedTransport(transport); |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 228 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 229 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 230 | // protocol |
| 231 | var protocol : TProtocol = null; |
| 232 | switch( args.protocol) |
| 233 | { |
| 234 | case binary: |
| 235 | trace("- binary protocol"); |
| 236 | protocol = new TBinaryProtocol(transport); |
| 237 | case json: |
| 238 | trace("- json protocol"); |
| 239 | protocol = new TJSONProtocol(transport); |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 240 | case compact: |
| 241 | trace("- compact protocol"); |
| 242 | protocol = new TCompactProtocol(transport); |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 243 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 244 | |
Jens Geyer | bbd6fd7 | 2015-05-30 19:33:44 +0200 | [diff] [blame] | 245 | // some quick and basic unit tests |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 246 | HaxeBasicsTest( args, rslt); |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 247 | ModuleUnitTests( args, rslt); |
Jens Geyer | bbd6fd7 | 2015-05-30 19:33:44 +0200 | [diff] [blame] | 248 | |
| 249 | // now run the test code |
| 250 | trace('- ${args.numIterations} iterations'); |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 251 | for( i in 0 ... args.numIterations) { |
| 252 | ClientTest( transport, protocol, args, rslt); |
| 253 | } |
| 254 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 255 | |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 256 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 257 | public static function HaxeBasicsTest( args : Arguments, rslt : TestResults) : Void |
| 258 | { |
| 259 | // We need to test a few basic things used in the ClientTest |
| 260 | // Anything else beyond this scope should go into /lib/haxe/ instead |
Jens Geyer | 26b36dc | 2016-05-28 23:22:51 +0200 | [diff] [blame^] | 261 | rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 262 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 263 | var map32 = new IntMap<Int32>(); |
| 264 | var map64 = new Int64Map<Int32>(); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 265 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 266 | rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #1"); |
| 267 | rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #2"); |
| 268 | rslt.Expect( map32.remove( 4711) == map64.remove( Int64.make(47,11)), "Int64Map<Int32> Test #3"); |
| 269 | 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] | 270 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 271 | map32.set( 42, 815); |
| 272 | map64.set( Int64.make(0,42), 815); |
| 273 | map32.set( -517, 23); |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 274 | map64.set( Int64.neg(Int64.make(0,517)), 23); |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 275 | map32.set( 0, -123); |
| 276 | map64.set( Int64.make(0,0), -123); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 277 | |
Jens Geyer | bbd6fd7 | 2015-05-30 19:33:44 +0200 | [diff] [blame] | 278 | //trace('map32 = $map32'); |
| 279 | //trace('map64 = $map64'); |
| 280 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 281 | rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #10"); |
| 282 | 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] | 283 | 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] | 284 | rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #13"); |
| 285 | rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #14"); |
| 286 | 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] | 287 | 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] | 288 | rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #Int64.make(-5,17)"); |
| 289 | rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #18"); |
| 290 | 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] | 291 | 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] | 292 | 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] | 293 | 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] | 294 | rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #23"); |
| 295 | rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #24"); |
| 296 | 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] | 297 | 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] | 298 | rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #27"); |
| 299 | 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] | 300 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 301 | map32.set( 42, 1); |
| 302 | map64.set( Int64.make(0,42), 1); |
| 303 | map32.set( -517, -2); |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 304 | map64.set( Int64.neg(Int64.make(0,517)), -2); |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 305 | map32.set( 0, 3); |
| 306 | map64.set( Int64.make(0,0), 3); |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 307 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 308 | var c32 = 0; |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 309 | var ksum32 = 0; |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 310 | for (key in map32.keys()) { |
| 311 | ++c32; |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 312 | ksum32 += key; |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 313 | } |
| 314 | var c64 = 0; |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 315 | var ksum64 = Int64.make(0,0); |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 316 | for (key in map64.keys()) { |
| 317 | ++c64; |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 318 | ksum64 = Int64.add( ksum64, key); |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 319 | } |
| 320 | rslt.Expect( c32 == c64, "Int64Map<Int32> Test #30"); |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 321 | rslt.Expect( '$ksum64' == '$ksum32', '$ksum64 == $ksum32 Test #31'); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 322 | |
Jens Geyer | 1d20a37 | 2016-03-15 23:04:27 +0200 | [diff] [blame] | 323 | //compare without spaces because differ in php and cpp |
| 324 | var s32 = map32.toString().replace(' ', ''); |
| 325 | var s64 = map64.toString().replace(' ', ''); |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 326 | rslt.Expect( s32 == s64, "Int64Map<Int32>.toString(): " + ' ("$s32" == "$s64") Test #32'); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 327 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 328 | map32.remove( 42); |
| 329 | map64.remove( Int64.make(0,42)); |
| 330 | map32.remove( -517); |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 331 | map64.remove( Int64.neg(Int64.make(0,517))); |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 332 | map32.remove( 0); |
| 333 | map64.remove( Int64.make(0,0)); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 334 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 335 | rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #90"); |
| 336 | 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] | 337 | 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] | 338 | rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #93"); |
| 339 | rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #94"); |
| 340 | rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #95"); |
| 341 | rslt.Expect( map32.get( -517) == map64.get( Int64.make(-5,17)), "Int64Map<Int32> Test #96"); |
| 342 | 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] | 343 | 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] | 344 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 345 | |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 346 | |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 347 | // core module unit tests |
| 348 | public static function ModuleUnitTests( args : Arguments, rslt : TestResults) : Void { |
Jens Geyer | 1d20a37 | 2016-03-15 23:04:27 +0200 | [diff] [blame] | 349 | #if debug |
| 350 | |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 351 | try { |
| 352 | BitConverter.UnitTest(); |
| 353 | rslt.Expect( true, 'BitConverter.UnitTest Test #100'); |
| 354 | } |
| 355 | catch( e : Dynamic) { |
| 356 | rslt.Expect( false, 'BitConverter.UnitTest: $e Test #100'); |
| 357 | } |
Jens Geyer | 43e195a | 2014-12-14 00:29:17 +0100 | [diff] [blame] | 358 | |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 359 | try { |
| 360 | ZigZag.UnitTest(); |
| 361 | rslt.Expect( true, 'ZigZag.UnitTest Test #101'); |
| 362 | } |
| 363 | catch( e : Dynamic) { |
| 364 | rslt.Expect( false, 'ZigZag.UnitTest: $e Test #101'); |
| 365 | } |
Jens Geyer | 1d20a37 | 2016-03-15 23:04:27 +0200 | [diff] [blame] | 366 | |
| 367 | #end |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 368 | } |
Jens Geyer | 43e195a | 2014-12-14 00:29:17 +0100 | [diff] [blame] | 369 | |
Jens Geyer | 43e195a | 2014-12-14 00:29:17 +0100 | [diff] [blame] | 370 | |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 371 | public static function BytesToHex(data : Bytes) : String { |
| 372 | var hex = ""; |
| 373 | for ( i in 0 ... data.length) { |
| 374 | hex += StringTools.hex( data.get(i), 2); |
| 375 | } |
| 376 | return hex; |
| 377 | } |
Jens Geyer | 43e195a | 2014-12-14 00:29:17 +0100 | [diff] [blame] | 378 | |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 379 | public static function PrepareTestData(randomDist : Bool) : Bytes { |
| 380 | var retval = Bytes.alloc(0x100); |
| 381 | var initLen : Int = (retval.length > 0x100 ? 0x100 : retval.length); |
| 382 | |
| 383 | // linear distribution, unless random is requested |
| 384 | if (!randomDist) { |
| 385 | for (i in 0 ... initLen) { |
| 386 | retval.set(i, i % 0x100); |
| 387 | } |
| 388 | return retval; |
| 389 | } |
| 390 | |
| 391 | // random distribution |
| 392 | for (i in 0 ... initLen) { |
| 393 | retval.set(i, 0); |
| 394 | } |
| 395 | for (i in 1 ... initLen) { |
| 396 | while( true) { |
| 397 | var nextPos = Std.random(initLen); |
| 398 | if (retval.get(nextPos) == 0) { |
| 399 | retval.set( nextPos, i % 0x100); |
| 400 | break; |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | return retval; |
| 405 | } |
| 406 | |
| 407 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 408 | public static function ClientTest( transport : TTransport, protocol : TProtocol, |
| 409 | args : Arguments, rslt : TestResults) : Void |
| 410 | { |
| 411 | var client = new ThriftTestImpl(protocol,protocol); |
| 412 | try |
| 413 | { |
| 414 | if (!transport.isOpen()) |
| 415 | { |
| 416 | transport.open(); |
| 417 | } |
| 418 | } |
| 419 | catch (e : TException) |
| 420 | { |
Jens Geyer | bbd6fd7 | 2015-05-30 19:33:44 +0200 | [diff] [blame] | 421 | rslt.Expect( false, 'unable to open transport: $e'); |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 422 | return; |
| 423 | } |
| 424 | catch (e : Dynamic) |
| 425 | { |
Jens Geyer | bbd6fd7 | 2015-05-30 19:33:44 +0200 | [diff] [blame] | 426 | rslt.Expect( false, 'unable to open transport: $e'); |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 427 | return; |
| 428 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 429 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 430 | var start = Date.now(); |
| 431 | |
| 432 | rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_EXCEPTIONS); |
| 433 | |
| 434 | // if arg == "Xception" throw Xception with errorCode = 1001 and message = arg |
| 435 | trace('testException("Xception")'); |
| 436 | try { |
| 437 | client.testException("Xception"); |
| 438 | rslt.Expect( false, 'testException("Xception") should throw'); |
| 439 | } |
| 440 | catch (e : Xception) |
| 441 | { |
| 442 | rslt.Expect( e.message == "Xception", 'testException("Xception") - e.message == "Xception"'); |
| 443 | rslt.Expect( e.errorCode == 1001, 'testException("Xception") - e.errorCode == 1001'); |
| 444 | } |
| 445 | catch (e : Dynamic) |
| 446 | { |
| 447 | rslt.Expect( false, 'testException("Xception") - $e'); |
| 448 | } |
| 449 | |
| 450 | // if arg == "TException" throw TException |
| 451 | trace('testException("TException")'); |
| 452 | try { |
| 453 | client.testException("TException"); |
| 454 | rslt.Expect( false, 'testException("TException") should throw'); |
| 455 | } |
| 456 | catch (e : TException) |
| 457 | { |
| 458 | rslt.Expect( true, 'testException("TException") - $e'); |
| 459 | } |
| 460 | catch (e : Dynamic) |
| 461 | { |
| 462 | rslt.Expect( false, 'testException("TException") - $e'); |
| 463 | } |
| 464 | |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 465 | // reopen the transport, just in case the server closed his end |
| 466 | if (transport.isOpen()) |
| 467 | transport.close(); |
| 468 | transport.open(); |
| 469 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 470 | // else do not throw anything |
| 471 | trace('testException("bla")'); |
| 472 | try { |
| 473 | client.testException("bla"); |
| 474 | rslt.Expect( true, 'testException("bla") should not throw'); |
| 475 | } |
| 476 | catch (e : Dynamic) |
| 477 | { |
| 478 | rslt.Expect( false, 'testException("bla") - $e'); |
| 479 | } |
| 480 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 481 | rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES); |
| 482 | |
| 483 | trace('testVoid()'); |
| 484 | client.testVoid(); |
| 485 | trace(' = void'); |
| 486 | rslt.Expect(true,"testVoid()"); // bump counter |
| 487 | |
Jens Geyer | fa2daef | 2015-09-22 00:11:01 +0200 | [diff] [blame] | 488 | trace('testBool(${true})'); |
| 489 | var b = client.testBool(true); |
| 490 | trace(' = $b'); |
Jens Geyer | 1d20a37 | 2016-03-15 23:04:27 +0200 | [diff] [blame] | 491 | rslt.Expect(b, '$b == "${true}"'); |
Jens Geyer | fa2daef | 2015-09-22 00:11:01 +0200 | [diff] [blame] | 492 | trace('testBool(${false})'); |
| 493 | b = client.testBool(false); |
| 494 | trace(' = $b'); |
Jens Geyer | 1d20a37 | 2016-03-15 23:04:27 +0200 | [diff] [blame] | 495 | rslt.Expect( ! b, '$b == "${false}"'); |
Jens Geyer | fa2daef | 2015-09-22 00:11:01 +0200 | [diff] [blame] | 496 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 497 | trace('testString("Test")'); |
| 498 | var s = client.testString("Test"); |
| 499 | trace(' = "$s"'); |
| 500 | rslt.Expect(s == "Test", '$s == "Test"'); |
| 501 | |
| 502 | trace('testByte(1)'); |
| 503 | var i8 = client.testByte(1); |
| 504 | trace(' = $i8'); |
| 505 | rslt.Expect(i8 == 1, '$i8 == 1'); |
| 506 | |
| 507 | trace('testI32(-1)'); |
| 508 | var i32 = client.testI32(-1); |
| 509 | trace(' = $i32'); |
| 510 | rslt.Expect(i32 == -1, '$i32 == -1'); |
| 511 | |
| 512 | trace('testI64(-34359738368)'); |
| 513 | var i64 = client.testI64( Int64.make( 0xFFFFFFF8, 0x00000000)); // -34359738368 |
| 514 | trace(' = $i64'); |
| 515 | rslt.Expect( Int64.compare( i64, Int64.make( 0xFFFFFFF8, 0x00000000)) == 0, |
| 516 | Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0xFFFFFFF8, 0x00000000))); |
| 517 | |
| 518 | // edge case: the largest negative Int64 has no positive Int64 equivalent |
| 519 | trace('testI64(-9223372036854775808)'); |
| 520 | i64 = client.testI64( Int64.make( 0x80000000, 0x00000000)); // -9223372036854775808 |
| 521 | trace(' = $i64'); |
| 522 | rslt.Expect( Int64.compare( i64, Int64.make( 0x80000000, 0x00000000)) == 0, |
| 523 | Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0x80000000, 0x00000000))); |
| 524 | |
| 525 | trace('testDouble(5.325098235)'); |
| 526 | var dub = client.testDouble(5.325098235); |
| 527 | trace(' = $dub'); |
| 528 | rslt.Expect(dub == 5.325098235, '$dub == 5.325098235'); |
| 529 | |
Jens Geyer | 43e195a | 2014-12-14 00:29:17 +0100 | [diff] [blame] | 530 | var binOut = PrepareTestData(true); |
| 531 | trace('testBinary('+BytesToHex(binOut)+')'); |
| 532 | try { |
| 533 | var binIn = client.testBinary(binOut); |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 534 | trace('testBinary() = '+BytesToHex(binIn)); |
| 535 | rslt.Expect( binIn.length == binOut.length, '${binIn.length} == ${binOut.length}'); |
| 536 | var len = ((binIn.length < binOut.length) ? binIn.length : binOut.length); |
Jens Geyer | 43e195a | 2014-12-14 00:29:17 +0100 | [diff] [blame] | 537 | for (ofs in 0 ... len) { |
| 538 | if (binIn.get(ofs) != binOut.get(ofs)) { |
Jens Geyer | 426ab86 | 2015-03-02 23:37:15 +0100 | [diff] [blame] | 539 | rslt.Expect( false, 'testBinary('+BytesToHex(binOut)+'): content mismatch at offset $ofs'); |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | catch (e : TApplicationException) { |
Jens Geyer | 43e195a | 2014-12-14 00:29:17 +0100 | [diff] [blame] | 544 | trace('testBinary('+BytesToHex(binOut)+'): '+e.errorMsg); // may not be supported by the server |
| 545 | } |
| 546 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 547 | |
| 548 | rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS); |
| 549 | |
| 550 | trace('testStruct({"Zero", 1, -3, -5})'); |
| 551 | var o = new Xtruct(); |
| 552 | o.string_thing = "Zero"; |
| 553 | o.byte_thing = 1; |
| 554 | o.i32_thing = -3; |
| 555 | o.i64_thing = Int64.make(0,-5); |
| 556 | var i = client.testStruct(o); |
| 557 | trace(' = {"' + i.string_thing + '", ' + i.byte_thing +', ' |
| 558 | + i.i32_thing +', '+ Int64.toStr(i.i64_thing) + '}'); |
| 559 | rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing"); |
| 560 | rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing"); |
| 561 | rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing"); |
| 562 | rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing"); |
| 563 | |
| 564 | trace('testNest({1, {\"Zero\", 1, -3, -5}, 5})'); |
| 565 | var o2 = new Xtruct2(); |
| 566 | o2.byte_thing = 1; |
| 567 | o2.struct_thing = o; |
| 568 | o2.i32_thing = 5; |
| 569 | var i2 = client.testNest(o2); |
| 570 | i = i2.struct_thing; |
| 571 | trace(" = {" + i2.byte_thing + ", {\"" + i.string_thing + "\", " |
| 572 | + i.byte_thing + ", " + i.i32_thing + ", " + Int64.toStr(i.i64_thing) + "}, " |
| 573 | + i2.i32_thing + "}"); |
| 574 | rslt.Expect( i2.byte_thing == o2.byte_thing, "i2.byte_thing == o2.byte_thing"); |
| 575 | rslt.Expect( i2.i32_thing == o2.i32_thing, "i2.i32_thing == o2.i32_thing"); |
| 576 | rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing"); |
| 577 | rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing"); |
| 578 | rslt.Expect( i.i32_thing == o.i32_thing, "i.i32_thing == o.i32_thing"); |
| 579 | rslt.Expect( Int64.compare( i.i64_thing, o.i64_thing) == 0, "i.i64_thing == o.i64_thing"); |
| 580 | |
| 581 | |
| 582 | rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS); |
| 583 | |
| 584 | var mapout = new IntMap< haxe.Int32>(); |
| 585 | for ( j in 0 ... 5) |
| 586 | { |
| 587 | mapout.set(j, j - 10); |
| 588 | } |
| 589 | trace("testMap({"); |
| 590 | var first : Bool = true; |
| 591 | for( key in mapout.keys()) |
| 592 | { |
| 593 | if (first) |
| 594 | { |
| 595 | first = false; |
| 596 | } |
| 597 | else |
| 598 | { |
| 599 | trace(", "); |
| 600 | } |
| 601 | trace(key + " => " + mapout.get(key)); |
| 602 | } |
| 603 | trace("})"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 604 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 605 | var mapin = client.testMap(mapout); |
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 | trace(" = {"); |
| 608 | first = true; |
| 609 | for( key in mapin.keys()) |
| 610 | { |
| 611 | if (first) |
| 612 | { |
| 613 | first = false; |
| 614 | } |
| 615 | else |
| 616 | { |
| 617 | trace(", "); |
| 618 | } |
| 619 | trace(key + " => " + mapin.get(key)); |
| 620 | rslt.Expect( mapin.get(key) == mapout.get(key), ' mapin.get($key) == mapout.get($key)'); |
| 621 | } |
| 622 | trace("}"); |
| 623 | for( key in mapout.keys()) |
| 624 | { |
| 625 | rslt.Expect(mapin.exists(key), 'mapin.exists($key)'); |
| 626 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 627 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 628 | var listout = new List<Int>(); |
| 629 | for (j in -2 ... 3) |
| 630 | { |
| 631 | listout.add(j); |
| 632 | } |
| 633 | trace("testList({"); |
| 634 | first = true; |
| 635 | for( j in listout) |
| 636 | { |
| 637 | if (first) |
| 638 | { |
| 639 | first = false; |
| 640 | } |
| 641 | else |
| 642 | { |
| 643 | trace(", "); |
| 644 | } |
| 645 | trace(j); |
| 646 | } |
| 647 | trace("})"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 648 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 649 | var listin = client.testList(listout); |
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 | trace(" = {"); |
| 652 | first = true; |
| 653 | for( j in listin) |
| 654 | { |
| 655 | if (first) |
| 656 | { |
| 657 | first = false; |
| 658 | } |
| 659 | else |
| 660 | { |
| 661 | trace(", "); |
| 662 | } |
| 663 | trace(j); |
| 664 | } |
| 665 | trace("}"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 666 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 667 | rslt.Expect(listin.length == listout.length, "listin.length == listout.length"); |
| 668 | var literout = listout.iterator(); |
| 669 | var literin = listin.iterator(); |
| 670 | while( literin.hasNext()) { |
| 671 | rslt.Expect(literin.next() == literout.next(), "literin[i] == literout[i]"); |
| 672 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 673 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 674 | //set |
| 675 | var setout = new IntSet(); |
| 676 | for (j in -2 ... 3) |
| 677 | { |
| 678 | setout.add(j); |
| 679 | } |
| 680 | trace("testSet({"); |
| 681 | first = true; |
| 682 | for( j in setout) |
| 683 | { |
| 684 | if (first) |
| 685 | { |
| 686 | first = false; |
| 687 | } |
| 688 | else |
| 689 | { |
| 690 | trace(", "); |
| 691 | } |
| 692 | trace(j); |
| 693 | } |
| 694 | trace("})"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 695 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 696 | var setin = client.testSet(setout); |
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 | trace(" = {"); |
| 699 | first = true; |
| 700 | for( j in setin) |
| 701 | { |
| 702 | if (first) |
| 703 | { |
| 704 | first = false; |
| 705 | } |
| 706 | else |
| 707 | { |
| 708 | trace(", "); |
| 709 | } |
| 710 | trace(j); |
| 711 | rslt.Expect(setout.contains(j), 'setout.contains($j)'); |
| 712 | } |
| 713 | trace("}"); |
| 714 | rslt.Expect(setin.size == setout.size, "setin.length == setout.length"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 715 | |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 716 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 717 | rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_BASETYPES); |
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 | trace("testEnum(ONE)"); |
| 720 | var ret = client.testEnum(Numberz.ONE); |
| 721 | trace(" = " + ret); |
| 722 | rslt.Expect(ret == Numberz.ONE, '$ret == Numberz.ONE'); |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 723 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 724 | trace("testEnum(TWO)"); |
| 725 | ret = client.testEnum(Numberz.TWO); |
| 726 | trace(" = " + ret); |
| 727 | rslt.Expect(ret == Numberz.TWO, '$ret == Numberz.TWO'); |
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(THREE)"); |
| 730 | ret = client.testEnum(Numberz.THREE); |
| 731 | trace(" = " + ret); |
| 732 | rslt.Expect(ret == Numberz.THREE, '$ret == Numberz.THREE'); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 733 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 734 | trace("testEnum(FIVE)"); |
| 735 | ret = client.testEnum(Numberz.FIVE); |
| 736 | trace(" = " + ret); |
| 737 | rslt.Expect(ret == Numberz.FIVE, '$ret == Numberz.FIVE'); |
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(EIGHT)"); |
| 740 | ret = client.testEnum(Numberz.EIGHT); |
| 741 | trace(" = " + ret); |
| 742 | rslt.Expect(ret == Numberz.EIGHT, '$ret == Numberz.EIGHT'); |
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("testTypedef(309858235082523)"); |
| 745 | var uid = client.testTypedef( Int64.make( 0x119D0, 0x7E08671B)); // 309858235082523 |
| 746 | trace(" = " + uid); |
| 747 | rslt.Expect( Int64.compare( uid, Int64.make( 0x119D0, 0x7E08671B)) == 0, |
| 748 | Int64.toStr(uid)+" == "+Int64.toStr(Int64.make( 0x119D0, 0x7E08671B))); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 749 | |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 750 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 751 | rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_CONTAINERS); |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 752 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 753 | trace("testMapMap(1)"); |
| 754 | var mm = client.testMapMap(1); |
| 755 | trace(" = {"); |
| 756 | for( key in mm.keys()) |
| 757 | { |
| 758 | trace(key + " => {"); |
| 759 | var m2 = mm.get(key); |
| 760 | for( k2 in m2.keys()) |
| 761 | { |
| 762 | trace(k2 + " => " + m2.get(k2) + ", "); |
| 763 | } |
| 764 | trace("}, "); |
| 765 | } |
| 766 | trace("}"); |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 767 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 768 | var pos = mm.get(4); |
| 769 | var neg = mm.get(-4); |
| 770 | rslt.Expect( (pos != null) && (neg != null), "(pos != null) && (neg != null)"); |
Jens Geyer | bbd6fd7 | 2015-05-30 19:33:44 +0200 | [diff] [blame] | 771 | for (i in 1 ... 5) { |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 772 | rslt.Expect( pos.get(i) == i, 'pos.get($i) == $i'); |
| 773 | rslt.Expect( neg.get(-i) == -i, 'neg.get(-$i) == -$i'); |
Jens Geyer | bbd6fd7 | 2015-05-30 19:33:44 +0200 | [diff] [blame] | 774 | } |
| 775 | rslt.Expect( ! pos.exists(0), '!pos.exists(0)'); |
| 776 | rslt.Expect( ! neg.exists(-0), '!neg.exists(-0)'); |
| 777 | rslt.Expect( ! pos.exists(42), '!pos.exists(42)'); |
| 778 | rslt.Expect( ! neg.exists(-42), '!neg.exists(-42)'); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 779 | |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 780 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 781 | rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS); |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 782 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 783 | var insane = new Insanity(); |
| 784 | insane.userMap = new IntMap< Int64>(); |
| 785 | insane.userMap.set( Numberz.FIVE, Int64.make(0,5000)); |
| 786 | var truck = new Xtruct(); |
| 787 | truck.string_thing = "Truck"; |
| 788 | truck.byte_thing = 8; |
| 789 | truck.i32_thing = 8; |
| 790 | truck.i64_thing = Int64.make(0,8); |
| 791 | insane.xtructs = new List<Xtruct>(); |
| 792 | insane.xtructs.add(truck); |
| 793 | trace("testInsanity()"); |
| 794 | var whoa = client.testInsanity(insane); |
| 795 | trace(" = {"); |
| 796 | for( key in whoa.keys()) |
| 797 | { |
| 798 | var val = whoa.get(key); |
| 799 | trace(key + " => {"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 800 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 801 | for( k2 in val.keys()) |
| 802 | { |
| 803 | var v2 = val.get(k2); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 804 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 805 | trace(k2 + " => {"); |
| 806 | var userMap = v2.userMap; |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 807 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 808 | trace("{"); |
| 809 | if (userMap != null) |
| 810 | { |
| 811 | for( k3 in userMap.keys()) |
| 812 | { |
| 813 | trace(k3 + " => " + userMap.get(k3) + ", "); |
| 814 | } |
| 815 | } |
| 816 | else |
| 817 | { |
| 818 | trace("null"); |
| 819 | } |
| 820 | trace("}, "); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 821 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 822 | var xtructs = v2.xtructs; |
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 | trace("{"); |
| 825 | if (xtructs != null) |
| 826 | { |
| 827 | for( x in xtructs) |
| 828 | { |
| 829 | trace("{\"" + x.string_thing + "\", " |
| 830 | + x.byte_thing + ", " + x.i32_thing + ", " |
| 831 | + x.i32_thing + "}, "); |
| 832 | } |
| 833 | } |
| 834 | else |
| 835 | { |
| 836 | trace("null"); |
| 837 | } |
| 838 | trace("}"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 839 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 840 | trace("}, "); |
| 841 | } |
| 842 | trace("}, "); |
| 843 | } |
| 844 | trace("}"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 845 | |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 846 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 847 | var first_map = whoa.get(Int64.make(0,1)); |
| 848 | var second_map = whoa.get(Int64.make(0,2)); |
| 849 | rslt.Expect( (first_map != null) && (second_map != null), "(first_map != null) && (second_map != null)"); |
| 850 | if ((first_map != null) && (second_map != null)) |
| 851 | { |
| 852 | var crazy2 = first_map.get(Numberz.TWO); |
| 853 | var crazy3 = first_map.get(Numberz.THREE); |
| 854 | var looney = second_map.get(Numberz.SIX); |
| 855 | rslt.Expect( (crazy2 != null) && (crazy3 != null) && (looney != null), |
| 856 | "(crazy2 != null) && (crazy3 != null) && (looney != null)"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 857 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 858 | rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0, |
| 859 | "crazy2.UserMap.get(Numberz.EIGHT) == 8"); |
| 860 | rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0, |
| 861 | "crazy3.UserMap.get(Numberz.EIGHT) == 8"); |
| 862 | rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0, |
| 863 | "crazy2.UserMap.get(Numberz.FIVE) == 5"); |
| 864 | rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0, |
| 865 | "crazy3.UserMap.get(Numberz.FIVE) == 5"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 866 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 867 | var crz2iter = crazy2.xtructs.iterator(); |
| 868 | var crz3iter = crazy3.xtructs.iterator(); |
| 869 | rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()"); |
| 870 | var goodbye2 = crz2iter.next(); |
| 871 | var goodbye3 = crz3iter.next(); |
| 872 | rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()"); |
| 873 | var hello2 = crz2iter.next(); |
| 874 | var hello3 = crz3iter.next(); |
| 875 | rslt.Expect( ! (crz2iter.hasNext() || crz3iter.hasNext()), "! (crz2iter.hasNext() || crz3iter.hasNext())"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 876 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 877 | rslt.Expect( hello2.string_thing == "Hello2", 'hello2.String_thing == "Hello2"'); |
| 878 | rslt.Expect( hello2.byte_thing == 2, 'hello2.Byte_thing == 2'); |
| 879 | rslt.Expect( hello2.i32_thing == 2, 'hello2.I32_thing == 2'); |
| 880 | rslt.Expect( Int64.compare( hello2.i64_thing, Int64.make(0,2)) == 0, 'hello2.I64_thing == 2'); |
| 881 | rslt.Expect( hello3.string_thing == "Hello2", 'hello3.String_thing == "Hello2"'); |
| 882 | rslt.Expect( hello3.byte_thing == 2, 'hello3.Byte_thing == 2'); |
| 883 | rslt.Expect( hello3.i32_thing == 2, 'hello3.I32_thing == 2'); |
| 884 | 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] | 885 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 886 | rslt.Expect( goodbye2.string_thing == "Goodbye4", 'goodbye2.String_thing == "Goodbye4"'); |
| 887 | rslt.Expect( goodbye2.byte_thing == 4, 'goodbye2.Byte_thing == 4'); |
| 888 | rslt.Expect( goodbye2.i32_thing == 4, 'goodbye2.I32_thing == 4'); |
| 889 | rslt.Expect( Int64.compare( goodbye2.i64_thing, Int64.make(0,4)) == 0, 'goodbye2.I64_thing == 4'); |
| 890 | rslt.Expect( goodbye3.string_thing == "Goodbye4", 'goodbye3.String_thing == "Goodbye4"'); |
| 891 | rslt.Expect( goodbye3.byte_thing == 4, 'goodbye3.Byte_thing == 4'); |
| 892 | rslt.Expect( goodbye3.i32_thing == 4, 'goodbye3.I32_thing == 4'); |
| 893 | rslt.Expect( Int64.compare( goodbye3.i64_thing, Int64.make(0,4)) == 0, 'goodbye3.I64_thing == 4'); |
| 894 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 895 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 896 | var arg0 = 1; |
| 897 | var arg1 = 2; |
| 898 | var arg2 = Int64.make( 0x7FFFFFFF,0xFFFFFFFF); |
| 899 | var multiDict = new IntMap< String>(); |
| 900 | multiDict.set(1, "one"); |
| 901 | var arg4 = Numberz.FIVE; |
| 902 | var arg5 = Int64.make(0,5000000); |
| 903 | trace("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")"); |
| 904 | var multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5); |
| 905 | trace(" = Xtruct(byte_thing:" + multiResponse.byte_thing + ",string_thing:" + multiResponse.string_thing |
| 906 | + ",i32_thing:" + multiResponse.i32_thing |
| 907 | + ",i64_thing:" + Int64.toStr(multiResponse.i64_thing) + ")"); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 908 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 909 | rslt.Expect( multiResponse.string_thing == "Hello2", 'multiResponse.String_thing == "Hello2"'); |
| 910 | rslt.Expect( multiResponse.byte_thing == arg0, 'multiResponse.Byte_thing == arg0'); |
| 911 | rslt.Expect( multiResponse.i32_thing == arg1, 'multiResponse.I32_thing == arg1'); |
| 912 | 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] | 913 | |
| 914 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 915 | rslt.StartTestGroup( 0); |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 916 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 917 | trace("Test Oneway(1)"); |
| 918 | client.testOneway(1); |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 919 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 920 | if( ! args.skipSpeedTest) { |
| 921 | trace("Test Calltime()"); |
| 922 | var difft = Timer.stamp(); |
| 923 | for ( k in 0 ... 1000) { |
| 924 | client.testVoid(); |
| 925 | } |
Jens Geyer | bbd6fd7 | 2015-05-30 19:33:44 +0200 | [diff] [blame] | 926 | difft = Math.round( 1000 * (Timer.stamp() - difft)) / 1000; |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame] | 927 | trace('$difft ms per testVoid() call'); |
| 928 | } |
| 929 | } |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 930 | } |