-
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.
- Loading branch information
Showing
2 changed files
with
432 additions
and
497 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,139 +1,118 @@ | ||
USING Simatic.Ax.Conversion; | ||
USING AxUnit.Assert; | ||
USING System.Strings; | ||
using Simatic.Ax.Json; | ||
|
||
USING Simatic.Ax.Json; | ||
|
||
NAMESPACE Deserializer | ||
NAMESPACE FindKeys | ||
|
||
{TestFixture} | ||
CLASS Test_FindKeyInBuffer | ||
VAR protected | ||
deserializer : Deserializer; | ||
|
||
buffer : ARRAY[0..999] OF CHAR; | ||
key: STRING; | ||
value: STRING; | ||
testIndex1: INT; | ||
testIndex2: INT; | ||
END_VAR | ||
|
||
{Test} | ||
Method Public Test_FindKeysPosition_in_JSON_SimpleEntries | ||
VAR | ||
JSON_Entry: STRING := '{"key ": " Elem ent1", "Hello": "something", "Nothing": 456, "Key 2": 1234 }'; | ||
|
||
len:DINT; | ||
keyStart : int; | ||
keyEnd : int; | ||
keyFound: BOOL; | ||
END_VAR | ||
|
||
len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); | ||
deserializer.buffer := REF(buffer); | ||
|
||
key := 'key '; | ||
keyFound := deserializer.TryParse( key, value); | ||
Equal(TRUE, keyFound); | ||
|
||
key := 'Key 2'; | ||
keyFound := deserializer.TryParse( key, value); | ||
Equal(TRUE, keyFound); | ||
|
||
key := 'not a key'; | ||
keyFound := deserializer.TryParse( key, value); | ||
Equal(FALSE, keyFound); | ||
END_Method | ||
|
||
{Test} | ||
Method Public Test_FindKeysPosition_in_JSON_Single_Nested_Entry | ||
VAR | ||
JSON_Entry: STRING := '{"nested": {"nested1" : "hello", "nested2" : 1234 }}'; | ||
|
||
len:DINT; | ||
keyStart : int; | ||
keyEnd : int; | ||
keyFound: BOOL; | ||
END_VAR | ||
|
||
len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); | ||
deserializer.buffer := REF(buffer); | ||
|
||
key := 'nested'; | ||
keyFound := deserializer.TryParse( key, value); | ||
Equal(TRUE, keyFound); | ||
END_Method | ||
|
||
{Test} | ||
Method Public Test_FindKeysPosition_with_JSON_Nested_Entry | ||
VAR | ||
JSON_Entry: STRING := '{"key ": " Elem ent1", "nested": {"nested1" : "hello", "nested2" : 1234 }, "key2": " Elem ent1"}'; | ||
|
||
len:DINT; | ||
keyStart : int; | ||
keyEnd : int; | ||
keyFound: BOOL; | ||
END_VAR | ||
|
||
len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); | ||
deserializer.buffer := REF(buffer); | ||
|
||
key := 'key '; | ||
keyFound := deserializer.TryParse( key, value); | ||
Equal(TRUE, keyFound); | ||
|
||
key := 'nested'; | ||
keyFound := deserializer.TryParse( key, value); | ||
Equal(TRUE, keyFound); | ||
|
||
key := 'key2'; | ||
keyFound := deserializer.TryParse( key, value); | ||
Equal(TRUE, keyFound); | ||
END_Method | ||
|
||
{Test} | ||
Method Public Test_FindKeysPosition_with_JSON_SimpleArray | ||
VAR | ||
JSON_Entry: STRING := '{ "simpleArray": [123, 456]}'; | ||
|
||
len:DINT; | ||
keyStart : int; | ||
keyEnd : int; | ||
keyFound: BOOL; | ||
END_VAR | ||
|
||
len:= Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); | ||
deserializer.buffer := REF(buffer); | ||
|
||
key := 'simpleArray'; | ||
keyFound := deserializer.TryParse( key, value); | ||
Equal(TRUE, keyFound); | ||
END_Method | ||
|
||
//Comment in to test the private KeyIsInIndexSpan method | ||
// {Test} | ||
// Method Public Test_KeyIsInIndexSpan_FindsKey | ||
// VAR | ||
// len:DINT; | ||
// keyStart : int := 0; | ||
// keyEnd : int := 2; | ||
// keyFound: BOOL; | ||
// END_VAR | ||
|
||
// key := 'key'; | ||
// len:= Strings.ToArray.OfCharCount(str := key, arr := buffer); | ||
// deserializer.SetBuffer(REF(buffer)); | ||
|
||
// keyFound := deserializer.KeyIsInIndexSpan(key, keyStart, keyEnd); | ||
// Equal(TRUE, keyFound); | ||
|
||
// key := 'not'; | ||
// keyFound := deserializer.KeyIsInIndexSpan(key, keyStart, keyEnd); | ||
// Equal(FALSE, keyFound); | ||
// END_Method | ||
|
||
END_CLASS | ||
NAMESPACE FindKeys | ||
|
||
{TestFixture} | ||
CLASS Test_FindKeyInBuffer | ||
VAR PROTECTED | ||
deserializer : Deserializer; | ||
buffer : ARRAY[0..999] OF CHAR; | ||
key : STRING; | ||
value : STRING; | ||
testIndex1 : INT; | ||
testIndex2 : INT; | ||
END_VAR | ||
|
||
{Test} | ||
METHOD PUBLIC Test_FindKeysPosition_in_JSON_SimpleEntries | ||
VAR | ||
JSON_Entry : STRING := '{"key ": " Elem ent1", "Hello": "something", "Nothing": 456, "Key 2": 1234 }'; | ||
len : DINT; | ||
keyStart : INT; | ||
keyEnd : INT; | ||
keyFound : BOOL; | ||
END_VAR | ||
len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); | ||
deserializer.buffer := REF(buffer); | ||
key := 'key '; | ||
keyFound := deserializer.TryParse(key, value); | ||
Equal(TRUE, keyFound); | ||
key := 'Key 2'; | ||
keyFound := deserializer.TryParse(key, value); | ||
Equal(TRUE, keyFound); | ||
key := 'not a key'; | ||
keyFound := deserializer.TryParse(key, value); | ||
Equal(FALSE, keyFound); | ||
END_METHOD | ||
|
||
{Test} | ||
METHOD PUBLIC Test_FindKeysPosition_in_JSON_Single_Nested_Entry | ||
VAR | ||
JSON_Entry : STRING := '{"nested": {"nested1" : "hello", "nested2" : 1234 }}'; | ||
len : DINT; | ||
keyStart : INT; | ||
keyEnd : INT; | ||
keyFound : BOOL; | ||
END_VAR | ||
len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); | ||
deserializer.buffer := REF(buffer); | ||
key := 'nested'; | ||
keyFound := deserializer.TryParse(key, value); | ||
Equal(TRUE, keyFound); | ||
END_METHOD | ||
|
||
{Test} | ||
METHOD PUBLIC Test_FindKeysPosition_with_JSON_Nested_Entry | ||
VAR | ||
JSON_Entry : STRING := '{"key ": " Elem ent1", "nested": {"nested1" : "hello", "nested2" : 1234 }, "key2": " Elem ent1"}'; | ||
len : DINT; | ||
keyStart : INT; | ||
keyEnd : INT; | ||
keyFound : BOOL; | ||
END_VAR | ||
len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); | ||
deserializer.buffer := REF(buffer); | ||
key := 'key '; | ||
keyFound := deserializer.TryParse(key, value); | ||
Equal(TRUE, keyFound); | ||
key := 'nested'; | ||
keyFound := deserializer.TryParse(key, value); | ||
Equal(TRUE, keyFound); | ||
key := 'key2'; | ||
keyFound := deserializer.TryParse(key, value); | ||
Equal(TRUE, keyFound); | ||
END_METHOD | ||
|
||
{Test} | ||
METHOD PUBLIC Test_FindKeysPosition_with_JSON_SimpleArray | ||
VAR | ||
JSON_Entry : STRING := '{ "simpleArray": [123, 456]}'; | ||
len : DINT; | ||
keyStart : INT; | ||
keyEnd : INT; | ||
keyFound : BOOL; | ||
END_VAR | ||
len := Strings.ToArray.OfCharCount(str := JSON_Entry, arr := buffer); | ||
deserializer.buffer := REF(buffer); | ||
key := 'simpleArray'; | ||
keyFound := deserializer.TryParse(key, value); | ||
Equal(TRUE, keyFound); | ||
END_METHOD | ||
//Comment in to test the private KeyIsInIndexSpan method | ||
// {Test} | ||
// Method Public Test_KeyIsInIndexSpan_FindsKey | ||
// VAR | ||
// len:DINT; | ||
// keyStart : int := 0; | ||
// keyEnd : int := 2; | ||
// keyFound: BOOL; | ||
// END_VAR | ||
// key := 'key'; | ||
// len:= Strings.ToArray.OfCharCount(str := key, arr := buffer); | ||
// deserializer.SetBuffer(REF(buffer)); | ||
// keyFound := deserializer.KeyIsInIndexSpan(key, keyStart, keyEnd); | ||
// Equal(TRUE, keyFound); | ||
// key := 'not'; | ||
// keyFound := deserializer.KeyIsInIndexSpan(key, keyStart, keyEnd); | ||
// Equal(FALSE, keyFound); | ||
// END_Method | ||
END_CLASS | ||
|
||
END_NAMESPACE | ||
|
||
END_NAMESPACE | ||
END_NAMESPACE |
Oops, something went wrong.