From d658a4293187b2878daf427506e94eb374d489d9 Mon Sep 17 00:00:00 2001 From: Jakob Sagatowski Date: Sun, 9 Dec 2018 11:37:00 +0100 Subject: [PATCH] Started implementation of array assertions. --- TcUnit/TcUnit/POUs/FB_Assert.TcPOU | 274 +++++++++++++++++++++ TcUnit/TcUnit/TcUnit.plcproj | 22 +- TcUnit/TcUnit/Version/Global_Version.TcGVL | 2 +- 3 files changed, 286 insertions(+), 12 deletions(-) diff --git a/TcUnit/TcUnit/POUs/FB_Assert.TcPOU b/TcUnit/TcUnit/POUs/FB_Assert.TcPOU index caa83dd..df7e84d 100644 --- a/TcUnit/TcUnit/POUs/FB_Assert.TcPOU +++ b/TcUnit/TcUnit/POUs/FB_Assert.TcPOU @@ -31,6 +31,241 @@ END_VAR]]> AddTestNameToInstancePath := Tc2_Utilities.CONCAT(STR1 := CompleteTestInstancePath, STR2 := GVL.CurrentTestNameBeingCalled);]]> + + + + LOWER_BOUND(Actuals, 1)) OR + (UPPER_BOUND(Expecteds, 1) <> UPPER_BOUND(Actuals, 1)) THEN + SizeOfExpecteds := UPPER_BOUND(Expecteds, 1) - LOWER_BOUND(Expecteds, 1) + 1; + SizeOfActuals := UPPER_BOUND(Actuals, 1) - LOWER_BOUND(Actuals, 1) + 1; + Equals := FALSE; + SizeEquals := FALSE; +ELSE + FOR Index := LOWER_BOUND(Expecteds, 1) TO UPPER_BOUND(Expecteds, 1) DO + IF Expecteds[Index] <> Actuals[Index] THEN + Equals := FALSE; + EXIT; + END_IF + 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(Index)); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := '] = '); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := BOOL_TO_STRING(Expecteds[Index])); + + ActualString := 'ARRAY['; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(Index)); + ActualString := CONCAT(STR1 := ActualString, STR2 := '] = '); + ActualString := CONCAT(STR1 := ActualString, STR2 := BOOL_TO_STRING(Actuals[Index])); + END_IF + + AssertMessageFormatter.LogAssertFailure(Expected := ExpectedString, + Actual := ActualString, + Message := Message, + TestInstancePath := TestInstancePath); +END_IF]]> + + + + + + LOWER_BOUND(Actuals, 1)) OR + (UPPER_BOUND(Expecteds, 1) <> UPPER_BOUND(Actuals, 1)) THEN + SizeOfExpecteds := UPPER_BOUND(Expecteds, 1) - LOWER_BOUND(Expecteds, 1) + 1; + SizeOfActuals := UPPER_BOUND(Actuals, 1) - LOWER_BOUND(Actuals, 1) + 1; + Equals := FALSE; + SizeEquals := FALSE; +ELSE + FOR Index := LOWER_BOUND(Expecteds, 1) TO UPPER_BOUND(Expecteds, 1) DO + IF Expecteds[Index] <> Actuals[Index] THEN + Equals := FALSE; + EXIT; + END_IF + 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 + ExpectedByteString := Tc2_Standard.CONCAT(STR1 := '0x', + STR2 := Tc2_Utilities.BYTE_TO_HEXSTR(in := Expecteds[Index], + iPrecision := 2, + bLoCase := FALSE)); + ExpectedString := 'ARRAY['; + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(Index)); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := '] = '); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := ExpectedByteString); + + ActualByteString := Tc2_Standard.CONCAT(STR1 := '0x', + STR2 := Tc2_Utilities.BYTE_TO_HEXSTR(in := Actuals[Index], + iPrecision := 2, + bLoCase := FALSE)); + ActualString := 'ARRAY['; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(Index)); + ActualString := CONCAT(STR1 := ActualString, STR2 := '] = '); + ActualString := CONCAT(STR1 := ActualString, STR2 := ActualByteString); + END_IF + + AssertMessageFormatter.LogAssertFailure(Expected := ExpectedString, + Actual := ActualString, + Message := Message, + TestInstancePath := TestInstancePath); +END_IF]]> + + + + + + LOWER_BOUND(Actuals, 1)) OR + (UPPER_BOUND(Expecteds, 1) <> UPPER_BOUND(Actuals, 1)) THEN + SizeOfExpecteds := UPPER_BOUND(Expecteds, 1) - LOWER_BOUND(Expecteds, 1) + 1; + SizeOfActuals := UPPER_BOUND(Actuals, 1) - LOWER_BOUND(Actuals, 1) + 1; + Equals := FALSE; + SizeEquals := FALSE; +ELSE + FOR Index := LOWER_BOUND(Expecteds, 1) TO UPPER_BOUND(Expecteds, 1) DO + IF Expecteds[Index] <> Actuals[Index] THEN + Equals := FALSE; + EXIT; + END_IF + 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(Index)); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := '] = '); + ExpectedString := CONCAT(STR1 := ExpectedString, STR2 := DINT_TO_STRING(Expecteds[Index])); + + ActualString := 'ARRAY['; + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(Index)); + ActualString := CONCAT(STR1 := ActualString, STR2 := '] = '); + ActualString := CONCAT(STR1 := ActualString, STR2 := DINT_TO_STRING(Actuals[Index])); + END_IF + + AssertMessageFormatter.LogAssertFailure(Expected := ExpectedString, + Actual := ActualString, + Message := Message, + TestInstancePath := TestInstancePath); +END_IF]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TcUnit/TcUnit/TcUnit.plcproj b/TcUnit/TcUnit/TcUnit.plcproj index df4f0f3..f28f7c1 100644 --- a/TcUnit/TcUnit/TcUnit.plcproj +++ b/TcUnit/TcUnit/TcUnit.plcproj @@ -32,7 +32,7 @@ Documentation and examples are available at www.tcunit.org www.tcunit.org Jakob Sagatowski and other contributors, see AUTHORS file on www.github.com/tcunit/TcUnit - 0.3.0.0 + 0.4.0.0 @@ -148,8 +148,8 @@ Documentation and examples are available at www.tcunit.org - - + + "<ProjectRoot>" {192FAD59-8248-4824-A8DE-9177C94C195A} @@ -204,14 +204,14 @@ Documentation and examples are available at www.tcunit.org - - - System.Boolean - System.Collections.Hashtable - {54dd0eac-a6d8-46f2-8c27-2f43c7e49861} - System.String - - + + + System.Boolean + System.Collections.Hashtable + {54dd0eac-a6d8-46f2-8c27-2f43c7e49861} + System.String + +