Skip to content

Commit

Permalink
refactor tests for json elements
Browse files Browse the repository at this point in the history
  • Loading branch information
sjuergen committed Feb 13, 2024
1 parent 548a582 commit 7c4ad0f
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 73 deletions.
7 changes: 7 additions & 0 deletions test/Numbers/ItemTestInt.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/Numbers/ItemTestSint.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/Numbers/ItemTestUInt.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/Numbers/ItemTestUSint.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/Numbers/TestJsonBoolean.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
146 changes: 73 additions & 73 deletions test/Object/TestJsonObject.st
Original file line number Diff line number Diff line change
@@ -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
// END_CLASS
// END_NAMESPACE

0 comments on commit 7c4ad0f

Please sign in to comment.