Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | // | |||
2 | // Created by FDSoftware on 21/04/25. | |||
3 | // | |||
4 | #include "pch.h" | |||
5 | ||||
6 | #include "main_loop.h" | |||
7 | #include "main_loop_controller.h" | |||
8 | #define MAIN_LOOP_RATE 1000 | |||
9 | ||||
10 | 4 | TEST(MainLoop, hzForPeriodTest){ | ||
11 | // Invalid value, should return 0 | |||
12 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(hzForPeriod((LoopPeriod)-1), 0); | |
13 | // valid value | |||
14 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(hzForPeriod(LoopPeriod::Period500hz), 500); | |
15 | 1 | } | ||
16 | ||||
17 | 4 | TEST(MainLoop, loopCountsTest){ | ||
18 | // valid value | |||
19 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(loopCounts<LoopPeriod::Period500hz>(), 2); | |
20 | // valid value | |||
21 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(loopCounts<LoopPeriod::Period1000hz>(), 1); | |
22 | 1 | } | ||
23 | ||||
24 | 4 | TEST(MainLoop, makePeriodFlagTest){ | ||
25 | // no in exec time, should be None | |||
26 | 1 | mainLoop.m_cycleCounter = 501; | ||
27 |
3/7✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 time.
✗ Branch 16 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
|
1 | EXPECT_EQ(mainLoop.makePeriodFlag<LoopPeriod::Period500hz>(), LoopPeriod::None); | |
28 | // valid value | |||
29 | 1 | mainLoop.m_cycleCounter = 1000; | ||
30 |
3/7✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 time.
✗ Branch 16 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
|
1 | EXPECT_EQ(mainLoop.makePeriodFlag<LoopPeriod::Period500hz>(), LoopPeriod::Period500hz); | |
31 | // valid value 200Hz | |||
32 | 1 | mainLoop.m_cycleCounter = 1000; | ||
33 |
3/7✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 time.
✗ Branch 16 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
|
1 | EXPECT_EQ(mainLoop.makePeriodFlag<LoopPeriod::Period200hz>(), LoopPeriod::Period200hz); | |
34 | // invalid value 200Hz | |||
35 | 1 | mainLoop.m_cycleCounter = 343; | ||
36 |
3/7✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 time.
✗ Branch 16 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
|
1 | EXPECT_EQ(mainLoop.makePeriodFlag<LoopPeriod::Period200hz>(), LoopPeriod::None); | |
37 | 1 | } | ||
38 | ||||
39 | 4 | TEST(MainLoop, operatorTest){ | ||
40 | 1 | mainLoop.m_cycleCounter = 500; | ||
41 | 1 | LoopPeriod lp = mainLoop.makePeriodFlags(); | ||
42 | ||||
43 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period1000hz); | |
44 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period500hz); | |
45 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period250hz); | |
46 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period200hz); | |
47 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period20hz); | |
48 | ||||
49 | // update time | |||
50 | 1 | mainLoop.m_cycleCounter = 60; | ||
51 | 1 | lp = mainLoop.makePeriodFlags(); | ||
52 | ||||
53 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period1000hz); | |
54 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period500hz); | |
55 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period250hz); | |
56 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period200hz); | |
57 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_FALSE(lp & LoopPeriod::Period20hz); | |
58 | ||||
59 | // update time | |||
60 | 1 | mainLoop.m_cycleCounter = 0; | ||
61 | 1 | lp = mainLoop.makePeriodFlags(); | ||
62 | ||||
63 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period1000hz); | |
64 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period500hz); | |
65 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period250hz); | |
66 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period200hz); | |
67 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period20hz); | |
68 | ||||
69 | // update time | |||
70 | 1 | mainLoop.m_cycleCounter = 1000; | ||
71 | 1 | lp = mainLoop.makePeriodFlags(); | ||
72 | ||||
73 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period1000hz); | |
74 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period500hz); | |
75 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period250hz); | |
76 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period200hz); | |
77 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period20hz); | |
78 | ||||
79 | // update time | |||
80 | 1 | mainLoop.m_cycleCounter = 423; | ||
81 | 1 | lp = mainLoop.makePeriodFlags(); | ||
82 | ||||
83 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_TRUE(lp & LoopPeriod::Period1000hz); | |
84 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_FALSE(lp & LoopPeriod::Period500hz); | |
85 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_FALSE(lp & LoopPeriod::Period250hz); | |
86 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_FALSE(lp & LoopPeriod::Period20hz); | |
87 |
1/6✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_FALSE(lp & LoopPeriod::Period200hz); | |
88 | ||||
89 | 1 | auto operatorResult = LoopPeriod::None & LoopPeriod::Period500hz; | ||
90 |
1/6✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
|
1 | EXPECT_FALSE(operatorResult); | |
91 | 1 | } | ||
92 |