Skip to content

Commit

Permalink
🤡 (mbed): Mock mbed::interface::DigitalOut
Browse files Browse the repository at this point in the history
To work we need to also stub mbed::gpio_read and mbed::gpio_is_connected
  • Loading branch information
ladislas committed May 31, 2021
1 parent 3118263 commit c3de701
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/unit/mbed-os/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_library(mbed-os INTERFACE)
target_include_directories(mbed-os
INTERFACE
${UNITTESTS_DIR}/mbed-os
${UNITTESTS_DIR}/mbed-os/mocks
${UNITTESTS_DIR}/mbed-os/stubs
${UNITTESTS_DIR}/mbed-os/include

Expand Down
1 change: 1 addition & 0 deletions tests/unit/mbed-os/include/mbed_target_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@
#define __CORTEX_M7 1
#define __FPU_PRESENT 1
#define __MBED_CMSIS_RTOS_CM 1
#define FEATURE_EXPERIMENTAL_API 1
27 changes: 27 additions & 0 deletions tests/unit/mbed-os/mocks/mock_DigitalOut.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Leka - LekaOS
// Copyright 2021 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#ifndef _LEKA_OS_MBED_MOCK_DIGITAL_OUT_H_
#define _LEKA_OS_MBED_MOCK_DIGITAL_OUT_H_

#include "PinNames.h"

#include "drivers/interfaces/InterfaceDigitalOut.h"

#include "gmock/gmock.h"

namespace mbed::mock {

class DigitalOut : public mbed::interface::DigitalOut
{
public:
DigitalOut(PinName pin) {};
MOCK_METHOD(void, write, (int value), (override));
MOCK_METHOD(int, read, (), (override));
MOCK_METHOD(int, is_connected, (), (override));
};

} // namespace mbed::mock

#endif // _LEKA_OS_MBED_MOCK_DIGITAL_OUT_H_
10 changes: 10 additions & 0 deletions tests/unit/mbed-os/stubs/stub_gpio_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ void gpio_write(gpio_t *gpio, int value)
{
return;
}

auto gpio_read(gpio_t *obj) -> int
{
return 0;
}

auto gpio_is_connected(const gpio_t *obj) -> int
{
return 1;
}

0 comments on commit c3de701

Please sign in to comment.