blob: ddf4ba243eb02a188394b82cb9526c03512b7f7b [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,
Jens Geyere9f63e02024-11-23 01:01:13 +010030 test.ExceptionStruct,
31 test.SimpleException,
Roger Meier2b2c0b22012-09-12 20:09:02 +000032 DebugProtoTest;
33
34
35type
36 Fixtures = class
37 public
38 class function CreateOneOfEach : IOneOfEach;
39 class function CreateNesting : INesting;
40 class function CreateHolyMoley : IHolyMoley;
41 class function CreateCompactProtoTestStruct : ICompactProtoTestStruct;
Jens Geyere9f63e02024-11-23 01:01:13 +010042 class function CreateBatchGetResponse : IBatchGetResponse;
43 class function CreateSimpleException : IError;
Roger Meier2b2c0b22012-09-12 20:09:02 +000044
45 // These byte arrays are serialized versions of the above structs.
46 // They were serialized in binary protocol using thrift 0.6.x and are used to
47 // test backwards compatibility with respect to the standard scheme.
48 (*
49 all data copied from JAVA version,
50 to be used later
51
52 public static final byte[] persistentBytesOneOfEach = new byte[] {
53 $02, $00, $01, $01, $02, $00, $02, $00, $03, $00,
54 $03, $D6, $06, $00, $04, $69, $78, $08, $00, $05,
55 $01, $00, $00, $00, $0A, $00, $06, $00, $00, $00,
56 $01, $65, $A0, $BC, $00, $04, $00, $07, $40, $09,
57 $21, $FB, $54, $44, $2D, $18, $0B, $00, $08, $00,
58 $00, $00, $0D, $4A, $53, $4F, $4E, $20, $54, $48,
59 $49, $53, $21, $20, $22, $01, $0B, $00, $09, $00,
60 $00, $00, $2E, $D3, $80, $E2, $85, $AE, $CE, $9D,
61 $20, $D0, $9D, $CE, $BF, $E2, $85, $BF, $D0, $BE,
62 $C9, $A1, $D0, $B3, $D0, $B0, $CF, $81, $E2, $84,
63 $8E, $20, $CE, $91, $74, $74, $CE, $B1, $E2, $85,
64 $BD, $CE, $BA, $EF, $BF, $BD, $E2, $80, $BC, $02,
65 $00, $0A, $00, $0B, $00, $0B, $00, $00, $00, $06,
66 $62, $61, $73, $65, $36, $34, $0F, $00, $0C, $03,
67 $00, $00, $00, $03, $01, $02, $03, $0F, $00, $0D,
68 $06, $00, $00, $00, $03, $00, $01, $00, $02, $00,
69 $03, $0F, $00, $0E, $0A, $00, $00, $00, $03, $00,
70 $00, $00, $00, $00, $00, $00, $01, $00, $00, $00,
71 $00, $00, $00, $00, $02, $00, $00, $00, $00, $00,
72 $00, $00, $03, $00 };
73
74
75 public static final byte[] persistentBytesNesting = new byte[] {
76 $0C, $00, $01, $08, $00, $01, $00, $00, $7A, $69,
77 $0B, $00, $02, $00, $00, $00, $13, $49, $20, $61,
78 $6D, $20, $61, $20, $62, $6F, $6E, $6B, $2E, $2E,
79 $2E, $20, $78, $6F, $72, $21, $00, $0C, $00, $02,
80 $02, $00, $01, $01, $02, $00, $02, $00, $03, $00,
81 $03, $D6, $06, $00, $04, $69, $78, $08, $00, $05,
82 $01, $00, $00, $00, $0A, $00, $06, $00, $00, $00,
83 $01, $65, $A0, $BC, $00, $04, $00, $07, $40, $09,
84 $21, $FB, $54, $44, $2D, $18, $0B, $00, $08, $00,
85 $00, $00, $0D, $4A, $53, $4F, $4E, $20, $54, $48,
86 $49, $53, $21, $20, $22, $01, $0B, $00, $09, $00,
87 $00, $00, $2E, $D3, $80, $E2, $85, $AE, $CE, $9D,
88 $20, $D0, $9D, $CE, $BF, $E2, $85, $BF, $D0, $BE,
89 $C9, $A1, $D0, $B3, $D0, $B0, $CF, $81, $E2, $84,
90 $8E, $20, $CE, $91, $74, $74, $CE, $B1, $E2, $85,
91 $BD, $CE, $BA, $EF, $BF, $BD, $E2, $80, $BC, $02,
92 $00, $0A, $00, $0B, $00, $0B, $00, $00, $00, $06,
93 $62, $61, $73, $65, $36, $34, $0F, $00, $0C, $03,
94 $00, $00, $00, $03, $01, $02, $03, $0F, $00, $0D,
95 $06, $00, $00, $00, $03, $00, $01, $00, $02, $00,
96 $03, $0F, $00, $0E, $0A, $00, $00, $00, $03, $00,
97 $00, $00, $00, $00, $00, $00, $01, $00, $00, $00,
98 $00, $00, $00, $00, $02, $00, $00, $00, $00, $00,
99 $00, $00, $03, $00, $00 };
100
101 public static final byte[] persistentBytesHolyMoley = new byte[] {
102 $0F, $00, $01, $0C, $00, $00, $00, $02, $02, $00,
103 $01, $01, $02, $00, $02, $00, $03, $00, $03, $23,
104 $06, $00, $04, $69, $78, $08, $00, $05, $01, $00,
105 $00, $00, $0A, $00, $06, $00, $00, $00, $01, $65,
106 $A0, $BC, $00, $04, $00, $07, $40, $09, $21, $FB,
107 $54, $44, $2D, $18, $0B, $00, $08, $00, $00, $00,
108 $0D, $4A, $53, $4F, $4E, $20, $54, $48, $49, $53,
109 $21, $20, $22, $01, $0B, $00, $09, $00, $00, $00,
110 $2E, $D3, $80, $E2, $85, $AE, $CE, $9D, $20, $D0,
111 $9D, $CE, $BF, $E2, $85, $BF, $D0, $BE, $C9, $A1,
112 $D0, $B3, $D0, $B0, $CF, $81, $E2, $84, $8E, $20,
113 $CE, $91, $74, $74, $CE, $B1, $E2, $85, $BD, $CE,
114 $BA, $EF, $BF, $BD, $E2, $80, $BC, $02, $00, $0A,
115 $00, $0B, $00, $0B, $00, $00, $00, $06, $62, $61,
116 $73, $65, $36, $34, $0F, $00, $0C, $03, $00, $00,
117 $00, $03, $01, $02, $03, $0F, $00, $0D, $06, $00,
118 $00, $00, $03, $00, $01, $00, $02, $00, $03, $0F,
119 $00, $0E, $0A, $00, $00, $00, $03, $00, $00, $00,
120 $00, $00, $00, $00, $01, $00, $00, $00, $00, $00,
121 $00, $00, $02, $00, $00, $00, $00, $00, $00, $00,
122 $03, $00, $02, $00, $01, $01, $02, $00, $02, $00,
123 $03, $00, $03, $D6, $06, $00, $04, $69, $78, $08,
124 $00, $05, $01, $00, $00, $00, $0A, $00, $06, $00,
125 $00, $00, $01, $65, $A0, $BC, $00, $04, $00, $07,
126 $40, $09, $21, $FB, $54, $44, $2D, $18, $0B, $00,
127 $08, $00, $00, $00, $0D, $4A, $53, $4F, $4E, $20,
128 $54, $48, $49, $53, $21, $20, $22, $01, $0B, $00,
129 $09, $00, $00, $00, $2E, $D3, $80, $E2, $85, $AE,
130 $CE, $9D, $20, $D0, $9D, $CE, $BF, $E2, $85, $BF,
131 $D0, $BE, $C9, $A1, $D0, $B3, $D0, $B0, $CF, $81,
132 $E2, $84, $8E, $20, $CE, $91, $74, $74, $CE, $B1,
133 $E2, $85, $BD, $CE, $BA, $EF, $BF, $BD, $E2, $80,
134 $BC, $02, $00, $0A, $00, $0B, $00, $0B, $00, $00,
135 $00, $06, $62, $61, $73, $65, $36, $34, $0F, $00,
136 $0C, $03, $00, $00, $00, $03, $01, $02, $03, $0F,
137 $00, $0D, $06, $00, $00, $00, $03, $00, $01, $00,
138 $02, $00, $03, $0F, $00, $0E, $0A, $00, $00, $00,
139 $03, $00, $00, $00, $00, $00, $00, $00, $01, $00,
140 $00, $00, $00, $00, $00, $00, $02, $00, $00, $00,
141 $00, $00, $00, $00, $03, $00, $0E, $00, $02, $0F,
142 $00, $00, $00, $03, $0B, $00, $00, $00, $00, $0B,
143 $00, $00, $00, $03, $00, $00, $00, $0F, $74, $68,
144 $65, $6E, $20, $61, $20, $6F, $6E, $65, $2C, $20,
145 $74, $77, $6F, $00, $00, $00, $06, $74, $68, $72,
146 $65, $65, $21, $00, $00, $00, $06, $46, $4F, $55,
147 $52, $21, $21, $0B, $00, $00, $00, $02, $00, $00,
148 $00, $09, $61, $6E, $64, $20, $61, $20, $6F, $6E,
149 $65, $00, $00, $00, $09, $61, $6E, $64, $20, $61,
150 $20, $74, $77, $6F, $0D, $00, $03, $0B, $0F, $00,
151 $00, $00, $03, $00, $00, $00, $03, $74, $77, $6F,
152 $0C, $00, $00, $00, $02, $08, $00, $01, $00, $00,
153 $00, $01, $0B, $00, $02, $00, $00, $00, $05, $57,
154 $61, $69, $74, $2E, $00, $08, $00, $01, $00, $00,
155 $00, $02, $0B, $00, $02, $00, $00, $00, $05, $57,
156 $68, $61, $74, $3F, $00, $00, $00, $00, $05, $74,
157 $68, $72, $65, $65, $0C, $00, $00, $00, $00, $00,
158 $00, $00, $04, $7A, $65, $72, $6F, $0C, $00, $00,
159 $00, $00, $00 };
160
161
162*)
163
164 private
165 const
166 kUnicodeBytes : packed array[0..43] of Byte
167 = ( $d3, $80, $e2, $85, $ae, $ce, $9d, $20, $d0, $9d,
168 $ce, $bf, $e2, $85, $bf, $d0, $be, $c9, $a1, $d0,
169 $b3, $d0, $b0, $cf, $81, $e2, $84, $8e, $20, $ce,
170 $91, $74, $74, $ce, $b1, $e2, $85, $bd, $ce, $ba,
171 $83, $e2, $80, $bc);
172
173 end;
174
175
176implementation
177
178
179class function Fixtures.CreateOneOfEach : IOneOfEach;
180var db : Double;
181 us : Utf8String;
182begin
183 result := TOneOfEachImpl.Create;
184 result.setIm_true( TRUE);
185 result.setIm_false( FALSE);
186 result.setA_bite( ShortInt($D6));
187 result.setInteger16( 27000);
188 result.setInteger32( 1 shl 24);
189 result.setInteger64( Int64(6000) * Int64(1000) * Int64(1000));
190 db := Pi;
191 result.setDouble_precision( db);
192 result.setSome_characters( 'JSON THIS! \"\1');
193
194 // ??
195 SetLength( us, Length(kUnicodeBytes));
196 Move( kUnicodeBytes[0], us[1], Length(kUnicodeBytes));
197 // ??
198 SetString( us, PChar(@kUnicodeBytes[0]), Length(kUnicodeBytes));
199 // !!
200 result.setZomg_unicode( UnicodeString( us));
201
Jens Geyer62445c12022-06-29 00:00:00 +0200202 result.Rfc4122_uuid := TGuid.Create('{00112233-4455-6677-8899-aabbccddeeff}');
203
Roger Meier2b2c0b22012-09-12 20:09:02 +0000204 {$IF cDebugProtoTest_Option_AnsiStr_Binary}
205 result.SetBase64('base64');
Jens Geyer07f4bb52022-09-03 14:50:06 +0200206 {$ELSEIF cDebugProtoTest_Option_COM_Types}
207 result.SetBase64( TThriftBytesImpl.Create( TEncoding.UTF8.GetBytes('base64')));
Roger Meier2b2c0b22012-09-12 20:09:02 +0000208 {$ELSE}
Jens Geyer17c3ad92017-09-05 20:31:27 +0200209 result.SetBase64( TEncoding.UTF8.GetBytes('base64'));
Roger Meier2b2c0b22012-09-12 20:09:02 +0000210 {$IFEND}
211
212 // byte, i16, and i64 lists are populated by default constructor
213end;
214
215
216class function Fixtures.CreateNesting : INesting;
217var bonk : IBonk;
218begin
219 bonk := TBonkImpl.Create;
Jens Geyercd7a2aa2022-10-17 14:21:18 +0200220 bonk.&Type := 31337;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000221 bonk.Message := 'I am a bonk... xor!';
222
223 result := TNestingImpl.Create;
224 result.My_bonk := bonk;
225 result.My_ooe := CreateOneOfEach;
226end;
227
228
229class function Fixtures.CreateHolyMoley : IHolyMoley;
Jens Geyer07f4bb52022-09-03 14:50:06 +0200230type
231 TStringType = {$IF cDebugProtoTest_Option_COM_Types} WideString {$ELSE} String {$IFEND};
Roger Meier2b2c0b22012-09-12 20:09:02 +0000232var big : IThriftList<IOneOfEach>;
Jens Geyer07f4bb52022-09-03 14:50:06 +0200233 stage1 : IThriftList<TStringType>;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000234 stage2 : IThriftList<IBonk>;
235 b : IBonk;
236begin
237 result := THolyMoleyImpl.Create;
238
239 big := TThriftListImpl<IOneOfEach>.Create;
240 big.add( CreateOneOfEach);
241 big.add( CreateNesting.my_ooe);
242 result.Big := big;
243 result.Big[0].setA_bite( $22);
244 result.Big[0].setA_bite( $23);
245
Jens Geyer07f4bb52022-09-03 14:50:06 +0200246 result.Contain := TThriftHashSetImpl< IThriftList<TStringType>>.Create;
247 stage1 := TThriftListImpl<TStringType>.Create;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000248 stage1.add( 'and a one');
249 stage1.add( 'and a two');
250 result.Contain.add( stage1);
251
Jens Geyer07f4bb52022-09-03 14:50:06 +0200252 stage1 := TThriftListImpl<TStringType>.Create;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000253 stage1.add( 'then a one, two');
254 stage1.add( 'three!');
255 stage1.add( 'FOUR!!');
256 result.Contain.add( stage1);
257
Jens Geyer07f4bb52022-09-03 14:50:06 +0200258 stage1 := TThriftListImpl<TStringType>.Create;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000259 result.Contain.add( stage1);
260
261 stage2 := TThriftListImpl<IBonk>.Create;
Jens Geyer07f4bb52022-09-03 14:50:06 +0200262 result.Bonks := TThriftDictionaryImpl< TStringType, IThriftList< IBonk>>.Create;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000263 // one empty
264 result.Bonks.Add( 'zero', stage2);
265
266 // one with two
267 stage2 := TThriftListImpl<IBonk>.Create;
268 b := TBonkImpl.Create;
Jens Geyercd7a2aa2022-10-17 14:21:18 +0200269 b.&type := 1;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000270 b.message := 'Wait.';
271 stage2.Add( b);
272 b := TBonkImpl.Create;
Jens Geyercd7a2aa2022-10-17 14:21:18 +0200273 b.&type := 2;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000274 b.message := 'What?';
275 stage2.Add( b);
276 result.Bonks.Add( 'two', stage2);
277
278 // one with three
279 stage2 := TThriftListImpl<IBonk>.Create;
280 b := TBonkImpl.Create;
Jens Geyercd7a2aa2022-10-17 14:21:18 +0200281 b.&type := 3;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000282 b.message := 'quoth';
283 stage2.Add( b);
284 b := TBonkImpl.Create;
Jens Geyercd7a2aa2022-10-17 14:21:18 +0200285 b.&type := 4;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000286 b.message := 'the raven';
287 stage2.Add( b);
288 b := TBonkImpl.Create;
Jens Geyercd7a2aa2022-10-17 14:21:18 +0200289 b.&type := 5;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000290 b.message := 'nevermore';
291 stage2.Add( b);
292 result.bonks.Add( 'three', stage2);
293end;
294
295
296class function Fixtures.CreateCompactProtoTestStruct : ICompactProtoTestStruct;
297// superhuge compact proto test struct
298begin
299 result := TCompactProtoTestStructImpl.Create;
Jens Geyer66f95362021-03-29 20:35:41 +0200300 result.A_byte := DebugProtoTest.TConstants.COMPACT_TEST.A_byte;
301 result.A_i16 := DebugProtoTest.TConstants.COMPACT_TEST.A_i16;
302 result.A_i32 := DebugProtoTest.TConstants.COMPACT_TEST.A_i32;
303 result.A_i64 := DebugProtoTest.TConstants.COMPACT_TEST.A_i64;
304 result.A_double := DebugProtoTest.TConstants.COMPACT_TEST.A_double;
305 result.A_string := DebugProtoTest.TConstants.COMPACT_TEST.A_string;
306 result.A_binary := DebugProtoTest.TConstants.COMPACT_TEST.A_binary;
307 result.True_field := DebugProtoTest.TConstants.COMPACT_TEST.True_field;
308 result.False_field := DebugProtoTest.TConstants.COMPACT_TEST.False_field;
309 result.Empty_struct_field := DebugProtoTest.TConstants.COMPACT_TEST.Empty_struct_field;
310 result.Byte_list := DebugProtoTest.TConstants.COMPACT_TEST.Byte_list;
311 result.I16_list := DebugProtoTest.TConstants.COMPACT_TEST.I16_list;
312 result.I32_list := DebugProtoTest.TConstants.COMPACT_TEST.I32_list;
313 result.I64_list := DebugProtoTest.TConstants.COMPACT_TEST.I64_list;
314 result.Double_list := DebugProtoTest.TConstants.COMPACT_TEST.Double_list;
315 result.String_list := DebugProtoTest.TConstants.COMPACT_TEST.String_list;
316 result.Binary_list := DebugProtoTest.TConstants.COMPACT_TEST.Binary_list;
317 result.Boolean_list := DebugProtoTest.TConstants.COMPACT_TEST.Boolean_list;
318 result.Struct_list := DebugProtoTest.TConstants.COMPACT_TEST.Struct_list;
319 result.Byte_set := DebugProtoTest.TConstants.COMPACT_TEST.Byte_set;
320 result.I16_set := DebugProtoTest.TConstants.COMPACT_TEST.I16_set;
321 result.I32_set := DebugProtoTest.TConstants.COMPACT_TEST.I32_set;
322 result.I64_set := DebugProtoTest.TConstants.COMPACT_TEST.I64_set;
323 result.Double_set := DebugProtoTest.TConstants.COMPACT_TEST.Double_set;
324 result.String_set := DebugProtoTest.TConstants.COMPACT_TEST.String_set;
325 result.String_set := DebugProtoTest.TConstants.COMPACT_TEST.String_set;
326 result.String_set := DebugProtoTest.TConstants.COMPACT_TEST.String_set;
327 result.Binary_set := DebugProtoTest.TConstants.COMPACT_TEST.Binary_set;
328 result.Boolean_set := DebugProtoTest.TConstants.COMPACT_TEST.Boolean_set;
329 result.Struct_set := DebugProtoTest.TConstants.COMPACT_TEST.Struct_set;
330 result.Byte_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_byte_map;
331 result.I16_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.I16_byte_map;
332 result.I32_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.I32_byte_map;
333 result.I64_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.I64_byte_map;
334 result.Double_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.Double_byte_map;
335 result.String_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.String_byte_map;
336 result.Binary_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.Binary_byte_map;
337 result.Boolean_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.Boolean_byte_map;
338 result.Byte_i16_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_i16_map;
339 result.Byte_i32_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_i32_map;
340 result.Byte_i64_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_i64_map;
341 result.Byte_double_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_double_map;
342 result.Byte_string_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_string_map;
343 result.Byte_binary_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_binary_map;
344 result.Byte_boolean_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_boolean_map;
345 result.List_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.List_byte_map;
346 result.Set_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.Set_byte_map;
347 result.Map_byte_map := DebugProtoTest.TConstants.COMPACT_TEST.Map_byte_map;
348 result.Byte_map_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_map_map;
349 result.Byte_set_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_set_map;
350 result.Byte_list_map := DebugProtoTest.TConstants.COMPACT_TEST.Byte_list_map;
Roger Meier2b2c0b22012-09-12 20:09:02 +0000351
Jens Geyera715f702019-08-28 22:56:13 +0200352 result.Field500 := 500;
353 result.Field5000 := 5000;
354 result.Field20000 := 20000;
355
Roger Meier2b2c0b22012-09-12 20:09:02 +0000356 {$IF cDebugProtoTest_Option_AnsiStr_Binary}
357 result.A_binary := AnsiString( #0#1#2#3#4#5#6#7#8);
Jens Geyer07f4bb52022-09-03 14:50:06 +0200358 {$ELSEIF cDebugProtoTest_Option_COM_Types}
359 result.A_binary := TThriftBytesImpl.Create( TEncoding.UTF8.GetBytes( #0#1#2#3#4#5#6#7#8));
Roger Meier2b2c0b22012-09-12 20:09:02 +0000360 {$ELSE}
Jens Geyer17c3ad92017-09-05 20:31:27 +0200361 result.A_binary := TEncoding.UTF8.GetBytes( #0#1#2#3#4#5#6#7#8);
Roger Meier2b2c0b22012-09-12 20:09:02 +0000362 {$IFEND}
363end;
364
365
Jens Geyere9f63e02024-11-23 01:01:13 +0100366class function Fixtures.CreateBatchGetResponse : IBatchGetResponse;
367var
368 data : IGetRequest;
369 error : ISomeException;
370const
371 REQUEST_ID = '123';
372begin
373 data := TGetRequestImpl.Create;
374 data.Id := REQUEST_ID;
375 data.Data := TThriftBytesImpl.Create( TEncoding.UTF8.GetBytes( #0#1#2#3#4#5#6#7#8));
376
377 error := TSomeExceptionImpl.Create;
378 error.Error := TErrorCode.GenericError;
379
380 result := TBatchGetResponseImpl.Create;
381 result.Responses := TThriftDictionaryImpl<WideString, IGetRequest>.Create;
382 result.Responses.Add( REQUEST_ID, data);
383 result.Errors := TThriftDictionaryImpl<WideString, ISomeException>.Create;
384 result.Errors.Add( REQUEST_ID, error);
385end;
386
387
388class function Fixtures.CreateSimpleException : IError;
389var i : Integer;
390 inner : IError;
391 guid : TGuid;
392const
393 IDL_GUID_VALUE : TGuid = '{00000000-4444-CCCC-ffff-0123456789ab}';
394begin
395 result := nil;
396 for i := 0 to 4 do begin
397 inner := result;
398 result := TErrorImpl.Create;
399
400 // validate const values set in IDL
401 ASSERT( result.ErrorCode = 42); // IDL default value
402 ASSERT( IsEqualGUID( result.ExceptionData, IDL_GUID_VALUE));
403
404 // set fresh, but reproducible values
405 FillChar( guid, SizeOf(guid), i);
406 result.ErrorCode := i;
407 result.ExceptionData := guid;
408 result.InnerException := inner;
409 end;
410end;
Jens Geyer9bb4c112014-07-03 23:05:54 +0200411
412
Roger Meier2b2c0b22012-09-12 20:09:02 +0000413end.
414