-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from simatic-ax/11-document-reset
feat: Add Reset method to JsonDocument
- Loading branch information
Showing
8 changed files
with
157 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Json Document | ||
|
||
## Description | ||
The JsonDocument contains the object model of the Json object. | ||
|
||
|
||
## Object | ||
```mermaid | ||
classDiagram | ||
IJsonContainerElement<|--JsonDocument | ||
IJsonContainerElement : AddElement(IJsonElement) | ||
JsonDocument : STRING ToString() | ||
JsonDocument : BOOL Serialize(ARRAY[*] OF CHAR) | ||
JsonDocument : IJsonElement GetRootElement() | ||
JsonDocument : ClearBuffer(BOOL) | ||
JsonDocument : Reset() | ||
``` | ||
|
||
## Methods | ||
|
||
### ToString() : STRING | ||
|
||
Returns the JSON string of the JSON document (max. 254 characters) | ||
|
||
### Serialize(IN_OUT buf : ARRAY[*] OF CHAR) : BOOL | ||
Serializes the JSON document ino a ARRAY OF CHAR | ||
|
||
### GetRootElement() : IJsonElement | ||
Returns root element of the JSON document | ||
|
||
### AddElement(elem : IJsonElement) | ||
Add a new element to the JSON document | ||
|
||
### ClearBuffer(hard : BOOL) | ||
Clear the buffer logically (fast). If `hard = TRUE` then delete the buffer also physically (slow) | ||
|
||
### Reset() | ||
Reset the complete object tree and the destination buffer of the JSON document for the purpose, a new JSON object should be created. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
USING AxUnit.Assert; | ||
USING System.Strings; | ||
USING Simatic.Ax.Conversion; | ||
USING Simatic.Ax.Json; | ||
|
||
NAMESPACE Document | ||
{TestFixture} | ||
CLASS TestResetDocument | ||
|
||
VAR PROTECTED | ||
e1 : JsonDInt := (Value := 999, Key := 'e1'); | ||
e2 : JsonBoolean := (Key := 'e2', Value := TRUE); | ||
e3 : JsonString := (Key := 'e3', Value := 'MyString'); | ||
o1 : JSonObject := (Key := 'o1'); | ||
oi1 : JsonSInt := (Key := 'oi1', Value := SINT#1); | ||
oi2 : JsonSInt := (Key := 'oi2', Value := SINT#1); | ||
e4 : JsonLInt := (Key := 'e4', Value := LINT#1); | ||
|
||
|
||
doc : JsonDocument; | ||
cmpBuff : ARRAY[0..399] OF CHAR; | ||
cmpBuffEmpty : ARRAY[0..399] OF CHAR; | ||
len : DINT; | ||
END_VAR | ||
|
||
{Test} | ||
METHOD PUBLIC Reset_flat_document_removes_all_next_elements_from_the_json_objects | ||
VAR_TEMP | ||
_to : IJsonElementMuteable; | ||
_elem : IJsonElement; | ||
END_VAR | ||
|
||
doc.AddElement(e1); | ||
doc.AddElement(e2); | ||
doc.AddElement(e3); | ||
doc.AddElement(o1); | ||
doc.AddElement(e4); | ||
o1.AddElement(oi1); | ||
o1.AddElement(oi2); | ||
|
||
|
||
doc.Reset(); | ||
|
||
Equal(expected := FALSE, actual := e1.HasNext()); | ||
Equal(expected := FALSE, actual := e2.HasNext()); | ||
Equal(expected := FALSE, actual := e3.HasNext()); | ||
Equal(expected := FALSE, actual := e4.HasNext()); | ||
Equal(expected := FALSE, actual := o1.HasNext()); | ||
Equal(expected := FALSE, actual := oi1.HasNext()); | ||
Equal(expected := FALSE, actual := oi2.HasNext()); | ||
Equal(expected := TRUE, actual := doc.GetRootElement() = NULL); | ||
Equal(expected := DINT#0, actual := doc.GetLength()); | ||
|
||
END_METHOD | ||
|
||
END_CLASS | ||
END_NAMESPACE |