Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | // | |||
2 | // Created by kifir on 11/11/24. | |||
3 | // | |||
4 | ||||
5 | #include "pch.h" | |||
6 | ||||
7 | namespace { | |||
8 | class MotorolaDbcTest : public testing::Test { | |||
9 | protected: | |||
10 | void SetUp() override; | |||
11 | ||||
12 | void checkRange( | |||
13 | int bitStart, | |||
14 | int length, | |||
15 | int testValue, | |||
16 | int expectedLSB, | |||
17 | const std::array<uint8_t, 8>& expectedData | |||
18 | ); | |||
19 | uint8_t* getTestDataPtr(); | |||
20 | ||||
21 | std::array<uint8_t, 8> testData; | |||
22 | }; | |||
23 | ||||
24 | 9 | void MotorolaDbcTest::SetUp() { | ||
25 |
1/1✓ Branch 2 taken 9 times.
|
9 | testData.fill(0x00); | |
26 | 9 | } | ||
27 | ||||
28 | 8 | void MotorolaDbcTest::checkRange( | ||
29 | const int bitStart, | |||
30 | const int length, | |||
31 | const int testValue, | |||
32 | const int expectedLSB, // Least Significant Bit | |||
33 | const std::array<uint8_t, 8>& expectedData | |||
34 | ) { | |||
35 |
3/7✓ Branch 5 taken 8 times.
✓ Branch 8 taken 8 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 8 times.
✗ Branch 17 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
|
8 | EXPECT_EQ(getBitRangeMoto(getTestDataPtr(), bitStart, length), 0x00); // 0000 | |
36 | ||||
37 |
4/9✓ Branch 3 taken 8 times.
✓ Branch 6 taken 8 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 8 times.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✓ Branch 29 taken 8 times.
✗ Branch 30 not taken.
|
8 | ASSERT_EQ(expectedLSB, motorolaMagicFromDbc(bitStart, length)); | |
38 | 8 | setBitRangeMoto(getTestDataPtr(), bitStart, length, testValue); | ||
39 | ||||
40 |
4/8✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
✓ Branch 10 taken 8 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 8 times.
✗ Branch 21 not taken.
✗ Branch 26 not taken.
✗ Branch 29 not taken.
|
8 | EXPECT_THAT(testData, testing::ElementsAreArray(expectedData)); | |
41 |
3/7✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 8 times.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
|
8 | EXPECT_EQ(getBitRangeMoto(getTestDataPtr(), bitStart, length), testValue); | |
42 | } | |||
43 | ||||
44 | 24 | uint8_t* MotorolaDbcTest::getTestDataPtr() { | ||
45 | 48 | return testData.data(); | ||
46 | } | |||
47 | ||||
48 | /***************************************************************************************************************/ | |||
49 | /* The following tests check `setBitRangeMoto` function writes messages in the proper bits, that are displayed */ | |||
50 | /* by Kvazer Database Editor. The sample file with `NewMessage_0001` - `NewMessage_0008` can be found here: */ | |||
51 | /* https://gist.github.com/rusefillc/8cef24fa188f868a2a7028c16c26627f */ | |||
52 | /***************************************************************************************************************/ | |||
53 | ||||
54 | 4 | TEST_F(MotorolaDbcTest, testNewMessage_0001) { | ||
55 | // Picture from Kvazer Database Editor for `27|4@0+`: | |||
56 | // | |||
57 | // | Bit Positions | |||
58 | // | 7 6 5 4 3 2 1 0 | |||
59 | // ----+---------------- | |||
60 | // B 0 | | |||
61 | // y 1 | | |||
62 | // t 2 | | |||
63 | // e 3 | <------| | |||
64 | // 4 | | |||
65 | // N 5 | | |||
66 | // u 6 | | |||
67 | // m 7 | | |||
68 | // . 8 | | |||
69 |
1/1✓ Branch 2 taken 1 time.
|
1 | checkRange( | |
70 | /* bitStart = */ 27, | |||
71 | /* length = */ 4, | |||
72 | /* testValue = */ 0xB, // 1011 | |||
73 | /* expectedLSB = */ 24, | |||
74 | // | Bit Positions | |||
75 | // | 7 6 5 4 3 2 1 0 | |||
76 | // ----+---------------- | |||
77 | // B 0 | 0 0 0 0 0 0 0 0 | |||
78 | // y 1 | 0 0 0 0 0 0 0 0 | |||
79 | // t 2 | 0 0 0 0 0 0 0 0 | |||
80 | // e 3 | 0 0 0 0 1-0-1-1 | |||
81 | // 4 | 0 0 0 0 0 0 0 0 | |||
82 | // N 5 | 0 0 0 0 0 0 0 0 | |||
83 | // u 6 | 0 0 0 0 0 0 0 0 | |||
84 | // m 7 | 0 0 0 0 0 0 0 0 | |||
85 | // . 8 | 0 0 0 0 0 0 0 0 | |||
86 | /* expectedData = */ { 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00 } | |||
87 | ); | |||
88 | 1 | } | ||
89 | ||||
90 | 4 | TEST_F(MotorolaDbcTest, testNewMessage_0002) { | ||
91 | // Picture from Kvazer Database Editor for `30|7@0+`: | |||
92 | // | |||
93 | // | Bit Positions | |||
94 | // | 7 6 5 4 3 2 1 0 | |||
95 | // ----+---------------- | |||
96 | // B 0 | | |||
97 | // y 1 | | |||
98 | // t 2 | | |||
99 | // e 3 | <-----------| | |||
100 | // 4 | | |||
101 | // N 5 | | |||
102 | // u 6 | | |||
103 | // m 7 | | |||
104 | // . 8 | | |||
105 |
1/1✓ Branch 2 taken 1 time.
|
1 | checkRange( | |
106 | /* bitStart = */ 30, | |||
107 | /* length = */ 7, | |||
108 | /* testValue = */ 0x59, // 0101 1001 | |||
109 | /* expectedLSB = */ 24, | |||
110 | // | Bit Positions | |||
111 | // | 7 6 5 4 3 2 1 0 | |||
112 | // ----+---------------- | |||
113 | // B 0 | 0 0 0 0 0 0 0 0 | |||
114 | // y 1 | 0 0 0 0 0 0 0 0 | |||
115 | // t 2 | 0 0 0 0 0 0 0 0 | |||
116 | // e 3 | 0 1-0-1-1-0-0-1 | |||
117 | // 4 | 0 0 0 0 0 0 0 0 | |||
118 | // N 5 | 0 0 0 0 0 0 0 0 | |||
119 | // u 6 | 0 0 0 0 0 0 0 0 | |||
120 | // m 7 | 0 0 0 0 0 0 0 0 | |||
121 | // . 8 | 0 0 0 0 0 0 0 0 | |||
122 | /* expectedData = */ { 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x00 } | |||
123 | ); | |||
124 | 1 | } | ||
125 | ||||
126 | 4 | TEST_F(MotorolaDbcTest, testNewMessage_0003) { | ||
127 | // Picture from Kvazer Database Editor for `31|8@0+`: | |||
128 | // | |||
129 | // | Bit Positions | |||
130 | // | 7 6 5 4 3 2 1 0 | |||
131 | // ----+---------------- | |||
132 | // B 0 | | |||
133 | // y 1 | | |||
134 | // t 2 | | |||
135 | // e 3 | <-------------| | |||
136 | // 4 | | |||
137 | // N 5 | | |||
138 | // u 6 | | |||
139 | // m 7 | | |||
140 | // . 8 | | |||
141 |
1/1✓ Branch 2 taken 1 time.
|
1 | checkRange( | |
142 | /* bitStart = */ 31, | |||
143 | /* length = */ 8, | |||
144 | /* testValue = */ 0xB3, // 1011 0011 | |||
145 | /* expectedLSB = */ 24, | |||
146 | // | Bit Positions | |||
147 | // | 7 6 5 4 3 2 1 0 | |||
148 | // ----+---------------- | |||
149 | // B 0 | 0 0 0 0 0 0 0 0 | |||
150 | // y 1 | 0 0 0 0 0 0 0 0 | |||
151 | // t 2 | 0 0 0 0 0 0 0 0 | |||
152 | // e 3 | 1-0-1-1-0-0-1-1 | |||
153 | // 4 | 0 0 0 0 0 0 0 0 | |||
154 | // N 5 | 0 0 0 0 0 0 0 0 | |||
155 | // u 6 | 0 0 0 0 0 0 0 0 | |||
156 | // m 7 | 0 0 0 0 0 0 0 0 | |||
157 | // . 8 | 0 0 0 0 0 0 0 0 | |||
158 | /* expectedData = */ { 0x00, 0x00, 0x00, 0xB3, 0x00, 0x00, 0x00, 0x00 } | |||
159 | ); | |||
160 | 1 | } | ||
161 | ||||
162 | 4 | TEST_F(MotorolaDbcTest, testNewMessage_0004) { | ||
163 | // Picture from Kvazer Database Editor for `17|10@0+`: | |||
164 | // | |||
165 | // | Bit Positions | |||
166 | // | 7 6 5 4 3 2 1 0 | |||
167 | // ----+---------------- | |||
168 | // B 0 | | |||
169 | // y 1 | | |||
170 | // t 2 | <-- | |||
171 | // e 3 | --------------| | |||
172 | // 4 | | |||
173 | // N 5 | | |||
174 | // u 6 | | |||
175 | // m 7 | | |||
176 | // . 8 | | |||
177 |
1/1✓ Branch 2 taken 1 time.
|
1 | checkRange( | |
178 | /* bitStart = */ 17, | |||
179 | /* length = */ 10, | |||
180 | /* testValue = */ 0x2C9, // 0010 1100 1001 | |||
181 | /* expectedLSB = */ 24, | |||
182 | // | Bit Positions | |||
183 | // | 7 6 5 4 3 2 1 0 | |||
184 | // ----+---------------- | |||
185 | // B 0 | 0 0 0 0 0 0 0 0 | |||
186 | // y 1 | 0 0 0 0 0 0 0 0 | |||
187 | // t 2 | 0 0 0 0 0 0 1-0- | |||
188 | // e 3 |-1-1-0-0-1-0-0-1 | |||
189 | // 4 | 0 0 0 0 0 0 0 0 | |||
190 | // N 5 | 0 0 0 0 0 0 0 0 | |||
191 | // u 6 | 0 0 0 0 0 0 0 0 | |||
192 | // m 7 | 0 0 0 0 0 0 0 0 | |||
193 | // . 8 | 0 0 0 0 0 0 0 0 | |||
194 | /* expectedData = */ { 0x00, 0x00, 0x02, 0xC9, 0x00, 0x00, 0x00, 0x00 } | |||
195 | ); | |||
196 | 1 | } | ||
197 | ||||
198 | 4 | TEST_F(MotorolaDbcTest, testNewMessage_0005) { | ||
199 | // Picture from Kvazer Database Editor for `16|9@0+`: | |||
200 | // | |||
201 | // | Bit Positions | |||
202 | // | 7 6 5 4 3 2 1 0 | |||
203 | // ----+---------------- | |||
204 | // B 0 | | |||
205 | // y 1 | | |||
206 | // t 2 | < | |||
207 | // e 3 | --------------| | |||
208 | // 4 | | |||
209 | // N 5 | | |||
210 | // u 6 | | |||
211 | // m 7 | | |||
212 | // . 8 | | |||
213 |
1/1✓ Branch 2 taken 1 time.
|
1 | checkRange( | |
214 | /* bitStart = */ 16, | |||
215 | /* length = */ 9, | |||
216 | /* testValue = */ 0x173, // 0001 0111 0011 | |||
217 | /* expectedLSB = */ 24, | |||
218 | // | Bit Positions | |||
219 | // | 7 6 5 4 3 2 1 0 | |||
220 | // ----+---------------- | |||
221 | // B 0 | 0 0 0 0 0 0 0 0 | |||
222 | // y 1 | 0 0 0 0 0 0 0 0 | |||
223 | // t 2 | 0 0 0 0 0 0 0 1- | |||
224 | // e 3 |-0-1-1-1-0-0-1-1 | |||
225 | // 4 | 0 0 0 0 0 0 0 0 | |||
226 | // N 5 | 0 0 0 0 0 0 0 0 | |||
227 | // u 6 | 0 0 0 0 0 0 0 0 | |||
228 | // m 7 | 0 0 0 0 0 0 0 0 | |||
229 | // . 8 | 0 0 0 0 0 0 0 0 | |||
230 | /* expectedData = */ { 0x00, 0x00, 0x01, 0x73, 0x00, 0x00, 0x00, 0x00 } | |||
231 | ); | |||
232 | 1 | } | ||
233 | ||||
234 | 4 | TEST_F(MotorolaDbcTest, testNewMessage_0006) { | ||
235 | // Picture from Kvazer Database Editor for `13|8@0+`: | |||
236 | // | |||
237 | // | Bit Positions | |||
238 | // | 7 6 5 4 3 2 1 0 | |||
239 | // ----+---------------- | |||
240 | // B 0 | | |||
241 | // y 1 | <---------- | |||
242 | // t 2 | --| | |||
243 | // e 3 | | |||
244 | // 4 | | |||
245 | // N 5 | | |||
246 | // u 6 | | |||
247 | // m 7 | | |||
248 | // . 8 | | |||
249 |
1/1✓ Branch 2 taken 1 time.
|
1 | checkRange( | |
250 | /* bitStart = */ 13, | |||
251 | /* length = */ 8, | |||
252 | /* testValue = */ 0xB3, // 1011 0011 | |||
253 | /* expectedLSB = */ 22, | |||
254 | // | Bit Positions | |||
255 | // | 7 6 5 4 3 2 1 0 | |||
256 | // ----+---------------- | |||
257 | // B 0 | 0 0 0 0 0 0 0 0 | |||
258 | // y 1 | 0 0 1-0-1-1-0-0- | |||
259 | // t 2 |-1-1 0 0 0 0 0 0 | |||
260 | // e 3 | 0 0 0 0 0 0 0 0 | |||
261 | // 4 | 0 0 0 0 0 0 0 0 | |||
262 | // N 5 | 0 0 0 0 0 0 0 0 | |||
263 | // u 6 | 0 0 0 0 0 0 0 0 | |||
264 | // m 7 | 0 0 0 0 0 0 0 0 | |||
265 | // . 8 | 0 0 0 0 0 0 0 0 | |||
266 | /* expectedData = */ { 0x00, 0x2C, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00 } | |||
267 | ); | |||
268 | 1 | } | ||
269 | ||||
270 | 4 | TEST_F(MotorolaDbcTest, testNewMessage_0007) { | ||
271 | // Picture from Kvazer Database Editor for `14|9@0+`: | |||
272 | // | |||
273 | // | Bit Positions | |||
274 | // | 7 6 5 4 3 2 1 0 | |||
275 | // ----+---------------- | |||
276 | // B 0 | | |||
277 | // y 1 | <------------ | |||
278 | // t 2 | --| | |||
279 | // e 3 | | |||
280 | // 4 | | |||
281 | // N 5 | | |||
282 | // u 6 | | |||
283 | // m 7 | | |||
284 | // . 8 | | |||
285 |
1/1✓ Branch 2 taken 1 time.
|
1 | checkRange( | |
286 | /* bitStart = */ 14, | |||
287 | /* length = */ 9, | |||
288 | /* testValue = */ 0x167, // 0001 0110 0111 | |||
289 | /* expectedLSB = */ 22, | |||
290 | // | Bit Positions | |||
291 | // | 7 6 5 4 3 2 1 0 | |||
292 | // ----+---------------- | |||
293 | // B 0 | 0 0 0 0 0 0 0 0 | |||
294 | // y 1 | 0 1 0-1-1-0-0-1- | |||
295 | // t 2 |-1-1 0 0 0 0 0 0 | |||
296 | // e 3 | 0 0 0 0 0 0 0 0 | |||
297 | // 4 | 0 0 0 0 0 0 0 0 | |||
298 | // N 5 | 0 0 0 0 0 0 0 0 | |||
299 | // u 6 | 0 0 0 0 0 0 0 0 | |||
300 | // m 7 | 0 0 0 0 0 0 0 0 | |||
301 | // . 8 | 0 0 0 0 0 0 0 0 | |||
302 | /* expectedData = */ { 0x00, 0x59, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00 } | |||
303 | ); | |||
304 | 1 | } | ||
305 | ||||
306 | 4 | TEST_F(MotorolaDbcTest, testNewMessage_0008) { | ||
307 | // Picture from Kvazer Database Editor for `14|8@0+`: | |||
308 | // | |||
309 | // | Bit Positions | |||
310 | // | 7 6 5 4 3 2 1 0 | |||
311 | // ----+---------------- | |||
312 | // B 0 | | |||
313 | // y 1 | <------------ | |||
314 | // t 2 | | | |||
315 | // e 3 | | |||
316 | // 4 | | |||
317 | // N 5 | | |||
318 | // u 6 | | |||
319 | // m 7 | | |||
320 | // . 8 | | |||
321 |
1/1✓ Branch 2 taken 1 time.
|
1 | checkRange( | |
322 | /* bitStart = */ 14, | |||
323 | /* length = */ 8, | |||
324 | /* testValue = */ 0xB3, // 1011 0011 | |||
325 | /* expectedLSB = */ 23, | |||
326 | // | Bit Positions | |||
327 | // | 7 6 5 4 3 2 1 0 | |||
328 | // ----+---------------- | |||
329 | // B 0 | 0 0 0 0 0 0 0 0 | |||
330 | // y 1 | 0 1-0-1-1-0-0-1- | |||
331 | // t 2 |-1 0 0 0 0 0 0 0 | |||
332 | // e 3 | 0 0 0 0 0 0 0 0 | |||
333 | // 4 | 0 0 0 0 0 0 0 0 | |||
334 | // N 5 | 0 0 0 0 0 0 0 0 | |||
335 | // u 6 | 0 0 0 0 0 0 0 0 | |||
336 | // m 7 | 0 0 0 0 0 0 0 0 | |||
337 | // . 8 | 0 0 0 0 0 0 0 0 | |||
338 | /* expectedData = */ { 0x00, 0x59, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00 } | |||
339 | ); | |||
340 | 1 | } | ||
341 | ||||
342 | // the following test completely duplicates functionality from `testNewMessage_0006`, we are leaving it as an | |||
343 | // outline to simplify debugging of the cases whan `checkRange` method fails | |||
344 | 4 | TEST_F(MotorolaDbcTest, testNewMessage_0006Simplified) { | ||
345 | 1 | std::array<uint8_t, 8> data { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; | ||
346 | ||||
347 | 1 | const int bitStart = 13; | ||
348 | 1 | const int length = 8; | ||
349 | ||||
350 | // Picture from Kvazer Database Editor for `13|8@0+`: | |||
351 | // | |||
352 | // | Bit Positions | |||
353 | // | 7 6 5 4 3 2 1 0 | |||
354 | // ----+---------------- | |||
355 | // B 0 | | |||
356 | // y 1 | <---------- | |||
357 | // t 2 | --| | |||
358 | // e 3 | | |||
359 | // 4 | | |||
360 | // N 5 | | |||
361 | // u 6 | | |||
362 | // m 7 | | |||
363 | // . 8 | | |||
364 |
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.
|
2 | EXPECT_EQ(getBitRangeMoto(data.data(), bitStart, length), 0x00); // 0000 | |
365 | ||||
366 | 1 | const int testValue = 0xB3; // 1011 0011 | ||
367 |
1/1✓ Branch 1 taken 1 time.
|
1 | setBitRangeMoto(data.data(), bitStart, length, testValue); | |
368 | ||||
369 | //// | Bit Positions | |||
370 | //// | 7 6 5 4 3 2 1 0 | |||
371 | //// ----+---------------- | |||
372 | //// B 0 | 0 0 0 0 0 0 0 0 | |||
373 | //// y 1 | 0 0 1-0-1-1-0-0- | |||
374 | //// t 2 |-1-1 0 0 0 0 0 0 | |||
375 | //// e 3 | 0 0 0 0 0 0 0 0 | |||
376 | //// 4 | 0 0 0 0 0 0 0 0 | |||
377 | //// N 5 | 0 0 0 0 0 0 0 0 | |||
378 | //// u 6 | 0 0 0 0 0 0 0 0 | |||
379 | //// m 7 | 0 0 0 0 0 0 0 0 | |||
380 | //// . 8 | 0 0 0 0 0 0 0 0 | |||
381 | 1 | const std::array<uint8_t, 8> expectedData = { 0x00, 0x2C, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00 }; | ||
382 |
4/8✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 time.
✗ Branch 21 not taken.
✗ Branch 26 not taken.
✗ Branch 29 not taken.
|
1 | EXPECT_THAT(data, testing::ElementsAreArray(expectedData)); | |
383 |
3/7✓ Branch 3 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.
|
2 | EXPECT_EQ(getBitRangeMoto(data.data(), bitStart, length), testValue); | |
384 | 1 | } | ||
385 | } | |||
386 |