@@ -12,7 +12,8 @@ class VerifyBorders_HeapBlockDevice : public mbed::HeapBlockDevice {
12
12
mutable bd_size_t upper_limit;
13
13
14
14
VerifyBorders_HeapBlockDevice (bd_size_t size)
15
- : HeapBlockDevice(size) {
15
+ : HeapBlockDevice(size)
16
+ {
16
17
borders_crossed = false ;
17
18
lower_limit = 0 ;
18
19
upper_limit = size;
@@ -21,21 +22,21 @@ class VerifyBorders_HeapBlockDevice : public mbed::HeapBlockDevice {
21
22
virtual bool is_valid_read (bd_addr_t addr, bd_size_t size) const
22
23
{
23
24
borders_crossed |= addr < lower_limit;
24
- borders_crossed |= addr+ size > upper_limit;
25
+ borders_crossed |= addr + size > upper_limit;
25
26
return BlockDevice::is_valid_read (addr, size);
26
27
}
27
28
28
29
virtual bool is_valid_program (bd_addr_t addr, bd_size_t size) const
29
30
{
30
31
borders_crossed |= addr < lower_limit;
31
- borders_crossed |= addr+ size > upper_limit;
32
+ borders_crossed |= addr + size > upper_limit;
32
33
return BlockDevice::is_valid_program (addr, size);
33
34
}
34
35
35
36
virtual bool is_valid_erase (bd_addr_t addr, bd_size_t size) const
36
37
{
37
38
borders_crossed |= addr < lower_limit;
38
- borders_crossed |= addr+ size > upper_limit;
39
+ borders_crossed |= addr + size > upper_limit;
39
40
return BlockDevice::is_valid_erase (addr, size);
40
41
}
41
42
};
@@ -51,7 +52,7 @@ class SlicingBlockModuleTest : public testing::Test {
51
52
magic = new uint8_t [BLOCK_SIZE];
52
53
buf = new uint8_t [BLOCK_SIZE];
53
54
// Generate simple pattern to verify against
54
- for (int i= 0 ; i < BLOCK_SIZE; i++) {
55
+ for (int i = 0 ; i < BLOCK_SIZE; i++) {
55
56
magic[i] = 0xaa + i;
56
57
}
57
58
}
@@ -77,20 +78,20 @@ TEST_F(SlicingBlockModuleTest, constructor)
77
78
78
79
TEST_F (SlicingBlockModuleTest, slice_in_middle)
79
80
{
80
- uint8_t *program = new uint8_t [BLOCK_SIZE]{0xbb ,0xbb ,0xbb };
81
+ uint8_t *program = new uint8_t [BLOCK_SIZE] {0xbb ,0xbb ,0xbb };
81
82
82
83
// Write magic value to heap block before and after the space for slice
83
84
bd.program (magic, 0 , BLOCK_SIZE);
84
- bd.program (magic, BLOCK_SIZE* 3 , BLOCK_SIZE);
85
+ bd.program (magic, BLOCK_SIZE * 3 , BLOCK_SIZE);
85
86
86
- bd.upper_limit = BLOCK_SIZE* 3 ;
87
+ bd.upper_limit = BLOCK_SIZE * 3 ;
87
88
bd.lower_limit = BLOCK_SIZE;
88
89
bd.borders_crossed = false ;
89
90
90
91
// Skip first block, then create sclicing device, with size of 2 blocks
91
- mbed::SlicingBlockDevice slice (&bd, BLOCK_SIZE, BLOCK_SIZE* 3 );
92
+ mbed::SlicingBlockDevice slice (&bd, BLOCK_SIZE, BLOCK_SIZE * 3 );
92
93
EXPECT_EQ (slice.init (), BD_ERROR_OK);
93
- EXPECT_EQ (BLOCK_SIZE* 2 , slice.size ());
94
+ EXPECT_EQ (BLOCK_SIZE * 2 , slice.size ());
94
95
EXPECT_EQ (bd.borders_crossed , false );
95
96
96
97
// Program a test value
@@ -101,44 +102,44 @@ TEST_F(SlicingBlockModuleTest, slice_in_middle)
101
102
// Verify that blocks before and after the slicing blocks are not touched
102
103
bd.read (buf, 0 , BLOCK_SIZE);
103
104
EXPECT_EQ (0 , memcmp (buf, magic, BLOCK_SIZE));
104
- bd.read (buf, BLOCK_SIZE* 3 , BLOCK_SIZE);
105
+ bd.read (buf, BLOCK_SIZE * 3 , BLOCK_SIZE);
105
106
EXPECT_EQ (0 , memcmp (buf, magic, BLOCK_SIZE));
106
107
}
107
108
108
109
TEST_F (SlicingBlockModuleTest, slice_at_the_end)
109
110
{
110
- uint8_t *program = new uint8_t [BLOCK_SIZE]{0xbb ,0xbb ,0xbb };
111
+ uint8_t *program = new uint8_t [BLOCK_SIZE] {0xbb ,0xbb ,0xbb };
111
112
112
113
// Write magic value to heap block before the space for slice
113
114
// our bd is 10*BLOCK_SIZE, so sector 7
114
- bd.program (magic, BLOCK_SIZE* 7 , BLOCK_SIZE);
115
+ bd.program (magic, BLOCK_SIZE * 7 , BLOCK_SIZE);
115
116
116
117
// Screate sclicing device, with size of 2 blocks
117
118
// Use negative index
118
119
mbed::SlicingBlockDevice slice (&bd, -BLOCK_SIZE*2 );
119
120
EXPECT_EQ (slice.init (), BD_ERROR_OK);
120
- EXPECT_EQ (BLOCK_SIZE* 2 , slice.size ());
121
+ EXPECT_EQ (BLOCK_SIZE * 2 , slice.size ());
121
122
122
123
// Program a test value
123
124
EXPECT_EQ (slice.program (program, 0 , BLOCK_SIZE), BD_ERROR_OK);
124
125
EXPECT_EQ (slice.program (program, BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_OK);
125
126
126
127
// Verify that blocks before and after the slicing blocks are not touched
127
- bd.read (buf, BLOCK_SIZE* 7 , BLOCK_SIZE);
128
+ bd.read (buf, BLOCK_SIZE * 7 , BLOCK_SIZE);
128
129
EXPECT_EQ (0 , memcmp (buf, magic, BLOCK_SIZE));
129
130
}
130
131
131
132
TEST_F (SlicingBlockModuleTest, over_write)
132
133
{
133
- uint8_t *program = new uint8_t [BLOCK_SIZE]{0xbb ,0xbb ,0xbb };
134
+ uint8_t *program = new uint8_t [BLOCK_SIZE] {0xbb ,0xbb ,0xbb };
134
135
135
136
// Screate sclicing device, with size of 2 blocks
136
- mbed::SlicingBlockDevice slice (&bd, BLOCK_SIZE, BLOCK_SIZE* 3 );
137
+ mbed::SlicingBlockDevice slice (&bd, BLOCK_SIZE, BLOCK_SIZE * 3 );
137
138
EXPECT_EQ (slice.init (), BD_ERROR_OK);
138
139
139
140
EXPECT_EQ (slice.program (program, 0 , BLOCK_SIZE), BD_ERROR_OK);
140
141
EXPECT_EQ (slice.program (program, BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_OK);
141
142
// Program a test value to address that is one pass the device size
142
- EXPECT_EQ (slice.program (program, 2 * BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
143
+ EXPECT_EQ (slice.program (program, 2 * BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
143
144
144
145
}
0 commit comments