GCC Code Coverage Report


Directory: ./
File: unit_tests/tests/test_binary_log.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 96.2% 25 0 26
Functions: 88.9% 8 0 9
Branches: 67.6% 25 0 37
Decisions: -% 0 - 0

Line Branch Decision Exec Source
1 #include "mlg_field.h"
2 #include "buffered_writer.h"
3
4 #include <gmock/gmock.h>
5
6 using namespace MLG;
7 using namespace MLG::Entries;
8
9 using ::testing::_;
10 using ::testing::ElementsAre;
11 using ::testing::StrictMock;
12
13 class MockWriter : public Writer {
14 public:
15
3/3
✓ Branch 3 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
2 MOCK_METHOD(size_t, write, (const char* buffer, size_t count), (override));
16 MOCK_METHOD(size_t, flush, (), (override));
17 };
18
19 4 TEST(BinaryLogField, FieldHeader) {
20 1 scaled_channel<int8_t, 10> channel;
21
1/1
✓ Branch 2 taken 1 time.
1 Field field(channel, "name", "units", 2, "category");
22
23 1 char buffer[89];
24
1/1
✓ Branch 2 taken 1 time.
1 StrictMock<MockWriter> bufWriter;
25
5/5
✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 9 taken 1 time.
✓ Branch 12 taken 1 time.
✓ Branch 16 taken 1 time.
3 EXPECT_CALL(bufWriter, write(_, 89))
26
2/2
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
3 .WillOnce([&] (const char* buf, size_t count) {
27 memcpy(buffer, buf, count);
28 return 0;
29 });
30
31 // Should write 89 bytes
32
1/1
✓ Branch 1 taken 1 time.
1 field.writeHeader(bufWriter);
33
34 // Expect correctly written header
35
4/8
✓ Branch 93 taken 1 time.
✓ Branch 96 taken 1 time.
✓ Branch 99 taken 1 time.
✗ Branch 193 not taken.
✓ Branch 194 taken 1 time.
✗ Branch 197 not taken.
✗ Branch 202 not taken.
✗ Branch 205 not taken.
1 EXPECT_THAT(buffer, ElementsAre(
36 1, // type: int8_t
37 // name - 34 bytes, 0 padded
38 'n', 'a', 'm', 'e', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
39 // units - 10 bytes, 0 padded
40 'u', 'n', 'i', 't', 's', 0, 0, 0, 0, 0,
41 // display style: float
42 0,
43 // Scale = 0.1 (float)
44 0x3d, 0xcc, 0xcc, 0xcd,
45 // Transform - we always use 0
46 0, 0, 0, 0,
47 // Digits - 2, as configured
48 2,
49 'c', 'a', 't', 'e', 'g', 'o', 'r', 'y', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
50 1 ));
51 2 }
52
53 4 TEST(BinaryLogField, Value) {
54 1 scaled_channel<uint32_t, 1> testValue = 12345678;
55
1/1
✓ Branch 2 taken 1 time.
1 Field lf(testValue, "test", "unit", 0);
56
57 1 char buffer[6];
58 1 memset(buffer, 0xAA, sizeof(buffer));
59
60 // Should write 4 bytes
61
3/7
✓ Branch 3 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(4u, lf.writeData(buffer, nullptr));
62
63 // Check that big endian data was written, and bytes after weren't touched
64
4/8
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
✗ Branch 27 not taken.
✓ Branch 28 taken 1 time.
✗ Branch 31 not taken.
✗ Branch 36 not taken.
✗ Branch 39 not taken.
1 EXPECT_THAT(buffer, ElementsAre(0x00, 0xbc, 0x61, 0x4e, 0xAA, 0xAA));
65 1 }
66