2021-06-19 12:04:17 -03:00
|
|
|
#include <AP_gtest.h>
|
|
|
|
#include <AP_HAL/UARTDriver.h>
|
|
|
|
#include <AP_Common/NMEA.h>
|
|
|
|
|
|
|
|
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
|
|
|
|
|
|
|
|
class DummyUart: public AP_HAL::UARTDriver {
|
|
|
|
public:
|
|
|
|
bool is_initialized() override { return true; };
|
|
|
|
bool tx_pending() override { return false; };
|
|
|
|
uint32_t txspace() override { return _txspace; };
|
|
|
|
|
|
|
|
void set_txspace(uint32_t space) {
|
|
|
|
_txspace = space;
|
|
|
|
}
|
|
|
|
uint32_t _txspace;
|
2023-07-07 05:46:52 -03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
uint32_t _available() override { return 1; };
|
|
|
|
void _begin(uint32_t baud, uint16_t rxSpace, uint16_t txSpace) override { };
|
|
|
|
void _end() override { };
|
|
|
|
void _flush() override { };
|
|
|
|
size_t _write(const uint8_t *buffer, size_t size) override { return 1; };
|
|
|
|
ssize_t _read(uint8_t *buf, uint16_t count) override { return 0; };
|
|
|
|
bool _discard_input() override { return false; }
|
2021-06-19 12:04:17 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
static DummyUart test_uart;
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NMEA, Printf)
|
|
|
|
{
|
2023-10-11 04:41:51 -03:00
|
|
|
// test not enough space
|
2021-08-04 03:54:05 -03:00
|
|
|
test_uart.set_txspace(2);
|
|
|
|
EXPECT_FALSE(nmea_printf(&test_uart, "TEST"));
|
2021-06-19 12:04:17 -03:00
|
|
|
// normal test
|
2021-08-04 03:54:05 -03:00
|
|
|
test_uart.set_txspace(9);
|
|
|
|
EXPECT_TRUE(nmea_printf(&test_uart, "TEST"));
|
2021-06-19 12:04:17 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
AP_GTEST_MAIN()
|