blob: 4744272a5a34db7b71563aa01d51df2ab3a2a15f [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;
Jens Geyere5ff9a82014-11-11 01:39:38 +010023import sys.FileSystem;
Jens Geyerfea00ac2014-10-01 02:22:48 +020024
25import org.apache.thrift.*;
26import org.apache.thrift.protocol.*;
27import org.apache.thrift.transport.*;
28import org.apache.thrift.server.*;
29import org.apache.thrift.meta_data.*;
30
31import thrift.test.*; // generated code
32
33
34class StreamTest extends TestBase {
Jens Geyerfea00ac2014-10-01 02:22:48 +020035
Jens Geyerfea00ac2014-10-01 02:22:48 +020036
Jens Geyere5ff9a82014-11-11 01:39:38 +010037 private inline static var tmpfile : String = "data.tmp";
Jens Geyerfea00ac2014-10-01 02:22:48 +020038
Jens Geyerfea00ac2014-10-01 02:22:48 +020039
Jens Geyerb5028322014-11-09 02:38:11 +010040 private static function MakeTestData() : Xtruct {
41 var data : Xtruct = new Xtruct();
42 data.string_thing = "Streamtest";
43 data.byte_thing = -128;
44 data.i32_thing = 4711;
45 data.i64_thing = Int64.make(0x12345678,0x9ABCDEF0);
46 return data;
47 }
48
49 public static function WriteData() : Xtruct
50 {
Jens Geyer76283922022-06-11 14:24:33 +020051 var config : TConfiguration = new TConfiguration();
Jens Geyerb5028322014-11-09 02:38:11 +010052 var stream : TStream = new TFileStream( tmpfile, CreateNew);
Jens Geyerce1d3142022-06-06 14:29:38 +020053 var trans : TTransport = new TStreamTransport( null, stream, config);
Jens Geyerb5028322014-11-09 02:38:11 +010054 var prot = new TJSONProtocol( trans);
55
56 var data = MakeTestData();
57 data.write(prot);
58 trans.close();
59
60 return data;
61 }
62
63 public static function ReadData() : Xtruct
64 {
Jens Geyer76283922022-06-11 14:24:33 +020065 var config : TConfiguration = new TConfiguration();
Jens Geyerb5028322014-11-09 02:38:11 +010066 var stream : TStream = new TFileStream( tmpfile, Read);
Jens Geyerce1d3142022-06-06 14:29:38 +020067 var trans : TTransport = new TStreamTransport( stream, null, config);
Jens Geyerb5028322014-11-09 02:38:11 +010068 var prot = new TJSONProtocol( trans);
69
70 var data : Xtruct = new Xtruct();
71 data.read(prot);
72 trans.close();
73
74 return data;
75 }
76
Jens Geyerce1d3142022-06-06 14:29:38 +020077 public static function Run(server : Bool) : Void
Jens Geyerb5028322014-11-09 02:38:11 +010078 {
Jens Geyere5ff9a82014-11-11 01:39:38 +010079 try {
80 var written = WriteData();
81 var read = ReadData();
82 FileSystem.deleteFile(tmpfile);
Jens Geyerb5028322014-11-09 02:38:11 +010083
Jens Geyere5ff9a82014-11-11 01:39:38 +010084 TestBase.Expect( read.string_thing == written.string_thing, "string data");
85 TestBase.Expect( read.byte_thing == written.byte_thing, "byte data");
86 TestBase.Expect( read.i32_thing == written.i32_thing, "i32 data");
87 TestBase.Expect( Int64.compare( read.i64_thing, written.i64_thing) == 0, "i64 data");
88
89 } catch(e:Dynamic) {
90 FileSystem.deleteFile(tmpfile);
91 throw e;
92 }
Jens Geyerb5028322014-11-09 02:38:11 +010093 }
Jens Geyerfea00ac2014-10-01 02:22:48 +020094
95}
96
97