From 9b62e218868b809df745d3e53ef49be241f39f95 Mon Sep 17 00:00:00 2001 From: Jakob Sagatowski Date: Sun, 9 Dec 2018 17:22:19 +0100 Subject: [PATCH] Solved issue #2 "Add functionality to make it possible to ASSERT arrays". --- TcUnit/TcUnit/POUs/FB_Assert.TcPOU | 709 +++++++++++++++++++++++++++++ 1 file changed, 709 insertions(+) diff --git a/TcUnit/TcUnit/POUs/FB_Assert.TcPOU b/TcUnit/TcUnit/POUs/FB_Assert.TcPOU index b27f155..62a024e 100644 --- a/TcUnit/TcUnit/POUs/FB_Assert.TcPOU +++ b/TcUnit/TcUnit/POUs/FB_Assert.TcPOU @@ -542,6 +542,607 @@ IF NOT AlreadyReported AND NOT Equals THEN ActualString := CONCAT(STR1 := ActualString, STR2 := LINT_TO_STRING(Actuals[ActualsIndex])); END_IF + AssertMessageFormatter.LogAssertFailure(Expected := ExpectedString, + Actual := ActualString, + Message := Message, + TestInstancePath := TestInstancePath); +END_IF]]> + + + + + + SizeOfActuals THEN + Equals := FALSE; + SizeEquals := FALSE; +ELSE + (* Even though we know that both arrays are equal in size, the two arrays can start at two completely different + indexes, which needs to be taken into account for. *) + ExpectedsIndex := LOWER_BOUND(Expecteds, 1); // The start position for the expecteds + ActualsIndex := LOWER_BOUND(Actuals, 1); // The start position for the actuals + FOR Index := 1 TO SizeOfExpecteds BY 1 DO + IF Expecteds[ExpectedsIndex] <> Actuals[ActualsIndex] THEN + Equals := FALSE; + EXIT; + END_IF + ExpectedsIndex := ExpectedsIndex + 1; + ActualsIndex := ActualsIndex + 1; + END_FOR +END_IF + +AssertResults.ReportResult(Expected := Expecteds, + Actual := Actuals, + Message := Message, + TestInstancePath := TestInstancePath, + AlreadyReported => AlreadyReported); + +IF NOT AlreadyReported AND NOT Equals THEN + SetTestFailed(); + + IF NOT SizeEquals THEN + Message := CONCAT(STR1 := Message, STR2 := ', size of arrays not matching.'); + ExpectedString := 'SIZE = '; + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(SizeOfExpecteds)); + ActualString := 'SIZE = '; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(SizeOfActuals)); + ELSE + ExpectedDWordString := Tc2_Standard.CONCAT(STR1 := '0x', + STR2 := Tc2_Utilities.LWORD_TO_HEXSTR(in := Expecteds[ExpectedsIndex], + iPrecision := 16, + bLoCase := FALSE)); + ExpectedString := 'ARRAY['; + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(ExpectedsIndex)); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := '] = '); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := ExpectedDWordString); + + ActualDWordString := Tc2_Standard.CONCAT(STR1 := '0x', + STR2 := Tc2_Utilities.LWORD_TO_HEXSTR(in := Actuals[ActualsIndex], + iPrecision := 16, + bLoCase := FALSE)); + ActualString := 'ARRAY['; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(ActualsIndex)); + ActualString := CONCAT(STR1 := ActualString, STR2 := '] = '); + ActualString := CONCAT(STR1 := ActualString, STR2 := ActualDWordString); + END_IF + + AssertMessageFormatter.LogAssertFailure(Expected := ExpectedString, + Actual := ActualString, + Message := Message, + TestInstancePath := TestInstancePath); +END_IF]]> + + + + + + SizeOfActuals THEN + Equals := FALSE; + SizeEquals := FALSE; +ELSE + (* Even though we know that both arrays are equal in size, the two arrays can start at two completely different + indexes, which needs to be taken into account for. *) + ExpectedsIndex := LOWER_BOUND(Expecteds, 1); // The start position for the expecteds + ActualsIndex := LOWER_BOUND(Actuals, 1); // The start position for the actuals + FOR Index := 1 TO SizeOfExpecteds BY 1 DO + IF Expecteds[ExpectedsIndex] <> Actuals[ActualsIndex] THEN + Equals := FALSE; + EXIT; + END_IF + ExpectedsIndex := ExpectedsIndex + 1; + ActualsIndex := ActualsIndex + 1; + END_FOR +END_IF + +AssertResults.ReportResult(Expected := Expecteds, + Actual := Actuals, + Message := Message, + TestInstancePath := TestInstancePath, + AlreadyReported => AlreadyReported); + +IF NOT AlreadyReported AND NOT Equals THEN + SetTestFailed(); + + IF NOT SizeEquals THEN + Message := CONCAT(STR1 := Message, STR2 := ', size of arrays not matching.'); + ExpectedString := 'SIZE = '; + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(SizeOfExpecteds)); + ActualString := 'SIZE = '; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(SizeOfActuals)); + ELSE + ExpectedString := 'ARRAY['; + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(ExpectedsIndex)); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := '] = '); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := SINT_TO_STRING(Expecteds[ExpectedsIndex])); + + ActualString := 'ARRAY['; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(ActualsIndex)); + ActualString := CONCAT(STR1 := ActualString, STR2 := '] = '); + ActualString := CONCAT(STR1 := ActualString, STR2 := SINT_TO_STRING(Actuals[ActualsIndex])); + END_IF + + AssertMessageFormatter.LogAssertFailure(Expected := ExpectedString, + Actual := ActualString, + Message := Message, + TestInstancePath := TestInstancePath); +END_IF]]> + + + + + + SizeOfActuals THEN + Equals := FALSE; + SizeEquals := FALSE; +ELSE + (* Even though we know that both arrays are equal in size, the two arrays can start at two completely different + indexes, which needs to be taken into account for. *) + ExpectedsIndex := LOWER_BOUND(Expecteds, 1); // The start position for the expecteds + ActualsIndex := LOWER_BOUND(Actuals, 1); // The start position for the actuals + FOR Index := 1 TO SizeOfExpecteds BY 1 DO + IF Expecteds[ExpectedsIndex] <> Actuals[ActualsIndex] THEN + Equals := FALSE; + EXIT; + END_IF + ExpectedsIndex := ExpectedsIndex + 1; + ActualsIndex := ActualsIndex + 1; + END_FOR +END_IF + +AssertResults.ReportResult(Expected := Expecteds, + Actual := Actuals, + Message := Message, + TestInstancePath := TestInstancePath, + AlreadyReported => AlreadyReported); + +IF NOT AlreadyReported AND NOT Equals THEN + SetTestFailed(); + + IF NOT SizeEquals THEN + Message := CONCAT(STR1 := Message, STR2 := ', size of arrays not matching.'); + ExpectedString := 'SIZE = '; + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(SizeOfExpecteds)); + ActualString := 'SIZE = '; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(SizeOfActuals)); + ELSE + ExpectedString := 'ARRAY['; + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(ExpectedsIndex)); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := '] = '); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := UDINT_TO_STRING(Expecteds[ExpectedsIndex])); + + ActualString := 'ARRAY['; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(ActualsIndex)); + ActualString := CONCAT(STR1 := ActualString, STR2 := '] = '); + ActualString := CONCAT(STR1 := ActualString, STR2 := UDINT_TO_STRING(Actuals[ActualsIndex])); + END_IF + + AssertMessageFormatter.LogAssertFailure(Expected := ExpectedString, + Actual := ActualString, + Message := Message, + TestInstancePath := TestInstancePath); +END_IF]]> + + + + + + SizeOfActuals THEN + Equals := FALSE; + SizeEquals := FALSE; +ELSE + (* Even though we know that both arrays are equal in size, the two arrays can start at two completely different + indexes, which needs to be taken into account for. *) + ExpectedsIndex := LOWER_BOUND(Expecteds, 1); // The start position for the expecteds + ActualsIndex := LOWER_BOUND(Actuals, 1); // The start position for the actuals + FOR Index := 1 TO SizeOfExpecteds BY 1 DO + IF Expecteds[ExpectedsIndex] <> Actuals[ActualsIndex] THEN + Equals := FALSE; + EXIT; + END_IF + ExpectedsIndex := ExpectedsIndex + 1; + ActualsIndex := ActualsIndex + 1; + END_FOR +END_IF + +AssertResults.ReportResult(Expected := Expecteds, + Actual := Actuals, + Message := Message, + TestInstancePath := TestInstancePath, + AlreadyReported => AlreadyReported); + +IF NOT AlreadyReported AND NOT Equals THEN + SetTestFailed(); + + IF NOT SizeEquals THEN + Message := CONCAT(STR1 := Message, STR2 := ', size of arrays not matching.'); + ExpectedString := 'SIZE = '; + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(SizeOfExpecteds)); + ActualString := 'SIZE = '; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(SizeOfActuals)); + ELSE + ExpectedString := 'ARRAY['; + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(ExpectedsIndex)); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := '] = '); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := UINT_TO_STRING(Expecteds[ExpectedsIndex])); + + ActualString := 'ARRAY['; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(ActualsIndex)); + ActualString := CONCAT(STR1 := ActualString, STR2 := '] = '); + ActualString := CONCAT(STR1 := ActualString, STR2 := UINT_TO_STRING(Actuals[ActualsIndex])); + END_IF + + AssertMessageFormatter.LogAssertFailure(Expected := ExpectedString, + Actual := ActualString, + Message := Message, + TestInstancePath := TestInstancePath); +END_IF]]> + + + + + + SizeOfActuals THEN + Equals := FALSE; + SizeEquals := FALSE; +ELSE + (* Even though we know that both arrays are equal in size, the two arrays can start at two completely different + indexes, which needs to be taken into account for. *) + ExpectedsIndex := LOWER_BOUND(Expecteds, 1); // The start position for the expecteds + ActualsIndex := LOWER_BOUND(Actuals, 1); // The start position for the actuals + FOR Index := 1 TO SizeOfExpecteds BY 1 DO + IF Expecteds[ExpectedsIndex] <> Actuals[ActualsIndex] THEN + Equals := FALSE; + EXIT; + END_IF + ExpectedsIndex := ExpectedsIndex + 1; + ActualsIndex := ActualsIndex + 1; + END_FOR +END_IF + +AssertResults.ReportResult(Expected := Expecteds, + Actual := Actuals, + Message := Message, + TestInstancePath := TestInstancePath, + AlreadyReported => AlreadyReported); + +IF NOT AlreadyReported AND NOT Equals THEN + SetTestFailed(); + + IF NOT SizeEquals THEN + Message := CONCAT(STR1 := Message, STR2 := ', size of arrays not matching.'); + ExpectedString := 'SIZE = '; + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(SizeOfExpecteds)); + ActualString := 'SIZE = '; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(SizeOfActuals)); + ELSE + ExpectedString := 'ARRAY['; + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(ExpectedsIndex)); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := '] = '); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := ULINT_TO_STRING(Expecteds[ExpectedsIndex])); + + ActualString := 'ARRAY['; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(ActualsIndex)); + ActualString := CONCAT(STR1 := ActualString, STR2 := '] = '); + ActualString := CONCAT(STR1 := ActualString, STR2 := ULINT_TO_STRING(Actuals[ActualsIndex])); + END_IF + + AssertMessageFormatter.LogAssertFailure(Expected := ExpectedString, + Actual := ActualString, + Message := Message, + TestInstancePath := TestInstancePath); +END_IF]]> + + + + + + SizeOfActuals THEN + Equals := FALSE; + SizeEquals := FALSE; +ELSE + (* Even though we know that both arrays are equal in size, the two arrays can start at two completely different + indexes, which needs to be taken into account for. *) + ExpectedsIndex := LOWER_BOUND(Expecteds, 1); // The start position for the expecteds + ActualsIndex := LOWER_BOUND(Actuals, 1); // The start position for the actuals + FOR Index := 1 TO SizeOfExpecteds BY 1 DO + IF Expecteds[ExpectedsIndex] <> Actuals[ActualsIndex] THEN + Equals := FALSE; + EXIT; + END_IF + ExpectedsIndex := ExpectedsIndex + 1; + ActualsIndex := ActualsIndex + 1; + END_FOR +END_IF + +AssertResults.ReportResult(Expected := Expecteds, + Actual := Actuals, + Message := Message, + TestInstancePath := TestInstancePath, + AlreadyReported => AlreadyReported); + +IF NOT AlreadyReported AND NOT Equals THEN + SetTestFailed(); + + IF NOT SizeEquals THEN + Message := CONCAT(STR1 := Message, STR2 := ', size of arrays not matching.'); + ExpectedString := 'SIZE = '; + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(SizeOfExpecteds)); + ActualString := 'SIZE = '; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(SizeOfActuals)); + ELSE + ExpectedString := 'ARRAY['; + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(ExpectedsIndex)); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := '] = '); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := USINT_TO_STRING(Expecteds[ExpectedsIndex])); + + ActualString := 'ARRAY['; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(ActualsIndex)); + ActualString := CONCAT(STR1 := ActualString, STR2 := '] = '); + ActualString := CONCAT(STR1 := ActualString, STR2 := USINT_TO_STRING(Actuals[ActualsIndex])); + END_IF + + AssertMessageFormatter.LogAssertFailure(Expected := ExpectedString, + Actual := ActualString, + Message := Message, + TestInstancePath := TestInstancePath); +END_IF]]> + + + + + + SizeOfActuals THEN + Equals := FALSE; + SizeEquals := FALSE; +ELSE + (* Even though we know that both arrays are equal in size, the two arrays can start at two completely different + indexes, which needs to be taken into account for. *) + ExpectedsIndex := LOWER_BOUND(Expecteds, 1); // The start position for the expecteds + ActualsIndex := LOWER_BOUND(Actuals, 1); // The start position for the actuals + FOR Index := 1 TO SizeOfExpecteds BY 1 DO + IF Expecteds[ExpectedsIndex] <> Actuals[ActualsIndex] THEN + Equals := FALSE; + EXIT; + END_IF + ExpectedsIndex := ExpectedsIndex + 1; + ActualsIndex := ActualsIndex + 1; + END_FOR +END_IF + +AssertResults.ReportResult(Expected := Expecteds, + Actual := Actuals, + Message := Message, + TestInstancePath := TestInstancePath, + AlreadyReported => AlreadyReported); + +IF NOT AlreadyReported AND NOT Equals THEN + SetTestFailed(); + + IF NOT SizeEquals THEN + Message := CONCAT(STR1 := Message, STR2 := ', size of arrays not matching.'); + ExpectedString := 'SIZE = '; + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(SizeOfExpecteds)); + ActualString := 'SIZE = '; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(SizeOfActuals)); + ELSE + ExpectedDWordString := Tc2_Standard.CONCAT(STR1 := '0x', + STR2 := Tc2_Utilities.WORD_TO_HEXSTR(in := Expecteds[ExpectedsIndex], + iPrecision := 4, + bLoCase := FALSE)); + ExpectedString := 'ARRAY['; + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(ExpectedsIndex)); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := '] = '); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := ExpectedDWordString); + + ActualDWordString := Tc2_Standard.CONCAT(STR1 := '0x', + STR2 := Tc2_Utilities.WORD_TO_HEXSTR(in := Actuals[ActualsIndex], + iPrecision := 4, + bLoCase := FALSE)); + ActualString := 'ARRAY['; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(ActualsIndex)); + ActualString := CONCAT(STR1 := ActualString, STR2 := '] = '); + ActualString := CONCAT(STR1 := ActualString, STR2 := ActualDWordString); + END_IF + AssertMessageFormatter.LogAssertFailure(Expected := ExpectedString, Actual := ActualString, Message := Message, @@ -1356,6 +1957,114 @@ END_FOR]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +