GCC Code Coverage Report


Directory: ./
File: unit_tests/tests/lua/test_can_filter.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 100.0% 24 0 24
Functions: 100.0% 9 0 9
Branches: 32.0% 16 0 50
Decisions: -% 0 - 0

Line Branch Decision Exec Source
1 #include "pch.h"
2 #include "can_filter.h"
3
4 4 TEST(CanFilterTest, acceptAny) {
5 1 CanFilter filterAny;
6
7 1 filterAny.Id = 0;
8 1 filterAny.Mask = 0;
9
10
2/8
✗ 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.
✓ Branch 31 taken 1 time.
✗ Branch 32 not taken.
1 ASSERT_TRUE(filterAny.accept(1));
11
2/8
✗ 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.
✓ Branch 31 taken 1 time.
✗ Branch 32 not taken.
1 ASSERT_TRUE(filterAny.accept(239));
12 }
13
14 4 TEST(CanFilterTest, acceptOnlyExact) {
15 1 CanFilter filterSpecific;
16
17 1 filterSpecific.Id = 239;
18 1 filterSpecific.Mask = FILTER_SPECIFIC;
19
20
2/8
✗ 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.
✓ Branch 31 taken 1 time.
✗ Branch 32 not taken.
1 ASSERT_FALSE(filterSpecific.accept(1));
21
2/8
✗ 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.
✓ Branch 31 taken 1 time.
✗ Branch 32 not taken.
1 ASSERT_TRUE(filterSpecific.accept(239));
22 }
23
24 #define CALLBACK_ALL 3
25 #define CALLBACK_239 5
26
27 4 TEST(CanFilterTest, orderOfBusinessOne) {
28 1 resetLuaCanRx();
29
30 // accept everything as first filter
31 1 addLuaCanRxFilter(/*eid*/0, 0, ANY_BUS, CALLBACK_ALL);
32
33 1 addLuaCanRxFilter(/*eid*/239, FILTER_SPECIFIC, ANY_BUS, CALLBACK_239);
34
35 // filters are applied in the order in which those were added
36
4/9
✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✓ Branch 29 taken 1 time.
✗ Branch 30 not taken.
1 ASSERT_EQ(CALLBACK_ALL, getFilterForId(/*bus*/0, /*id*/ 0)->Callback);
37
4/9
✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✓ Branch 29 taken 1 time.
✗ Branch 30 not taken.
1 ASSERT_EQ(CALLBACK_ALL, getFilterForId(/*bus*/0, /*id*/ 239)->Callback);
38 }
39
40 TEST(CanFilterTest, orderOfBusinessTwo) {
41 resetLuaCanRx();
42
43 addLuaCanRxFilter(/*eid*/239, FILTER_SPECIFIC, ANY_BUS, CALLBACK_239);
44 // accept everything as last filter
45 addLuaCanRxFilter(/*eid*/0, 0, ANY_BUS, CALLBACK_ALL);
46
47 // filters are applied in the order in which those were added
48 ASSERT_EQ(CALLBACK_ALL, getFilterForId(/*bus*/0, /*id*/ 0)->Callback);
49 ASSERT_EQ(CALLBACK_239, getFilterForId(/*bus*/0, /*id*/ 239)->Callback);
50 }
51