forked from rusefi/rusefi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_scattered_outputs.cpp
89 lines (68 loc) · 1.99 KB
/
test_scattered_outputs.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "pch.h"
#include "FragmentEntry.h"
struct obj1 {
const uint8_t x[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
};
static_assert(sizeof(obj1) == 10);
struct obj2 {
const uint8_t x[5] = { 11, 12, 13, 14, 15 };
};
static_assert(sizeof(obj2) == 5);
obj1 buffer10;
obj2 buffer5;
static FragmentEntry fragmentBuffer[] = {
&buffer10,
&buffer5,
reinterpret_cast<obj2*>(0), // null fragment for fun
&buffer10
};
static uint8_t buffer[120];
static void resetBuffer() {
memset(buffer, 0xFF, sizeof(buffer));
}
TEST(outputs, fragments) {
static_assert(4 == efi::size(fragmentBuffer));
FragmentList fragments{ fragmentBuffer, efi::size(fragmentBuffer) };
resetBuffer();
{
// Check overlap between first and second fragments
uint8_t expected[] = {9, 10, 11, 12, 13};
copyRange(buffer, fragments, 8, 5);
EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected)));
}
resetBuffer();
{
// Check partial of only second fragment
uint8_t expected[] = {13, 14, 15};
copyRange(buffer, fragments, 12, 3);
EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected)));
}
resetBuffer();
{
// Check overlap between second fragment and null fragment
uint8_t expected[] = {15, 0, 0};
copyRange(buffer, fragments, 14, 3);
EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected)));
}
resetBuffer();
{
// Check overlap between null fragment and 4th fragment
uint8_t expected[] = {0, 1, 2};
copyRange(buffer, fragments, 19, 3);
EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected)));
}
resetBuffer();
{
// Check overlap between last fragment and off-end of buffer (off-buffer should give 0s)
uint8_t expected[] = {9, 10, 0, 0};
copyRange(buffer, fragments, 28, 4);
EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected)));
}
resetBuffer();
{
// Check way off the end of the buffer
uint8_t expected[] = {0, 0, 0};
copyRange(buffer, fragments, 1000, 3);
EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected)));
}
}