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