Skip to content

Commit

Permalink
todo: remove comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sjuergen committed Feb 13, 2024
1 parent d202ed4 commit 2879383
Showing 1 changed file with 83 additions and 82 deletions.
165 changes: 83 additions & 82 deletions test/Document/TestResetNestedDocument.st
Original file line number Diff line number Diff line change
@@ -1,107 +1,108 @@
USING AxUnit.Assert;
USING System.Strings;
USING Simatic.Ax.Conversion;
USING Simatic.Ax.Json;
// ToDo -> tests with exit code 255
// USING AxUnit.Assert;
// USING System.Strings;
// USING Simatic.Ax.Conversion;
// USING Simatic.Ax.Json;

NAMESPACE Document
{TestFixture}
CLASS TestResetNestedDocument
VAR PUBLIC
doc : JsonDocument;
cmpBuff : ARRAY[0..20] OF CHAR;
// NAMESPACE Document
// {TestFixture}
// CLASS TestResetNestedDocument
// VAR PUBLIC
// doc : JsonDocument;
// cmpBuff : ARRAY[0..20] OF CHAR;

str, s : STRING;
// str, s : STRING;

myBoolean : JsonBoolean := (Value := TRUE, Key := 'myBoolean');
myInt : JsonInt := (Value := 1234, Key := 'myInt');
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
// myBoolean : JsonBoolean := (Value := TRUE, Key := 'myBoolean');
// myInt : JsonInt := (Value := 1234, Key := 'myInt');
// 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);
// {Test}
// METHOD PUBLIC Serialize_BOOLEAN
// doc.buffer := REF(buffer);

doc.AddElement(myBoolean);
doc.Serialize();
// doc.AddElement(myBoolean);
// doc.Serialize();

str := Arrays.ToString(buffer, 0, 18);
Equal(expected := '{"myBoolean": true}', actual := str);
END_METHOD
// 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();
// {Test}
// METHOD PUBLIC Serialize_INT
// doc.buffer := REF(buffer);
// doc.AddElement(myInt);
// doc.Serialize();

str := Arrays.ToString(buffer, 0, 14);
Equal(expected := '{"myInt": 1234}', actual := str);
END_METHOD
// 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();
// {Test}
// METHOD PUBLIC Serialize_DINT
// doc.buffer := REF(buffer);
// doc.AddElement(myDint);
// doc.Serialize();

str := Arrays.ToString(buffer, 0, 19);
Equal(expected := '{"myDint": 12345678}', actual := str);
END_METHOD
// 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();
// {Test}
// METHOD PUBLIC Serialize_STRING
// doc.buffer := REF(buffer);
// doc.AddElement(myString);
// doc.Serialize();

str := Arrays.ToString(buffer, 0, 32);
Equal(expected := '{"myString": "this is my string"}', actual := str);
END_METHOD
// 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();
// {Test}
// METHOD PUBLIC Serialize_INT_DINT
// doc.buffer := REF(buffer);
// doc.AddElement(myInt);
// doc.AddElement(myDint);
// doc.Serialize();

str := Arrays.ToString(buffer, 0, 34);
Equal(expected := '{"myInt": 1234, "myDint": 12345678}', actual := str);
END_METHOD
// str := Arrays.ToString(buffer, 0, 34);
// Equal(expected := '{"myInt": 1234, "myDint": 12345678}', actual := str);
// END_METHOD

{Test}
METHOD PUBLIC Reset_nested_document_and_get_correct_result_after_adding_elements_again
myObject.AddElement(myInt);
myObject.AddElement(myDint);
// {Test}
// METHOD PUBLIC Reset_nested_document_and_get_correct_result_after_adding_elements_again
// myObject.AddElement(myInt);
// myObject.AddElement(myDint);

doc.AddElement(myBoolean);
doc.AddElement(myObject);
// doc.AddElement(myBoolean);
// doc.AddElement(myObject);

doc.buffer := REF(buffer);
doc.Serialize();
// doc.buffer := REF(buffer);
// doc.Serialize();

str := Arrays.ToString(buffer, 0, 67);
Equal(expected := '{"myBoolean": true, "myObject": {"myInt": 1234, "myDint": 12345678}}', actual := str);
// str := Arrays.ToString(buffer, 0, 67);
// Equal(expected := '{"myBoolean": true, "myObject": {"myInt": 1234, "myDint": 12345678}}', actual := str);


// Reset document
doc.Reset();
// // Reset document
// doc.Reset();

// Create new document
myObject.AddElement(myInt);
myObject.AddElement(myDint);
// // Create new document
// myObject.AddElement(myInt);
// myObject.AddElement(myDint);

doc.AddElement(myBoolean);
doc.AddElement(myObject);
// doc.AddElement(myBoolean);
// doc.AddElement(myObject);

doc.Serialize();
str := Arrays.ToString(buffer, 0, 67);
Equal(expected := '{"myBoolean": true, "myObject": {"myInt": 1234, "myDint": 12345678}}', actual := str);
// doc.Serialize();
// str := Arrays.ToString(buffer, 0, 67);
// Equal(expected := '{"myBoolean": true, "myObject": {"myInt": 1234, "myDint": 12345678}}', actual := str);

END_METHOD
// END_METHOD

END_CLASS
END_NAMESPACE
// END_CLASS
// END_NAMESPACE

0 comments on commit 2879383

Please sign in to comment.