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; |
| 24 | import haxe.Timer; |
| 25 | import haxe.ds.IntMap; |
| 26 | import haxe.ds.StringMap; |
| 27 | import haxe.ds.ObjectMap; |
| 28 | |
| 29 | import org.apache.thrift.*; |
| 30 | import org.apache.thrift.helper.*; |
| 31 | import org.apache.thrift.protocol.*; |
| 32 | import org.apache.thrift.transport.*; |
| 33 | import org.apache.thrift.server.*; |
| 34 | import org.apache.thrift.meta_data.*; |
| 35 | |
| 36 | #if cpp |
| 37 | import cpp.vm.Thread; |
| 38 | #else |
| 39 | // no thread support (yet) |
| 40 | #end |
| 41 | |
| 42 | import thrift.test.*; // generated code |
| 43 | |
| 44 | |
| 45 | class TestResults { |
| 46 | private var successCnt : Int = 0; |
| 47 | private var errorCnt : Int = 0; |
| 48 | private var failedTests : String = ""; |
| 49 | private var print_direct : Bool = false; |
| 50 | |
| 51 | public function new(direct : Bool) { |
| 52 | print_direct = direct; |
| 53 | } |
| 54 | |
| 55 | public function Expect( expr : Bool, msg : String) : Void { |
| 56 | if ( expr) { |
| 57 | ++successCnt; |
| 58 | } else { |
| 59 | ++errorCnt; |
| 60 | failedTests += "\n " + msg; |
| 61 | if( print_direct) { |
| 62 | trace('FAIL: $msg'); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | |
| 68 | public function PrintSummary() : Void { |
| 69 | var total = successCnt + errorCnt; |
| 70 | var sp = (100 * successCnt) / total; |
| 71 | var ep = (100 * errorCnt) / total; |
| 72 | |
| 73 | trace('==========================='); |
| 74 | trace('Tests executed $total'); |
| 75 | trace('Tests succeeded $successCnt ($sp%)'); |
| 76 | trace('Tests failed $errorCnt ($ep%)'); |
| 77 | if ( errorCnt > 0) |
| 78 | { |
| 79 | trace('==========================='); |
| 80 | trace('FAILED TESTS: $failedTests'); |
| 81 | } |
| 82 | trace('==========================='); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
| 87 | class TestClient { |
| 88 | |
| 89 | public static function Execute(args : Arguments) : Void |
| 90 | { |
| 91 | try |
| 92 | { |
| 93 | var difft = Timer.stamp(); |
| 94 | |
| 95 | if( args.numThreads > 1) { |
| 96 | var threads = new List<Thread>(); |
| 97 | for( test in 0 ... args.numThreads) { |
| 98 | threads.add( StartThread( args)); |
| 99 | } |
| 100 | for( thread in threads) { |
| 101 | Thread.readMessage(true); |
| 102 | } |
| 103 | } else { |
| 104 | var rslt = new TestResults(true); |
| 105 | RunClient(args,rslt); |
| 106 | rslt.PrintSummary(); |
| 107 | } |
| 108 | |
| 109 | difft = Timer.stamp() - difft; |
| 110 | trace('total test time: $difft seconds'); |
| 111 | } |
| 112 | catch (e : TException) |
| 113 | { |
| 114 | trace('$e'); |
| 115 | } |
| 116 | catch (e : Dynamic) |
| 117 | { |
| 118 | trace('$e'); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | |
| 123 | private static function StartThread(args : Arguments) : Thread { |
| 124 | var thread = Thread.create( |
| 125 | function() : Void { |
| 126 | var main : Thread = Thread.readMessage(true); |
| 127 | try |
| 128 | { |
| 129 | var rslt = new TestResults(false); |
| 130 | RunClient(args,rslt); |
| 131 | // TODO: promote rslt values to main thread |
| 132 | } |
| 133 | catch (e : TException) |
| 134 | { |
| 135 | trace('$e'); |
| 136 | } |
| 137 | catch (e : Dynamic) |
| 138 | { |
| 139 | trace('$e'); |
| 140 | } |
| 141 | main.sendMessage("done"); |
| 142 | }); |
| 143 | |
| 144 | thread.sendMessage(Thread.current()); |
| 145 | return thread; |
| 146 | } |
| 147 | |
| 148 | |
| 149 | public static function RunClient(args : Arguments, rslt : TestResults) |
| 150 | { |
| 151 | var transport : TTransport = null; |
| 152 | switch (args.transport) |
| 153 | { |
| 154 | case socket: |
| 155 | transport = new TSocket(args.host, args.port); |
| 156 | case http: |
| 157 | throw "http transport not supported yet"; |
| 158 | //transport = new THttpClient(args.host); |
| 159 | default: |
| 160 | throw "Unhandled transport"; |
| 161 | } |
| 162 | |
| 163 | // optional: layered transport |
| 164 | if ( args.framed) { |
| 165 | trace("- framed transport"); |
| 166 | transport = new TFramedTransport(transport); |
| 167 | } else if ( args.buffered) { |
| 168 | trace("- buffered transport"); |
| 169 | throw "TBufferedTransport not implemented yet"; |
| 170 | //transport = new TBufferedTransport(transport); |
| 171 | } |
| 172 | |
| 173 | // protocol |
| 174 | var protocol : TProtocol = null; |
| 175 | switch( args.protocol) |
| 176 | { |
| 177 | case binary: |
| 178 | trace("- binary protocol"); |
| 179 | protocol = new TBinaryProtocol(transport); |
| 180 | case json: |
| 181 | trace("- json protocol"); |
| 182 | protocol = new TJSONProtocol(transport); |
| 183 | default: |
| 184 | throw "Unhandled protocol"; |
| 185 | } |
| 186 | |
| 187 | |
| 188 | // run the test code |
| 189 | HaxeBasicsTest( rslt); |
| 190 | ClientTest( transport, protocol, rslt); |
| 191 | |
| 192 | } |
| 193 | |
| 194 | |
| 195 | public static function HaxeBasicsTest( rslt : TestResults) : Void |
| 196 | { |
| 197 | // We need to test a few basic things used in the ClientTest |
| 198 | // Anything else beyond this scope should go into /lib/haxe/ instead |
| 199 | |
| 200 | var map32 = new IntMap<Int32>(); |
| 201 | var map64 = new Int64Map<Int32>(); |
| 202 | |
| 203 | rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #1"); |
| 204 | rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #2"); |
| 205 | rslt.Expect( map32.remove( 4711) == map64.remove( Int64.make(47,11)), "Int64Map<Int32> Test #3"); |
| 206 | rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #4"); |
| 207 | |
| 208 | map32.set( 42, 815); |
| 209 | map64.set( Int64.make(0,42), 815); |
| 210 | map32.set( -517, 23); |
| 211 | map64.set( Int64.make(-5,17), 23); |
| 212 | map32.set( 0, -123); |
| 213 | map64.set( Int64.make(0,0), -123); |
| 214 | |
| 215 | rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #10"); |
| 216 | rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #11"); |
| 217 | rslt.Expect( map32.exists( -517) == map64.exists( Int64.make(-5,17)), "Int64Map<Int32> Test #12"); |
| 218 | rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #13"); |
| 219 | rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #14"); |
| 220 | rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #15"); |
| 221 | rslt.Expect( map32.get( -517) == map64.get( Int64.make(-5,17)), "Int64Map<Int32> Test #16"); |
| 222 | rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #Int64.make(-5,17)"); |
| 223 | rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #18"); |
| 224 | rslt.Expect( map32.remove( 4711) == map64.remove( Int64.make(47,11)), "Int64Map<Int32> Test #19"); |
| 225 | rslt.Expect( map32.remove( -517) == map64.remove( Int64.make(-5,17)), "Int64Map<Int32> Test #20"); |
| 226 | rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #21"); |
| 227 | rslt.Expect( map32.exists( -517) == map64.exists( Int64.make(-5,17)), "Int64Map<Int32> Test #22"); |
| 228 | rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #23"); |
| 229 | rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #24"); |
| 230 | rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #25"); |
| 231 | rslt.Expect( map32.get( -517) == map64.get( Int64.make(-5,17)), "Int64Map<Int32> Test #26"); |
| 232 | rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #27"); |
| 233 | rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #28"); |
| 234 | |
| 235 | map32.set( 42, 1); |
| 236 | map64.set( Int64.make(0,42), 1); |
| 237 | map32.set( -517, -2); |
| 238 | map64.set( Int64.make(-5,17), -2); |
| 239 | map32.set( 0, 3); |
| 240 | map64.set( Int64.make(0,0), 3); |
| 241 | |
| 242 | var c32 = 0; |
| 243 | for (key in map32.keys()) { |
| 244 | ++c32; |
| 245 | } |
| 246 | var c64 = 0; |
| 247 | for (key in map64.keys()) { |
| 248 | ++c64; |
| 249 | } |
| 250 | rslt.Expect( c32 == c64, "Int64Map<Int32> Test #30"); |
| 251 | |
| 252 | var s32 = map32.toString(); |
| 253 | var s64 = map64.toString(); |
| 254 | trace("Int64Map<Int32>.toString(): " + ' ("$s32" == "$s64")'); |
| 255 | |
| 256 | map32.remove( 42); |
| 257 | map64.remove( Int64.make(0,42)); |
| 258 | map32.remove( -517); |
| 259 | map64.remove( Int64.make(-5,17)); |
| 260 | map32.remove( 0); |
| 261 | map64.remove( Int64.make(0,0)); |
| 262 | |
| 263 | rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #90"); |
| 264 | rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #91"); |
| 265 | rslt.Expect( map32.exists( -517) == map64.exists( Int64.make(-5,17)), "Int64Map<Int32> Test #92"); |
| 266 | rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #93"); |
| 267 | rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #94"); |
| 268 | rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #95"); |
| 269 | rslt.Expect( map32.get( -517) == map64.get( Int64.make(-5,17)), "Int64Map<Int32> Test #96"); |
| 270 | rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #97"); |
| 271 | rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #98"); |
| 272 | } |
| 273 | |
| 274 | |
| 275 | public static function ClientTest( transport : TTransport, protocol : TProtocol, rslt : TestResults) : Void |
| 276 | { |
| 277 | var client = new ThriftTestImpl(protocol,protocol); |
| 278 | try |
| 279 | { |
| 280 | if (!transport.isOpen()) |
| 281 | { |
| 282 | transport.open(); |
| 283 | } |
| 284 | } |
| 285 | catch (e : TException) |
| 286 | { |
| 287 | trace('$e'); |
| 288 | return; |
| 289 | } |
| 290 | catch (e : Dynamic) |
| 291 | { |
| 292 | trace('$e'); |
| 293 | return; |
| 294 | } |
| 295 | |
| 296 | var start = Date.now(); |
| 297 | |
| 298 | trace('testVoid()'); |
| 299 | client.testVoid(); |
| 300 | trace(' = void'); |
| 301 | rslt.Expect(true,"testVoid()"); // bump counter |
| 302 | |
| 303 | trace('testString("Test")'); |
| 304 | var s = client.testString("Test"); |
| 305 | trace(' = "$s"'); |
| 306 | rslt.Expect(s == "Test", '$s == "Test"'); |
| 307 | |
| 308 | trace('testByte(1)'); |
| 309 | var i8 = client.testByte(1); |
| 310 | trace(' = $i8'); |
| 311 | rslt.Expect(i8 == 1, '$i8 == 1'); |
| 312 | |
| 313 | trace('testI32(-1)'); |
| 314 | var i32 = client.testI32(-1); |
| 315 | trace(' = $i32'); |
| 316 | rslt.Expect(i32 == -1, '$i32 == -1'); |
| 317 | |
| 318 | trace('testI64(-34359738368)'); |
| 319 | var i64 = client.testI64( Int64.make( 0xFFFFFFF8, 0x00000000)); // -34359738368 |
| 320 | trace(' = $i64'); |
| 321 | rslt.Expect( Int64.compare( i64, Int64.make( 0xFFFFFFF8, 0x00000000)) == 0, |
| 322 | Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0xFFFFFFF8, 0x00000000))); |
| 323 | |
| 324 | // edge case: the largest negative Int64 has no positive Int64 equivalent |
| 325 | trace('testI64(-9223372036854775808)'); |
| 326 | i64 = client.testI64( Int64.make( 0x80000000, 0x00000000)); // -9223372036854775808 |
| 327 | trace(' = $i64'); |
| 328 | rslt.Expect( Int64.compare( i64, Int64.make( 0x80000000, 0x00000000)) == 0, |
| 329 | Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0x80000000, 0x00000000))); |
| 330 | |
| 331 | trace('testDouble(5.325098235)'); |
| 332 | var dub = client.testDouble(5.325098235); |
| 333 | trace(' = $dub'); |
| 334 | rslt.Expect(dub == 5.325098235, '$dub == 5.325098235'); |
| 335 | |
| 336 | trace('testStruct({"Zero", 1, -3, -5})'); |
| 337 | var o = new Xtruct(); |
| 338 | o.string_thing = "Zero"; |
| 339 | o.byte_thing = 1; |
| 340 | o.i32_thing = -3; |
| 341 | o.i64_thing = Int64.make(0,-5); |
| 342 | var i = client.testStruct(o); |
| 343 | trace(' = {"' + i.string_thing + '", ' + i.byte_thing +', ' |
| 344 | + i.i32_thing +', '+ Int64.toStr(i.i64_thing) + '}'); |
| 345 | rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing"); |
| 346 | rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing"); |
| 347 | rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing"); |
| 348 | rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing"); |
| 349 | |
| 350 | trace('testNest({1, {\"Zero\", 1, -3, -5}, 5})'); |
| 351 | var o2 = new Xtruct2(); |
| 352 | o2.byte_thing = 1; |
| 353 | o2.struct_thing = o; |
| 354 | o2.i32_thing = 5; |
| 355 | var i2 = client.testNest(o2); |
| 356 | i = i2.struct_thing; |
| 357 | trace(" = {" + i2.byte_thing + ", {\"" + i.string_thing + "\", " |
| 358 | + i.byte_thing + ", " + i.i32_thing + ", " + Int64.toStr(i.i64_thing) + "}, " |
| 359 | + i2.i32_thing + "}"); |
| 360 | rslt.Expect( i2.byte_thing == o2.byte_thing, "i2.byte_thing == o2.byte_thing"); |
| 361 | rslt.Expect( i2.i32_thing == o2.i32_thing, "i2.i32_thing == o2.i32_thing"); |
| 362 | rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing"); |
| 363 | rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing"); |
| 364 | rslt.Expect( i.i32_thing == o.i32_thing, "i.i32_thing == o.i32_thing"); |
| 365 | rslt.Expect( Int64.compare( i.i64_thing, o.i64_thing) == 0, "i.i64_thing == o.i64_thing"); |
| 366 | |
| 367 | var mapout = new IntMap< haxe.Int32>(); |
| 368 | for ( j in 0 ... 5) |
| 369 | { |
| 370 | mapout.set(j, j - 10); |
| 371 | } |
| 372 | trace("testMap({"); |
| 373 | var first : Bool = true; |
| 374 | for( key in mapout.keys()) |
| 375 | { |
| 376 | if (first) |
| 377 | { |
| 378 | first = false; |
| 379 | } |
| 380 | else |
| 381 | { |
| 382 | trace(", "); |
| 383 | } |
| 384 | trace(key + " => " + mapout.get(key)); |
| 385 | } |
| 386 | trace("})"); |
| 387 | |
| 388 | var mapin = client.testMap(mapout); |
| 389 | |
| 390 | trace(" = {"); |
| 391 | first = true; |
| 392 | for( key in mapin.keys()) |
| 393 | { |
| 394 | if (first) |
| 395 | { |
| 396 | first = false; |
| 397 | } |
| 398 | else |
| 399 | { |
| 400 | trace(", "); |
| 401 | } |
| 402 | trace(key + " => " + mapin.get(key)); |
| 403 | rslt.Expect( mapin.get(key) == mapout.get(key), ' mapin.get($key) == mapout.get($key)'); |
| 404 | } |
| 405 | trace("}"); |
| 406 | for( key in mapout.keys()) |
| 407 | { |
| 408 | rslt.Expect(mapin.exists(key), 'mapin.exists($key)'); |
| 409 | } |
| 410 | |
| 411 | var listout = new List<Int>(); |
| 412 | for (j in -2 ... 3) |
| 413 | { |
| 414 | listout.add(j); |
| 415 | } |
| 416 | trace("testList({"); |
| 417 | first = true; |
| 418 | for( j in listout) |
| 419 | { |
| 420 | if (first) |
| 421 | { |
| 422 | first = false; |
| 423 | } |
| 424 | else |
| 425 | { |
| 426 | trace(", "); |
| 427 | } |
| 428 | trace(j); |
| 429 | } |
| 430 | trace("})"); |
| 431 | |
| 432 | var listin = client.testList(listout); |
| 433 | |
| 434 | trace(" = {"); |
| 435 | first = true; |
| 436 | for( j in listin) |
| 437 | { |
| 438 | if (first) |
| 439 | { |
| 440 | first = false; |
| 441 | } |
| 442 | else |
| 443 | { |
| 444 | trace(", "); |
| 445 | } |
| 446 | trace(j); |
| 447 | } |
| 448 | trace("}"); |
| 449 | |
| 450 | rslt.Expect(listin.length == listout.length, "listin.length == listout.length"); |
| 451 | var literout = listout.iterator(); |
| 452 | var literin = listin.iterator(); |
| 453 | while( literin.hasNext()) { |
| 454 | rslt.Expect(literin.next() == literout.next(), "literin[i] == literout[i]"); |
| 455 | } |
| 456 | |
| 457 | //set |
| 458 | var setout = new IntSet(); |
| 459 | for (j in -2 ... 3) |
| 460 | { |
| 461 | setout.add(j); |
| 462 | } |
| 463 | trace("testSet({"); |
| 464 | first = true; |
| 465 | for( j in setout) |
| 466 | { |
| 467 | if (first) |
| 468 | { |
| 469 | first = false; |
| 470 | } |
| 471 | else |
| 472 | { |
| 473 | trace(", "); |
| 474 | } |
| 475 | trace(j); |
| 476 | } |
| 477 | trace("})"); |
| 478 | |
| 479 | var setin = client.testSet(setout); |
| 480 | |
| 481 | trace(" = {"); |
| 482 | first = true; |
| 483 | for( j in setin) |
| 484 | { |
| 485 | if (first) |
| 486 | { |
| 487 | first = false; |
| 488 | } |
| 489 | else |
| 490 | { |
| 491 | trace(", "); |
| 492 | } |
| 493 | trace(j); |
| 494 | rslt.Expect(setout.contains(j), 'setout.contains($j)'); |
| 495 | } |
| 496 | trace("}"); |
| 497 | rslt.Expect(setin.size == setout.size, "setin.length == setout.length"); |
| 498 | |
| 499 | |
| 500 | trace("testEnum(ONE)"); |
| 501 | var ret = client.testEnum(Numberz.ONE); |
| 502 | trace(" = " + ret); |
| 503 | rslt.Expect(ret == Numberz.ONE, '$ret == Numberz.ONE'); |
| 504 | |
| 505 | trace("testEnum(TWO)"); |
| 506 | ret = client.testEnum(Numberz.TWO); |
| 507 | trace(" = " + ret); |
| 508 | rslt.Expect(ret == Numberz.TWO, '$ret == Numberz.TWO'); |
| 509 | |
| 510 | trace("testEnum(THREE)"); |
| 511 | ret = client.testEnum(Numberz.THREE); |
| 512 | trace(" = " + ret); |
| 513 | rslt.Expect(ret == Numberz.THREE, '$ret == Numberz.THREE'); |
| 514 | |
| 515 | trace("testEnum(FIVE)"); |
| 516 | ret = client.testEnum(Numberz.FIVE); |
| 517 | trace(" = " + ret); |
| 518 | rslt.Expect(ret == Numberz.FIVE, '$ret == Numberz.FIVE'); |
| 519 | |
| 520 | trace("testEnum(EIGHT)"); |
| 521 | ret = client.testEnum(Numberz.EIGHT); |
| 522 | trace(" = " + ret); |
| 523 | rslt.Expect(ret == Numberz.EIGHT, '$ret == Numberz.EIGHT'); |
| 524 | |
| 525 | trace("testTypedef(309858235082523)"); |
| 526 | var uid = client.testTypedef( Int64.make( 0x119D0, 0x7E08671B)); // 309858235082523 |
| 527 | trace(" = " + uid); |
| 528 | rslt.Expect( Int64.compare( uid, Int64.make( 0x119D0, 0x7E08671B)) == 0, |
| 529 | Int64.toStr(uid)+" == "+Int64.toStr(Int64.make( 0x119D0, 0x7E08671B))); |
| 530 | |
| 531 | trace("testMapMap(1)"); |
| 532 | var mm = client.testMapMap(1); |
| 533 | trace(" = {"); |
| 534 | for( key in mm.keys()) |
| 535 | { |
| 536 | trace(key + " => {"); |
| 537 | var m2 = mm.get(key); |
| 538 | for( k2 in m2.keys()) |
| 539 | { |
| 540 | trace(k2 + " => " + m2.get(k2) + ", "); |
| 541 | } |
| 542 | trace("}, "); |
| 543 | } |
| 544 | trace("}"); |
| 545 | |
| 546 | var pos = mm.get(4); |
| 547 | var neg = mm.get(-4); |
| 548 | rslt.Expect( (pos != null) && (neg != null), "(pos != null) && (neg != null)"); |
| 549 | for (i in 0 ... 5) { |
| 550 | rslt.Expect( pos.get(i) == i, 'pos.get($i) == $i'); |
| 551 | rslt.Expect( neg.get(-i) == -i, 'neg.get(-$i) == -$i'); |
| 552 | } |
| 553 | |
| 554 | var insane = new Insanity(); |
| 555 | insane.userMap = new IntMap< Int64>(); |
| 556 | insane.userMap.set( Numberz.FIVE, Int64.make(0,5000)); |
| 557 | var truck = new Xtruct(); |
| 558 | truck.string_thing = "Truck"; |
| 559 | truck.byte_thing = 8; |
| 560 | truck.i32_thing = 8; |
| 561 | truck.i64_thing = Int64.make(0,8); |
| 562 | insane.xtructs = new List<Xtruct>(); |
| 563 | insane.xtructs.add(truck); |
| 564 | trace("testInsanity()"); |
| 565 | var whoa = client.testInsanity(insane); |
| 566 | trace(" = {"); |
| 567 | for( key in whoa.keys()) |
| 568 | { |
| 569 | var val = whoa.get(key); |
| 570 | trace(key + " => {"); |
| 571 | |
| 572 | for( k2 in val.keys()) |
| 573 | { |
| 574 | var v2 = val.get(k2); |
| 575 | |
| 576 | trace(k2 + " => {"); |
| 577 | var userMap = v2.userMap; |
| 578 | |
| 579 | trace("{"); |
| 580 | if (userMap != null) |
| 581 | { |
| 582 | for( k3 in userMap.keys()) |
| 583 | { |
| 584 | trace(k3 + " => " + userMap.get(k3) + ", "); |
| 585 | } |
| 586 | } |
| 587 | else |
| 588 | { |
| 589 | trace("null"); |
| 590 | } |
| 591 | trace("}, "); |
| 592 | |
| 593 | var xtructs = v2.xtructs; |
| 594 | |
| 595 | trace("{"); |
| 596 | if (xtructs != null) |
| 597 | { |
| 598 | for( x in xtructs) |
| 599 | { |
| 600 | trace("{\"" + x.string_thing + "\", " |
| 601 | + x.byte_thing + ", " + x.i32_thing + ", " |
| 602 | + x.i32_thing + "}, "); |
| 603 | } |
| 604 | } |
| 605 | else |
| 606 | { |
| 607 | trace("null"); |
| 608 | } |
| 609 | trace("}"); |
| 610 | |
| 611 | trace("}, "); |
| 612 | } |
| 613 | trace("}, "); |
| 614 | } |
| 615 | trace("}"); |
| 616 | |
| 617 | var first_map = whoa.get(Int64.make(0,1)); |
| 618 | var second_map = whoa.get(Int64.make(0,2)); |
| 619 | rslt.Expect( (first_map != null) && (second_map != null), "(first_map != null) && (second_map != null)"); |
| 620 | if ((first_map != null) && (second_map != null)) |
| 621 | { |
| 622 | var crazy2 = first_map.get(Numberz.TWO); |
| 623 | var crazy3 = first_map.get(Numberz.THREE); |
| 624 | var looney = second_map.get(Numberz.SIX); |
| 625 | rslt.Expect( (crazy2 != null) && (crazy3 != null) && (looney != null), |
| 626 | "(crazy2 != null) && (crazy3 != null) && (looney != null)"); |
| 627 | |
| 628 | rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0, |
| 629 | "crazy2.UserMap.get(Numberz.EIGHT) == 8"); |
| 630 | rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0, |
| 631 | "crazy3.UserMap.get(Numberz.EIGHT) == 8"); |
| 632 | rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0, |
| 633 | "crazy2.UserMap.get(Numberz.FIVE) == 5"); |
| 634 | rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0, |
| 635 | "crazy3.UserMap.get(Numberz.FIVE) == 5"); |
| 636 | |
| 637 | var crz2iter = crazy2.xtructs.iterator(); |
| 638 | var crz3iter = crazy3.xtructs.iterator(); |
| 639 | rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()"); |
| 640 | var goodbye2 = crz2iter.next(); |
| 641 | var goodbye3 = crz3iter.next(); |
| 642 | rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()"); |
| 643 | var hello2 = crz2iter.next(); |
| 644 | var hello3 = crz3iter.next(); |
| 645 | rslt.Expect( ! (crz2iter.hasNext() || crz3iter.hasNext()), "! (crz2iter.hasNext() || crz3iter.hasNext())"); |
| 646 | |
| 647 | rslt.Expect( hello2.string_thing == "Hello2", 'hello2.String_thing == "Hello2"'); |
| 648 | rslt.Expect( hello2.byte_thing == 2, 'hello2.Byte_thing == 2'); |
| 649 | rslt.Expect( hello2.i32_thing == 2, 'hello2.I32_thing == 2'); |
| 650 | rslt.Expect( Int64.compare( hello2.i64_thing, Int64.make(0,2)) == 0, 'hello2.I64_thing == 2'); |
| 651 | rslt.Expect( hello3.string_thing == "Hello2", 'hello3.String_thing == "Hello2"'); |
| 652 | rslt.Expect( hello3.byte_thing == 2, 'hello3.Byte_thing == 2'); |
| 653 | rslt.Expect( hello3.i32_thing == 2, 'hello3.I32_thing == 2'); |
| 654 | rslt.Expect( Int64.compare( hello3.i64_thing, Int64.make(0,2)) == 0, 'hello3.I64_thing == 2'); |
| 655 | |
| 656 | rslt.Expect( goodbye2.string_thing == "Goodbye4", 'goodbye2.String_thing == "Goodbye4"'); |
| 657 | rslt.Expect( goodbye2.byte_thing == 4, 'goodbye2.Byte_thing == 4'); |
| 658 | rslt.Expect( goodbye2.i32_thing == 4, 'goodbye2.I32_thing == 4'); |
| 659 | rslt.Expect( Int64.compare( goodbye2.i64_thing, Int64.make(0,4)) == 0, 'goodbye2.I64_thing == 4'); |
| 660 | rslt.Expect( goodbye3.string_thing == "Goodbye4", 'goodbye3.String_thing == "Goodbye4"'); |
| 661 | rslt.Expect( goodbye3.byte_thing == 4, 'goodbye3.Byte_thing == 4'); |
| 662 | rslt.Expect( goodbye3.i32_thing == 4, 'goodbye3.I32_thing == 4'); |
| 663 | rslt.Expect( Int64.compare( goodbye3.i64_thing, Int64.make(0,4)) == 0, 'goodbye3.I64_thing == 4'); |
| 664 | } |
| 665 | |
| 666 | var arg0 = 1; |
| 667 | var arg1 = 2; |
| 668 | var arg2 = Int64.make( 0x7FFFFFFF,0xFFFFFFFF); |
| 669 | var multiDict = new IntMap< String>(); |
| 670 | multiDict.set(1, "one"); |
| 671 | var arg4 = Numberz.FIVE; |
| 672 | var arg5 = Int64.make(0,5000000); |
| 673 | trace("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")"); |
| 674 | var multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5); |
| 675 | trace(" = Xtruct(byte_thing:" + multiResponse.byte_thing + ",string_thing:" + multiResponse.string_thing |
| 676 | + ",i32_thing:" + multiResponse.i32_thing |
| 677 | + ",i64_thing:" + Int64.toStr(multiResponse.i64_thing) + ")"); |
| 678 | |
| 679 | rslt.Expect( multiResponse.string_thing == "Hello2", 'multiResponse.String_thing == "Hello2"'); |
| 680 | rslt.Expect( multiResponse.byte_thing == arg0, 'multiResponse.Byte_thing == arg0'); |
| 681 | rslt.Expect( multiResponse.i32_thing == arg1, 'multiResponse.I32_thing == arg1'); |
| 682 | rslt.Expect( Int64.compare( multiResponse.i64_thing, arg2) == 0, 'multiResponse.I64_thing == arg2'); |
| 683 | |
| 684 | |
| 685 | trace("Test Oneway(1)"); |
| 686 | client.testOneway(1); |
| 687 | |
| 688 | trace("Test Calltime()"); |
| 689 | var difft = Timer.stamp(); |
| 690 | for ( k in 0 ... 1000) { |
| 691 | client.testVoid(); |
| 692 | } |
| 693 | difft = Timer.stamp() - difft; |
| 694 | trace('$difft ms per testVoid() call'); |
| 695 | } |
| 696 | } |