Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1 | unit TestSerializer.Tests; |
| 2 | (* |
| 3 | * Licensed to the Apache Software Foundation (ASF) under one |
| 4 | * or more contributor license agreements. See the NOTICE file |
| 5 | * distributed with this work for additional information |
| 6 | * regarding copyright ownership. The ASF licenses this file |
| 7 | * to you under the Apache License, Version 2.0 (the |
| 8 | * "License"); you may not use this file except in compliance |
| 9 | * with the License. You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, |
| 14 | * software distributed under the License is distributed on an |
| 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | * KIND, either express or implied. See the License for the |
| 17 | * specific language governing permissions and limitations |
| 18 | * under the License. |
| 19 | *) |
| 20 | |
| 21 | interface |
| 22 | |
| 23 | uses |
| 24 | Classes, |
| 25 | Windows, |
| 26 | SysUtils, |
| 27 | Generics.Collections, |
| 28 | Thrift, |
| 29 | Thrift.Exception, |
| 30 | Thrift.Socket, |
| 31 | Thrift.Transport, |
| 32 | Thrift.Protocol, |
| 33 | Thrift.Protocol.JSON, |
| 34 | Thrift.Protocol.Compact, |
| 35 | Thrift.Collections, |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 36 | Thrift.Configuration, |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 37 | Thrift.Server, |
| 38 | Thrift.Utils, |
| 39 | Thrift.Serializer, |
| 40 | Thrift.Stream, |
| 41 | Thrift.WinHTTP, |
| 42 | Thrift.TypeRegistry, |
| 43 | System_, |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 44 | DebugProtoTest; |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 45 | |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame^] | 46 | {$TYPEINFO ON} |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 47 | |
| 48 | type |
| 49 | TFactoryPair = record |
| 50 | prot : IProtocolFactory; |
| 51 | trans : ITransportFactory; |
| 52 | end; |
| 53 | |
| 54 | TTestSerializer = class //extends TestCase { |
| 55 | private type |
| 56 | TMethod = ( |
| 57 | mt_Bytes, |
| 58 | mt_Stream |
| 59 | ); |
| 60 | |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 61 | strict private |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 62 | FProtocols : TList< TFactoryPair>; |
| 63 | procedure AddFactoryCombination( const aProto : IProtocolFactory; const aTrans : ITransportFactory); |
| 64 | class function UserFriendlyName( const factory : TFactoryPair) : string; overload; |
| 65 | class function UserFriendlyName( const method : TMethod) : string; overload; |
| 66 | |
| 67 | class function Serialize(const input : IBase; const factory : TFactoryPair) : TBytes; overload; |
| 68 | class procedure Serialize(const input : IBase; const factory : TFactoryPair; const aStream : TStream); overload; |
| 69 | |
| 70 | class procedure Deserialize( const input : TBytes; const target : IBase; const factory : TFactoryPair); overload; |
| 71 | class procedure Deserialize( const input : TStream; const target : IBase; const factory : TFactoryPair); overload; |
| 72 | |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 73 | class procedure ValidateReadToEnd( const input : TBytes; const serial : TDeserializer); overload; |
| 74 | class procedure ValidateReadToEnd( const input : TStream; const serial : TDeserializer); overload; |
| 75 | |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 76 | class function LengthOf( const bytes : TBytes) : Integer; overload; inline; |
| 77 | class function LengthOf( const bytes : IThriftBytes) : Integer; overload; inline; |
| 78 | |
| 79 | class function DataPtrOf( const bytes : TBytes) : Pointer; overload; inline; |
| 80 | class function DataPtrOf( const bytes : IThriftBytes) : Pointer; overload; inline; |
| 81 | |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 82 | procedure Test_Serializer_Deserializer; |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 83 | procedure Test_COM_Types; |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 84 | procedure Test_OneOfEach( const method : TMethod; const factory : TFactoryPair; const stream : TFileStream); |
| 85 | procedure Test_CompactStruct( const method : TMethod; const factory : TFactoryPair; const stream : TFileStream); |
| 86 | |
| 87 | public |
| 88 | constructor Create; |
| 89 | destructor Destroy; override; |
| 90 | |
| 91 | procedure RunTests; |
| 92 | end; |
| 93 | |
| 94 | |
| 95 | implementation |
| 96 | |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 97 | const SERIALIZERDATA_DLL = 'SerializerData.dll'; |
| 98 | function CreateOneOfEach : IOneOfEach; stdcall; external SERIALIZERDATA_DLL; |
| 99 | function CreateNesting : INesting; stdcall; external SERIALIZERDATA_DLL; |
| 100 | function CreateHolyMoley : IHolyMoley; stdcall; external SERIALIZERDATA_DLL; |
| 101 | function CreateCompactProtoTestStruct : ICompactProtoTestStruct; stdcall; external SERIALIZERDATA_DLL; |
| 102 | |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 103 | |
| 104 | { TTestSerializer } |
| 105 | |
| 106 | constructor TTestSerializer.Create; |
| 107 | begin |
| 108 | inherited Create; |
| 109 | FProtocols := TList< TFactoryPair>.Create; |
| 110 | |
| 111 | AddFactoryCombination( TBinaryProtocolImpl.TFactory.Create, nil); |
| 112 | AddFactoryCombination( TCompactProtocolImpl.TFactory.Create, nil); |
| 113 | AddFactoryCombination( TJSONProtocolImpl.TFactory.Create, nil); |
| 114 | |
| 115 | AddFactoryCombination( TBinaryProtocolImpl.TFactory.Create, TFramedTransportImpl.TFactory.Create); |
| 116 | AddFactoryCombination( TCompactProtocolImpl.TFactory.Create, TFramedTransportImpl.TFactory.Create); |
| 117 | AddFactoryCombination( TJSONProtocolImpl.TFactory.Create, TFramedTransportImpl.TFactory.Create); |
| 118 | |
| 119 | AddFactoryCombination( TBinaryProtocolImpl.TFactory.Create, TBufferedTransportImpl.TFactory.Create); |
| 120 | AddFactoryCombination( TCompactProtocolImpl.TFactory.Create, TBufferedTransportImpl.TFactory.Create); |
| 121 | AddFactoryCombination( TJSONProtocolImpl.TFactory.Create, TBufferedTransportImpl.TFactory.Create); |
| 122 | end; |
| 123 | |
| 124 | |
| 125 | destructor TTestSerializer.Destroy; |
| 126 | begin |
| 127 | try |
| 128 | FreeAndNil( FProtocols); |
| 129 | finally |
| 130 | inherited Destroy; |
| 131 | end; |
| 132 | end; |
| 133 | |
| 134 | |
| 135 | procedure TTestSerializer.AddFactoryCombination( const aProto : IProtocolFactory; const aTrans : ITransportFactory); |
| 136 | var rec : TFactoryPair; |
| 137 | begin |
| 138 | rec.prot := aProto; |
| 139 | rec.trans := aTrans; |
| 140 | FProtocols.Add( rec); |
| 141 | end; |
| 142 | |
| 143 | |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 144 | class function TTestSerializer.LengthOf( const bytes : TBytes) : Integer; |
| 145 | begin |
| 146 | result := Length(bytes); |
| 147 | end; |
| 148 | |
| 149 | |
| 150 | class function TTestSerializer.LengthOf( const bytes : IThriftBytes) : Integer; |
| 151 | begin |
| 152 | if bytes <> nil |
| 153 | then result := bytes.Count |
| 154 | else result := 0; |
| 155 | end; |
| 156 | |
| 157 | |
| 158 | class function TTestSerializer.DataPtrOf( const bytes : TBytes) : Pointer; |
| 159 | begin |
| 160 | result := bytes; |
| 161 | end; |
| 162 | |
| 163 | |
| 164 | class function TTestSerializer.DataPtrOf( const bytes : IThriftBytes) : Pointer; |
| 165 | begin |
| 166 | if bytes <> nil |
| 167 | then result := bytes.QueryRawDataPtr |
| 168 | else result := nil; |
| 169 | end; |
| 170 | |
| 171 | |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 172 | procedure TTestSerializer.Test_OneOfEach( const method : TMethod; const factory : TFactoryPair; const stream : TFileStream); |
| 173 | var tested, correct : IOneOfEach; |
| 174 | bytes : TBytes; |
| 175 | i : Integer; |
| 176 | begin |
| 177 | // write |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 178 | tested := CreateOneOfEach; |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 179 | case method of |
| 180 | mt_Bytes: bytes := Serialize( tested, factory); |
| 181 | mt_Stream: begin |
| 182 | stream.Size := 0; |
| 183 | Serialize( tested, factory, stream); |
| 184 | end |
| 185 | else |
| 186 | ASSERT( FALSE); |
| 187 | end; |
| 188 | |
| 189 | // init + read |
| 190 | tested := TOneOfEachImpl.Create; |
| 191 | case method of |
| 192 | mt_Bytes: Deserialize( bytes, tested, factory); |
| 193 | mt_Stream: begin |
| 194 | stream.Position := 0; |
| 195 | Deserialize( stream, tested, factory); |
| 196 | end |
| 197 | else |
| 198 | ASSERT( FALSE); |
| 199 | end; |
| 200 | |
| 201 | // check |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 202 | correct := CreateOneOfEach; |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 203 | ASSERT( tested.Im_true = correct.Im_true); |
| 204 | ASSERT( tested.Im_false = correct.Im_false); |
| 205 | ASSERT( tested.A_bite = correct.A_bite); |
| 206 | ASSERT( tested.Integer16 = correct.Integer16); |
| 207 | ASSERT( tested.Integer32 = correct.Integer32); |
| 208 | ASSERT( tested.Integer64 = correct.Integer64); |
| 209 | ASSERT( Abs( tested.Double_precision - correct.Double_precision) < 1E-12); |
| 210 | ASSERT( tested.Some_characters = correct.Some_characters); |
| 211 | ASSERT( tested.Zomg_unicode = correct.Zomg_unicode); |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame^] | 212 | ASSERT( tested.Rfc4122_uuid = correct.Rfc4122_uuid); |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 213 | ASSERT( tested.What_who = correct.What_who); |
| 214 | |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 215 | ASSERT( LengthOf(tested.Base64) = LengthOf(correct.Base64)); |
| 216 | ASSERT( CompareMem( DataPtrOf(tested.Base64), DataPtrOf(correct.Base64), LengthOf(correct.Base64))); |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 217 | |
| 218 | ASSERT( tested.Byte_list.Count = correct.Byte_list.Count); |
| 219 | for i := 0 to tested.Byte_list.Count-1 |
| 220 | do ASSERT( tested.Byte_list[i] = correct.Byte_list[i]); |
| 221 | |
| 222 | ASSERT( tested.I16_list.Count = correct.I16_list.Count); |
| 223 | for i := 0 to tested.I16_list.Count-1 |
| 224 | do ASSERT( tested.I16_list[i] = correct.I16_list[i]); |
| 225 | |
| 226 | ASSERT( tested.I64_list.Count = correct.I64_list.Count); |
| 227 | for i := 0 to tested.I64_list.Count-1 |
| 228 | do ASSERT( tested.I64_list[i] = correct.I64_list[i]); |
| 229 | end; |
| 230 | |
| 231 | |
| 232 | procedure TTestSerializer.Test_CompactStruct( const method : TMethod; const factory : TFactoryPair; const stream : TFileStream); |
| 233 | var tested, correct : ICompactProtoTestStruct; |
| 234 | bytes : TBytes; |
| 235 | begin |
| 236 | // write |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 237 | tested := CreateCompactProtoTestStruct; |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 238 | case method of |
| 239 | mt_Bytes: bytes := Serialize( tested, factory); |
| 240 | mt_Stream: begin |
| 241 | stream.Size := 0; |
| 242 | Serialize( tested, factory, stream); |
| 243 | end |
| 244 | else |
| 245 | ASSERT( FALSE); |
| 246 | end; |
| 247 | |
| 248 | // init + read |
| 249 | correct := TCompactProtoTestStructImpl.Create; |
| 250 | case method of |
| 251 | mt_Bytes: Deserialize( bytes, tested, factory); |
| 252 | mt_Stream: begin |
| 253 | stream.Position := 0; |
| 254 | Deserialize( stream, tested, factory); |
| 255 | end |
| 256 | else |
| 257 | ASSERT( FALSE); |
| 258 | end; |
| 259 | |
| 260 | // check |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 261 | correct := CreateCompactProtoTestStruct; |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 262 | ASSERT( correct.Field500 = tested.Field500); |
| 263 | ASSERT( correct.Field5000 = tested.Field5000); |
| 264 | ASSERT( correct.Field20000 = tested.Field20000); |
| 265 | end; |
| 266 | |
| 267 | |
| 268 | procedure TTestSerializer.Test_Serializer_Deserializer; |
| 269 | var factory : TFactoryPair; |
| 270 | stream : TFileStream; |
| 271 | method : TMethod; |
| 272 | begin |
| 273 | stream := TFileStream.Create( 'TestSerializer.dat', fmCreate); |
| 274 | try |
| 275 | for method in [Low(TMethod)..High(TMethod)] do begin |
| 276 | Writeln( UserFriendlyName(method)); |
| 277 | |
| 278 | for factory in FProtocols do begin |
| 279 | Writeln('- '+UserFriendlyName(factory)); |
| 280 | |
| 281 | Test_OneOfEach( method, factory, stream); |
| 282 | Test_CompactStruct( method, factory, stream); |
| 283 | end; |
| 284 | |
| 285 | Writeln; |
| 286 | end; |
| 287 | |
| 288 | finally |
| 289 | stream.Free; |
| 290 | end; |
| 291 | end; |
| 292 | |
| 293 | |
| 294 | class function TTestSerializer.UserFriendlyName( const factory : TFactoryPair) : string; |
| 295 | begin |
| 296 | result := Copy( (factory.prot as TObject).ClassName, 2, MAXINT); |
| 297 | |
| 298 | if factory.trans <> nil |
| 299 | then result := Copy( (factory.trans as TObject).ClassName, 2, MAXINT) +' '+ result; |
| 300 | |
| 301 | result := StringReplace( result, 'Impl', '', [rfReplaceAll]); |
| 302 | result := StringReplace( result, 'Transport.TFactory', '', [rfReplaceAll]); |
| 303 | result := StringReplace( result, 'Protocol.TFactory', '', [rfReplaceAll]); |
| 304 | end; |
| 305 | |
| 306 | |
| 307 | class function TTestSerializer.UserFriendlyName( const method : TMethod) : string; |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame^] | 308 | const NAMES : array[TMethod] of string = ('TBytes','Stream'); |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 309 | begin |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame^] | 310 | result := NAMES[method]; |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 311 | end; |
| 312 | |
| 313 | |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 314 | procedure TTestSerializer.Test_COM_Types; |
| 315 | var tested : IOneOfEach; |
| 316 | begin |
| 317 | {$IF cDebugProtoTest_Option_COM_types} |
| 318 | ASSERT( SizeOf(TSomeEnum) = SizeOf(Int32)); // -> MINENUMSIZE 4 |
| 319 | |
| 320 | // try to set values that allocate memory |
| 321 | tested := CreateOneOfEach; |
| 322 | tested.Zomg_unicode := 'This is a test'; |
| 323 | tested.Base64 := TThriftBytesImpl.Create( TEncoding.UTF8.GetBytes('abc')); |
| 324 | {$IFEND} |
| 325 | end; |
| 326 | |
| 327 | |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 328 | procedure TTestSerializer.RunTests; |
| 329 | begin |
| 330 | try |
| 331 | Test_Serializer_Deserializer; |
Jens Geyer | 07f4bb5 | 2022-09-03 14:50:06 +0200 | [diff] [blame] | 332 | Test_COM_Types; |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 333 | except |
| 334 | on e:Exception do begin |
| 335 | Writeln( e.ClassName+': '+ e.Message); |
| 336 | Write('Hit ENTER to close ... '); Readln; |
| 337 | end; |
| 338 | end; |
| 339 | end; |
| 340 | |
| 341 | |
| 342 | class function TTestSerializer.Serialize(const input : IBase; const factory : TFactoryPair) : TBytes; |
| 343 | var serial : TSerializer; |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 344 | config : IThriftConfiguration; |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 345 | begin |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 346 | config := TThriftConfigurationImpl.Create; |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame^] | 347 | //config.MaxMessageSize := 0; // we don't read anything here |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 348 | |
| 349 | serial := TSerializer.Create( factory.prot, factory.trans, config); |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 350 | try |
| 351 | result := serial.Serialize( input); |
| 352 | finally |
| 353 | serial.Free; |
| 354 | end; |
| 355 | end; |
| 356 | |
| 357 | |
| 358 | class procedure TTestSerializer.Serialize(const input : IBase; const factory : TFactoryPair; const aStream : TStream); |
| 359 | var serial : TSerializer; |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 360 | config : IThriftConfiguration; |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 361 | begin |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 362 | config := TThriftConfigurationImpl.Create; |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame^] | 363 | //config.MaxMessageSize := 0; // we don't read anything here |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 364 | |
| 365 | serial := TSerializer.Create( factory.prot, factory.trans, config); |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 366 | try |
| 367 | serial.Serialize( input, aStream); |
| 368 | finally |
| 369 | serial.Free; |
| 370 | end; |
| 371 | end; |
| 372 | |
| 373 | |
| 374 | class procedure TTestSerializer.Deserialize( const input : TBytes; const target : IBase; const factory : TFactoryPair); |
| 375 | var serial : TDeserializer; |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 376 | config : IThriftConfiguration; |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 377 | begin |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 378 | config := TThriftConfigurationImpl.Create; |
| 379 | config.MaxMessageSize := Length(input); |
| 380 | |
| 381 | serial := TDeserializer.Create( factory.prot, factory.trans, config); |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 382 | try |
| 383 | serial.Deserialize( input, target); |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 384 | ValidateReadToEnd( input, serial); |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 385 | finally |
| 386 | serial.Free; |
| 387 | end; |
| 388 | end; |
| 389 | |
| 390 | |
| 391 | class procedure TTestSerializer.Deserialize( const input : TStream; const target : IBase; const factory : TFactoryPair); |
| 392 | var serial : TDeserializer; |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 393 | config : IThriftConfiguration; |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 394 | begin |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 395 | config := TThriftConfigurationImpl.Create; |
| 396 | config.MaxMessageSize := input.Size; |
| 397 | |
| 398 | serial := TDeserializer.Create( factory.prot, factory.trans, config); |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 399 | try |
| 400 | serial.Deserialize( input, target); |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 401 | ValidateReadToEnd( input, serial); |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 402 | finally |
| 403 | serial.Free; |
| 404 | end; |
| 405 | end; |
| 406 | |
| 407 | |
Jens Geyer | 41f47af | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 408 | class procedure TTestSerializer.ValidateReadToEnd( const input : TBytes; const serial : TDeserializer); |
| 409 | // we should not have any more byte to read |
| 410 | var dummy : IBase; |
| 411 | begin |
| 412 | try |
| 413 | dummy := TOneOfEachImpl.Create; |
| 414 | serial.Deserialize( input, dummy); |
| 415 | raise EInOutError.Create('Expected exception not thrown?'); |
| 416 | except |
| 417 | on e:TTransportExceptionEndOfFile do {expected}; |
| 418 | on e:Exception do raise; // unexpected |
| 419 | end; |
| 420 | end; |
| 421 | |
| 422 | |
| 423 | class procedure TTestSerializer.ValidateReadToEnd( const input : TStream; const serial : TDeserializer); |
| 424 | // we should not have any more byte to read |
| 425 | var dummy : IBase; |
| 426 | begin |
| 427 | try |
| 428 | input.Position := 0; |
| 429 | dummy := TOneOfEachImpl.Create; |
| 430 | serial.Deserialize( input, dummy); |
| 431 | raise EInOutError.Create('Expected exception not thrown?'); |
| 432 | except |
| 433 | on e:TTransportExceptionEndOfFile do {expected}; |
| 434 | on e:Exception do raise; // unexpected |
| 435 | end; |
| 436 | end; |
| 437 | |
Jens Geyer | ed99455 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 438 | end. |