blob: 11b266c0cb87d9de2c4a39ff61085c812665a63d [file] [log] [blame]
Jens Geyera420a242025-02-07 01:58:30 +01001/*
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 tests;
21
22import haxe.Int64;
23import haxe.io.BytesBuffer;
24import tests.TestBase;
25
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 constantsDemo.*; // generated code
33
34
35class ConstantsTest extends tests.TestBase {
36
37 public static function Run(server : Bool) : Void
38 {
39 TestConstants();
40 TestProtocolConformity();
41 }
42
43
44 private static function TestConstants() : Void
45 {
46 tests.TestBase.Expect( ConstantsDemoConstants.myInt == 3, "myInt = 3");
47 tests.TestBase.Expect( ConstantsDemoConstants.hex_const == 0x0001F, "hex_const = 31");
48 tests.TestBase.Expect( ConstantsDemoConstants.negative_hex_constant == -0x0001F, "negative_hex_constant = -31");
49 tests.TestBase.Expect( ConstantsDemoConstants.GEN_ME == -3523553, "GEN_ME = -3523553");
50 tests.TestBase.Expect( ConstantsDemoConstants.GEn_DUB == 325.532, "GEn_DUB = 325.532");
51 tests.TestBase.Expect( ConstantsDemoConstants.GEn_DU == 85.2355, "GEn_DU = 85.2355");
52 tests.TestBase.Expect( ConstantsDemoConstants.GEN_STRING == "asldkjasfd", "GEN_STRING = \"asldkjasfd\"");
53 tests.TestBase.Expect( ConstantsDemoConstants.e10 == 1e+10, "e10 = 1e+10");
54 tests.TestBase.Expect( ConstantsDemoConstants.e11 == -1e+10, "e11 = -1e+10");
55 tests.TestBase.Expect( ConstantsDemoConstants.GEN_UUID == "00000000-4444-CCCC-ffff-0123456789ab", "GEN_UUID = \"00000000-4444-CCCC-ffff-0123456789ab\"");
56
57 tests.TestBase.Expect( ConstantsDemoConstants.GEN_MAP.get(35532) == 233, "GEN_MAP.get(35532) == 233");
58 tests.TestBase.Expect( ConstantsDemoConstants.GEN_MAP.get(43523) == 853, "GEN_MAP.get(43523) == 853");
59
60 tests.TestBase.Expect( ConstantsDemoConstants.GEN_LIST.length == 3, "GEN_LIST.size() == 3");
61 tests.TestBase.Expect( ConstantsDemoConstants.GEN_LIST.join("/") == "235235/23598352/3253523", "GEN_LIST elements");
62
63 tests.TestBase.Expect( ConstantsDemoConstants.GEN_MAPMAP.get(235).get(532) == 53255, "GEN_MAPMAP.get(235).get(532) == 53255");
64 tests.TestBase.Expect( ConstantsDemoConstants.GEN_MAPMAP.get(235).get(235) == 235, "GEN_MAPMAP.get(235).get(235) == 235");
65
66 tests.TestBase.Expect( ConstantsDemoConstants.GEN_MAP2.get("hello") == 233, "GEN_MAP2.get(\"hello\") == 233");
67 tests.TestBase.Expect( ConstantsDemoConstants.GEN_MAP2.get("lkj98d") == 853, "GEN_MAP2.get(\"lkj98d\") == 853");
68 tests.TestBase.Expect( ConstantsDemoConstants.GEN_MAP2.get('lkjsdf') == 98325, "GEN_MAP2.get('lkjsdf') == 98325");
69
70 tests.TestBase.Expect( ConstantsDemoConstants.GEN_THING.hello == 325, "GEN_THING.hello == 325");
71 tests.TestBase.Expect( ConstantsDemoConstants.GEN_THING.goodbye == 325352, "GEN_THING.goodbye == 325352");
72
73 tests.TestBase.Expect( ConstantsDemoConstants.GEN_WHAT.get(35).hello == 325, "GEN_WHAT.get(35).hello == 325");
74 tests.TestBase.Expect( ConstantsDemoConstants.GEN_WHAT.get(35).goodbye == 325352, "GEN_WHAT.get(35).goodbye == 325352");
75
76 tests.TestBase.Expect( ConstantsDemoConstants.GEN_SET.size == 2, "GEN_SET.size() == 2");
77 tests.TestBase.Expect( ConstantsDemoConstants.GEN_SET.contains(235), "GEN_SET.contains(235)"); // added twice, but this is a set
78 tests.TestBase.Expect( ConstantsDemoConstants.GEN_SET.contains(53235), "GEN_SET.contains(53235)");
79 }
80
81 private static function TestProtocolConformity() : Void
82 {
83 for( factory in [new TBinaryProtocolFactory(), new TCompactProtocolFactory(), new TJSONProtocolFactory()])
84 {
85 DeserializeGuidData(factory);
86 }
87 }
88
89 private static function DeserializeGuidData(factory : TProtocolFactory) : Void
90 {
91 var data = new BytesBuffer();
92 var sCase = Type.getClassName(Type.getClass(factory)).split('.').pop();
93 switch(sCase)
94 {
95 case "TJSONProtocolFactory":
96 data.addString('"00112233-4455-6677-8899-aabbccddeeff"');
97
98 case "TCompactProtocolFactory":
99 data.addByte(0x00);
100 data.addByte(0x11);
101 data.addByte(0x22);
102 data.addByte(0x33);
103 data.addByte(0x44);
104 data.addByte(0x55);
105 data.addByte(0x66);
106 data.addByte(0x77);
107 data.addByte(0x88);
108 data.addByte(0x99);
109 data.addByte(0xaa);
110 data.addByte(0xbb);
111 data.addByte(0xcc);
112 data.addByte(0xdd);
113 data.addByte(0xee);
114 data.addByte(0xff);
115
116 case "TBinaryProtocolFactory":
117 data.addByte(0x00);
118 data.addByte(0x11);
119 data.addByte(0x22);
120 data.addByte(0x33);
121 data.addByte(0x44);
122 data.addByte(0x55);
123 data.addByte(0x66);
124 data.addByte(0x77);
125 data.addByte(0x88);
126 data.addByte(0x99);
127 data.addByte(0xaa);
128 data.addByte(0xbb);
129 data.addByte(0xcc);
130 data.addByte(0xdd);
131 data.addByte(0xee);
132 data.addByte(0xff);
133
134 default:
135 tests.TestBase.Expect( false, 'Unhandled ${sCase}');
136 }
137
138 var stream = new TMemoryStream(data.getBytes());
139 stream.Position = 0;
140
141 var config = new TConfiguration();
142 var transport = new TStreamTransport(stream, stream, config);
143 var protocol = factory.getProtocol(transport);
144
145 var sUuid = protocol.readUuid();
146 tests.TestBase.Expect( sUuid == "00112233-4455-6677-8899-aabbccddeeff", 'DeserializeGuidData(${sCase}): ${sUuid}');
147 }
148}
149
150