Skip to content

Commit c538047

Browse files
committed
Add sleep_ms() to PicoWrapper and its test.
1 parent bfdea68 commit c538047

4 files changed

Lines changed: 38 additions & 0 deletions

File tree

rpi_pico/samples/interrupt_sample/pico_driver/picowrapper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#endif
99

10+
void PicoWrapper::sleep_ms(uint32_t ms) { ::sleep_ms(ms); }
11+
1012
void PicoWrapper::gpio_init(uint gpio) { ::gpio_init(gpio); }
1113

1214
void PicoWrapper::gpio_set_dir(uint gpio, bool out) {

rpi_pico/samples/interrupt_sample/pico_driver/picowrapper.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ class PicoWrapper {
2020
public:
2121
virtual ~PicoWrapper() {}
2222
virtual void gpio_init(uint gpio);
23+
24+
/**
25+
* @brief Wait for the given number of milliseconds before returning.
26+
* @param ms the number of milliseconds to sleep
27+
*/
28+
virtual void sleep_ms(uint32_t ms);
29+
2330
/**
2431
* @brief Set a single GPIO direction.
2532
* @param gpio GPIO number.

test/test_picowrapper.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ typedef int i2c_inst_t;
1818
DEFINE_FFF_GLOBALS;
1919

2020
// Create Test Spies
21+
FAKE_VOID_FUNC(sleep_ms, uint32_t);
2122
FAKE_VOID_FUNC(gpio_init, uint);
2223
FAKE_VOID_FUNC(gpio_set_dir, uint, bool);
2324
FAKE_VOID_FUNC(gpio_put, uint, bool);
@@ -34,6 +35,30 @@ FAKE_VALUE_FUNC(int, i2c_write_blocking, i2c_inst_t *, uint8_t, const uint8_t *,
3435
// The cpp file of the library to test.
3536
#include "../rpi_pico/samples/interrupt_sample/pico_driver/picowrapper.cpp"
3637

38+
TEST(PicoWrapper, sleep_ms) {
39+
PicoWrapper pico;
40+
uint ms_array[] = {17, 11};
41+
42+
FFF_RESET_HISTORY();
43+
RESET_FAKE(sleep_ms);
44+
45+
for (auto &&ms : ms_array) {
46+
pico.sleep_ms(ms);
47+
}
48+
49+
// Check the data from test spy. How many time called?
50+
ASSERT_EQ(sleep_ms_fake.call_count, std::size(ms_array));
51+
52+
int index = 0;
53+
for (auto &&ms : ms_array) {
54+
// Check the data from test spy. Call order.
55+
ASSERT_EQ(fff.call_history[index], (void *)sleep_ms);
56+
// Check the data from test spy. DrawRelative Parameters.
57+
ASSERT_EQ(sleep_ms_fake.arg0_history[index], ms);
58+
index++;
59+
}
60+
}
61+
3762
TEST(PicoWrapper, gpio_init) {
3863
PicoWrapper pico;
3964
uint gpioarray[] = {17, 11};

test/todo/test_picowrapper.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# test_picowrapper TDD
22

3+
- [x] Create PicoWrapper.sleep_ms() to fail.
4+
- [x] Make it success.
5+
- [x] Remove the duplication.
6+
37
- [x] Create PicoWrapper.i2c_write_blocking() to fail.
48
- [x] Make it success.
59
- [x] Remove the duplication.

0 commit comments

Comments
 (0)