Skip to content

Commit bfdea68

Browse files
committed
Refined i2c_write_blocking
1 parent 242d45e commit bfdea68

1 file changed

Lines changed: 33 additions & 20 deletions

File tree

test/test_picowrapper.cpp

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ TEST(PicoWrapper, i2c_read_blocking) {
235235
// Check the data from test spy. How many time called?
236236
ASSERT_EQ(i2c_read_blocking_fake.call_count, 8);
237237

238-
// Check wether return value is correct.
238+
// Check wether parameters are passed collectly.
239239
index = 0;
240240
for (auto &&addrs : addrs_array) {
241241
for (auto &&bufsize : bufsize_array) {
@@ -260,34 +260,47 @@ TEST(PicoWrapper, i2c_write_blocking) {
260260
PicoWrapper pico;
261261
i2c_inst_t i2c = 17;
262262
uint8_t buf[10];
263-
uint8_t addrs[8] = {3, 3, 3, 3, 5, 5, 5, 5};
264-
size_t bufsize[8] = {6, 6, 7, 7, 6, 6, 7, 7};
265-
bool nostop[8] = {true, false, true, false, true, false, true, false};
266-
int myReturnVals[] = {1, 2, 3, 4, 5, 6, 7, 8};
263+
uint8_t addrs_array[] = {3, 5};
264+
size_t bufsize_array[2] = {2, 7};
265+
bool nostop_array[2] = {true, false};
266+
int myReturnVals_array[8] = {1, 2, 3, 4, 5, 6, 7, 8};
267267

268268
FFF_RESET_HISTORY();
269269
RESET_FAKE(i2c_write_blocking);
270270

271-
SET_RETURN_SEQ(i2c_write_blocking, myReturnVals,
272-
sizeof(myReturnVals) / sizeof(bool));
271+
SET_RETURN_SEQ(i2c_write_blocking, myReturnVals_array,
272+
std::size(myReturnVals_array));
273273

274-
for (int i = 0; i < 8; i++) {
275-
ASSERT_EQ(
276-
pico.i2c_write_blocking(&i2c, addrs[i], buf, bufsize[i], nostop[i]),
277-
myReturnVals[i]);
274+
// Check wether return value is correct.
275+
int index = 0;
276+
for (auto &&addrs : addrs_array) {
277+
for (auto &&bufsize : bufsize_array) {
278+
for (auto &&nostop : nostop_array) {
279+
ASSERT_EQ(pico.i2c_write_blocking(&i2c, addrs, buf, bufsize, nostop),
280+
myReturnVals_array[index]);
281+
index++;
282+
}
283+
}
278284
}
279285

280286
// Check the data from test spy. How many time called?
281287
ASSERT_EQ(i2c_write_blocking_fake.call_count, 8);
282288

283-
for (int i = 0; i < 8; i++) {
284-
// Check the data from test spy. Call order.
285-
ASSERT_EQ(fff.call_history[i], (void *)i2c_write_blocking);
286-
// Check the data from test spy. DrawRelative Parameters.
287-
ASSERT_EQ(i2c_write_blocking_fake.arg0_history[i], &i2c);
288-
ASSERT_EQ(i2c_write_blocking_fake.arg1_history[i], addrs[i]);
289-
ASSERT_EQ(i2c_write_blocking_fake.arg2_history[i], buf);
290-
ASSERT_EQ(i2c_write_blocking_fake.arg3_history[i], bufsize[i]);
291-
ASSERT_EQ(i2c_write_blocking_fake.arg4_history[i], nostop[i]);
289+
// Check wether parameters are passed collectly.
290+
index = 0;
291+
for (auto &&addrs : addrs_array) {
292+
for (auto &&bufsize : bufsize_array) {
293+
for (auto &&nostop : nostop_array) {
294+
// Check the data from test spy. Call order.
295+
ASSERT_EQ(fff.call_history[index], (void *)i2c_write_blocking);
296+
// Check the data from test spy. DrawRelative Parameters.
297+
ASSERT_EQ(i2c_write_blocking_fake.arg0_history[index], &i2c);
298+
ASSERT_EQ(i2c_write_blocking_fake.arg1_history[index], addrs);
299+
ASSERT_EQ(i2c_write_blocking_fake.arg2_history[index], buf);
300+
ASSERT_EQ(i2c_write_blocking_fake.arg3_history[index], bufsize);
301+
ASSERT_EQ(i2c_write_blocking_fake.arg4_history[index], nostop);
302+
index++;
303+
}
304+
}
292305
}
293306
}

0 commit comments

Comments
 (0)