Added more components
This commit is contained in:
188
PLC/POUs/Unittests/ReleaseSignalTests/FB_ReleaseSignalTest.TcPOU
Normal file
188
PLC/POUs/Unittests/ReleaseSignalTests/FB_ReleaseSignalTest.TcPOU
Normal file
@@ -0,0 +1,188 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<POU Name="FB_ReleaseSignalTest" Id="{8b18b04a-432b-48e8-9173-e18ffc6e0a72}" SpecialFunc="None">
|
||||
<Declaration><![CDATA[FUNCTION_BLOCK FB_ReleaseSignalTest EXTENDS TcUnit.FB_TestSuite
|
||||
VAR
|
||||
// variables for onTimeTest
|
||||
_fbReleaseSignalWithOnTime : FB_ReleaseSignal;
|
||||
_fbOnTimer : TON;
|
||||
_xTestWithOnTimeFinished : BOOL := FALSE;
|
||||
|
||||
// variables for offTimeTest
|
||||
_fbReleaseSignalWithOffTime : FB_ReleaseSignal;
|
||||
_fbOffTimer : TON;
|
||||
_xTestWithOffTimeFinished : BOOL := FALSE;
|
||||
_xSignalForOffTest : BOOL := TRUE;
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[// run tests with different time behaviour
|
||||
TestWithoutTime();
|
||||
TestWithOnTime();
|
||||
TestWithOffTime();]]></ST>
|
||||
</Implementation>
|
||||
<Method Name="TestWithOffTime" Id="{59bccf19-8c18-4516-9bfc-d8ecab97a196}">
|
||||
<Declaration><![CDATA[METHOD TestWithOffTime
|
||||
VAR
|
||||
// result
|
||||
_xReturnValue : BOOL;
|
||||
END_VAR
|
||||
|
||||
VAR CONSTANT
|
||||
// off timing
|
||||
timOffTime : TIME := T#100MS;
|
||||
END_VAR]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[TEST('TestWithOffTime');
|
||||
|
||||
// Test off time delay
|
||||
_fbReleaseSignalWithOffTime(
|
||||
xSignal:= _xSignalForOffTest,
|
||||
xRelease:= TRUE,
|
||||
timOnDelay:= T#0MS,
|
||||
timOffDelay:= timOffTime,
|
||||
xReleaseSignal=> _xReturnValue);
|
||||
|
||||
// Start timer after which the output of the Signal fb will be checked
|
||||
_fbOffTimer(IN := TRUE, PT := (timOffTime + T#50MS));
|
||||
|
||||
IF _xSignalForOffTest THEN
|
||||
_xSignalForOffTest := FALSE;
|
||||
END_IF
|
||||
|
||||
// Signal must be true at the start of the test
|
||||
// If not, abort the test
|
||||
IF _xSignalForOffTest AND (NOT _xReturnValue) THEN
|
||||
AssertTrue(Condition := _xReturnValue, Message := 'Signal not true at start of test');
|
||||
_xTestWithOffTimeFinished := TRUE;
|
||||
END_IF
|
||||
|
||||
// Check value after a time which is longer than the signal delay time
|
||||
IF NOT _fbOffTimer.Q THEN
|
||||
IF (NOT _xReturnValue) THEN
|
||||
AssertFalse(Condition := _xReturnValue, Message := 'Signal was false before the time was over');
|
||||
_fbOnTimer.IN := FALSE;
|
||||
_xTestWithOffTimeFinished := TRUE;
|
||||
END_IF
|
||||
ELSE
|
||||
AssertFalse(Condition := _xReturnValue, Message := 'Signal was not false after the time elapsed');
|
||||
_fbOnTimer.IN := FALSE;
|
||||
_xTestWithOffTimeFinished := TRUE;
|
||||
END_IF
|
||||
|
||||
IF _xTestWithOffTimeFinished THEN
|
||||
TEST_FINISHED();
|
||||
END_IF]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
<Method Name="TestWithOnTime" Id="{adc27bca-ad94-40db-8c4a-cead392adedc}">
|
||||
<Declaration><![CDATA[METHOD TestWithOnTime
|
||||
VAR
|
||||
// result
|
||||
_xReturnValue : BOOL;
|
||||
END_VAR
|
||||
|
||||
VAR CONSTANT
|
||||
// on timing
|
||||
timOnTime : TIME := T#100MS;
|
||||
END_VAR]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[TEST('TestWithOnTime');
|
||||
|
||||
// Test on time delay
|
||||
_fbReleaseSignalWithOnTime(
|
||||
xSignal:= TRUE,
|
||||
xRelease:= TRUE,
|
||||
timOnDelay:= timOnTime,
|
||||
timOffDelay:= T#0MS,
|
||||
xReleaseSignal=> _xReturnValue);
|
||||
|
||||
// Start timer after which the output of the Signal fb will be checked
|
||||
_fbOnTimer(IN := TRUE, PT := (timOnTime + T#50MS));
|
||||
|
||||
// Check value after a time which is longer than the signal delay time
|
||||
IF NOT _fbOnTimer.Q THEN
|
||||
IF _xReturnValue THEN
|
||||
AssertTrue(Condition := _xReturnValue, Message := 'Signal was true before the time was over');
|
||||
_fbOnTimer.IN := FALSE;
|
||||
_xTestWithOnTimeFinished := TRUE;
|
||||
END_IF
|
||||
ELSE
|
||||
AssertTrue(Condition := _xReturnValue, Message := 'Signal was not true after the time elapsed');
|
||||
_fbOnTimer.IN := FALSE;
|
||||
_xTestWithOnTimeFinished := TRUE;
|
||||
END_IF
|
||||
|
||||
IF _xTestWithOnTimeFinished THEN
|
||||
TEST_FINISHED();
|
||||
END_IF]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
<Method Name="TestWithoutTime" Id="{394513b0-dc3f-4f97-9cfc-0254521f5ce3}">
|
||||
<Declaration><![CDATA[METHOD TestWithoutTime
|
||||
VAR
|
||||
// reslease signal instance
|
||||
_fbReleaseSignal : FB_ReleaseSignal;
|
||||
|
||||
// input signal
|
||||
_xSignal : BOOL;
|
||||
|
||||
// expected result
|
||||
_xExpected : BOOL;
|
||||
|
||||
// release result
|
||||
_xReturnValue : BOOL;
|
||||
|
||||
// release signal
|
||||
_xRelease : BOOL := TRUE;
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[TEST('TestWithoutTime');
|
||||
|
||||
// Test with active release
|
||||
_xRelease := TRUE;
|
||||
|
||||
// Test low signal
|
||||
_xSignal := FALSE;
|
||||
_xExpected := FALSE;
|
||||
_fbReleaseSignal(
|
||||
xSignal:= _xSignal,
|
||||
xRelease:= _xRelease,
|
||||
timOnDelay:= T#0MS,
|
||||
timOffDelay:= T#0MS,
|
||||
xReleaseSignal=> _xReturnValue);
|
||||
|
||||
AssertEquals(Expected:= _xExpected, Actual:= _xReturnValue, Message:= 'Signal is not false');
|
||||
|
||||
|
||||
// Test high signal
|
||||
_xSignal := TRUE;
|
||||
_xExpected := TRUE;
|
||||
_fbReleaseSignal(
|
||||
xSignal:= _xSignal,
|
||||
xRelease:= _xRelease,
|
||||
timOnDelay:= T#0MS,
|
||||
timOffDelay:= T#0MS,
|
||||
xReleaseSignal=> _xReturnValue);
|
||||
|
||||
AssertEquals(Expected:= _xExpected, Actual:= _xReturnValue, Message:= 'Signal is not true');
|
||||
|
||||
// Test with inactive release
|
||||
_xRelease := FALSE;
|
||||
_xSignal := TRUE;
|
||||
_xExpected := FALSE;
|
||||
_fbReleaseSignal(
|
||||
xSignal:= _xSignal,
|
||||
xRelease:= _xRelease,
|
||||
timOnDelay:= T#0MS,
|
||||
timOffDelay:= T#0MS,
|
||||
xReleaseSignal=> _xReturnValue);
|
||||
|
||||
AssertEquals(Expected:= _xExpected, Actual:= _xReturnValue, Message:= 'Signal is not false with no active release');
|
||||
|
||||
TEST_FINISHED();]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
</POU>
|
||||
</TcPlcObject>
|
||||
Reference in New Issue
Block a user