GCC Code Coverage Report


Directory: ./
File: unit_tests/tests/lua/test_bit_range_msb.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 100.0% 65 0 65
Functions: 100.0% 24 0 24
Branches: 45.1% 69 0 153
Decisions: -% 0 - 0

Line Branch Decision Exec Source
1 //
2 // Created by kifir on 11/8/24.
3 //
4
5 #include "pch.h"
6
7 #include "lua_lib.h"
8
9 // inspired by TEST(LuaE65, offtopicTestGetBitRangeMsb) from test_lua_e65.cpp
10 4 TEST(BitRangeMsbTest, offtopicTestGetBitRangeMsb) {
11 // 1001 1111 0100 0001 0011 0010 0010 0000 0010 0011 0011 0000 1111 1111 0100 0011
12 // ^------------^
13 1 uint8_t data[] = { 0x9F, 0x41, 0x32, 0x20, 0x23, 0x30, 0xFF, 0x43 };
14
15
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(getBitRangeMsb(data, 12, 12), 0x9F4); // 1001 1111 0100
16 1 }
17
18 // inspired by TEST(LuaE65, offtopicTestGetBitRangeMsb2) from test_lua_e65.cpp
19 4 TEST(BitRangeMsbTest, offtopicTestGetBitRangeMsb2) {
20 // 0111 0000 0000 0100 0001 1111
21 // ^-----------------^
22 1 uint8_t data[] = { 0x70, 0x04, 0x1F};
23
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(getBitRangeMsb(data, 16, 16), 0x41F); // 0111 0000 0000 0100
24 1 }
25
26 // inspired by TEST(LuaE65, offtopicTestSetBitRangeMsb2) from test_lua_e65.cpp
27 4 TEST(BitRangeMsbTest, offtopicTestSetBitRangeMsb2) {
28 // 1000 0000 0111
29 // v------------v
30 // 0110 1000 0000 0111
31 1 uint8_t data[] = { 0x68, 0x07 };
32
1/1
✓ Branch 1 taken 1 time.
1 setBitRangeMsb(data, 8, 13, 0x807); // 1000 0000 0111
33
4/8
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
✓ Branch 12 taken 1 time.
✗ Branch 19 not taken.
✓ Branch 20 taken 1 time.
✗ Branch 23 not taken.
✗ Branch 28 not taken.
✗ Branch 31 not taken.
1 EXPECT_THAT(data, testing::ElementsAre(0x68, 0x07));
34
35
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(getBitRangeMsb(data, 8, 13), 0x807);
36 1 }
37
38 // inspired by TEST(LuaE65, offtopicTestSetBitRangeMsb3) from test_lua_e65.cpp
39 4 TEST(BitRangeMsbTest, offtopicTestSetBitRangeMsb3) {
40 // 0011 0000 0100
41 // v------------v
42 // 0110 1000 0000 0111
43 1 uint8_t data[] = { 0x68, 0x07 };
44
1/1
✓ Branch 1 taken 1 time.
1 setBitRangeMsb(data, 8, 13, 0x304); // 0011 0000 0100
45
4/8
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
✓ Branch 12 taken 1 time.
✗ Branch 19 not taken.
✓ Branch 20 taken 1 time.
✗ Branch 23 not taken.
✗ Branch 28 not taken.
✗ Branch 31 not taken.
1 EXPECT_THAT(data, testing::ElementsAre(0x63, 0x04));
46
47
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(getBitRangeMsb(data, 8, 13), 0x304);
48 1 }
49
50 // inspired by TEST(LuaE65, offtopicTestGetBitRangeMsb2) from test_lua_e65.cpp
51 4 TEST(BitRangeMsbTest, getBitRangeMsbTest) {
52 // 1001 1111 0000 0001 0011 0010 0010 0000 0010 0011 0110 0111 0100 0000 0000 0000
53 // ^------------^
54 1 uint8_t data[] = { 0x9F, 0x01, 0x32, 0x20, 0x23, 0x67, 0x40, 0x00 };
55
56
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(getBitRangeMsb(data, 6 * 8, 13), 0x740); // 0111 0100 0000
57 1 }
58
59 // inspired by TEST(LuaE65, setBitRangeMsbTest) from test_lua_e65.cpp
60 4 TEST(BitRangeMsbTest, setBitRangeMsbTest) {
61 // v--------------v
62 // 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
63 1 uint8_t data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
64
1/1
✓ Branch 1 taken 1 time.
1 setBitRangeMsb(data, 6 * 8, 13, 0x740); // 0111 0100 0000
65
4/8
✓ Branch 12 taken 1 time.
✓ Branch 15 taken 1 time.
✓ Branch 18 taken 1 time.
✗ Branch 31 not taken.
✓ Branch 32 taken 1 time.
✗ Branch 35 not taken.
✗ Branch 40 not taken.
✗ Branch 43 not taken.
1 EXPECT_THAT(
66 data,
67 // 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0111 0100 0000 0000 0000
68 testing::ElementsAre(0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x40, 0x00)
69 1 );
70
71
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(getBitRangeMsb(data, 6 * 8, 13), 0x740);
72 1 }
73
74 4 TEST(BitRangeMsbTest, getBitRangeMsbTest1) {
75 // 0000 0000 1111 1111 0000 0000
76 1 uint8_t data[] = {0x00, 0xFF, 0x00};
77
78 // 0000 0000 1111 1111 0000 0000
79 // ^-------^
80
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(getBitRangeMsb(data, 8, 8), 0xFF); // 1111 1111
81
82 // 0000 0000 1111 1111 0000 0000
83 // ^--------^
84
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(getBitRangeMsb(data, 9, 8), 0x7F); // 0111 1111
85
86 // 0000 0000 1111 1111 0000 0000
87 // ^--------^
88
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(getBitRangeMsb(data, 23, 8), 0xFE); // 1111 1110
89
90 // 0000 0000 1111 1111 0000 0000
91 // ^---------^
92
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(getBitRangeMsb(data, 23, 9), 0x1FE); // 0001 1111 1110
93
94 // 0000 0000 1111 1111 0000 0000
95 // ^---------^
96
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(getBitRangeMsb(data, 8, 9), 0x0FF); // 0 1111 1111
97
98 // 0000 0000 1111 1111 0000 0000
99 // ^-----------^
100
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(getBitRangeMsb(data, 23, 10), 0x1FE); // 0001 1111 1110
101 1 }
102
103 4 TEST(BitRangeMsbTest, getBitRangeMsbTest2) {
104 // 1111 1111 0111 1110 1111 1111
105 1 uint8_t data[] = {0xFF, 0x7E, 0xFF};
106
107 // 1111 1111 0111 1110 1111 1111
108 // ^-------^
109
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(getBitRangeMsb(data, 8, 8), 0x7E); // 0111 1110
110
111 // 1111 1111 0111 1110 1111 1111
112 // ^--------^
113
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(getBitRangeMsb(data, 9, 8), 0xBF); // 1011 1111
114
115 // 1111 1111 0111 1110 1111 1111
116 // ^--------^
117
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(getBitRangeMsb(data, 23, 8), 0xFD); // 1111 1101
118
119 // 1111 1111 0111 1110 1111 1111
120 // ^---------^
121
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(getBitRangeMsb(data, 23, 9), 0x0FD); // 0000 1111 1101
122
123 // 1111 1111 0111 1110 1111 1111
124 // ^---------^
125
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(getBitRangeMsb(data, 8, 9), 0x17E); // 0001 0111 1110
126
127 // 1111 1111 0111 1110 1111 1111
128 // ^-----------^
129
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_NE(getBitRangeMsb(data, 23, 10), 0x2FD); // 0010 1111 1101
130 1 }
131