diff --git a/src/Document/JsonDocument.st b/src/Document/JsonDocument.st index bc550d1..a65c46b 100644 --- a/src/Document/JsonDocument.st +++ b/src/Document/JsonDocument.st @@ -6,7 +6,7 @@ NAMESPACE Simatic.Ax.Json {axcode:docs-v0:@simatic-ax/json:JsonDocument.md} CLASS FINAL JsonDocument IMPLEMENTS IJsonContainerElement VAR PUBLIC - buffer : ARRAY[0..999] OF CHAR; + buffer : REF_TO ARRAY[*] OF CHAR; END_VAR VAR PROTECTED @@ -14,7 +14,6 @@ NAMESPACE Simatic.Ax.Json _lastElement : IJsonElementMuteable; _rootElement : IJsonElement; _lentgh : DINT; - _bufLowerBound : DINT; _bufIndex : DINT; END_VAR @@ -42,17 +41,18 @@ NAMESPACE Simatic.Ax.Json /// Serializes the JSON document ino a ARRAY OF CHAR {axcode:docs-v0:@simatic-ax/json:JsonDocument.md} METHOD PUBLIC Serialize : BOOL - VAR_IN_OUT - buf : ARRAY[*] OF CHAR; - END_VAR VAR_TEMP _to : IJsonElementMuteable; + _bufLowerBound : DINT; END_VAR - + IF (buffer = NULL) THEN + Serialize := FALSE; + RETURN; + END_IF; // Clear buffer (not hard before serializing) THIS.ClearBuffer(); - _bufLowerBound := LOWER_BOUND(buf, 1); + _bufLowerBound := LOWER_BOUND(buffer^, 1); _bufIndex := _bufLowerBound; THIS.AddChar(c := '{'); @@ -73,7 +73,11 @@ NAMESPACE Simatic.Ax.Json VAR_INPUT c : CHAR; END_VAR - buffer[_bufIndex] := c; + IF (buffer = NULL) THEN + AddChar := FALSE; + RETURN; + END_IF; + buffer^[_bufIndex] := c; _bufIndex := _bufIndex + 1; _lentgh := _lentgh + 1; AddChar := TRUE; @@ -87,8 +91,12 @@ NAMESPACE Simatic.Ax.Json VAR_TEMP i : INT; END_VAR + IF (buffer = NULL) THEN + AddString := FALSE; + RETURN; + END_IF; FOR i := 1 TO LengthOf(s) DO - buffer[_bufIndex] := s[i]; + buffer^[_bufIndex] := s[i]; _bufIndex := _bufIndex + 1; _lentgh := _lentgh + 1; END_FOR; @@ -141,11 +149,15 @@ NAMESPACE Simatic.Ax.Json END_VAR VAR_TEMP i : DINT; + _bufLowerBound : DINT; END_VAR - + IF (buffer = NULL) THEN + RETURN; + END_IF; + _bufLowerBound := LOWER_BOUND(buffer^, 1); IF (hard) THEN FOR i := _bufLowerBound TO _bufIndex DO - buffer[i] := TO_CHAR(BYTE#16#00); + buffer^[i] := TO_CHAR(BYTE#16#00); END_FOR; END_IF; _bufLowerBound := 0; diff --git a/test/Document/TestCleanResetDocument.st b/test/Document/TestCleanResetDocument.st index 4f7e7a7..08afd12 100644 --- a/test/Document/TestCleanResetDocument.st +++ b/test/Document/TestCleanResetDocument.st @@ -22,6 +22,7 @@ NAMESPACE Document doc : JsonDocument; cmpBuff : ARRAY[0..399] OF CHAR; cmpBuffEmpty : ARRAY[0..399] OF CHAR; + buffer : ARRAY[0..200] OF CHAR; len : DINT; END_VAR @@ -36,16 +37,18 @@ NAMESPACE Document o2.AddElement(o3); o1.AddElement(o2); doc.AddElement(o1); - doc.Serialize(doc.buffer); + doc.buffer := REF(buffer); + doc.Serialize(); len := Strings.ToArray.OfCharCount(str := expString, arr := cmpBuff); - res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := res); Equal(expected := LengthOf(expString), actual := doc.GetLength()); END_METHOD {Test} METHOD PUBLIC TestCleanBuffer + doc.buffer := REF(buffer); // Fill Buffer THIS.Test_Build_nested_object_And_expect_correct_JSON(); Equal(expected := LengthOf(expString), actual := doc.GetLength()); @@ -55,13 +58,14 @@ NAMESPACE Document Equal(expected := 0, actual := doc.GetLength()); // compare result buffer with compare array - res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := res); // Serialize again - doc.Serialize(doc.buffer); + + doc.Serialize(); len := Strings.ToArray.OfCharCount(str := expString, arr := cmpBuff); - res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := res); Equal(expected := LengthOf(expString), actual := doc.GetLength()); @@ -79,7 +83,7 @@ NAMESPACE Document Equal(expected := 0, actual := doc.GetLength()); // compare result buffer with compare array - res := CompareArray(first := doc.buffer, scnd := cmpBuffEmpty, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuffEmpty, count := TO_INT(len)); Equal(expected := TRUE, actual := res); END_METHOD diff --git a/test/Document/TestDoubleNestetdObject.st b/test/Document/TestDoubleNestetdObject.st index e0714fd..66717b9 100644 --- a/test/Document/TestDoubleNestetdObject.st +++ b/test/Document/TestDoubleNestetdObject.st @@ -21,6 +21,7 @@ NAMESPACE Document res : BOOL; doc : JsonDocument; cmpBuff : ARRAY[0..399] OF CHAR; + buffer : ARRAY[0..200] OF CHAR; len : DINT; END_VAR @@ -35,10 +36,11 @@ NAMESPACE Document o2.AddElement(o3); o1.AddElement(o2); doc.AddElement(o1); - doc.Serialize(doc.buffer); + doc.buffer := REF(buffer); + doc.Serialize(); len := Strings.ToArray.OfCharCount(str := expString, arr := cmpBuff); - res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := res); Equal(expected := LengthOf(expString), actual := doc.GetLength()); END_METHOD diff --git a/test/Document/TestJsonDocument.st b/test/Document/TestJsonDocument.st index b53d401..e22f1c3 100644 --- a/test/Document/TestJsonDocument.st +++ b/test/Document/TestJsonDocument.st @@ -33,7 +33,7 @@ NAMESPACE Document expString : STRING; actString : STRING; result : BOOL; - + buffer : ARRAY[0..200] OF CHAR; END_VAR @@ -49,8 +49,9 @@ NAMESPACE Document // Test Serialize expArrayCnt := Strings.ToArray.OfCharCount(str := expString, arr := expArray); - doc.Serialize(doc.buffer); - result := CompareArray(first := doc.buffer, scnd := expArray, count := TO_INT(expArrayCnt)); + doc.buffer := REF(buffer); + doc.Serialize(); + result := CompareArray(first := buffer, scnd := expArray, count := TO_INT(expArrayCnt)); Equal(expected := TRUE, actual := result); END_METHOD @@ -66,9 +67,10 @@ NAMESPACE Document // Test Serialize expArrayCnt := Strings.ToArray.OfCharCount(str := expString, arr := expArray); - doc.Serialize(doc.buffer); - doc.Serialize(doc.buffer); - result := CompareArray(first := doc.buffer, scnd := expArray, count := TO_INT(expArrayCnt)); + doc.buffer := REF(buffer); + doc.Serialize(); + doc.Serialize(); + result := CompareArray(first := buffer, scnd := expArray, count := TO_INT(expArrayCnt)); Equal(expected := TRUE, actual := result); END_METHOD @@ -84,8 +86,9 @@ NAMESPACE Document // Test Serialize expArrayCnt := Strings.ToArray.OfCharCount(str := expString, arr := expArray); - doc.Serialize(doc.buffer); - result := CompareArray(first := doc.buffer, scnd := expArray, count := TO_INT(expArrayCnt)); + doc.buffer := REF(buffer); + doc.Serialize(); + result := CompareArray(first := buffer, scnd := expArray, count := TO_INT(expArrayCnt)); Equal(expected := TRUE, actual := result); END_METHOD @@ -99,8 +102,9 @@ NAMESPACE Document // Test Serialize expArrayCnt := Strings.ToArray.OfCharCount(str := expString, arr := expArray); - doc.Serialize(doc.buffer); - result := CompareArray(first := doc.buffer, scnd := expArray, count := TO_INT(expArrayCnt)); + doc.buffer := REF(buffer); + doc.Serialize(); + result := CompareArray(first := buffer, scnd := expArray, count := TO_INT(expArrayCnt)); Equal(expected := TRUE, actual := result); END_METHOD @@ -118,8 +122,9 @@ NAMESPACE Document // Test Serialize expArrayCnt := Strings.ToArray.OfCharCount(str := expString, arr := expArray); - doc.Serialize(doc.buffer); - result := CompareArray(first := doc.buffer, scnd := expArray, count := TO_INT(expArrayCnt)); + doc.buffer := REF(buffer); + doc.Serialize(); + result := CompareArray(first := buffer, scnd := expArray, count := TO_INT(expArrayCnt)); Equal(expected := TRUE, actual := result); END_METHOD @@ -137,8 +142,9 @@ NAMESPACE Document // Test Serialize expArrayCnt := Strings.ToArray.OfCharCount(str := expString, arr := expArray); - doc.Serialize(doc.buffer); - result := CompareArray(first := doc.buffer, scnd := expArray, count := TO_INT(expArrayCnt)); + doc.buffer := REF(buffer); + doc.Serialize(); + result := CompareArray(first := buffer, scnd := expArray, count := TO_INT(expArrayCnt)); Equal(expected := TRUE, actual := result); END_METHOD @@ -154,8 +160,9 @@ NAMESPACE Document // Test Serialize expArrayCnt := Strings.ToArray.OfCharCount(str := expString, arr := expArray); - doc.Serialize(doc.buffer); - result := CompareArray(first := doc.buffer, scnd := expArray, count := TO_INT(expArrayCnt)); + doc.buffer := REF(buffer); + doc.Serialize(); + result := CompareArray(first := buffer, scnd := expArray, count := TO_INT(expArrayCnt)); Equal(expected := TRUE, actual := result); END_METHOD @@ -190,8 +197,8 @@ NAMESPACE Document // // Test Serialize // expArrayCnt := Strings.ToArray.OfCharCount(str := expString, arr := expArray); - // doc.Serialize(doc.buffer); - // result := CompareArray(first := doc.buffer, scnd := expArray, count := TO_INT(expArrayCnt)); + // doc.Serialize(); + // result := CompareArray(first := buffer, scnd := expArray, count := TO_INT(expArrayCnt)); // Equal(expected := TRUE, actual := result); END_METHOD @@ -216,8 +223,9 @@ NAMESPACE Document // Test Serialize expArrayCnt := Strings.ToArray.OfCharCount(str := expString, arr := expArray); - doc.Serialize(doc.buffer); - result := CompareArray(first := doc.buffer, scnd := expArray, count := TO_INT(expArrayCnt)); + doc.buffer := REF(buffer); + doc.Serialize(); + result := CompareArray(first := buffer, scnd := expArray, count := TO_INT(expArrayCnt)); Equal(expected := TRUE, actual := result); END_METHOD diff --git a/test/Document/TestJsonLongDocument.st b/test/Document/TestJsonLongDocument.st index 7d9f3c4..02c1abd 100644 --- a/test/Document/TestJsonLongDocument.st +++ b/test/Document/TestJsonLongDocument.st @@ -11,13 +11,14 @@ NAMESPACE Document e2 : JsonLInt := (Key := 'elem2', Value := 1); e3 : JsonDInt := (Key := 'elem3', Value := 2); doc :JsonDocument; + buffer : ARRAY[0..200] OF CHAR; END_VAR METHOD PUBLIC MyMethod doc.AddElement(e1); doc.AddElement(e2); doc.AddElement(e3); - doc.Serialize(doc.buffer); //--> {elem1: 0, elem2: 1, elem3: 2}\n + doc.Serialize(); //--> {elem1: 0, elem2: 1, elem3: 2}\n // nice to have --> doc.Deserialize('{elem1: 99, elem2: 100, elem3: 111}\n') END_METHOD diff --git a/test/Document/TestResetNestedDocument.st b/test/Document/TestResetNestedDocument.st index b664826..365bdf3 100644 --- a/test/Document/TestResetNestedDocument.st +++ b/test/Document/TestResetNestedDocument.st @@ -17,51 +17,58 @@ NAMESPACE Document myDint : JsonDInt := (Value := DINT#12345678, Key := 'myDint'); myString : JsonString := (Value := 'this is my string', Key := 'myString'); myObject : JsonObject := (Key := 'myObject'); + buffer : ARRAY[0..200] OF CHAR; END_VAR {Test} METHOD PUBLIC Serialize_BOOLEAN + doc.buffer := REF(buffer); + doc.AddElement(myBoolean); - doc.Serialize(doc.buffer); + doc.Serialize(); - str := Arrays.ToString(doc.buffer, 0, 18); + str := Arrays.ToString(buffer, 0, 18); Equal(expected := '{"myBoolean": true}', actual := str); END_METHOD {Test} METHOD PUBLIC Serialize_INT + doc.buffer := REF(buffer); doc.AddElement(myInt); - doc.Serialize(doc.buffer); + doc.Serialize(); - str := Arrays.ToString(doc.buffer, 0, 14); + str := Arrays.ToString(buffer, 0, 14); Equal(expected := '{"myInt": 1234}', actual := str); END_METHOD {Test} METHOD PUBLIC Serialize_DINT + doc.buffer := REF(buffer); doc.AddElement(myDint); - doc.Serialize(doc.buffer); + doc.Serialize(); - str := Arrays.ToString(doc.buffer, 0, 19); + str := Arrays.ToString(buffer, 0, 19); Equal(expected := '{"myDint": 12345678}', actual := str); END_METHOD {Test} METHOD PUBLIC Serialize_STRING + doc.buffer := REF(buffer); doc.AddElement(myString); - doc.Serialize(doc.buffer); + doc.Serialize(); - str := Arrays.ToString(doc.buffer, 0, 32); + str := Arrays.ToString(buffer, 0, 32); Equal(expected := '{"myString": "this is my string"}', actual := str); END_METHOD {Test} METHOD PUBLIC Serialize_INT_DINT + doc.buffer := REF(buffer); doc.AddElement(myInt); doc.AddElement(myDint); - doc.Serialize(doc.buffer); + doc.Serialize(); - str := Arrays.ToString(doc.buffer, 0, 34); + str := Arrays.ToString(buffer, 0, 34); Equal(expected := '{"myInt": 1234, "myDint": 12345678}', actual := str); END_METHOD @@ -73,9 +80,10 @@ NAMESPACE Document doc.AddElement(myBoolean); doc.AddElement(myObject); - doc.Serialize(doc.buffer); + doc.buffer := REF(buffer); + doc.Serialize(); - str := Arrays.ToString(doc.buffer, 0, 67); + str := Arrays.ToString(buffer, 0, 67); Equal(expected := '{"myBoolean": true, "myObject": {"myInt": 1234, "myDint": 12345678}}', actual := str); @@ -89,8 +97,8 @@ NAMESPACE Document doc.AddElement(myBoolean); doc.AddElement(myObject); - doc.Serialize(doc.buffer); - str := Arrays.ToString(doc.buffer, 0, 67); + doc.Serialize(); + str := Arrays.ToString(buffer, 0, 67); Equal(expected := '{"myBoolean": true, "myObject": {"myInt": 1234, "myDint": 12345678}}', actual := str); END_METHOD diff --git a/test/Numbers/ItemTestInt.st b/test/Numbers/ItemTestInt.st index 2bd4a84..054a932 100644 --- a/test/Numbers/ItemTestInt.st +++ b/test/Numbers/ItemTestInt.st @@ -13,6 +13,7 @@ NAMESPACE Simatic.Ax.Json s_test_minus_999 : STRING := '"second_key": -999'; cmpBuff : ARRAY[0..20] OF CHAR; doc : JsonDocument; + buffer : ARRAY[0..200] OF CHAR; END_VAR {Test} @@ -35,10 +36,12 @@ NAMESPACE Simatic.Ax.Json len : DINT; res : BOOL; END_VAR + doc.buffer := REF(buffer); + e.Serialize(REF(doc)); len := Strings.ToArray.OfCharCount(str := s_test_999, arr := cmpBuff); - res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := res); END_METHOD @@ -49,10 +52,10 @@ NAMESPACE Simatic.Ax.Json len : DINT; res : BOOL; END_VAR - + doc.buffer := REF(buffer); e2.Serialize(REF(doc)); len := Strings.ToArray.OfCharCount(str := s_test_minus_999, arr := cmpBuff); - res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := res); END_METHOD diff --git a/test/Numbers/ItemTestSint.st b/test/Numbers/ItemTestSint.st index c48cdef..ae55830 100644 --- a/test/Numbers/ItemTestSint.st +++ b/test/Numbers/ItemTestSint.st @@ -13,6 +13,7 @@ NAMESPACE Simatic.Ax.Json s_test_min : STRING := '"second_key": -128'; cmpBuff : ARRAY[0..20] OF CHAR; doc : JsonDocument; + buffer : ARRAY[0..200] OF CHAR; END_VAR {Test} @@ -35,10 +36,11 @@ NAMESPACE Simatic.Ax.Json len : DINT; res : BOOL; END_VAR + doc.buffer := REF(buffer); e.Serialize(REF(doc)); len := Strings.ToArray.OfCharCount(str := s_test_max, arr := cmpBuff); - res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := res); END_METHOD @@ -49,10 +51,10 @@ NAMESPACE Simatic.Ax.Json len : DINT; res : BOOL; END_VAR - + doc.buffer := REF(buffer); e2.Serialize(REF(doc)); len := Strings.ToArray.OfCharCount(str := s_test_min, arr := cmpBuff); - res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := res); END_METHOD diff --git a/test/Numbers/ItemTestUInt.st b/test/Numbers/ItemTestUInt.st index 5d753fb..9e5e0ca 100644 --- a/test/Numbers/ItemTestUInt.st +++ b/test/Numbers/ItemTestUInt.st @@ -13,6 +13,7 @@ NAMESPACE Simatic.Ax.Json s_test_max : STRING := '"second_key": 65535'; cmpBuff : ARRAY[0..20] OF CHAR; doc : JsonDocument; + buffer : ARRAY[0..200] OF CHAR; END_VAR {Test} @@ -35,10 +36,11 @@ NAMESPACE Simatic.Ax.Json len : DINT; res : BOOL; END_VAR + doc.buffer := REF(buffer); e.Serialize(REF(doc)); len := Strings.ToArray.OfCharCount(str := s_test_min, arr := cmpBuff); - res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := res); END_METHOD @@ -49,10 +51,10 @@ NAMESPACE Simatic.Ax.Json len : DINT; res : BOOL; END_VAR - + doc.buffer := REF(buffer); e2.Serialize(REF(doc)); len := Strings.ToArray.OfCharCount(str := s_test_max, arr := cmpBuff); - res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := res); END_METHOD diff --git a/test/Numbers/ItemTestUSint.st b/test/Numbers/ItemTestUSint.st index 159acd3..6fa7cdb 100644 --- a/test/Numbers/ItemTestUSint.st +++ b/test/Numbers/ItemTestUSint.st @@ -13,6 +13,7 @@ NAMESPACE Simatic.Ax.Json s_test_minus_min : STRING := '"second_key": 0'; cmpBuff : ARRAY[0..20] OF CHAR; doc : JsonDocument; + buffer : ARRAY[0..200] OF CHAR; END_VAR {Test} @@ -35,10 +36,11 @@ NAMESPACE Simatic.Ax.Json len : DINT; res : BOOL; END_VAR + doc.buffer := REF(buffer); e.Serialize(REF(doc)); len := Strings.ToArray.OfCharCount(str := s_test_max, arr := cmpBuff); - res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := res); END_METHOD @@ -49,10 +51,10 @@ NAMESPACE Simatic.Ax.Json len : DINT; res : BOOL; END_VAR - + doc.buffer := REF(buffer); e2.Serialize(REF(doc)); len := Strings.ToArray.OfCharCount(str := s_test_minus_min, arr := cmpBuff); - res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := res); END_METHOD diff --git a/test/Numbers/TestJsonBoolean.st b/test/Numbers/TestJsonBoolean.st index ac7ce31..9cec56c 100644 --- a/test/Numbers/TestJsonBoolean.st +++ b/test/Numbers/TestJsonBoolean.st @@ -12,6 +12,7 @@ NAMESPACE Simatic.Ax.Json expString, actString : STRING; cmpBuff : ARRAY[0..20] OF CHAR; doc : JsonDocument; + buffer : ARRAY[0..200] OF CHAR; END_VAR {Test} @@ -20,11 +21,12 @@ NAMESPACE Simatic.Ax.Json len : DINT; res : BOOL; END_VAR + doc.buffer := REF(buffer); e.Serialize(REF(doc)); expString := '"test": true'; len := Strings.ToArray.OfCharCount(str := expString, arr := cmpBuff); - res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := res); END_METHOD @@ -35,11 +37,11 @@ NAMESPACE Simatic.Ax.Json len : DINT; res : BOOL; END_VAR - + doc.buffer := REF(buffer); e2.Serialize(REF(doc)); expString := '"second_key": false'; len := Strings.ToArray.OfCharCount(str := expString, arr := cmpBuff); - res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := res); END_METHOD diff --git a/test/Object/TestJsonObject.st b/test/Object/TestJsonObject.st index 6fb04d7..5b8d599 100644 --- a/test/Object/TestJsonObject.st +++ b/test/Object/TestJsonObject.st @@ -14,6 +14,7 @@ NAMESPACE Simatic.Ax.Json doc : JsonDocument; cmpBuff : ARRAY[0..399] OF CHAR; len : DINT; + buffer : ARRAY[0..200] OF CHAR; END_VAR {Test} @@ -74,11 +75,11 @@ NAMESPACE Simatic.Ax.Json THIS.Test_Object_with_three_elements(); _expStr := '"Name": {"test": 999, "second_key": -999, "3rd": 1}'; - + doc.buffer := REF(buffer); o.Serialize(REF(doc)); len := Strings.ToArray.OfCharCount(str := _expStr, arr := cmpBuff); - _res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + _res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := _res); END_METHOD diff --git a/test/String/TestJsonString.st b/test/String/TestJsonString.st index 05ebdc3..015e15f 100644 --- a/test/String/TestJsonString.st +++ b/test/String/TestJsonString.st @@ -12,6 +12,7 @@ NAMESPACE Simatic.Ax.Json expString, actString : STRING; cmpBuff : ARRAY[0..20] OF CHAR; doc : JsonDocument; + buffer : ARRAY[0..200] OF CHAR; END_VAR {Test} @@ -20,11 +21,12 @@ NAMESPACE Simatic.Ax.Json len : DINT; res : BOOL; END_VAR + doc.buffer := REF(buffer); e.Serialize(REF(doc)); expString := '"test": "my#1234,,,,"'; len := Strings.ToArray.OfCharCount(str := expString, arr := cmpBuff); - res := CompareArray(first := doc.buffer, scnd := cmpBuff, count := TO_INT(len)); + res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); Equal(expected := TRUE, actual := res); END_METHOD