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