|
1 | | -// USING Simatic.Ax.Generators; |
2 | | -// USING Simatic.Ax.Mocks; |
3 | | - |
4 | | -// NAMESPACE Simatic.Ax.Generators.Test |
5 | | -// {TestFixture} |
6 | | -// CLASS TestActiveWait |
7 | | -// VAR |
8 | | -// _state : OnDelayMockState; |
9 | | -// testInstance : PulseGenerator; |
10 | | -// END_VAR |
| 1 | +USING Simatic.Ax.Generators; |
| 2 | +USING Simatic.Ax.Mocks; |
| 3 | +USING System.Timer; |
| 4 | +NAMESPACE Simatic.Ax.Generators.Test |
| 5 | + {TestFixture} |
| 6 | + CLASS TestActiveWait |
| 7 | + VAR |
| 8 | + _state : OnDelayMockState; |
| 9 | + testInstance : PulseGenerator; |
| 10 | + END_VAR |
11 | 11 |
|
12 | | -// {Test} |
13 | | -// METHOD PUBLIC Test_One_Clock_Cycle_Expect_True_False_True |
14 | | -// VAR_TEMP |
15 | | -// res : BOOL; |
16 | | -// END_VAR |
17 | | -// testInstance.PulseTime := T#1s; // give the mocked timer an value to distiguish in the mock |
18 | | -// testInstance.PauseTime := T#2s; |
19 | | - |
20 | | -// // Initial state --> Clock returns true, no timer is running |
21 | | -// _state.StatusTimer1 := FALSE; |
22 | | -// _state.StatusTimer2 := FALSE; |
23 | | - |
24 | | -// AxUnit.Mocking.Mock('System.Timer.OnDelay', NAME_OF(OnDelayMock2Timer), THIS._state); |
25 | | -// testInstance.Execute(); |
26 | | -// res := testInstance.Q(); |
27 | | -// AxUnit.Assert.Equal(TRUE, res); |
| 12 | + {Test} |
| 13 | + METHOD PUBLIC Test_One_Clock_Cycle_Expect_True_False_True |
| 14 | + VAR_TEMP |
| 15 | + res : BOOL; |
| 16 | + END_VAR |
| 17 | + testInstance.PulseTime := T#1s; // give the mocked timer an value to distiguish in the mock |
| 18 | + testInstance.PauseTime := T#2s; |
| 19 | + |
| 20 | + // Initial state --> Clock returns true, no timer is running |
| 21 | + _state.StatusTimer1 := FALSE; |
| 22 | + _state.StatusTimer2 := FALSE; |
| 23 | + |
| 24 | + AxUnit.Mocking.Mock(NAME_OF(OnDelay), NAME_OF(OnDelayMock2Timer), _state); |
| 25 | + testInstance.Execute(); |
| 26 | + res := testInstance.Q(); |
| 27 | + AxUnit.Assert.Equal(TRUE, res); |
28 | 28 |
|
29 | | -// // second cycle --> Clock returns still true |
30 | | -// testInstance.Execute(); |
31 | | - |
32 | | -// res := testInstance.Q(); |
33 | | -// AxUnit.Assert.Equal(TRUE, res); |
34 | | - |
35 | | -// // third cycle --> PulseTime has elapsed --> Clock returns false |
36 | | -// _state.StatusTimer1 := TRUE; |
37 | | -// _state.StatusTimer2 := FALSE; |
38 | | -// testInstance.Execute(); |
39 | | -// res := testInstance.Q(); |
40 | | -// AxUnit.Assert.Equal(FALSE, res); |
| 29 | + // second cycle --> Clock returns still true |
| 30 | + testInstance.Execute(); |
| 31 | + |
| 32 | + res := testInstance.Q(); |
| 33 | + AxUnit.Assert.Equal(TRUE, res); |
| 34 | + |
| 35 | + // third cycle --> PulseTime has elapsed --> Clock returns false |
| 36 | + _state.StatusTimer1 := TRUE; |
| 37 | + _state.StatusTimer2 := FALSE; |
| 38 | + testInstance.Execute(); |
| 39 | + res := testInstance.Q(); |
| 40 | + AxUnit.Assert.Equal(FALSE, res); |
41 | 41 |
|
42 | | -// // 4th Cycle --> Clock returns still false. PauseTimer is running but is not elapsed |
43 | | -// _state.StatusTimer1 := FALSE; |
44 | | -// _state.StatusTimer2 := FALSE; |
45 | | -// testInstance.Execute(); |
46 | | -// res := testInstance.Q(); |
47 | | -// AxUnit.Assert.Equal(FALSE, res); |
48 | | - |
49 | | -// // 5th cycle --> PauseTime has elapsed --> Clock returns false |
50 | | -// _state.StatusTimer1 := FALSE; |
51 | | -// _state.StatusTimer2 := TRUE; |
52 | | -// testInstance.Execute(); |
53 | | -// res := testInstance.Q(); |
54 | | -// AxUnit.Assert.Equal(TRUE, res); |
55 | | -// END_METHOD |
| 42 | + // 4th Cycle --> Clock returns still false. PauseTimer is running but is not elapsed |
| 43 | + _state.StatusTimer1 := FALSE; |
| 44 | + _state.StatusTimer2 := FALSE; |
| 45 | + testInstance.Execute(); |
| 46 | + res := testInstance.Q(); |
| 47 | + AxUnit.Assert.Equal(FALSE, res); |
| 48 | + |
| 49 | + // 5th cycle --> PauseTime has elapsed --> Clock returns false |
| 50 | + _state.StatusTimer1 := FALSE; |
| 51 | + _state.StatusTimer2 := TRUE; |
| 52 | + testInstance.Execute(); |
| 53 | + res := testInstance.Q(); |
| 54 | + AxUnit.Assert.Equal(TRUE, res); |
| 55 | + END_METHOD |
56 | 56 |
|
57 | | -// END_CLASS |
| 57 | + END_CLASS |
58 | 58 |
|
59 | | -// END_NAMESPACE |
| 59 | +END_NAMESPACE |
60 | 60 |
|
61 | 61 |
|
62 | 62 |
|
|
0 commit comments