Skip to content

Commit

Permalink
move tests in another file
Browse files Browse the repository at this point in the history
  • Loading branch information
sjuergen committed Oct 11, 2024
1 parent f635a5a commit a80c480
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/TwoWayActuatorTest.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ USING AxUnit.Assert;
NAMESPACE Simatic.Ax.axftcmlib

{TestFixture}
CLASS TwoWayActuatorTest
CLASS TwoWayActuatorTest_old
VAR PROTECTED
_actuator : TwoWayActuator;
_actuatorStateLess : TwoWayActuator;
Expand Down
124 changes: 124 additions & 0 deletions test/test.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
USING Simatic.Ax.IO.Input;
USING Simatic.Ax.Commands;
USING Simatic.Ax.axftcmlib;
USING Simatic.Ax.IO.Output;
USING AxUnit.Assert;

NAMESPACE Simatic.Ax.axftcmlib

{TestFixture}
CLASS TwoWayActuatorTest
VAR PROTECTED
_actuator : TwoWayActuator;
_actuatorStateLess : TwoWayActuator;
_qToWork : BinOutput;
_qToHome : BinOutput;
_outputStateLess : BinOutput;
_iInHomePos : BinSignal;
_iInWorkPos : BinSignal;
_binSignalStateless : BinSignal;
cmd : itfCommand;
done : BOOL;
busy : BOOL;
END_VAR

{TestSetup}
METHOD PUBLIC SetUp
_actuator := _actuatorStateLess;
_actuator.Q_ToWorkPosition := _qToWork;
_actuator.Q_ToHomePosition := _qToHome;
_actuator.I_InHomePosition := _iInHomePos;
_actuator.I_InWorkPosition := _iInWorkPos;
_iInHomePos := _binSignalStateless;
_iInWorkPos := _binSignalStateless;
_qToWork := _outputStateLess;
_qToHome := _outputStateLess;
busy := FALSE;
cmd := NULL;
END_METHOD

{Test}
METHOD PUBLIC GoToWorkPosition_Swiches_Q_ToWorkPosition_On_And_Returns_Busy
cmd := _actuator.GoToWorkPosition();
busy := cmd.Busy();
AxUnit.Assert.Equal(expected := TRUE, actual := busy);
AxUnit.Assert.Equal(expected := TRUE, actual := _qToWork.IsOn());
AxUnit.Assert.Equal(expected := FALSE, actual := _qToHome.IsOn());
Equal(expected := TRUE, actual := _actuator.GetState() = ActuatorState#MoveToWorkPosition);
END_METHOD

{Test}
METHOD PUBLIC GoToWorkPosition_Returns_Done_When_end_position_is_already_reached
_iInWorkPos.ReadCyclic(signal := TRUE);
cmd := _actuator.GoToWorkPosition();
busy := cmd.Busy();
IF NOT(busy) THEN
done := cmd.Done();
END_IF;
AxUnit.Assert.Equal(expected := FALSE, actual := busy);
AxUnit.Assert.Equal(expected := TRUE, actual := done);
AxUnit.Assert.Equal(expected := FALSE, actual := _qToWork.IsOn());
AxUnit.Assert.Equal(expected := FALSE, actual := _qToHome.IsOn());
Equal(expected := TRUE, actual := _actuator.GetState() = ActuatorState#InWorkPosition);
END_METHOD

{Test}
METHOD PUBLIC Reaching_WorkPosition_Switches_Q_ToWorkPosition_Off_And_Returns_Done
THIS.GoToWorkPosition_Swiches_Q_ToWorkPosition_On_And_Returns_Busy();
_iInWorkPos.ReadCyclic(signal := TRUE);
busy := cmd.Busy();
IF NOT(busy) THEN
done := cmd.Done();
END_IF;
AxUnit.Assert.Equal(expected := FALSE, actual := busy);
AxUnit.Assert.Equal(expected := TRUE, actual := done);
AxUnit.Assert.Equal(expected := FALSE, actual := _qToWork.IsOn());
AxUnit.Assert.Equal(expected := FALSE, actual := _qToHome.IsOn());
Equal(expected := TRUE, actual := _actuator.GetState() = ActuatorState#InWorkPosition);
END_METHOD


// Test Home Position
{Test}
METHOD PUBLIC GoToHomePosition_Swiches_Q_ToHomePosition_On_And_Returns_Busy
cmd := _actuator.GoToHomePosition();
busy := cmd.Busy();
AxUnit.Assert.Equal(expected := TRUE, actual := busy);
AxUnit.Assert.Equal(expected := FALSE, actual := _qToWork.IsOn());
AxUnit.Assert.Equal(expected := TRUE, actual := _qToHome.IsOn());
Equal(expected := TRUE, actual := _actuator.GetState() = ActuatorState#MoveToHomePosition);
END_METHOD

{Test}
METHOD PUBLIC GoToHomePosition_Returns_Done_When_end_position_is_already_reached
_iInHomePos.ReadCyclic(signal := TRUE);
cmd := _actuator.GoToHomePosition();
busy := cmd.Busy();
IF NOT(busy) THEN
done := cmd.Done();
END_IF;
AxUnit.Assert.Equal(expected := FALSE, actual := busy);
AxUnit.Assert.Equal(expected := TRUE, actual := done);
AxUnit.Assert.Equal(expected := FALSE, actual := _qToWork.IsOn());
AxUnit.Assert.Equal(expected := FALSE, actual := _qToHome.IsOn());
Equal(expected := TRUE, actual := _actuator.GetState() = ActuatorState#InHomePosition);
END_METHOD

{Test}
METHOD PUBLIC Reaching_HomePosition_Switches_Q_ToHomePosition_Off_And_Returns_Done
THIS.GoToHomePosition_Swiches_Q_ToHomePosition_On_And_Returns_Busy();
_iInHomePos.ReadCyclic(signal := TRUE);
busy := cmd.Busy();
IF NOT(busy) THEN
done := cmd.Done();
END_IF;
AxUnit.Assert.Equal(expected := FALSE, actual := busy);
AxUnit.Assert.Equal(expected := TRUE, actual := done);
AxUnit.Assert.Equal(expected := FALSE, actual := _qToWork.IsOn());
AxUnit.Assert.Equal(expected := FALSE, actual := _qToHome.IsOn());
Equal(expected := TRUE, actual := _actuator.GetState() = ActuatorState#InHomePosition);
END_METHOD
END_CLASS

END_NAMESPACE

0 comments on commit a80c480

Please sign in to comment.