forked from rusefi/rusefi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_binary_log.cpp
More file actions
65 lines (53 loc) · 1.72 KB
/
Copy pathtest_binary_log.cpp
File metadata and controls
65 lines (53 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "mlg_field.h"
#include "buffered_writer.h"
#include <gmock/gmock.h>
using namespace MLG;
using namespace MLG::Entries;
using ::testing::_;
using ::testing::ElementsAre;
using ::testing::StrictMock;
class MockWriter : public Writer {
public:
MOCK_METHOD(size_t, write, (const char* buffer, size_t count), (override));
MOCK_METHOD(size_t, flush, (), (override));
};
TEST(BinaryLogField, FieldHeader) {
scaled_channel<int8_t, 10> channel;
Field field(channel, "name", "units", 2, "category");
char buffer[89];
StrictMock<MockWriter> bufWriter;
EXPECT_CALL(bufWriter, write(_, 89))
.WillOnce([&] (const char* buf, size_t count) {
memcpy(buffer, buf, count);
return 0;
});
// Should write 89 bytes
field.writeHeader(bufWriter);
// Expect correctly written header
EXPECT_THAT(buffer, ElementsAre(
1, // type: int8_t
// name - 34 bytes, 0 padded
'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,
// units - 10 bytes, 0 padded
'u', 'n', 'i', 't', 's', 0, 0, 0, 0, 0,
// display style: float
0,
// Scale = 0.1 (float)
0x3d, 0xcc, 0xcc, 0xcd,
// Transform - we always use 0
0, 0, 0, 0,
// Digits - 2, as configured
2,
'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
));
}
TEST(BinaryLogField, Value) {
scaled_channel<uint32_t, 1> testValue = 12345678;
Field lf(testValue, "test", "unit", 0);
char buffer[6];
memset(buffer, 0xAA, sizeof(buffer));
// Should write 4 bytes
EXPECT_EQ(4u, lf.writeData(buffer, nullptr));
// Check that big endian data was written, and bytes after weren't touched
EXPECT_THAT(buffer, ElementsAre(0x00, 0xbc, 0x61, 0x4e, 0xAA, 0xAA));
}