blob: 7500eee1aec94cdffa58d377c9ec2b08b33ba434 [file] [log] [blame]
Jens Geyerfea00ac2014-10-01 02:22:48 +02001/*
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
20package;
21
22import haxe.Int64;
23
24import org.apache.thrift.*;
25import org.apache.thrift.protocol.*;
26import org.apache.thrift.transport.*;
27import org.apache.thrift.server.*;
28import org.apache.thrift.meta_data.*;
29
30import thrift.test.*; // generated code
31
32
33class StreamTest extends TestBase {
Jens Geyerfea00ac2014-10-01 02:22:48 +020034
Jens Geyerfea00ac2014-10-01 02:22:48 +020035
Jens Geyerb5028322014-11-09 02:38:11 +010036 private inline static var tmpfile : String = "bin/data.tmp";
Jens Geyerfea00ac2014-10-01 02:22:48 +020037
Jens Geyerfea00ac2014-10-01 02:22:48 +020038
Jens Geyerb5028322014-11-09 02:38:11 +010039 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 Geyerfea00ac2014-10-01 02:22:48 +020044
Jens Geyerb5028322014-11-09 02:38:11 +010045 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 Geyerfea00ac2014-10-01 02:22:48 +020090
91}
92
93