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