Jens Geyer | fea00ac | 2014-10-01 02:22:48 +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.Int64; |
| 23 | |
| 24 | import org.apache.thrift.*; |
| 25 | import org.apache.thrift.protocol.*; |
| 26 | import org.apache.thrift.transport.*; |
| 27 | import org.apache.thrift.server.*; |
| 28 | import org.apache.thrift.meta_data.*; |
| 29 | |
| 30 | import thrift.test.*; // generated code |
| 31 | |
| 32 | |
| 33 | class StreamTest extends TestBase { |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 34 | |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 35 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame^] | 36 | private inline static var tmpfile : String = "bin/data.tmp"; |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 37 | |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 38 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame^] | 39 | private static function Expect( expr : Bool, info : String, ?pos : haxe.PosInfos) : Void { |
| 40 | if( ! expr) { |
| 41 | throw ('Test "$info" failed at '+pos.methodName+' in '+pos.fileName+':'+pos.lineNumber); |
| 42 | } |
| 43 | } |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 44 | |
Jens Geyer | b502832 | 2014-11-09 02:38:11 +0100 | [diff] [blame^] | 45 | private static function MakeTestData() : Xtruct { |
| 46 | var data : Xtruct = new Xtruct(); |
| 47 | data.string_thing = "Streamtest"; |
| 48 | data.byte_thing = -128; |
| 49 | data.i32_thing = 4711; |
| 50 | data.i64_thing = Int64.make(0x12345678,0x9ABCDEF0); |
| 51 | return data; |
| 52 | } |
| 53 | |
| 54 | public static function WriteData() : Xtruct |
| 55 | { |
| 56 | var stream : TStream = new TFileStream( tmpfile, CreateNew); |
| 57 | var trans : TTransport = new TStreamTransport( null, stream); |
| 58 | var prot = new TJSONProtocol( trans); |
| 59 | |
| 60 | var data = MakeTestData(); |
| 61 | data.write(prot); |
| 62 | trans.close(); |
| 63 | |
| 64 | return data; |
| 65 | } |
| 66 | |
| 67 | public static function ReadData() : Xtruct |
| 68 | { |
| 69 | var stream : TStream = new TFileStream( tmpfile, Read); |
| 70 | var trans : TTransport = new TStreamTransport( stream, null); |
| 71 | var prot = new TJSONProtocol( trans); |
| 72 | |
| 73 | var data : Xtruct = new Xtruct(); |
| 74 | data.read(prot); |
| 75 | trans.close(); |
| 76 | |
| 77 | return data; |
| 78 | } |
| 79 | |
| 80 | public static override function Run() : Void |
| 81 | { |
| 82 | var written = WriteData(); |
| 83 | var read = ReadData(); |
| 84 | |
| 85 | Expect( read.string_thing == written.string_thing, "string data"); |
| 86 | Expect( read.byte_thing == written.byte_thing, "byte data"); |
| 87 | Expect( read.i32_thing == written.i32_thing, "i32 data"); |
| 88 | Expect( Int64.compare( read.i64_thing, written.i64_thing) == 0, "i64 data"); |
| 89 | } |
Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 90 | |
| 91 | } |
| 92 | |
| 93 | |