blob: 3e70adaf5bd8459848103d9cebaabcb67c630e50 [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;
Jens Geyer18564d22022-06-05 11:36:40 +020021#if sys
Jens Geyerfea00ac2014-10-01 02:22:48 +020022
23import haxe.Int64;
Jens Geyere5ff9a82014-11-11 01:39:38 +010024import sys.FileSystem;
Jens Geyerfea00ac2014-10-01 02:22:48 +020025
26import org.apache.thrift.*;
27import org.apache.thrift.protocol.*;
28import org.apache.thrift.transport.*;
29import org.apache.thrift.server.*;
30import org.apache.thrift.meta_data.*;
31
32import thrift.test.*; // generated code
33
34
35class StreamTest extends TestBase {
Jens Geyerfea00ac2014-10-01 02:22:48 +020036
Jens Geyerfea00ac2014-10-01 02:22:48 +020037
Jens Geyere5ff9a82014-11-11 01:39:38 +010038 private inline static var tmpfile : String = "data.tmp";
Jens Geyerfea00ac2014-10-01 02:22:48 +020039
Jens Geyerfea00ac2014-10-01 02:22:48 +020040
Jens Geyerb5028322014-11-09 02:38:11 +010041 private static function MakeTestData() : Xtruct {
42 var data : Xtruct = new Xtruct();
43 data.string_thing = "Streamtest";
44 data.byte_thing = -128;
45 data.i32_thing = 4711;
46 data.i64_thing = Int64.make(0x12345678,0x9ABCDEF0);
47 return data;
48 }
49
50 public static function WriteData() : Xtruct
51 {
Jens Geyer76283922022-06-11 14:24:33 +020052 var config : TConfiguration = new TConfiguration();
Jens Geyerb5028322014-11-09 02:38:11 +010053 var stream : TStream = new TFileStream( tmpfile, CreateNew);
Jens Geyerce1d3142022-06-06 14:29:38 +020054 var trans : TTransport = new TStreamTransport( null, stream, config);
Jens Geyerb5028322014-11-09 02:38:11 +010055 var prot = new TJSONProtocol( trans);
56
57 var data = MakeTestData();
58 data.write(prot);
59 trans.close();
60
61 return data;
62 }
63
64 public static function ReadData() : Xtruct
65 {
Jens Geyer76283922022-06-11 14:24:33 +020066 var config : TConfiguration = new TConfiguration();
Jens Geyerb5028322014-11-09 02:38:11 +010067 var stream : TStream = new TFileStream( tmpfile, Read);
Jens Geyerce1d3142022-06-06 14:29:38 +020068 var trans : TTransport = new TStreamTransport( stream, null, config);
Jens Geyerb5028322014-11-09 02:38:11 +010069 var prot = new TJSONProtocol( trans);
70
71 var data : Xtruct = new Xtruct();
72 data.read(prot);
73 trans.close();
74
75 return data;
76 }
77
Jens Geyerce1d3142022-06-06 14:29:38 +020078 public static function Run(server : Bool) : Void
Jens Geyerb5028322014-11-09 02:38:11 +010079 {
Jens Geyere5ff9a82014-11-11 01:39:38 +010080 try {
81 var written = WriteData();
82 var read = ReadData();
83 FileSystem.deleteFile(tmpfile);
Jens Geyerb5028322014-11-09 02:38:11 +010084
Jens Geyere5ff9a82014-11-11 01:39:38 +010085 TestBase.Expect( read.string_thing == written.string_thing, "string data");
86 TestBase.Expect( read.byte_thing == written.byte_thing, "byte data");
87 TestBase.Expect( read.i32_thing == written.i32_thing, "i32 data");
88 TestBase.Expect( Int64.compare( read.i64_thing, written.i64_thing) == 0, "i64 data");
89
90 } catch(e:Dynamic) {
91 FileSystem.deleteFile(tmpfile);
92 throw e;
93 }
Jens Geyerb5028322014-11-09 02:38:11 +010094 }
Jens Geyerfea00ac2014-10-01 02:22:48 +020095
96}
97
98
Jens Geyer18564d22022-06-05 11:36:40 +020099#end