| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #include "pch.h" | |||
| 2 | ||||
| 3 | #include "can_listener.h" | |||
| 4 | ||||
| 5 | using ::testing::StrictMock; | |||
| 6 | using ::testing::_; | |||
| 7 | ||||
| 8 | class MockCanListener : public CanListener { | |||
| 9 | public: | |||
| 10 |
1/1✓ Branch 3 taken 2 times.
|
2 | MockCanListener(uint32_t id) : CanListener(id) { } | |
| 11 | ||||
| 12 |
3/3✓ Branch 3 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
|
2 | MOCK_METHOD(void, decodeFrame, (const CANRxFrame& frame, efitick_t nowNt), (override)); | |
| 13 |
3/3✓ Branch 3 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
|
4 | MOCK_METHOD(bool, acceptFrame, (const size_t busIndex, const CANRxFrame& frame), (const, override)); | |
| 14 | }; | |||
| 15 | ||||
| 16 | 4 | TEST(CanListener, FrameAccepted) { | ||
| 17 |
1/1✓ Branch 3 taken 1 time.
|
1 | StrictMock<MockCanListener> dut(0x123); | |
| 18 | ||||
| 19 | 1 | CANRxFrame frame; | ||
| 20 | ||||
| 21 | // Accept should be called, returns true | |||
| 22 |
8/8✓ Branch 3 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 14 taken 1 time.
✓ Branch 18 taken 1 time.
✓ Branch 23 taken 1 time.
✓ Branch 26 taken 1 time.
✓ Branch 29 taken 1 time.
|
1 | EXPECT_CALL(dut, acceptFrame(0, _)).WillOnce(Return(true)); | |
| 23 | ||||
| 24 | // Because accept returns true, decode is called | |||
| 25 |
5/5✓ Branch 3 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 14 taken 1 time.
✓ Branch 18 taken 1 time.
|
1 | EXPECT_CALL(dut, decodeFrame(_, 1234)); | |
| 26 | ||||
| 27 |
1/1✓ Branch 1 taken 1 time.
|
1 | dut.processFrame(0, frame, 1234); | |
| 28 | 2 | } | ||
| 29 | ||||
| 30 | 4 | TEST(CanListener, FrameNotAccepted) { | ||
| 31 |
1/1✓ Branch 3 taken 1 time.
|
1 | StrictMock<MockCanListener> dut(0x123); | |
| 32 | ||||
| 33 | 1 | CANRxFrame frame; | ||
| 34 | ||||
| 35 | // Accept should be called, returns false, so decode not called | |||
| 36 |
8/8✓ Branch 3 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 14 taken 1 time.
✓ Branch 18 taken 1 time.
✓ Branch 23 taken 1 time.
✓ Branch 26 taken 1 time.
✓ Branch 29 taken 1 time.
|
1 | EXPECT_CALL(dut, acceptFrame(0, _)).WillOnce(Return(false)); | |
| 37 | ||||
| 38 |
1/1✓ Branch 1 taken 1 time.
|
1 | dut.processFrame(0, frame, 1234); | |
| 39 | 2 | } | ||
| 40 | ||||
| 41 | struct CanListenerNoDecode : public CanListener { | |||
| 42 | 2 | CanListenerNoDecode(uint32_t id) : CanListener(id) { } | ||
| 43 | ||||
| 44 | ✗ | void decodeFrame(const CANRxFrame& frame, efitick_t nowNt) override { } | ||
| 45 | }; | |||
| 46 | ||||
| 47 | 4 | TEST(CanListener, FrameAcceptedChecksId) { | ||
| 48 | 1 | CanListenerNoDecode dut(0x123); | ||
| 49 | ||||
| 50 | 1 | CANRxFrame frame; | ||
| 51 | ||||
| 52 | 1 | frame.SID = 0x123; | ||
| 53 | 1 | frame.IDE = false; | ||
| 54 | ||||
| 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(dut.acceptFrame(0, frame)); | |
| 56 | 1 | } | ||
| 57 | ||||
| 58 | 4 | TEST(CanListener, FrameNotAcceptedChecksId) { | ||
| 59 | 1 | CanListenerNoDecode dut(0x123); | ||
| 60 | ||||
| 61 | 1 | CANRxFrame frame; | ||
| 62 | ||||
| 63 | 1 | frame.SID = 0x456; | ||
| 64 | 1 | frame.IDE = false; | ||
| 65 | ||||
| 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_FALSE(dut.acceptFrame(0, frame)); | |
| 67 | 1 | } | ||
| 68 |