Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion apax-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
},
"devDependencies": {
"@ax/sdk": "^2504.0.0",
"@simatic-ax/snippetscollection": "^1.0.0"
"@simatic-ax/snippetscollection": "^1.0.0",
"@ax/axunit-mocking": "^8.0.33"
},
"catalogs": {
"@ax/simatic-ax": "^2504.0.0"
Expand Down Expand Up @@ -50,6 +51,17 @@
"@ax/trace": "2.9.0"
}
},
"@ax/axunit-mocking": {
"name": "@ax/axunit-mocking",
"version": "8.0.33",
"integrity": "sha512-lv5kR6zmh1kBaAoeDwhx2/WiXkenf8QTRY04xVTv1vbM55V1eLq/B4L2Zp7muPGBmyhlck1rJ12IGiv0LuBi6Q==",
"resolved": "https://registry.simatic-ax.siemens.io/@ax/axunit-mocking/-/axunit-mocking-8.0.33.tgz",
"dependencies": {
"@ax/target-mocking": "8.0.33",
"@ax/mocking-library": "8.0.33",
"@ax/mocking-ls-contrib": "8.0.33"
}
},
"@ax/system-timer": {
"name": "@ax/system-timer",
"version": "10.0.24",
Expand Down Expand Up @@ -295,6 +307,30 @@
"@ax/trace-linux-x64": "2.9.0"
}
},
"@ax/target-mocking": {
"name": "@ax/target-mocking",
"version": "8.0.33",
"integrity": "sha512-2lFVgj16QNoFgDVMoa+9vL4+i8+D47VIP73ENEChMfea+5UOBZ/zAcy4VGQiJ5wqLOirkk3NHLjyJCrp0e45iQ==",
"resolved": "https://registry.simatic-ax.siemens.io/@ax/target-mocking/-/target-mocking-8.0.33.tgz",
"dependencies": {
"@ax/target-mocking-linux-x64": "8.0.33",
"@ax/target-mocking-win-x64": "8.0.33"
}
},
"@ax/mocking-library": {
"name": "@ax/mocking-library",
"version": "8.0.33",
"integrity": "sha512-QO3YsqI4JTrYSmWaGC8Rl/X7ks97EVT9++Y3h4rTO3ZFp7GATKyN6KokQoq1QDwKdODIR7TLtqGymsBdwL0tzQ==",
"resolved": "https://registry.simatic-ax.siemens.io/@ax/mocking-library/-/mocking-library-8.0.33.tgz",
"dependencies": {}
},
"@ax/mocking-ls-contrib": {
"name": "@ax/mocking-ls-contrib",
"version": "8.0.33",
"integrity": "sha512-Rhd89jqT/yPic9eCydHF/1F66xNNc+r+84aaoiSsx3Fyvey402ML0jsYcxwfx7SFoNJ8uOMCk1NPzljQd8Aqeg==",
"resolved": "https://registry.simatic-ax.siemens.io/@ax/mocking-ls-contrib/-/mocking-ls-contrib-8.0.33.tgz",
"dependencies": {}
},
"@ax/system-math": {
"name": "@ax/system-math",
"version": "10.0.24",
Expand Down Expand Up @@ -621,6 +657,32 @@
],
"dependencies": {}
},
"@ax/target-mocking-linux-x64": {
"name": "@ax/target-mocking-linux-x64",
"version": "8.0.33",
"integrity": "sha512-q+q0t7I0dpNGQIaEPJaAws4L5IbXfPGed3y08vbVYT7I6TEvGW0Pu40ZOJikvRCQ8SgBwiLycKgYzpFgkwB+VQ==",
"resolved": "https://registry.simatic-ax.siemens.io/@ax/target-mocking-linux-x64/-/target-mocking-linux-x64-8.0.33.tgz",
"os": [
"linux"
],
"cpu": [
"x64"
],
"dependencies": {}
},
"@ax/target-mocking-win-x64": {
"name": "@ax/target-mocking-win-x64",
"version": "8.0.33",
"integrity": "sha512-7UZ7LKBq4Pbw/PkbQ0C4+lwH1KKcsyUmOcYP7quXypJB7lbZpdkiuF+xF1osHs07iIJl1wAg3dQ1iuMsE0D66A==",
"resolved": "https://registry.simatic-ax.siemens.io/@ax/target-mocking-win-x64/-/target-mocking-win-x64-8.0.33.tgz",
"os": [
"win32"
],
"cpu": [
"x64"
],
"dependencies": {}
},
"@ax/st-docs": {
"name": "@ax/st-docs",
"version": "10.0.85",
Expand Down
6 changes: 4 additions & 2 deletions apax.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: This library contains a collection of signal generators
repository:
type: git
url: https://github.com/simatic-ax/generators

# Environment variables
variables:
APAX_BUILD_ARGS:
Expand All @@ -19,13 +19,15 @@ targets:
# Registry information, where the package will be published
registries:
'@simatic-ax': 'https://npm.pkg.github.com/'

# Dependencies
catalogs:
"@ax/simatic-ax": ^2504.0.0
devDependencies:
"@ax/sdk": ^2504.0.0
"@simatic-ax/snippetscollection": ^1.0.0
"@ax/axunit-mocking": ^8.0.33
# "@simatic-ax/mocks": ^3.0.0
dependencies:
"@simatic-ax/io": ^9.0.0
"@ax/system-timer": ^10.0.24
Expand Down
49 changes: 49 additions & 0 deletions test/OnDelayMockWithTwoTimers.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
NAMESPACE Simatic.Ax.Mocks
/// This Mock can be used in Classes/FunctionBlocks where are two OnDelay instances are used
{axcode:docs-v0:@simatic-ax/generators:OnDelayMockWithTwoTimers.md}
FUNCTION_BLOCK OnDelayMock2Timer
VAR
iecTimer : ARRAY[0..27] of BYTE;
END_VAR
VAR_INPUT
duration : LTIME;
signal : BOOL;
END_VAR
VAR_OUTPUT
output : BOOL;
elapsedTime : LTIME;
END_VAR
VAR_TEMP
state : REF_TO OnDelayMockState;
END_VAR
VAR PRIVATE
END_VAR
state ?= AxUnit.Mocking.GetPayload();
output := TRUE;

IF (signal = FALSE) THEN
output := FALSE;
ELSE
IF duration = T#1s THEN
output := state^.StatusTimer1;
END_IF;
IF duration = T#2s THEN
output := state^.StatusTimer2 ;
END_IF;
END_IF;

END_FUNCTION_BLOCK

/// The returned states for the Timer1 and Timer2
{axcode:docs-v0:@simatic-ax/generators:OnDelayMockWithTwoTimers.md}
CLASS OnDelayMockState IMPLEMENTS AxUnit.Mocking.IPayload
VAR PUBLIC
StatusTimer1 : BOOL;
StatusTimer2 : BOOL;
END_VAR
END_CLASS
END_NAMESPACE




108 changes: 54 additions & 54 deletions test/TestOnCycle.st
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
// USING Simatic.Ax.Generators;
// USING Simatic.Ax.Mocks;

// NAMESPACE Simatic.Ax.Generators.Test
// {TestFixture}
// CLASS TestActiveWait
// VAR
// _state : OnDelayMockState;
// testInstance : PulseGenerator;
// END_VAR
USING Simatic.Ax.Generators;
USING Simatic.Ax.Mocks;
USING System.Timer;
NAMESPACE Simatic.Ax.Generators.Test
{TestFixture}
CLASS TestActiveWait
VAR
_state : OnDelayMockState;
testInstance : PulseGenerator;
END_VAR

// {Test}
// METHOD PUBLIC Test_One_Clock_Cycle_Expect_True_False_True
// VAR_TEMP
// res : BOOL;
// END_VAR
// testInstance.PulseTime := T#1s; // give the mocked timer an value to distiguish in the mock
// testInstance.PauseTime := T#2s;

// // Initial state --> Clock returns true, no timer is running
// _state.StatusTimer1 := FALSE;
// _state.StatusTimer2 := FALSE;

// AxUnit.Mocking.Mock('System.Timer.OnDelay', NAME_OF(OnDelayMock2Timer), THIS._state);
// testInstance.Execute();
// res := testInstance.Q();
// AxUnit.Assert.Equal(TRUE, res);
{Test}
METHOD PUBLIC Test_One_Clock_Cycle_Expect_True_False_True
VAR_TEMP
res : BOOL;
END_VAR
testInstance.PulseTime := T#1s; // give the mocked timer an value to distiguish in the mock
testInstance.PauseTime := T#2s;

// Initial state --> Clock returns true, no timer is running
_state.StatusTimer1 := FALSE;
_state.StatusTimer2 := FALSE;

AxUnit.Mocking.Mock(NAME_OF(OnDelay), NAME_OF(OnDelayMock2Timer), _state);
testInstance.Execute();
res := testInstance.Q();
AxUnit.Assert.Equal(TRUE, res);

// // second cycle --> Clock returns still true
// testInstance.Execute();

// res := testInstance.Q();
// AxUnit.Assert.Equal(TRUE, res);

// // third cycle --> PulseTime has elapsed --> Clock returns false
// _state.StatusTimer1 := TRUE;
// _state.StatusTimer2 := FALSE;
// testInstance.Execute();
// res := testInstance.Q();
// AxUnit.Assert.Equal(FALSE, res);
// second cycle --> Clock returns still true
testInstance.Execute();

res := testInstance.Q();
AxUnit.Assert.Equal(TRUE, res);

// third cycle --> PulseTime has elapsed --> Clock returns false
_state.StatusTimer1 := TRUE;
_state.StatusTimer2 := FALSE;
testInstance.Execute();
res := testInstance.Q();
AxUnit.Assert.Equal(FALSE, res);

// // 4th Cycle --> Clock returns still false. PauseTimer is running but is not elapsed
// _state.StatusTimer1 := FALSE;
// _state.StatusTimer2 := FALSE;
// testInstance.Execute();
// res := testInstance.Q();
// AxUnit.Assert.Equal(FALSE, res);

// // 5th cycle --> PauseTime has elapsed --> Clock returns false
// _state.StatusTimer1 := FALSE;
// _state.StatusTimer2 := TRUE;
// testInstance.Execute();
// res := testInstance.Q();
// AxUnit.Assert.Equal(TRUE, res);
// END_METHOD
// 4th Cycle --> Clock returns still false. PauseTimer is running but is not elapsed
_state.StatusTimer1 := FALSE;
_state.StatusTimer2 := FALSE;
testInstance.Execute();
res := testInstance.Q();
AxUnit.Assert.Equal(FALSE, res);

// 5th cycle --> PauseTime has elapsed --> Clock returns false
_state.StatusTimer1 := FALSE;
_state.StatusTimer2 := TRUE;
testInstance.Execute();
res := testInstance.Q();
AxUnit.Assert.Equal(TRUE, res);
END_METHOD

// END_CLASS
END_CLASS

// END_NAMESPACE
END_NAMESPACE



Expand Down