From d639b8d8d07cf8145aec149cdbcd52eb904352a8 Mon Sep 17 00:00:00 2001 From: inoussa Date: Wed, 7 Oct 2009 13:06:19 +0000 Subject: [PATCH] DateTime, Duration and Time argument creation ( Avoid AV ) git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@976 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../tests/test_suite/testformatter_unit.pas | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/wst/trunk/tests/test_suite/testformatter_unit.pas b/wst/trunk/tests/test_suite/testformatter_unit.pas index c3ac9ef59..3e13a7afa 100644 --- a/wst/trunk/tests/test_suite/testformatter_unit.pas +++ b/wst/trunk/tests/test_suite/testformatter_unit.pas @@ -538,6 +538,10 @@ type procedure Test_Record_simple(); procedure Test_Record_nested(); + + procedure test_Date_ReadNil(); + procedure test_Duration_ReadNil(); + procedure test_Time_ReadNil(); procedure test_GetScopeItemNames(); procedure test_GetFormaterName(); @@ -4610,6 +4614,135 @@ begin end; end; +procedure TTestFormatter.test_Date_ReadNil(); +const DATE_VALUE = 39000.123; +var + f : IFormatterBase; + s : TMemoryStream; + x : string; + a : TDateTimeRemotable; +begin + if not Support_ComplextType_with_SimpleContent() then + Exit; + + s := nil; + a := nil; + try + a := TDateTimeRemotable.Create(); + a.AsDate := DATE_VALUE; + f := CreateFormatter(TypeInfo(TClass_Int)); + + f.BeginObject('Root',TypeInfo(TClass_Int)); + f.Put('a',TypeInfo(TDateTimeRemotable),a); + f.EndScope(); + FreeAndNil(a); + s := TMemoryStream.Create(); + f.SaveToStream(s); + + a := nil; + f := CreateFormatter(TypeInfo(TClass_Int)); + s.Position := 0; + f.LoadFromStream(s); + x := 'Root'; + f.BeginObjectRead(x,TypeInfo(TClass_Int)); + x := 'a'; + f.Get(TypeInfo(TDateTimeRemotable),x,a); + f.EndScopeRead(); + + CheckNotNull(a); + CheckEquals(TDateTimeRemotable.ToStr(DATE_VALUE),TDateTimeRemotable.ToStr(a.AsDate)); + finally + s.Free(); + FreeAndNil(a); + end; +end; + +procedure TTestFormatter.test_Duration_ReadNil(); +const TEST_VALUE = 'P1Y2M3DT4H5M6S'; +var + f : IFormatterBase; + s : TMemoryStream; + x : string; + a : TDurationRemotable; +begin + if not Support_ComplextType_with_SimpleContent() then + Exit; + + s := nil; + a := nil; + try + a := TDurationRemotable.Create(); + a.AsString := TEST_VALUE; + f := CreateFormatter(TypeInfo(TClass_Int)); + + f.BeginObject('Root',TypeInfo(TClass_Int)); + f.Put('a',TypeInfo(TDurationRemotable),a); + f.EndScope(); + FreeAndNil(a); + s := TMemoryStream.Create(); + f.SaveToStream(s); + + a := nil; + f := CreateFormatter(TypeInfo(TClass_Int)); + s.Position := 0; + f.LoadFromStream(s); + x := 'Root'; + f.BeginObjectRead(x,TypeInfo(TClass_Int)); + x := 'a'; + f.Get(TypeInfo(TDurationRemotable),x,a); + f.EndScopeRead(); + + CheckNotNull(a); + CheckEquals(TEST_VALUE,a.AsString); + finally + s.Free(); + FreeAndNil(a); + end; +end; + +procedure TTestFormatter.test_Time_ReadNil(); +const TEST_VALUE = '23:34:56Z'; +var + f : IFormatterBase; + s : TMemoryStream; + x : string; + a : TTimeRemotable; +begin + if not Support_ComplextType_with_SimpleContent() then + Exit; + + s := nil; + a := nil; + try + a := TTimeRemotable.Create(); + a.AsString := TEST_VALUE; + f := CreateFormatter(TypeInfo(TClass_Int)); + + f.BeginObject('Root',TypeInfo(TClass_Int)); + f.Put('a',TypeInfo(TTimeRemotable),a); + f.EndScope(); + FreeAndNil(a); + s := TMemoryStream.Create(); + f.SaveToStream(s); + + a := nil; + f := CreateFormatter(TypeInfo(TClass_Int)); + s.Position := 0; + f.LoadFromStream(s); + x := 'Root'; + f.BeginObjectRead(x,TypeInfo(TClass_Int)); + x := 'a'; + f.Get(TypeInfo(TTimeRemotable),x,a); + f.EndScopeRead(); + + CheckNotNull(a); + CheckEquals(TEST_VALUE,a.AsString); + finally + s.Free(); + FreeAndNil(a); + end; +end; + procedure TTestFormatter.test_GetScopeItemNames(); Var f : IFormatterBase;