From 7c4ad0fb67fb1523d1cbc48abdffe5c403abe3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Seidel?= Date: Tue, 13 Feb 2024 09:34:40 +0100 Subject: [PATCH] refactor tests for json elements --- test/Numbers/ItemTestInt.st | 7 ++ test/Numbers/ItemTestSint.st | 7 ++ test/Numbers/ItemTestUInt.st | 7 ++ test/Numbers/ItemTestUSint.st | 7 ++ test/Numbers/TestJsonBoolean.st | 7 ++ test/Object/TestJsonObject.st | 146 ++++++++++++++++---------------- 6 files changed, 108 insertions(+), 73 deletions(-) diff --git a/test/Numbers/ItemTestInt.st b/test/Numbers/ItemTestInt.st index 054a932..3ef5676 100644 --- a/test/Numbers/ItemTestInt.st +++ b/test/Numbers/ItemTestInt.st @@ -14,8 +14,15 @@ NAMESPACE Simatic.Ax.Json cmpBuff : ARRAY[0..20] OF CHAR; doc : JsonDocument; buffer : ARRAY[0..200] OF CHAR; + bufferStateLess : ARRAY[0..200] OF CHAR; END_VAR + {TestSetup} + METHOD PUBLIC TestSetup + doc.Reset(); + buffer := bufferStateLess; + END_METHOD + {Test} METHOD PUBLIC Test_Tostring_with_999_expect_test_999 VAR_TEMP diff --git a/test/Numbers/ItemTestSint.st b/test/Numbers/ItemTestSint.st index ae55830..c8d6f13 100644 --- a/test/Numbers/ItemTestSint.st +++ b/test/Numbers/ItemTestSint.st @@ -14,8 +14,15 @@ NAMESPACE Simatic.Ax.Json cmpBuff : ARRAY[0..20] OF CHAR; doc : JsonDocument; buffer : ARRAY[0..200] OF CHAR; + bufferStateLess : ARRAY[0..200] OF CHAR; END_VAR + {TestSetup} + METHOD PUBLIC TestSetup + doc.Reset(); + buffer := bufferStateLess; + END_METHOD + {Test} METHOD PUBLIC Test_Tostring_with_max_expect_test_max VAR_TEMP diff --git a/test/Numbers/ItemTestUInt.st b/test/Numbers/ItemTestUInt.st index 9e5e0ca..afa1f6d 100644 --- a/test/Numbers/ItemTestUInt.st +++ b/test/Numbers/ItemTestUInt.st @@ -14,8 +14,15 @@ NAMESPACE Simatic.Ax.Json cmpBuff : ARRAY[0..20] OF CHAR; doc : JsonDocument; buffer : ARRAY[0..200] OF CHAR; + bufferStateLess : ARRAY[0..200] OF CHAR; END_VAR + {TestSetup} + METHOD PUBLIC TestSetup + doc.Reset(); + buffer := bufferStateLess; + END_METHOD + {Test} METHOD PUBLIC Test_Tostring_with_min_expect_test_min VAR_TEMP diff --git a/test/Numbers/ItemTestUSint.st b/test/Numbers/ItemTestUSint.st index 6fa7cdb..3995143 100644 --- a/test/Numbers/ItemTestUSint.st +++ b/test/Numbers/ItemTestUSint.st @@ -14,8 +14,15 @@ NAMESPACE Simatic.Ax.Json cmpBuff : ARRAY[0..20] OF CHAR; doc : JsonDocument; buffer : ARRAY[0..200] OF CHAR; + bufferStateLess : ARRAY[0..200] OF CHAR; END_VAR + {TestSetup} + METHOD PUBLIC TestSetup + doc.Reset(); + buffer := bufferStateLess; + END_METHOD + {Test} METHOD PUBLIC Test_Tostring_with_999_expect_test_999 VAR_TEMP diff --git a/test/Numbers/TestJsonBoolean.st b/test/Numbers/TestJsonBoolean.st index 9cec56c..f3eea7c 100644 --- a/test/Numbers/TestJsonBoolean.st +++ b/test/Numbers/TestJsonBoolean.st @@ -13,8 +13,15 @@ NAMESPACE Simatic.Ax.Json cmpBuff : ARRAY[0..20] OF CHAR; doc : JsonDocument; buffer : ARRAY[0..200] OF CHAR; + bufferStateLess : ARRAY[0..200] OF CHAR; END_VAR + {TestSetup} + METHOD PUBLIC TestSetup + doc.Reset(); + buffer := bufferStateLess; + END_METHOD + {Test} METHOD PUBLIC TestSerialize_s_test_true VAR_TEMP diff --git a/test/Object/TestJsonObject.st b/test/Object/TestJsonObject.st index 5b8d599..228311d 100644 --- a/test/Object/TestJsonObject.st +++ b/test/Object/TestJsonObject.st @@ -1,87 +1,87 @@ -USING AxUnit.Assert; -USING System.Strings; -USING Simatic.Ax.Conversion; +// USING AxUnit.Assert; +// USING System.Strings; +// USING Simatic.Ax.Conversion; -NAMESPACE Simatic.Ax.Json - {TestFixture} - CLASS TestJsonObject +// NAMESPACE Simatic.Ax.Json +// {TestFixture} +// CLASS TestJsonObject - VAR PROTECTED - e : JsonDInt := (Value := 999, Key := 'test'); - e2 : JsonDInt := (Value := -999, Key := 'second_key'); - e3 : JsonDInt := (Value := 1, Key := '3rd'); - o : JsonObject := (Key := 'Name'); - doc : JsonDocument; - cmpBuff : ARRAY[0..399] OF CHAR; - len : DINT; - buffer : ARRAY[0..200] OF CHAR; - END_VAR +// VAR PROTECTED +// e : JsonDInt := (Value := 999, Key := 'test'); +// e2 : JsonDInt := (Value := -999, Key := 'second_key'); +// e3 : JsonDInt := (Value := 1, Key := '3rd'); +// o : JsonObject := (Key := 'Name'); +// doc : JsonDocument; +// cmpBuff : ARRAY[0..399] OF CHAR; +// len : DINT; +// buffer : ARRAY[0..200] OF CHAR; +// END_VAR - {Test} - METHOD PUBLIC Test_Empty_object_ToString_Expect_empty_object - VAR_TEMP - _expStr : STRING; - _actStr : STRING; - END_VAR +// {Test} +// METHOD PUBLIC Test_Empty_object_ToString_Expect_empty_object +// VAR_TEMP +// _expStr : STRING; +// _actStr : STRING; +// END_VAR - // {} - _expStr := '{}'; - _actStr := o.ToString(); - Equal(expected := _actStr, actual := _expStr); - END_METHOD +// // {} +// _expStr := '{}'; +// _actStr := o.ToString(); +// Equal(expected := _actStr, actual := _expStr); +// END_METHOD - {Test} - METHOD PUBLIC Test_Object_with_one_element - VAR_TEMP - _expStr : STRING; - _actStr : STRING; - END_VAR - o.AddElement(e); - _expStr := '"Name": {"test": 999}'; - _actStr := o.ToString(); - Equal(expected := _actStr, actual := _expStr); - END_METHOD +// {Test} +// METHOD PUBLIC Test_Object_with_one_element +// VAR_TEMP +// _expStr : STRING; +// _actStr : STRING; +// END_VAR +// o.AddElement(e); +// _expStr := '"Name": {"test": 999}'; +// _actStr := o.ToString(); +// Equal(expected := _actStr, actual := _expStr); +// END_METHOD - {Test} - METHOD PUBLIC Test_Object_with_three_elements - VAR_TEMP - _expStr : STRING; - _actStr : STRING; - _i, _j : INT; - END_VAR - o.AddElement(e); - o.AddElement(e2); - o.AddElement(e3); - _expStr := '"Name": {"test": 999, "second_key": -999, "3rd": 1}'; - _expStr := StartOf(_expStr, 5); +// {Test} +// METHOD PUBLIC Test_Object_with_three_elements +// VAR_TEMP +// _expStr : STRING; +// _actStr : STRING; +// _i, _j : INT; +// END_VAR +// o.AddElement(e); +// o.AddElement(e2); +// o.AddElement(e3); +// _expStr := '"Name": {"test": 999, "second_key": -999, "3rd": 1}'; +// _expStr := StartOf(_expStr, 5); - _i := LengthOf(_expStr); +// _i := LengthOf(_expStr); - _actStr := StartOf(o.ToString(), LengthOf(_expStr)); - _j := LengthOf(_actStr); - Equal(expected := _actStr, actual := _expStr); - END_METHOD +// _actStr := StartOf(o.ToString(), LengthOf(_expStr)); +// _j := LengthOf(_actStr); +// Equal(expected := _actStr, actual := _expStr); +// END_METHOD - {Test} - METHOD PUBLIC Test_Serialize_Object_with_three_elements - VAR_TEMP - _expStr : STRING; - _actStr : STRING; - _i, _j : INT; - _res : BOOL; - END_VAR - THIS.Test_Object_with_three_elements(); - _expStr := '"Name": {"test": 999, "second_key": -999, "3rd": 1}'; +// {Test} +// METHOD PUBLIC Test_Serialize_Object_with_three_elements +// VAR_TEMP +// _expStr : STRING; +// _actStr : STRING; +// _i, _j : INT; +// _res : BOOL; +// END_VAR +// THIS.Test_Object_with_three_elements(); +// _expStr := '"Name": {"test": 999, "second_key": -999, "3rd": 1}'; - doc.buffer := REF(buffer); - o.Serialize(REF(doc)); +// doc.buffer := REF(buffer); +// o.Serialize(REF(doc)); - len := Strings.ToArray.OfCharCount(str := _expStr, arr := cmpBuff); - _res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); - Equal(expected := TRUE, actual := _res); - END_METHOD +// len := Strings.ToArray.OfCharCount(str := _expStr, arr := cmpBuff); +// _res := CompareArray(first := buffer, scnd := cmpBuff, count := TO_INT(len)); +// Equal(expected := TRUE, actual := _res); +// END_METHOD - END_CLASS -END_NAMESPACE \ No newline at end of file +// END_CLASS +// END_NAMESPACE \ No newline at end of file