blob: 97af6f3add8a721de84a7c42581e3539064823f0 [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
Jens Geyera420a242025-02-07 01:58:30 +010020package tests;
21import tests.TestBase;
Jens Geyer18564d22022-06-05 11:36:40 +020022#if sys
Jens Geyerfea00ac2014-10-01 02:22:48 +020023
24import haxe.Int64;
Jens Geyere5ff9a82014-11-11 01:39:38 +010025import sys.FileSystem;
Jens Geyerfea00ac2014-10-01 02:22:48 +020026
27import org.apache.thrift.*;
28import org.apache.thrift.protocol.*;
29import org.apache.thrift.transport.*;
30import org.apache.thrift.server.*;
31import org.apache.thrift.meta_data.*;
32
33import thrift.test.*; // generated code
34
35
Jens Geyera420a242025-02-07 01:58:30 +010036class StreamTest extends tests.TestBase {
Jens Geyerfea00ac2014-10-01 02:22:48 +020037
Jens Geyerfea00ac2014-10-01 02:22:48 +020038
Jens Geyere5ff9a82014-11-11 01:39:38 +010039 private inline static var tmpfile : String = "data.tmp";
Jens Geyerfea00ac2014-10-01 02:22:48 +020040
Jens Geyerfea00ac2014-10-01 02:22:48 +020041
Jens Geyerb5028322014-11-09 02:38:11 +010042 private static function MakeTestData() : Xtruct {
43 var data : Xtruct = new Xtruct();
44 data.string_thing = "Streamtest";
45 data.byte_thing = -128;
46 data.i32_thing = 4711;
47 data.i64_thing = Int64.make(0x12345678,0x9ABCDEF0);
48 return data;
49 }
50
51 public static function WriteData() : Xtruct
52 {
Jens Geyer76283922022-06-11 14:24:33 +020053 var config : TConfiguration = new TConfiguration();
Jens Geyerb5028322014-11-09 02:38:11 +010054 var stream : TStream = new TFileStream( tmpfile, CreateNew);
Jens Geyerce1d3142022-06-06 14:29:38 +020055 var trans : TTransport = new TStreamTransport( null, stream, config);
Jens Geyerb5028322014-11-09 02:38:11 +010056 var prot = new TJSONProtocol( trans);
57
58 var data = MakeTestData();
59 data.write(prot);
60 trans.close();
61
62 return data;
63 }
64
65 public static function ReadData() : Xtruct
66 {
Jens Geyer76283922022-06-11 14:24:33 +020067 var config : TConfiguration = new TConfiguration();
Jens Geyerb5028322014-11-09 02:38:11 +010068 var stream : TStream = new TFileStream( tmpfile, Read);
Jens Geyerce1d3142022-06-06 14:29:38 +020069 var trans : TTransport = new TStreamTransport( stream, null, config);
Jens Geyerb5028322014-11-09 02:38:11 +010070 var prot = new TJSONProtocol( trans);
71
72 var data : Xtruct = new Xtruct();
73 data.read(prot);
74 trans.close();
75
76 return data;
77 }
78
Jens Geyerce1d3142022-06-06 14:29:38 +020079 public static function Run(server : Bool) : Void
Jens Geyerb5028322014-11-09 02:38:11 +010080 {
Jens Geyere5ff9a82014-11-11 01:39:38 +010081 try {
82 var written = WriteData();
83 var read = ReadData();
84 FileSystem.deleteFile(tmpfile);
Jens Geyerb5028322014-11-09 02:38:11 +010085
Jens Geyera420a242025-02-07 01:58:30 +010086 tests.TestBase.Expect( read.string_thing == written.string_thing, "string data");
87 tests.TestBase.Expect( read.byte_thing == written.byte_thing, "byte data");
88 tests.TestBase.Expect( read.i32_thing == written.i32_thing, "i32 data");
89 tests.TestBase.Expect( Int64.compare( read.i64_thing, written.i64_thing) == 0, "i64 data");
Jens Geyere5ff9a82014-11-11 01:39:38 +010090
91 } catch(e:Dynamic) {
92 FileSystem.deleteFile(tmpfile);
93 throw e;
94 }
Jens Geyerb5028322014-11-09 02:38:11 +010095 }
Jens Geyerfea00ac2014-10-01 02:22:48 +020096
97}
98
99
Jens Geyer18564d22022-06-05 11:36:40 +0200100#end