diff options
author | Jens Geyer <jensg@apache.org> | 2014-12-14 00:29:17 +0100 |
---|---|---|
committer | Jens Geyer <jensg@apache.org> | 2015-01-03 17:37:22 +0100 |
commit | 43e195afcd4cd3db67c7343271920af147e268e6 (patch) | |
tree | 62fc999a763b6ee19ac25738c99093ba4bd34e87 /test/haxe | |
parent | fd1b3585596fdec749372f383208069d0ca1d9b0 (diff) | |
download | thrift-43e195afcd4cd3db67c7343271920af147e268e6.tar.gz |
THRIFT-2886 Integrate binary type in standard Thrift cross test
Client: Haxe
Patch: Jens Geyer
Diffstat (limited to 'test/haxe')
-rw-r--r-- | test/haxe/src/TestClient.hx | 55 | ||||
-rw-r--r-- | test/haxe/src/TestServerHandler.hx | 17 |
2 files changed, 72 insertions, 0 deletions
diff --git a/test/haxe/src/TestClient.hx b/test/haxe/src/TestClient.hx index 276cd0f7e..f77620f38 100644 --- a/test/haxe/src/TestClient.hx +++ b/test/haxe/src/TestClient.hx @@ -21,6 +21,7 @@ package; import haxe.Int32; import haxe.Int64; +import haxe.io.Bytes; import haxe.Timer; import haxe.ds.IntMap; import haxe.ds.StringMap; @@ -307,6 +308,43 @@ class TestClient { } + public static function BytesToHex(data : Bytes) : String { + var hex = ""; + for ( i in 0 ... data.length) { + hex += StringTools.hex( data.get(i), 2); + } + return hex; + } + + public static function PrepareTestData(randomDist : Bool) : Bytes { + var retval = Bytes.alloc(0x100); + var initLen : Int = (retval.length > 0x100 ? 0x100 : retval.length); + + // linear distribution, unless random is requested + if (!randomDist) { + for (i in 0 ... initLen) { + retval.set(i, i % 0x100); + } + return retval; + } + + // random distribution + for (i in 0 ... initLen) { + retval.set(i, 0); + } + for (i in 1 ... initLen) { + while( true) { + var nextPos = Std.random(initLen); + if (retval.get(nextPos) == 0) { + retval.set( nextPos, i % 0x100); + break; + } + } + } + return retval; + } + + public static function ClientTest( transport : TTransport, protocol : TProtocol, args : Arguments, rslt : TestResults) : Void { @@ -417,6 +455,23 @@ class TestClient { trace(' = $dub'); rslt.Expect(dub == 5.325098235, '$dub == 5.325098235'); + var binOut = PrepareTestData(true); + trace('testBinary('+BytesToHex(binOut)+')'); + try { + var binIn = client.testBinary(binOut); + trace('testBinary() = '+BytesToHex(binIn)); + rslt.Expect( binIn.length == binOut.length, '${binIn.length} == ${binOut.length}'); + var len = ((binIn.length < binOut.length) ? binIn.length : binOut.length); + for (ofs in 0 ... len) { + if (binIn.get(ofs) != binOut.get(ofs)) { + rslt.Expect( false, 'testBinary('+BytesToHex(binOut)+'): content mismatch at offset $ofs'); + } + } + } + catch (e : TApplicationException) { + trace('testBinary('+BytesToHex(binOut)+'): '+e.errorMsg); // may not be supported by the server + } + rslt.StartTestGroup( TestResults.EXITCODE_FAILBIT_STRUCTS); diff --git a/test/haxe/src/TestServerHandler.hx b/test/haxe/src/TestServerHandler.hx index 9fc7d1413..9e2a633bb 100644 --- a/test/haxe/src/TestServerHandler.hx +++ b/test/haxe/src/TestServerHandler.hx @@ -117,6 +117,23 @@ class TestServerHandler implements ThriftTest { } /** + * Prints 'testBinary("%s")' where '%s' is a hex-formatted string of thing's data + * @param binary thing - the binary data to print + * @return binary - returns the binary 'thing' + * + * @param thing + */ + public function testBinary(thing : haxe.io.Bytes) : haxe.io.Bytes + { + var hex = ""; + for ( i in 0 ... thing.length) { + hex += StringTools.hex( thing.get(i), 2); + } + trace('testBinary($hex)'); + return thing; + } + + /** * Prints 'testStruct("{%s}")' where thing has been formatted * into a string of comma separated values * @param Xtruct thing - the Xtruct to print |