From 3670ae0745fae0c5dd2ca0ef1db26a209b40ea18 Mon Sep 17 00:00:00 2001 From: inoussa Date: Fri, 3 Jul 2009 10:38:07 +0000 Subject: [PATCH] JSON : native Int64 support through fcl-json ( only on fpc trunck ) git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@894 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- wst/trunk/tests/test_suite/test_json.pas | 11 ++++ .../tests/test_suite/testformatter_unit.pas | 62 +++++++++++-------- .../tests/test_suite/wst_test_suite_gui.lpi | 6 +- .../tests/test_suite/wst_tests_defines.inc | 7 +++ 4 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 wst/trunk/tests/test_suite/wst_tests_defines.inc diff --git a/wst/trunk/tests/test_suite/test_json.pas b/wst/trunk/tests/test_suite/test_json.pas index d3d46ee04..0a04fa99a 100644 --- a/wst/trunk/tests/test_suite/test_json.pas +++ b/wst/trunk/tests/test_suite/test_json.pas @@ -11,6 +11,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. } {$INCLUDE wst_global.inc} +{$INCLUDE wst_tests_defines.inc} unit test_json; interface @@ -39,6 +40,7 @@ type function Support_ComplextType_with_SimpleContent():Boolean;override; function Support_nil():Boolean;override; class function SupportInt64() : Boolean;override; + class function SupportUInt64() : Boolean;override; published //procedure test_WriteBuffer(); end; @@ -82,6 +84,15 @@ begin end; class function TTestJsonRpcFormatter.SupportInt64(): Boolean; +begin +{$IFDEF WST_HAS_JSON_INT64} + Result := True; +{$ELSE WST_HAS_JSON_INT64} + Result := False; +{$ENDIF WST_HAS_JSON_INT64} +end; + +class function TTestJsonRpcFormatter.SupportUInt64(): Boolean; begin Result := False; end; diff --git a/wst/trunk/tests/test_suite/testformatter_unit.pas b/wst/trunk/tests/test_suite/testformatter_unit.pas index 82611092e..94d3747ea 100644 --- a/wst/trunk/tests/test_suite/testformatter_unit.pas +++ b/wst/trunk/tests/test_suite/testformatter_unit.pas @@ -429,6 +429,7 @@ type function Support_ComplextType_with_SimpleContent():Boolean;virtual; function Support_nil():Boolean;virtual; class function SupportInt64() : Boolean;virtual; + class function SupportUInt64() : Boolean;virtual; published procedure Test_AnsiChar; procedure Test_AnsiChar_ScopeData; @@ -814,6 +815,11 @@ begin Result := True; end; +class function TTestFormatterSimpleType.SupportUInt64(): Boolean; +begin + Result := True; +end; + procedure TTestFormatterSimpleType.Test_AnsiChar; const VAL_1 : AnsiChar = 'O'; VAL_2 : AnsiChar = 'i'; Var @@ -1386,13 +1392,14 @@ Var begin s := Nil; Try - if SupportInt64() then begin - intVal_U := VAL_1; - intVal_S := VAL_2; - end else begin - intVal_U := VAL_32_1; + if SupportInt64() then + intVal_S := VAL_2 + else intVal_S := VAL_32_2; - end; + if SupportUInt64() then + intVal_U := VAL_1 + else + intVal_U := VAL_32_1; f := CreateFormatter(TypeInfo(TClass_Int)); f.BeginObject('Root',TypeInfo(TClass_Int)); @@ -1416,13 +1423,14 @@ begin f.Get(TypeInfo(Int64),x,intVal_S); f.EndScopeRead(); - if SupportInt64() then begin - CheckEquals(QWord(VAL_1),intVal_U); - CheckEquals(VAL_2,intVal_S); - end else begin - CheckEquals(QWord(VAL_32_1),intVal_U); + if SupportInt64() then + CheckEquals(VAL_2,intVal_S) + else CheckEquals(VAL_32_2,intVal_S); - end; + if SupportUInt64() then + CheckEquals(QWord(VAL_1),intVal_U) + else + CheckEquals(QWord(VAL_32_1),intVal_U); Finally s.Free(); End; @@ -1440,7 +1448,7 @@ var begin s := Nil; Try - if SupportInt64() then + if SupportUInt64() then intVal_U := VAL_1 else intVal_U := VAL_32_1; @@ -1460,7 +1468,7 @@ begin f.BeginObjectRead(x,TypeInfo(TClass_Int)); f.GetScopeInnerValue(TypeInfo(QWord),intVal_U); f.EndScopeRead(); - if SupportInt64() then + if SupportUInt64() then CheckEquals(VAL_1,intVal_U) else CheckEquals(VAL_32_1,intVal_U); @@ -2189,13 +2197,14 @@ begin a.Val_16S := CONST_Val_16S; a.Val_32U := CONST_Val_32U; a.Val_32S := CONST_Val_32S; - if SupportInt64() then begin - a.Val_64U := CONST_Val_64U; - a.Val_64S := CONST_Val_64S; - end else begin + if SupportInt64() then + a.Val_64S := CONST_Val_64S + else + a.Val_64S := CONST_Val_32S; + if SupportUInt64() then + a.Val_64U := CONST_Val_64U + else a.Val_64U := CONST_Val_32U; - a.Val_64S := CONST_Val_32S; - end; f := CreateFormatter(TypeInfo(TClass_Int)); @@ -2223,13 +2232,14 @@ begin CheckEquals(CONST_Val_16S,a.Val_16S); CheckEquals(CONST_Val_32U,a.Val_32U); CheckEquals(CONST_Val_32S,a.Val_32S); - if SupportInt64() then begin - CheckEquals(QWord(CONST_Val_64U),a.Val_64U); - CheckEquals(CONST_Val_64S,a.Val_64S); - end else begin + if SupportInt64() then + CheckEquals(CONST_Val_64S,a.Val_64S) + else + CheckEquals(CONST_Val_32S,a.Val_64S); + if SupportUInt64() then + CheckEquals(QWord(CONST_Val_64U),a.Val_64U) + else CheckEquals(QWord(CONST_Val_32U),a.Val_64U); - CheckEquals(CONST_Val_32S,a.Val_64S); - end; Finally a.Free(); s.Free(); diff --git a/wst/trunk/tests/test_suite/wst_test_suite_gui.lpi b/wst/trunk/tests/test_suite/wst_test_suite_gui.lpi index 1deab770f..604f3024e 100644 --- a/wst/trunk/tests/test_suite/wst_test_suite_gui.lpi +++ b/wst/trunk/tests/test_suite/wst_test_suite_gui.lpi @@ -37,7 +37,7 @@ - + @@ -148,6 +148,10 @@ + + + + diff --git a/wst/trunk/tests/test_suite/wst_tests_defines.inc b/wst/trunk/tests/test_suite/wst_tests_defines.inc new file mode 100644 index 000000000..19e86367c --- /dev/null +++ b/wst/trunk/tests/test_suite/wst_tests_defines.inc @@ -0,0 +1,7 @@ +{$UNDEF WST_HAS_JSON_INT64} + +{$IFDEF FPC} + {$IF (FPC_VERSION > 2) OR ( (FPC_VERSION = 2) AND (FPC_RELEASE > 2) ) } + {$DEFINE WST_HAS_JSON_INT64} + {$IFEND} +{$IFEND}