blob: 24f850d2f613108ab28736f45fc8ecd0a4e26e4d [file] [log] [blame]
Roger Meier2b2c0b22012-09-12 20:09:02 +00001(*
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
20unit TestSerializer.Data;
21
22interface
23
24uses
Jens Geyer17c3ad92017-09-05 20:31:27 +020025 SysUtils,
Jens Geyer62445c12022-06-29 00:00:00 +020026 ActiveX,
27 ComObj,
Jens Geyer07f4bb52022-09-03 14:50:06 +020028 Thrift.Protocol,
Roger Meier2b2c0b22012-09-12 20:09:02 +000029 Thrift.Collections,
30 DebugProtoTest;
31
32
33type
34 Fixtures = class
35 public
36 class function CreateOneOfEach : IOneOfEach;
37 class function CreateNesting : INesting;
38 class function CreateHolyMoley : IHolyMoley;
39 class function CreateCompactProtoTestStruct : ICompactProtoTestStruct;
40
41 // These byte arrays are serialized versions of the above structs.
42 // They were serialized in binary protocol using thrift 0.6.x and are used to
43 // test backwards compatibility with respect to the standard scheme.
44 (*
45 all data copied from JAVA version,
46 to be used later
47
48 public static final byte[] persistentBytesOneOfEach = new byte[] {
49 $02, $00, $01, $01, $02, $00, $02, $00, $03, $00,
50 $03, $D6, $06, $00, $04, $69, $78, $08, $00, $05,
51 $01, $00, $00, $00, $0A, $00, $06, $00, $00, $00,
52 $01, $65, $A0, $BC, $00, $04, $00, $07, $40, $09,
53 $21, $FB, $54, $44, $2D, $18, $0B, $00, $08, $00,
54 $00, $00, $0D, $4A, $53, $4F, $4E, $20, $54, $48,
55 $49, $53, $21, $20, $22, $01, $0B, $00, $09, $00,
56 $00, $00, $2E, $D3, $80, $E2, $85, $AE, $CE, $9D,
57 $20, $D0, $9D, $CE, $BF, $E2, $85, $BF, $D0, $BE,
58 $C9, $A1, $D0, $B3, $D0, $B0, $CF, $81, $E2, $84,
59 $8E, $20, $CE, $91, $74, $74, $CE, $B1, $E2, $85,
60 $BD, $CE, $BA, $EF, $BF, $BD, $E2, $80, $BC, $02,
61 $00, $0A, $00, $0B, $00, $0B, $00, $00, $00, $06,
62 $62, $61, $73, $65, $36, $34, $0F, $00, $0C, $03,
63 $00, $00, $00, $03, $01, $02, $03, $0F, $00, $0D,
64 $06, $00, $00, $00, $03, $00, $01, $00, $02, $00,
65 $03, $0F, $00, $0E, $0A, $00, $00, $00, $03, $00,
66 $00, $00, $00, $00, $00, $00, $01, $00, $00, $00,
67 $00, $00, $00, $00, $02, $00, $00, $00, $00, $00,
68 $00, $00, $03, $00 };
69
70
71 public static final byte[] persistentBytesNesting = new byte[] {
72 $0C, $00, $01, $08, $00, $01, $00, $00, $7A, $69,
73 $0B, $00, $02, $00, $00, $00, $13, $49, $20, $61,
74 $6D, $20, $61, $20, $62, $6F, $6E, $6B, $2E, $2E,
75 $2E, $20, $78, $6F, $72, $21, $00, $0C, $00, $02,
76 $02, $00, $01, $01, $02, $00, $02, $00, $03, $00,
77 $03, $D6, $06, $00, $04, $69, $78, $08, $00, $05,
78 $01, $00, $00, $00, $0A, $00, $06, $00, $00, $00,
79 $01, $65, $A0, $BC, $00, $04, $00, $07, $40, $09,
80 $21, $FB, $54, $44, $2D, $18, $0B, $00, $08, $00,
81 $00, $00, $0D, $4A, $53, $4F, $4E, $20, $54, $48,
82 $49, $53, $21, $20, $22, $01, $0B, $00, $09, $00,
83 $00, $00, $2E, $D3, $80, $E2, $85, $AE, $CE, $9D,
84 $20, $D0, $9D, $CE, $BF, $E2, $85, $BF, $D0, $BE,
85 $C9, $A1, $D0, $B3, $D0, $B0, $CF, $81, $E2, $84,
86 $8E, $20, $CE, $91, $74, $74, $CE, $B1, $E2, $85,
87 $BD, $CE, $BA, $EF, $BF, $BD, $E2, $80, $BC, $02,
88 $00, $0A, $00, $0B, $00, $0B, $00, $00, $00, $06,
89 $62, $61, $73, $65, $36, $34, $0F, $00, $0C, $03,
90 $00, $00, $00, $03, $01, $02, $03, $0F, $00, $0D,
91 $06, $00, $00, $00, $03, $00, $01, $00, $02, $00,
92 $03, $0F, $00, $0E, $0A, $00, $00, $00, $03, $00,
93 $00, $00, $00, $00, $00, $00, $01, $00, $00, $00,
94 $00, $00, $00, $00, $02, $00, $00, $00, $00, $00,
95 $00, $00, $03, $00, $00 };
96
97 public static final byte[] persistentBytesHolyMoley = new byte[] {
98 $0F, $00, $01, $0C, $00, $00, $00, $02, $02, $00,
99 $01, $01, $02, $00, $02, $00, $03, $00, $03, $23,
100 $06, $00, $04, $69, $78, $08, $00, $05, $01, $00,
101 $00, $00, $0A, $00, $06, $00, $00, $00, $01, $65,
102 $A0, $BC, $00, $04, $00, $07, $40, $09, $21, $FB,
103 $54, $44, $2D, $18, $0B, $00, $08, $00, $00, $00,
104 $0D, $4A, $53, $4F, $4E, $20, $54, $48, $49, $53,
105 $21, $20, $22, $01, $0B, $00, $09, $00, $00, $00,
106 $2E, $D3, $80, $E2, $85, $AE, $CE, $9D, $20, $D0,
107 $9D, $CE, $BF, $E2, $85, $BF, $D0, $BE, $C9, $A1,
108 $D0, $B3, $D0, $B0, $CF, $81, $E2, $84, $8E, $20,
109 $CE, $91, $74, $74, $CE, $B1, $E2, $85, $BD, $CE,
110 $BA, $EF, $BF, $BD, $E2, $80, $BC, $02, $00, $0A,
111 $00, $0B, $00, $0B, $00, $00, $00, $06, $62, $61,
112 $73, $65, $36, $34, $0F, $00, $0C, $03, $00, $00,
113 $00, $03, $01, $02, $03, $0F, $00, $0D, $06, $00,
114 $00, $00, $03, $00, $01, $00, $02, $00, $03, $0F,
115 $00, $0E, $0A, $00, $00, $00, $03, $00, $00, $00,
116 $00, $00, $00, $00, $01, $00, $00, $00, $00, $00,
117 $00, $00, $02, $00, $00, $00, $00, $00, $00, $00,
118 $03, $00, $02, $00, $01, $01, $02, $00, $02, $00,
119 $03, $00, $03, $D6, $06, $00, $04, $69, $78, $08,
120 $00, $05, $01, $00, $00, $00, $0A, $00, $06, $00,
121 $00, $00, $01, $65, $A0, $BC, $00, $04, $00, $07,
122 $40, $09, $21, $FB, $54, $44, $2D, $18, $0B, $00,
123 $08, $00, $00, $00, $0D, $4A, $53, $4F, $4E, $20,
124 $54, $48, $49, $53, $21, $20, $22, $01, $0B, $00,
125 $09, $00, $00, $00, $2E, $D3, $80, $E2, $85, $AE,
126 $CE, $9D, $20, $D0, $9D, $CE, $BF, $E2, $85, $BF,
127 $D0, $BE, $C9, $A1, $D0, $B3, $D0, $B0, $CF, $81,
128 $E2, $84, $8E, $20, $CE, $91, $74, $74, $CE, $B1,
129 $E2, $85, $BD, $CE, $BA, $EF, $BF, $BD, $E2, $80,
130 $BC, $02, $00, $0A, $00, $0B, $00, $0B, $00, $00,
131 $00, $06, $62, $61, $73, $65, $36, $34, $0F, $00,
132 $0C, $03, $00, $00, $00, $03, $01, $02, $03, $0F,
133 $00, $0D, $06, $00, $00, $00, $03, $00, $01, $00,
134 $02, $00, $03, $0F, $00, $0E, $0A, $00, $00, $00,
135 $03, $00, $00, $00, $00, $00, $00, $00, $01, $00,
136 $00, $00, $00, $00, $00, $00, $02, $00, $00, $00,
137 $00, $00, $00, $00, $03, $00, $0E, $00, $02, $0F,
138 $00, $00, $00, $03, $0B, $00, $00, $00, $00, $0B,
139 $00, $00, $00, $03, $00, $00, $00, $0F, $74, $68,
140 $65, $6E, $20, $61, $20, $6F, $6E, $65, $2C, $20,
141 $74, $77, $6F, $00, $00, $00, $06, $74, $68, $72,
142 $65, $65, $21, $00, $00, $00, $06, $46, $4F, $55,
143 $52, $21, $21, $0B, $00, $00, $00, $02, $00, $00,
144 $00, $09, $61, $6E, $64, $20, $61, $20, $6F, $6E,
145 $65, $00, $00, $00, $09, $61, $6E, $64, $20, $61,
146 $20, $74, $77, $6F, $0D, $00, $03, $0B, $0F, $00,
147 $00, $00, $03, $00, $00, $00, $03, $74, $77, $6F,
148 $0C, $00, $00, $00, $02, $08, $00, $01, $00, $00,
149 $00, $01, $0B, $00, $02, $00, $00, $00, $05, $57,
150 $61, $69, $74, $2E, $00, $08, $00, $01, $00, $00,
151 $00, $02, $0B, $00, $02, $00, $00, $00, $05, $57,
152 $68, $61, $74, $3F, $00, $00, $00, $00, $05, $74,
153 $68, $72, $65, $65, $0C, $00, $00, $00, $00, $00,
154 $00, $00, $04, $7A, $65, $72, $6F, $0C, $00, $00,
155 $00, $00, $00 };
156
157
158*)
159
160 private
161 const
162 kUnicodeBytes : packed array[0..43] of Byte
163 = ( $d3, $80, $e2, $85, $ae, $ce, $9d, $20, $d0, $9d,
164 $ce, $bf, $e2, $85, $bf, $d0, $be, $c9, $a1, $d0,
165 $b3, $d0, $b0, $cf, $81, $e2, $84, $8e, $20, $ce,
166 $91, $74, $74, $ce, $b1, $e2, $85, $bd, $ce, $ba,
167 $83, $e2, $80, $bc);
168
169 end;
170
171
172implementation
173
174
175class function Fixtures.CreateOneOfEach : IOneOfEach;
176var db : Double;
177 us : Utf8String;
178begin
179 result := TOneOfEachImpl.Create;
180 result.setIm_true( TRUE);
181 result.setIm_false( FALSE);
182 result.setA_bite( ShortInt($D6));
183 result.setInteger16( 27000);
184 result.setInteger32( 1 shl 24);
185 result.setInteger64( Int64(6000) * Int64(1000) * Int64(1000));
186 db := Pi;
187 result.setDouble_precision( db);
188 result.setSome_characters( 'JSON THIS! \"\1');
189
190 // ??
191 SetLength( us, Length(kUnicodeBytes));
192 Move( kUnicodeBytes[0], us[1], Length(kUnicodeBytes));
193 // ??
194 SetString( us, PChar(@kUnicodeBytes[0]), Length(kUnicodeBytes));
195 // !!
196 result.setZomg_unicode( UnicodeString( us));
197
Jens Geyer62445c12022-06-29 00:00:00 +0200198 result.Rfc4122_uuid := TGuid.Create('{00112233-4455-6677-8899-aabbccddeeff}');
199
Roger Meier2b2c0b22012-09-12 20:09:02 +0000200 {$IF cDebugProtoTest_Option_AnsiStr_Binary}
201 result.SetBase64('base64');
Jens Geyer07f4bb52022-09-03 14:50:06 +0200202 {$ELSEIF cDebugProtoTest_Option_COM_Types}
203 result.SetBase64( TThriftBytesImpl.Create( TEncoding.UTF8.GetBytes('base64')));
Roger Meier2b2c0b22012-09-12 20:09:02 +0000204 {$ELSE}
Jens Geyer17c3ad92017-09-05 20:31:27 +0200205 result.SetBase64( TEncoding.UTF8.GetBytes('base64'));
Roger Meier2b2c0b22012-09-12 20:09:02 +0000206 {$IFEND}
207
208 // byte, i16, and i64 lists are populated by default constructor
209end;
210
211
212class function Fixtures.CreateNesting : INesting;
213var bonk : IBonk;
214begin
215 bonk := TBonkImpl.Create;
Jens Geyercd7a2aa2022-10-17 14:21:18 +0200216 bonk.&Type := 31337;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000217 bonk.Message := 'I am a bonk... xor!';
218
219 result := TNestingImpl.Create;
220 result.My_bonk := bonk;
221 result.My_ooe := CreateOneOfEach;
222end;
223
224
225class function Fixtures.CreateHolyMoley : IHolyMoley;
Jens Geyer07f4bb52022-09-03 14:50:06 +0200226type
227 TStringType = {$IF cDebugProtoTest_Option_COM_Types} WideString {$ELSE} String {$IFEND};
Roger Meier2b2c0b22012-09-12 20:09:02 +0000228var big : IThriftList<IOneOfEach>;
Jens Geyer07f4bb52022-09-03 14:50:06 +0200229 stage1 : IThriftList<TStringType>;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000230 stage2 : IThriftList<IBonk>;
231 b : IBonk;
232begin
233 result := THolyMoleyImpl.Create;
234
235 big := TThriftListImpl<IOneOfEach>.Create;
236 big.add( CreateOneOfEach);
237 big.add( CreateNesting.my_ooe);
238 result.Big := big;
239 result.Big[0].setA_bite( $22);
240 result.Big[0].setA_bite( $23);
241
Jens Geyer07f4bb52022-09-03 14:50:06 +0200242 result.Contain := TThriftHashSetImpl< IThriftList<TStringType>>.Create;
243 stage1 := TThriftListImpl<TStringType>.Create;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000244 stage1.add( 'and a one');
245 stage1.add( 'and a two');
246 result.Contain.add( stage1);
247
Jens Geyer07f4bb52022-09-03 14:50:06 +0200248 stage1 := TThriftListImpl<TStringType>.Create;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000249 stage1.add( 'then a one, two');
250 stage1.add( 'three!');
251 stage1.add( 'FOUR!!');
252 result.Contain.add( stage1);
253
Jens Geyer07f4bb52022-09-03 14:50:06 +0200254 stage1 := TThriftListImpl<TStringType>.Create;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000255 result.Contain.add( stage1);
256
257 stage2 := TThriftListImpl<IBonk>.Create;
Jens Geyer07f4bb52022-09-03 14:50:06 +0200258 result.Bonks := TThriftDictionaryImpl< TStringType, IThriftList< IBonk>>.Create;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000259 // one empty
260 result.Bonks.Add( 'zero', stage2);
261
262 // one with two
263 stage2 := TThriftListImpl<IBonk>.Create;
264 b := TBonkImpl.Create;
Jens Geyercd7a2aa2022-10-17 14:21:18 +0200265 b.&type := 1;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000266 b.message := 'Wait.';
267 stage2.Add( b);
268 b := TBonkImpl.Create;
Jens Geyercd7a2aa2022-10-17 14:21:18 +0200269 b.&type := 2;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000270 b.message := 'What?';
271 stage2.Add( b);
272 result.Bonks.Add( 'two', stage2);
273
274 // one with three
275 stage2 := TThriftListImpl<IBonk>.Create;
276 b := TBonkImpl.Create;
Jens Geyercd7a2aa2022-10-17 14:21:18 +0200277 b.&type := 3;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000278 b.message := 'quoth';
279 stage2.Add( b);
280 b := TBonkImpl.Create;
Jens Geyercd7a2aa2022-10-17 14:21:18 +0200281 b.&type := 4;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000282 b.message := 'the raven';
283 stage2.Add( b);
284 b := TBonkImpl.Create;
Jens Geyercd7a2aa2022-10-17 14:21:18 +0200285 b.&type := 5;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000286 b.message := 'nevermore';
287 stage2.Add( b);
288 result.bonks.Add( 'three', stage2);
289end;
290
291
292class function Fixtures.CreateCompactProtoTestStruct : ICompactProtoTestStruct;
293// superhuge compact proto test struct
294begin
295 result := TCompactProtoTestStructImpl.Create;
Jens Geyer66f95362021-03-29 20:35:41 +0200296 result.A_byte := DebugProtoTest.TConstants.COMPACT_TEST.A_byte;
297 result.A_i16 := DebugProtoTest.TConstants.COMPACT_TEST.A_i16;
298 result.A_i32 := DebugProtoTest.TConstants.COMPACT_TEST.A_i32;
299 result.A_i64 := DebugProtoTest.TConstants.COMPACT_TEST.A_i64;
300 result.A_double := DebugProtoTest.TConstants.COMPACT_TEST.A_double;
301 result.A_string := DebugProtoTest.TConstants.COMPACT_TEST.A_string;
302 result.A_binary := DebugProtoTest.TConstants.COMPACT_TEST.A_binary;
303 result.True_field := DebugProtoTest.TConstants.COMPACT_TEST.True_field;
304 result.False_field := DebugProtoTest.TConstants.COMPACT_TEST.False_field;
305 result.Empty_struct_field := DebugProtoTest.TConstants.COMPACT_TEST.Empty_struct_field;
306 result.Byte_list := DebugProtoTest.TConstants.COMPACT_TEST.Byte_list;
307 result.I16_list := DebugProtoTest.TConstants.COMPACT_TEST.I16_list;
308 result.I32_list := DebugProtoTest.TConstants.COMPACT_TEST.I32_list;
309 result.I64_list := DebugProtoTest.TConstants.COMPACT_TEST.I64_list;
310 result.Double_list := DebugProtoTest.TConstants.COMPACT_TEST.Double_list;
311 result.String_list := DebugProtoTest.TConstants.COMPACT_TEST.String_list;
312 result.Binary_list := DebugProtoTest.TConstants.COMPACT_TEST.Binary_list;
313 result.Boolean_list := DebugProtoTest.TConstants.COMPACT_TEST.Boolean_list;
314 result.Struct_list := DebugProtoTest.TConstants.COMPACT_TEST.Struct_list;
315 result.Byte_set := DebugProtoTest.TConstants.COMPACT_TEST.Byte_set;
316 result.I16_set := DebugProtoTest.TConstants.COMPACT_TEST.I16_set;
317 result.I32_set := DebugProtoTest.TConstants.COMPACT_TEST.I32_set;
318 result.I64_set := DebugProtoTest.TConstants.COMPACT_TEST.I64_set;
319 result.Double_set := DebugProtoTest.TConstants.COMPACT_TEST.Double_set;
320 result.String_set := DebugProtoTest.TConstants.COMPACT_TEST.String_set;
321 result.String_set := DebugProtoTest.TConstants.COMPACT_TEST.String_set;
322 result.String_set := DebugProtoTest.TConstants.COMPACT_TEST.String_set;
323 result.Binary_set := DebugProtoTest.TConstants.COMPACT_TEST.Binary_set;
324 result.Boolean_set := DebugProtoTest.TConstants.COMPACT_TEST.Boolean_set;
325 result.Struct_set := DebugProtoTest.TConstants.COMPACT_TEST.Struct_set;
326 result.Byte_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_byte_map;
327 result.I16_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.I16_byte_map;
328 result.I32_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.I32_byte_map;
329 result.I64_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.I64_byte_map;
330 result.Double_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.Double_byte_map;
331 result.String_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.String_byte_map;
332 result.Binary_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.Binary_byte_map;
333 result.Boolean_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.Boolean_byte_map;
334 result.Byte_i16_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_i16_map;
335 result.Byte_i32_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_i32_map;
336 result.Byte_i64_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_i64_map;
337 result.Byte_double_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_double_map;
338 result.Byte_string_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_string_map;
339 result.Byte_binary_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_binary_map;
340 result.Byte_boolean_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_boolean_map;
341 result.List_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.List_byte_map;
342 result.Set_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.Set_byte_map;
343 result.Map_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.Map_byte_map;
344 result.Byte_map_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_map_map;
345 result.Byte_set_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_set_map;
346 result.Byte_list_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_list_map;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000347
Jens Geyera715f702019-08-28 22:56:13 +0200348 result.Field500 := 500;
349 result.Field5000 := 5000;
350 result.Field20000 := 20000;
351
Roger Meier2b2c0b22012-09-12 20:09:02 +0000352 {$IF cDebugProtoTest_Option_AnsiStr_Binary}
353 result.A_binary := AnsiString( #0#1#2#3#4#5#6#7#8);
Jens Geyer07f4bb52022-09-03 14:50:06 +0200354 {$ELSEIF cDebugProtoTest_Option_COM_Types}
355 result.A_binary := TThriftBytesImpl.Create( TEncoding.UTF8.GetBytes( #0#1#2#3#4#5#6#7#8));
Roger Meier2b2c0b22012-09-12 20:09:02 +0000356 {$ELSE}
Jens Geyer17c3ad92017-09-05 20:31:27 +0200357 result.A_binary := TEncoding.UTF8.GetBytes( #0#1#2#3#4#5#6#7#8);
Roger Meier2b2c0b22012-09-12 20:09:02 +0000358 {$IFEND}
359end;
360
361
Jens Geyer9bb4c112014-07-03 23:05:54 +0200362
363
Roger Meier2b2c0b22012-09-12 20:09:02 +0000364end.
365