-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge pull request #243 from leka/benjamin/feature/mock_buffered_se…
…rial
- Loading branch information
Showing
10 changed files
with
210 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
add_library(CoreBufferedSerial STATIC) | ||
|
||
target_include_directories(CoreBufferedSerial | ||
PUBLIC | ||
include | ||
) | ||
|
||
target_sources(CoreBufferedSerial | ||
PRIVATE | ||
source/CoreBufferedSerial.cpp | ||
) | ||
|
||
target_link_libraries(CoreBufferedSerial | ||
mbed-os | ||
) | ||
|
||
if (${CMAKE_PROJECT_NAME} STREQUAL "LekaOSUnitTests") | ||
|
||
leka_unit_tests_sources( | ||
tests/CoreBufferedSerial_test.cpp | ||
) | ||
|
||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Leka - LekaOS | ||
// Copyright 2021 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef _LEKA_OS_DRIVER_CORE_BUFFERED_SERIAL_H_ | ||
#define _LEKA_OS_DRIVER_CORE_BUFFERED_SERIAL_H_ | ||
|
||
#include "drivers/BufferedSerial.h" | ||
|
||
namespace leka::interface { | ||
|
||
class BufferedSerial | ||
{ | ||
public: | ||
virtual ~BufferedSerial() = default; | ||
|
||
virtual auto read(uint8_t *buffer, ssize_t length) -> ssize_t = 0; | ||
virtual auto write(const uint8_t *buffer, ssize_t length) -> ssize_t = 0; | ||
}; | ||
|
||
} // namespace leka::interface | ||
|
||
namespace leka { | ||
|
||
class CoreBufferedSerial : public interface::BufferedSerial | ||
{ | ||
public: | ||
explicit CoreBufferedSerial(mbed::BufferedSerial &serial) : _serial {serial} {}; | ||
|
||
auto read(uint8_t *buffer, ssize_t length) -> ssize_t final; | ||
auto write(const uint8_t *buffer, ssize_t length) -> ssize_t final; | ||
|
||
private: | ||
mbed::BufferedSerial &_serial; | ||
}; | ||
|
||
} // namespace leka | ||
|
||
#endif //_LEKA_OS_DRIVER_CORE_BUFFERED_SERIAL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Leka - LekaOS | ||
// Copyright 2021 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// ? LCOV_EXCL_START - Exclude from coverage report | ||
|
||
#include "CoreBufferedSerial.h" | ||
|
||
using namespace leka; | ||
|
||
auto CoreBufferedSerial::read(uint8_t *buffer, ssize_t length) -> ssize_t | ||
{ | ||
return _serial.read(buffer, length); | ||
} | ||
|
||
auto CoreBufferedSerial::write(const uint8_t *buffer, ssize_t length) -> ssize_t | ||
{ | ||
return _serial.write(buffer, length); | ||
} | ||
|
||
// ? LCOV_EXCL_STOP - Exclude from coverage report |
17 changes: 17 additions & 0 deletions
17
drivers/CoreBufferedSerial/tests/CoreBufferedSerial_test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Leka - LekaOS | ||
// Copyright 2021 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "CoreBufferedSerial.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
using namespace leka; | ||
|
||
TEST(CoreBufferedSerialTest, initialization) | ||
{ | ||
auto serial = mbed::BufferedSerial {RFID_UART_TX, RFID_UART_RX, 57600}; | ||
auto coreserial = CoreBufferedSerial {serial}; | ||
|
||
ASSERT_NE(&coreserial, nullptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Leka - LekaOS | ||
// Copyright 2021 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "stub_BufferedSerial.h" | ||
|
||
namespace mbed { | ||
|
||
BufferedSerial::BufferedSerial(PinName tx, PinName rx, int baud) : SerialBase(tx, rx, baud) | ||
{ | ||
return; | ||
} | ||
|
||
BufferedSerial::~BufferedSerial() | ||
{ | ||
return; | ||
} | ||
|
||
auto BufferedSerial::poll(short events) const -> short | ||
{ | ||
return 0; | ||
} | ||
|
||
auto BufferedSerial::write(const void *buffer, size_t length) -> ssize_t | ||
{ | ||
return length; | ||
} | ||
|
||
auto BufferedSerial::read(void *buffer, size_t length) -> ssize_t | ||
{ | ||
return length; | ||
} | ||
|
||
auto BufferedSerial::close() -> int | ||
{ | ||
return 0; | ||
} | ||
|
||
auto BufferedSerial::isatty() -> int | ||
{ | ||
return 0; | ||
} | ||
|
||
auto BufferedSerial::seek(off_t offset, int whence) -> off_t | ||
{ | ||
return 0; | ||
} | ||
|
||
auto BufferedSerial::sync() -> int | ||
{ | ||
return 0; | ||
} | ||
|
||
auto BufferedSerial::enable_input(bool enabled) -> int | ||
{ | ||
return 0; | ||
} | ||
|
||
auto BufferedSerial::enable_output(bool enabled) -> int | ||
{ | ||
return 0; | ||
} | ||
|
||
void BufferedSerial::sigio(Callback<void()> func) {} | ||
|
||
} // namespace mbed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Leka - LekaOS | ||
// Copyright 2021 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "drivers/BufferedSerial.h" | ||
|
||
namespace leka { | ||
|
||
} // namespace leka |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Leka - LekaOS | ||
// Copyright 2021 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef _LEKA_OS_BUFFERED_SERIAL_MOCK_H_ | ||
#define _LEKA_OS_BUFFERED_SERIAL_MOCK_H_ | ||
|
||
#include "CoreBufferedSerial.h" | ||
#include "gmock/gmock.h" | ||
|
||
namespace leka { | ||
|
||
class CoreBufferedSerialMock : public interface::BufferedSerial | ||
{ | ||
public: | ||
MOCK_METHOD(ssize_t, read, (uint8_t *, ssize_t), (override)); | ||
MOCK_METHOD(ssize_t, write, (const uint8_t *, ssize_t), (override)); | ||
}; | ||
|
||
} // namespace leka | ||
|
||
#endif // _LEKA_OS_BUFFERED_SERIAL_MOCK_H_ |