CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Common/tests/test_nmea_print.cpp
Views: 1799
1
#include <AP_gtest.h>
2
#include <AP_HAL/UARTDriver.h>
3
#include <AP_Common/NMEA.h>
4
5
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
6
7
class DummyUart: public AP_HAL::UARTDriver {
8
public:
9
bool is_initialized() override { return true; };
10
bool tx_pending() override { return false; };
11
uint32_t txspace() override { return _txspace; };
12
13
void set_txspace(uint32_t space) {
14
_txspace = space;
15
}
16
uint32_t _txspace;
17
18
protected:
19
uint32_t _available() override { return 1; };
20
void _begin(uint32_t baud, uint16_t rxSpace, uint16_t txSpace) override { };
21
void _end() override { };
22
void _flush() override { };
23
size_t _write(const uint8_t *buffer, size_t size) override { return 1; };
24
ssize_t _read(uint8_t *buf, uint16_t count) override { return 0; };
25
bool _discard_input() override { return false; }
26
};
27
28
static DummyUart test_uart;
29
30
31
TEST(NMEA, Printf)
32
{
33
// test not enough space
34
test_uart.set_txspace(2);
35
EXPECT_FALSE(nmea_printf(&test_uart, "TEST"));
36
// normal test
37
test_uart.set_txspace(9);
38
EXPECT_TRUE(nmea_printf(&test_uart, "TEST"));
39
}
40
41
AP_GTEST_MAIN()
42
43