]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/haxe/test/src/StreamTest.hx
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / haxe / test / src / StreamTest.hx
CommitLineData
f67539c2
TL
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
20package;
21
22import haxe.Int64;
23import sys.FileSystem;
24
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 {
35
36
37 private inline static var tmpfile : String = "data.tmp";
38
39
40 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 {
51 var stream : TStream = new TFileStream( tmpfile, CreateNew);
52 var trans : TTransport = new TStreamTransport( null, stream);
53 var prot = new TJSONProtocol( trans);
54
55 var data = MakeTestData();
56 data.write(prot);
57 trans.close();
58
59 return data;
60 }
61
62 public static function ReadData() : Xtruct
63 {
64 var stream : TStream = new TFileStream( tmpfile, Read);
65 var trans : TTransport = new TStreamTransport( stream, null);
66 var prot = new TJSONProtocol( trans);
67
68 var data : Xtruct = new Xtruct();
69 data.read(prot);
70 trans.close();
71
72 return data;
73 }
74
75 public static override function Run(server : Bool) : Void
76 {
77 try {
78 var written = WriteData();
79 var read = ReadData();
80 FileSystem.deleteFile(tmpfile);
81
82 TestBase.Expect( read.string_thing == written.string_thing, "string data");
83 TestBase.Expect( read.byte_thing == written.byte_thing, "byte data");
84 TestBase.Expect( read.i32_thing == written.i32_thing, "i32 data");
85 TestBase.Expect( Int64.compare( read.i64_thing, written.i64_thing) == 0, "i64 data");
86
87 } catch(e:Dynamic) {
88 FileSystem.deleteFile(tmpfile);
89 throw e;
90 }
91 }
92
93}
94
95