Skip to content

Commit

Permalink
Added support for WSTRING. Added test code (TwinCAT + C#/.NET) for WS…
Browse files Browse the repository at this point in the history
…TRING. Corrected length check handling for STRING (and used the same for WSTRING).

This commit solves the following issues:
#106 - "Implementing WSTRING support"
#108 - "AssertEquals(ANY) for STRING and WSTRING should look at LEN/WLEN"
  • Loading branch information
sagatowski committed May 25, 2020
1 parent 1af2b96 commit 13276ed
Show file tree
Hide file tree
Showing 21 changed files with 501 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public FB_AnyPrimitiveTypes(IEnumerable<ErrorList.Error> errors, string testFunc
Test_ANY_SINT_Differ();
Test_ANY_STRING_Equals();
Test_ANY_STRING_Differ();
Test_ANY_STRING_Differ_2();
Test_ANY_TIME_Equals();
Test_ANY_TIME_Differ();
Test_ANY_TIME_OF_DAY_Equals();
Expand All @@ -49,6 +50,9 @@ public FB_AnyPrimitiveTypes(IEnumerable<ErrorList.Error> errors, string testFunc
Test_ANY_USINT_Differ();
Test_ANY_WORD_Equals();
Test_ANY_WORD_Differ();
Test_ANY_WSTRING_Equals();
Test_ANY_WSTRING_Differ();
Test_ANY_WSTRING_Differ_2();
}


Expand Down Expand Up @@ -217,10 +221,17 @@ private void Test_ANY_STRING_Equals()

private void Test_ANY_STRING_Differ()
{
string testMessage = CreateFailedTestMessage("Test_ANY_STRING_Differ", "This is a string", "This is another string", "Values differ");
string testMessage = CreateFailedTestMessage("Test_ANY_STRING_Differ", "(Data size (LEN) = 16)", "(Data size (LEN) = 22)", "Values differ");
AssertContainsMessage(testMessage, EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh);
}

private void Test_ANY_STRING_Differ_2()
{
string testMessage = CreateFailedTestMessage("Test_ANY_STRING_Differ_2", "This is a string", "This is b string", "Values differ");
AssertContainsMessage(testMessage, EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh);
}


private void Test_ANY_TIME_Equals()
{
// TwinCAT 3.1.4020 & 3.1.4022
Expand Down Expand Up @@ -311,5 +322,24 @@ private void Test_ANY_WORD_Differ()
string testMessage = CreateFailedTestMessage("Test_ANY_WORD_Differ", "0xEF01", "0x2345", "Values differ");
AssertContainsMessage(testMessage, EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh);
}

private void Test_ANY_WSTRING_Equals()
{
string testMessage = CreateFailedTestMessage("Test_ANY_WSTRING_Equals", "Not possible to print EXP unicode WSTRING value", "Not possible to print ACT unicode WSTRING value", "Values differ");
AssertDoesNotContainMessage(testMessage, EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh);
}

private void Test_ANY_WSTRING_Differ()
{
string testMessage = CreateFailedTestMessage("Test_ANY_WSTRING_Differ", "Not possible to print EXP unicode WSTRING value", "Not possible to print ACT unicode WSTRING value", "Values differ");
AssertContainsMessage(testMessage, EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh);
}

private void Test_ANY_WSTRING_Differ_2()
{
string testMessage = CreateFailedTestMessage("Test_ANY_WSTRING_Differ_2", "(Data size (WLEN) = 3)", "(Data size (WLEN) = 2)", "Values differ");
AssertContainsMessage(testMessage, EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ private void Test_LREAL()

private void Test_STRING()
{
string testMessage = CreateFailedTestMessage("Test_STRING", "(Data size = 81)", "(Data size = 256)", "Values differ");
AssertContainsMessage(testMessage, EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh);
AssertDoesNotContainMessage("'PRG_TEST." + _testFunctionBlockInstance + "@Test_STRING'", EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh);
}

private void Test_STRING_2()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ private void TwiceAssertCall()

testMessage = CreateFailedTestMessage("TwiceAssertCall", "0xABCD", "0x89EF", "Not equal WORD");
AssertMessageCount(testMessage, 1, EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh);

testMessage = CreateFailedTestMessage("TwiceAssertCall", "Not possible to print EXP unicode WSTRING value", "Not possible to print ACT unicode WSTRING value", "Not equal WSTRING");
AssertMessageCount(testMessage, 1, EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public FB_PrimitiveTypes(IEnumerable<ErrorList.Error> errors, string testFunctio
Test_USINT_Differ();
Test_WORD_Equals();
Test_WORD_Differ();
Test_WSTRING_Equals();
Test_WSTRING_Differ();
}

private void Test_ANY_Equals()
Expand Down Expand Up @@ -323,5 +325,17 @@ private void Test_WORD_Differ()
string testMessage = CreateFailedTestMessage("Test_WORD_Differ", "0xEF01", "0x2345", "Values differ");
AssertContainsMessage(testMessage, EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh);
}

private void Test_WSTRING_Equals()
{
string testMessage = CreateFailedTestMessage("Test_WSTRING_Equals", "Not possible to print EXP unicode WSTRING value", "Not possible to print ACT unicode WSTRING value", "Values differ");
AssertDoesNotContainMessage(testMessage, EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh);
}

private void Test_WSTRING_Differ()
{
string testMessage = CreateFailedTestMessage("Test_WSTRING_Differ", "Not possible to print EXP unicode WSTRING value", "Not possible to print ACT unicode WSTRING value", "Values differ");
AssertContainsMessage(testMessage, EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public FB_WriteProtectedFunctions(IEnumerable<ErrorList.Error> errors, string te
Test_WRITE_PROTECTED_USINT();
Test_WRITE_PROTECTED_ULINT();
Test_WRITE_PROTECTED_WORD();
Test_WRITE_PROTECTED_WSTRING();
}

private void Test_WRITE_PROTECTED_BOOL()
Expand Down Expand Up @@ -147,5 +148,11 @@ private void Test_WRITE_PROTECTED_WORD()
string testMessage = "PRG_TEST." + _testFunctionBlockInstance + "@Test_WRITE_PROTECTED_WORD";
AssertDoesNotContainMessage(testMessage, EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh);
}

private void Test_WRITE_PROTECTED_WSTRING()
{
string testMessage = "PRG_TEST." + _testFunctionBlockInstance + "@Test_WRITE_PROTECTED_WSTRING";
AssertDoesNotContainMessage(testMessage, EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Program
private static string tcUnitTargetNetId = "127.0.0.1.1.1";
private static VisualStudioInstance vsInstance = null;
private static ILog log = LogManager.GetLogger("TcUnit-Verifier");
private static int expectedNumberOfFailedTests = 112; // Update this if you add intentionally failing tests
private static int expectedNumberOfFailedTests = 115; // Update this if you add intentionally failing tests

[STAThread]
static int Main(string[] args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ VAR_INPUT
InputULINT AT %I* : ULINT;
InputUSINT AT %I* : USINT;
InputWORD AT %I* : WORD;
InputWSTRING AT %I* : WSTRING;
END_VAR
VAR
VarBOOL : BOOL;
Expand All @@ -50,6 +51,7 @@ VAR
VarULINT : ULINT;
VarUSINT : USINT;
VarWORD : WORD;
VarWSTRING : WSTRING;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[]]></ST>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Test_ANY_SINT_Equals();
Test_ANY_SINT_Differ();
Test_ANY_STRING_Equals();
Test_ANY_STRING_Differ();
Test_ANY_STRING_Differ_2();
Test_ANY_TIME_Equals();
Test_ANY_TIME_Differ();
Test_ANY_TIME_OF_DAY_Equals();
Expand All @@ -53,7 +54,10 @@ Test_ANY_ULINT_Differ();
Test_ANY_USINT_Equals();
Test_ANY_USINT_Differ();
Test_ANY_WORD_Equals();
Test_ANY_WORD_Differ();]]></ST>
Test_ANY_WORD_Differ();
Test_ANY_WSTRING_Equals();
Test_ANY_WSTRING_Differ();
Test_ANY_WSTRING_Differ_2();]]></ST>
</Implementation>
<Method Name="Test_ANY_BOOL_Differ" Id="{9def4202-9b1d-4fca-a694-7baecaa73c6d}">
<Declaration><![CDATA[METHOD PRIVATE Test_ANY_BOOL_Differ
Expand Down Expand Up @@ -484,6 +488,22 @@ AssertEquals(Expected := a,
Actual := b,
Message := 'Values differ');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="Test_ANY_STRING_Differ_2" Id="{1979c19d-5f81-4ca1-b2ab-1e735e3c2f9f}">
<Declaration><![CDATA[METHOD PRIVATE Test_ANY_STRING_Differ_2
VAR
a : STRING := 'This is a string';
b : STRING := 'This is b string';
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('Test_ANY_STRING_Differ_2');
AssertEquals(Expected := a,
Actual := b,
Message := 'Values differ');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
Expand Down Expand Up @@ -724,6 +744,54 @@ AssertEquals(Expected := a,
Actual := b,
Message := 'Values differ');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="Test_ANY_WSTRING_Differ" Id="{47cc195f-2b65-4c94-84a6-ca1ea74f987f}">
<Declaration><![CDATA[METHOD PRIVATE Test_ANY_WSTRING_Differ
VAR
a : WSTRING := "äö";
b : WSTRING := "æå";
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('Test_ANY_WSTRING_Differ');
AssertEquals(Expected := a,
Actual := b,
Message := 'Values differ');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="Test_ANY_WSTRING_Differ_2" Id="{edbbe9e9-fe3b-4d3b-8d0a-cb170d68100f}">
<Declaration><![CDATA[METHOD PRIVATE Test_ANY_WSTRING_Differ_2
VAR
a : WSTRING := "äö◦";
b : WSTRING := "æå";
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('Test_ANY_WSTRING_Differ_2');
AssertEquals(Expected := a,
Actual := b,
Message := 'Values differ');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="Test_ANY_WSTRING_Equals" Id="{2359fafa-0714-42b0-8ab4-3be6341813c5}">
<Declaration><![CDATA[METHOD PRIVATE Test_ANY_WSTRING_Equals
VAR
a : WSTRING := "ĠĦ";
b : WSTRING := "ĠĦ";
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('Test_ANY_WSTRING_Equals');
AssertEquals(Expected := a,
Actual := b,
Message := 'Values differ');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ TEST_FINISHED();]]></ST>
<Method Name="Test_WSTRING" Id="{cd24edfa-28c7-4bf7-ad9e-262f073a3ddf}">
<Declaration><![CDATA[METHOD PRIVATE Test_WSTRING
VAR
a : WSTRING := "This is a random string";
a : WSTRING := "åäöĦ";
result : U_ExpectedOrActual;
END_VAR]]></Declaration>
<Implementation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ VAR
aWORD : WORD := 16#ABCD;
bWORD : WORD := 16#89EF;
END_VAR
]]></Declaration>
aWSTRING : WSTRING := "åäöĦ";
bWSTRING : WSTRING := "åäöŅ";
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('TwiceAssertCall');
Expand Down Expand Up @@ -175,6 +177,10 @@ AssertEquals_WORD(Expected := aWORD,
Actual := bWORD,
Message := 'Not equal WORD');
AssertEquals_WSTRING(Expected := aWSTRING,
Actual := bWSTRING,
Message := 'Not equal WSTRING');
AssertCount := AssertCount + 1;
IF AssertCount = 2 THEN
TEST_FINISHED();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ Test_ULINT_Differ();
Test_USINT_Equals();
Test_USINT_Differ();
Test_WORD_Equals();
Test_WORD_Differ();]]></ST>
Test_WORD_Differ();
Test_WSTRING_Equals();
Test_WSTRING_Differ();]]></ST>
</Implementation>
<Method Name="Test_ANY_Differ_DataType" Id="{727d1587-a665-48c7-a3e8-8439592b1864}">
<Declaration><![CDATA[METHOD PRIVATE Test_ANY_Differ_DataType
Expand Down Expand Up @@ -758,6 +760,38 @@ AssertEquals_WORD(Expected := a,
Actual := b,
Message := 'Values differ');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="Test_WSTRING_Differ" Id="{8fbeeeba-b533-41a8-91bb-389fcf0748bd}">
<Declaration><![CDATA[METHOD PRIVATE Test_WSTRING_Differ
VAR
a : WSTRING := "äö";
b : WSTRING := "æåŅ";
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('Test_WSTRING_Differ');
AssertEquals_WSTRING(Expected := a,
Actual := b,
Message := 'Values differ');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="Test_WSTRING_Equals" Id="{d7d2e6c7-63c9-4daa-904c-3a5afe4aeb59}">
<Declaration><![CDATA[METHOD PRIVATE Test_WSTRING_Equals
VAR
a : WSTRING := "ŏŜŢ";
b : WSTRING := "ŏŜŢ";
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('Test_WSTRING_Equals');
AssertEquals_WSTRING(Expected := a,
Actual := b,
Message := 'Values differ');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Test_WRITE_PROTECTED_UDINT();
Test_WRITE_PROTECTED_UINT();
Test_WRITE_PROTECTED_USINT();
Test_WRITE_PROTECTED_ULINT();
Test_WRITE_PROTECTED_WORD();]]></ST>
Test_WRITE_PROTECTED_WORD();
Test_WRITE_PROTECTED_WSTRING();]]></ST>
</Implementation>
<Method Name="Test_WRITE_PROTECTED_BOOL" Id="{11a2dddd-2fbe-4039-a6b5-d4eaf7d9434c}">
<Declaration><![CDATA[METHOD Test_WRITE_PROTECTED_BOOL
Expand Down Expand Up @@ -364,6 +365,23 @@ AssertEquals_WORD(1, ProtectedVariables.InputWORD, 'Overwriting protected InputW
WRITE_PROTECTED_WORD(ADR(ProtectedVariables.VarWORD), 1);
AssertEquals_WORD(1, ProtectedVariables.VarWORD, 'Overwriting protected VarWORD');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="Test_WRITE_PROTECTED_WSTRING" Id="{2de6c70d-8caa-48f3-bf87-e9275e199bed}">
<Declaration><![CDATA[METHOD Test_WRITE_PROTECTED_WSTRING
VAR
ProtectedVariables : FB_ProtectedVariables;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('Test_WRITE_PROTECTED_WSTRING');
WRITE_PROTECTED_WSTRING(ADR(ProtectedVariables.InputWSTRING), "ŢŶǮ");
AssertEquals_WSTRING("ŢŶǮ", ProtectedVariables.InputWSTRING, 'Overwriting protected InputWSTRING');
WRITE_PROTECTED_WSTRING(ADR(ProtectedVariables.VarWSTRING), "ŢŶǮ");
AssertEquals_WSTRING("ŢŶǮ", ProtectedVariables.VarWSTRING, 'Overwriting protected VarWSTRING');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
Expand Down
6 changes: 3 additions & 3 deletions TcUnit/TcUnit/DUTs/E_AssertionType.TcDUT
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ TYPE E_AssertionType :
Type_ULINT,
Type_USINT,
Type_WORD,
Type_WSTRING,
(* Array types *)
Type_Array2D_LREAL,
Type_Array2D_REAL,
Expand All @@ -52,7 +53,6 @@ TYPE E_AssertionType :
Type_Array_USINT,
Type_Array_WORD
) BYTE;
END_TYPE
]]></Declaration>
END_TYPE]]></Declaration>
</DUT>
</TcPlcObject>
2 changes: 1 addition & 1 deletion TcUnit/TcUnit/DUTs/ST_TestSuiteResults.TcDUT
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ STRUCT
NumberOfTestCases : UINT; // The total number of test cases (for all test suites)
NumberOfSuccessfulTestCases : UINT; // The total number of test cases that had all ASSERTS successful
NumberOfFailedTestCases : UINT; // The total number of test cases that had at least one ASSERT failed
(* Test results for each individiual test suite *)
TestSuiteResults : ARRAY[1..GVL_Param_TcUnit.MaxNumberOfTestSuites] OF ST_TestSuiteResult;
END_STRUCT
Expand Down
Loading

0 comments on commit 13276ed

Please sign in to comment.