From 3bc97533f42358989e12bc84d0803df383899d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Seidel?= Date: Tue, 13 Feb 2024 09:46:05 +0100 Subject: [PATCH] add try parse tests --- test/Deserializer/TestFindKeyInBuffer.st | 241 ++++--- test/Deserializer/TryParse/Test_TryParse.st | 688 +++++++++----------- 2 files changed, 432 insertions(+), 497 deletions(-) diff --git a/test/Deserializer/TestFindKeyInBuffer.st b/test/Deserializer/TestFindKeyInBuffer.st index cd7927a..54f6e86 100644 --- a/test/Deserializer/TestFindKeyInBuffer.st +++ b/test/Deserializer/TestFindKeyInBuffer.st @@ -1,139 +1,118 @@ USING Simatic.Ax.Conversion; USING AxUnit.Assert; USING System.Strings; -using Simatic.Ax.Json; - +USING Simatic.Ax.Json; NAMESPACE Deserializer -NAMESPACE FindKeys - -{TestFixture} -CLASS Test_FindKeyInBuffer - VAR protected - deserializer : Deserializer; - - buffer : ARRAY[0..999] OF CHAR; - key: STRING; - value: STRING; - testIndex1: INT; - testIndex2: INT; - END_VAR - - {Test} - Method Public Test_FindKeysPosition_in_JSON_SimpleEntries - VAR - JSON_Entry: STRING := '{"key ": " Elem ent1", "Hello": "something", "Nothing": 456, "Key 2": 1234 }'; - - len:DINT; - keyStart : int; - keyEnd : int; - keyFound: BOOL; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - key := 'key '; - keyFound := deserializer.TryParse( key, value); - Equal(TRUE, keyFound); - - key := 'Key 2'; - keyFound := deserializer.TryParse( key, value); - Equal(TRUE, keyFound); - - key := 'not a key'; - keyFound := deserializer.TryParse( key, value); - Equal(FALSE, keyFound); - END_Method - - {Test} - Method Public Test_FindKeysPosition_in_JSON_Single_Nested_Entry - VAR - JSON_Entry: STRING := '{"nested": {"nested1" : "hello", "nested2" : 1234 }}'; - - len:DINT; - keyStart : int; - keyEnd : int; - keyFound: BOOL; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - key := 'nested'; - keyFound := deserializer.TryParse( key, value); - Equal(TRUE, keyFound); - END_Method - - {Test} - Method Public Test_FindKeysPosition_with_JSON_Nested_Entry - VAR - JSON_Entry: STRING := '{"key ": " Elem ent1", "nested": {"nested1" : "hello", "nested2" : 1234 }, "key2": " Elem ent1"}'; - - len:DINT; - keyStart : int; - keyEnd : int; - keyFound: BOOL; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - key := 'key '; - keyFound := deserializer.TryParse( key, value); - Equal(TRUE, keyFound); - - key := 'nested'; - keyFound := deserializer.TryParse( key, value); - Equal(TRUE, keyFound); - - key := 'key2'; - keyFound := deserializer.TryParse( key, value); - Equal(TRUE, keyFound); - END_Method - - {Test} - Method Public Test_FindKeysPosition_with_JSON_SimpleArray - VAR - JSON_Entry: STRING := '{ "simpleArray": [123, 456]}'; - - len:DINT; - keyStart : int; - keyEnd : int; - keyFound: BOOL; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - key := 'simpleArray'; - keyFound := deserializer.TryParse( key, value); - Equal(TRUE, keyFound); - END_Method - - //Comment in to test the private KeyIsInIndexSpan method - // {Test} - // Method Public Test_KeyIsInIndexSpan_FindsKey - // VAR - // len:DINT; - // keyStart : int := 0; - // keyEnd : int := 2; - // keyFound: BOOL; - // END_VAR - - // key := 'key'; - // len:= Strings.ToArray.OfCharCount(str := key, arr := buffer); - // deserializer.SetBuffer(REF(buffer)); - - // keyFound := deserializer.KeyIsInIndexSpan(key, keyStart, keyEnd); - // Equal(TRUE, keyFound); - - // key := 'not'; - // keyFound := deserializer.KeyIsInIndexSpan(key, keyStart, keyEnd); - // Equal(FALSE, keyFound); - // END_Method -END_CLASS + NAMESPACE FindKeys + + {TestFixture} + CLASS Test_FindKeyInBuffer + VAR PROTECTED + deserializer : Deserializer; + buffer : ARRAY[0..999] OF CHAR; + key : STRING; + value : STRING; + testIndex1 : INT; + testIndex2 : INT; + END_VAR + + {Test} + METHOD PUBLIC Test_FindKeysPosition_in_JSON_SimpleEntries + VAR + JSON_Entry : STRING := '{"key ": " Elem ent1", "Hello": "something", "Nothing": 456, "Key 2": 1234 }'; + len : DINT; + keyStart : INT; + keyEnd : INT; + keyFound : BOOL; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + key := 'key '; + keyFound := deserializer.TryParse(key, value); + Equal(TRUE, keyFound); + key := 'Key 2'; + keyFound := deserializer.TryParse(key, value); + Equal(TRUE, keyFound); + key := 'not a key'; + keyFound := deserializer.TryParse(key, value); + Equal(FALSE, keyFound); + END_METHOD + + {Test} + METHOD PUBLIC Test_FindKeysPosition_in_JSON_Single_Nested_Entry + VAR + JSON_Entry : STRING := '{"nested": {"nested1" : "hello", "nested2" : 1234 }}'; + len : DINT; + keyStart : INT; + keyEnd : INT; + keyFound : BOOL; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + key := 'nested'; + keyFound := deserializer.TryParse(key, value); + Equal(TRUE, keyFound); + END_METHOD + + {Test} + METHOD PUBLIC Test_FindKeysPosition_with_JSON_Nested_Entry + VAR + JSON_Entry : STRING := '{"key ": " Elem ent1", "nested": {"nested1" : "hello", "nested2" : 1234 }, "key2": " Elem ent1"}'; + len : DINT; + keyStart : INT; + keyEnd : INT; + keyFound : BOOL; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + key := 'key '; + keyFound := deserializer.TryParse(key, value); + Equal(TRUE, keyFound); + key := 'nested'; + keyFound := deserializer.TryParse(key, value); + Equal(TRUE, keyFound); + key := 'key2'; + keyFound := deserializer.TryParse(key, value); + Equal(TRUE, keyFound); + END_METHOD + + {Test} + METHOD PUBLIC Test_FindKeysPosition_with_JSON_SimpleArray + VAR + JSON_Entry : STRING := '{ "simpleArray": [123, 456]}'; + len : DINT; + keyStart : INT; + keyEnd : INT; + keyFound : BOOL; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + key := 'simpleArray'; + keyFound := deserializer.TryParse(key, value); + Equal(TRUE, keyFound); + END_METHOD +//Comment in to test the private KeyIsInIndexSpan method +// {Test} +// Method Public Test_KeyIsInIndexSpan_FindsKey +// VAR +// len:DINT; +// keyStart : int := 0; +// keyEnd : int := 2; +// keyFound: BOOL; +// END_VAR +// key := 'key'; +// len:= Strings.ToArray.OfCharCount(str := key, arr := buffer); +// deserializer.SetBuffer(REF(buffer)); +// keyFound := deserializer.KeyIsInIndexSpan(key, keyStart, keyEnd); +// Equal(TRUE, keyFound); +// key := 'not'; +// keyFound := deserializer.KeyIsInIndexSpan(key, keyStart, keyEnd); +// Equal(FALSE, keyFound); +// END_Method + END_CLASS + + END_NAMESPACE END_NAMESPACE -END_NAMESPACE \ No newline at end of file diff --git a/test/Deserializer/TryParse/Test_TryParse.st b/test/Deserializer/TryParse/Test_TryParse.st index 2bdf360..4c45bed 100644 --- a/test/Deserializer/TryParse/Test_TryParse.st +++ b/test/Deserializer/TryParse/Test_TryParse.st @@ -1,374 +1,330 @@ USING Simatic.Ax.Conversion; USING AxUnit.Assert; USING System.Strings; -using Simatic.Ax.Json; - +USING Simatic.Ax.Json; NAMESPACE Deserializer -{TestFixture} -CLASS TryParse - VAR protected - deserializer : Deserializer; - buffer : ARRAY[0..999] OF CHAR; - END_VAR - - {Test} - Method Public Test_TryParse_Value_as_String - VAR - JSON_Entry: STRING := '{ "key1": "nestedkey1"}'; - key: STRING := 'key1'; - len:DINT; - keyFound: BOOL; - value: STRING; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( key, value); - Equal('nestedkey1', value); - END_Method - - {Test} - Method Public Test_TryParse_Value_as_String2 - VAR - JSON_Entry: STRING := '{"Name": "SIMATIC", data: {plc_type: 1518, OPC_SERVER_ENABLED: true}}'; - key: STRING := 'Name'; - len:DINT; - keyFound: BOOL; - value: STRING; - END_VAR - JSON_Entry:= '{"Name": "SIMATIC", data: {plc_type: 1518, OPC_SERVER_ENABLED: true}}'; - key := 'Name'; - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( key, value); - Equal('SIMATIC', value); - END_Method - - {Test} - Method Public Test_TryParse_String - VAR - JSON_Entry: STRING := '{ "key1": {"nestedkey1": 123}}'; - key: STRING := 'key1'; - len:DINT; - keyFound: BOOL; - value: STRING; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( key, value); - Equal('{"nestedkey1": 123}', value); - END_Method - - {Test} - Method Public Test_TryParse_String_Nested - VAR - JSON_Entry: STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; - keyArray: ARRAY [0..1] OF STRING := ['key1', 'nestedkey1']; - len:DINT; - keyFound: BOOL; - value: STRING; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( keyArray, value); - Equal('123', value); - END_Method - - {Test} - Method Public Test_TryParse_LINT - VAR - JSON_Entry: STRING := '{ "leftBoundary": -9223372036854775808, "rightBoundary": 9223372036854775807, "outofBoundaryLeft": 9223372036854775808, "outofBoundaryRight": -9223372036854775809}'; - key: STRING; - len:DINT; - keyFound: BOOL; - value: LINT; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - key:= 'leftBoundary'; - keyFound := deserializer.TryParse( key, value); - Equal(LINT#-9223372036854775808, value); - - key:= 'rightBoundary'; - keyFound := deserializer.TryParse( key, value); - Equal(LINT#9223372036854775807, value); - - key:= 'outofBoundaryLeft'; - keyFound := deserializer.TryParse( key, value); - Equal(FALSE, keyFound); - Equal(0, value); - - key:= 'outofBoundaryRight'; - keyFound := deserializer.TryParse( key, value); - Equal(FALSE, keyFound); - Equal(0, value); - END_Method - - {Test} - Method Public Test_TryParse_LINT_Nested - VAR - JSON_Entry: STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; - keyArray: ARRAY [0..1] OF STRING := ['key1', 'nestedkey1']; - len:DINT; - keyFound: BOOL; - value: LINT; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( keyArray, value); - Equal(123, value); - END_Method - - {Test} - Method Public Test_TryParse_SINT - VAR - JSON_Entry: STRING := '{ "key1": -128}'; - key: STRING := 'key1'; - len:DINT; - keyFound: BOOL; - value: SINT; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( key, value); - Equal(-128, value); - END_Method - - {Test} - Method Public Test_TryParse_SINT_Nested - VAR - JSON_Entry: STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; - keyArray: ARRAY [0..1] OF STRING := ['key1', 'nestedkey1']; - len:DINT; - keyFound: BOOL; - value: SINT; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( keyArray, value); - Equal(123, value); - END_Method - - {Test} - Method Public Test_TryParse_DINT - VAR - JSON_Entry: STRING := '{ "key1": 1234}'; - key: STRING := 'key1'; - len:DINT; - keyFound: BOOL; - value: DINT; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( key, value); - Equal(1234, value); - END_Method - - {Test} - Method Public Test_TryParse_DINT_Nested - VAR - JSON_Entry: STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; - keyArray: ARRAY [0..1] OF STRING := ['key1', 'nestedkey1']; - len:DINT; - keyFound: BOOL; - value: SINT; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( keyArray, value); - Equal(123, value); - END_Method - - {Test} - Method Public Test_TryParse_INT - VAR - JSON_Entry: STRING := '{ "key1": 1234}'; - key: STRING := 'key1'; - len:DINT; - keyFound: BOOL; - value: INT; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( key, value); - Equal(1234, value); - END_Method - - {Test} - Method Public Test_TryParse_INT_Nested - VAR - JSON_Entry: STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; - keyArray: ARRAY [0..1] OF STRING := ['key1', 'nestedkey1']; - len:DINT; - keyFound: BOOL; - value: INT; + {TestFixture} + CLASS TryParse + VAR PROTECTED + deserializer : Deserializer; + buffer : ARRAY[0..999] OF CHAR; END_VAR - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( keyArray, value); - Equal(123, value); - END_Method - - {Test} - Method Public Test_TryParse_USINT - VAR - JSON_Entry: STRING := '{ "key1": 123}'; - key: STRING := 'key1'; - len:DINT; - keyFound: BOOL; - value: USINT; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( key, value); - Equal(USINT#123, value); - END_Method - - {Test} - Method Public Test_TryParse_USINT_Nested - VAR - JSON_Entry: STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; - keyArray: ARRAY [0..1] OF STRING := ['key1', 'nestedkey1']; - len:DINT; - keyFound: BOOL; - value: USINT; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( keyArray, value); - Equal(123, value); - END_Method - - {Test} - Method Public Test_TryParse_UINT - VAR - JSON_Entry: STRING := '{ "key1": 1234}'; - key: STRING := 'key1'; - len:DINT; - keyFound: BOOL; - value: UINT; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( key, value); - Equal(UINT#1234, value); - END_Method - - {Test} - Method Public Test_TryParse_UINT_Nested - VAR - JSON_Entry: STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; - keyArray: ARRAY [0..1] OF STRING := ['key1', 'nestedkey1']; - len:DINT; - keyFound: BOOL; - value: UINT; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( keyArray, value); - Equal(UINT#123, value); - END_Method - - {Test} - Method Public Test_TryParse_UDINT - VAR - JSON_Entry: STRING := '{ "key1": 1234}'; - key: STRING := 'key1'; - len:DINT; - keyFound: BOOL; - value: UDINT; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( key, value); - Equal(UDINT#1234, value); - END_Method - - {Test} - Method Public Test_TryParse_UDINT_Nested - VAR - JSON_Entry: STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; - keyArray: ARRAY [0..1] OF STRING := ['key1', 'nestedkey1']; - len:DINT; - keyFound: BOOL; - value: UDINT; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( keyArray, value); - Equal(UDINT#123, value); - END_Method - - {Test} - Method Public Test_TryParse_ULINT - VAR - JSON_Entry: STRING := '{ "key1": 1234}'; - key: STRING := 'key1'; - len:DINT; - keyFound: BOOL; - value: ULINT; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( key, value); - Equal(ULINT#1234, value); - END_Method - - {Test} - Method Public Test_TryParse_ULINT_Nested - VAR - JSON_Entry: STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; - keyArray: ARRAY [0..1] OF STRING := ['key1', 'nestedkey1']; - len:DINT; - keyFound: BOOL; - value: ULINT; - END_VAR - - len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); - deserializer.buffer := REF(buffer); - - keyFound := deserializer.TryParse( keyArray, value); - Equal(ULINT#123, value); - END_Method - -END_CLASS - -END_NAMESPACE \ No newline at end of file + {Test} + METHOD PUBLIC Test_TryParse_Value_as_String + VAR + JSON_Entry : STRING := '{ "key1": "nestedkey1"}'; + key : STRING := 'key1'; + len : DINT; + keyFound : BOOL; + value : STRING; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(key, value); + Equal('nestedkey1', value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_Value_as_String2 + VAR + JSON_Entry : STRING := '{"Name": "SIMATIC", data: {plc_type: 1518, OPC_SERVER_ENABLED: true}}'; + key : STRING := 'Name'; + len : DINT; + keyFound : BOOL; + value : STRING; + END_VAR + JSON_Entry := '{"Name": "SIMATIC", data: {plc_type: 1518, OPC_SERVER_ENABLED: true}}'; + key := 'Name'; + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(key, value); + Equal('SIMATIC', value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_String + VAR + JSON_Entry : STRING := '{ "key1": {"nestedkey1": 123}}'; + key : STRING := 'key1'; + len : DINT; + keyFound : BOOL; + value : STRING; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(key, value); + Equal('{"nestedkey1": 123}', value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_String_Nested + VAR + JSON_Entry : STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; + keyArray : ARRAY[0..1] OF STRING := ['key1', 'nestedkey1']; + len : DINT; + keyFound : BOOL; + value : STRING; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(keyArray, value); + Equal('123', value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_LINT + VAR + JSON_Entry : STRING := '{ "leftBoundary": -9223372036854775808, "rightBoundary": 9223372036854775807, "outofBoundaryLeft": 9223372036854775808, "outofBoundaryRight": -9223372036854775809}'; + key : STRING; + len : DINT; + keyFound : BOOL; + value : LINT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + key := 'leftBoundary'; + keyFound := deserializer.TryParse(key, value); + Equal(LINT#-9223372036854775808, value); + key := 'rightBoundary'; + keyFound := deserializer.TryParse(key, value); + Equal(LINT#9223372036854775807, value); + key := 'outofBoundaryLeft'; + keyFound := deserializer.TryParse(key, value); + Equal(FALSE, keyFound); + Equal(0, value); + key := 'outofBoundaryRight'; + keyFound := deserializer.TryParse(key, value); + Equal(FALSE, keyFound); + Equal(0, value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_LINT_Nested + VAR + JSON_Entry : STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; + keyArray : ARRAY[0..1] OF STRING := ['key1', 'nestedkey1']; + len : DINT; + keyFound : BOOL; + value : LINT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(keyArray, value); + Equal(123, value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_SINT + VAR + JSON_Entry : STRING := '{ "key1": -128}'; + key : STRING := 'key1'; + len : DINT; + keyFound : BOOL; + value : SINT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(key, value); + Equal(-128, value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_SINT_Nested + VAR + JSON_Entry : STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; + keyArray : ARRAY[0..1] OF STRING := ['key1', 'nestedkey1']; + len : DINT; + keyFound : BOOL; + value : SINT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(keyArray, value); + Equal(123, value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_DINT + VAR + JSON_Entry : STRING := '{ "key1": 1234}'; + key : STRING := 'key1'; + len : DINT; + keyFound : BOOL; + value : DINT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(key, value); + Equal(1234, value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_DINT_Nested + VAR + JSON_Entry : STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; + keyArray : ARRAY[0..1] OF STRING := ['key1', 'nestedkey1']; + len : DINT; + keyFound : BOOL; + value : SINT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(keyArray, value); + Equal(123, value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_INT + VAR + JSON_Entry : STRING := '{ "key1": 1234}'; + key : STRING := 'key1'; + len : DINT; + keyFound : BOOL; + value : INT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(key, value); + Equal(1234, value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_INT_Nested + VAR + JSON_Entry : STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; + keyArray : ARRAY[0..1] OF STRING := ['key1', 'nestedkey1']; + len : DINT; + keyFound : BOOL; + value : INT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(keyArray, value); + Equal(123, value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_USINT + VAR + JSON_Entry : STRING := '{ "key1": 123}'; + key : STRING := 'key1'; + len : DINT; + keyFound : BOOL; + value : USINT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(key, value); + Equal(USINT#123, value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_USINT_Nested + VAR + JSON_Entry : STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; + keyArray : ARRAY[0..1] OF STRING := ['key1', 'nestedkey1']; + len : DINT; + keyFound : BOOL; + value : USINT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(keyArray, value); + Equal(123, value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_UINT + VAR + JSON_Entry : STRING := '{ "key1": 1234}'; + key : STRING := 'key1'; + len : DINT; + keyFound : BOOL; + value : UINT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(key, value); + Equal(UINT#1234, value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_UINT_Nested + VAR + JSON_Entry : STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; + keyArray : ARRAY[0..1] OF STRING := ['key1', 'nestedkey1']; + len : DINT; + keyFound : BOOL; + value : UINT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(keyArray, value); + Equal(UINT#123, value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_UDINT + VAR + JSON_Entry : STRING := '{ "key1": 1234}'; + key : STRING := 'key1'; + len : DINT; + keyFound : BOOL; + value : UDINT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(key, value); + Equal(UDINT#1234, value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_UDINT_Nested + VAR + JSON_Entry : STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; + keyArray : ARRAY[0..1] OF STRING := ['key1', 'nestedkey1']; + len : DINT; + keyFound : BOOL; + value : UDINT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(keyArray, value); + Equal(UDINT#123, value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_ULINT + VAR + JSON_Entry : STRING := '{ "key1": 1234}'; + key : STRING := 'key1'; + len : DINT; + keyFound : BOOL; + value : ULINT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(key, value); + Equal(ULINT#1234, value); + END_METHOD + + {Test} + METHOD PUBLIC Test_TryParse_ULINT_Nested + VAR + JSON_Entry : STRING := '{ "aKey": "hallo", "anotherKey": 1234, "key1": {"nestedkey1": 123, "nestedkey2": "hallo", "nestedkey3": {"nestedInNestedkey1": 1234 }}}'; + keyArray : ARRAY[0..1] OF STRING := ['key1', 'nestedkey1']; + len : DINT; + keyFound : BOOL; + value : ULINT; + END_VAR + len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); + deserializer.buffer := REF(buffer); + keyFound := deserializer.TryParse(keyArray, value); + Equal(ULINT#123, value); + END_METHOD + END_CLASS + +END_NAMESPACE