Workaround: SERIAL_CHECK_TX is broken on F7 (#14052)
[betaflight.git] / src / test / unit / io_serial_unittest.cc
blob4f5a1998941845d6cb1058809e119878e343ab05
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdint.h>
19 #include <stdbool.h>
21 #include <limits.h>
23 extern "C" {
24 #include "platform.h"
26 #include "drivers/serial.h"
27 #include "drivers/serial_softserial.h"
28 #include "drivers/serial_uart.h"
30 #include "io/serial.h"
32 #include "pg/pg.h"
33 #include "pg/pg_ids.h"
34 #include "pg/rx.h"
36 void serialInit(bool softserialEnabled, serialPortIdentifier_e serialPortToDisable);
38 PG_REGISTER(rxConfig_t, rxConfig, PG_RX_CONFIG, 0);
39 PG_REGISTER(serialPinConfig_t, serialPinConfig, PG_SERIAL_PIN_CONFIG, 0);
42 #include "unittest_macros.h"
43 #include "gtest/gtest.h"
45 TEST(IoSerialTest, TestFindPortConfig)
47 // given
48 serialInit(false, SERIAL_PORT_NONE);
50 // when
51 const serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_MSP);
53 // then
54 EXPECT_EQ(NULL, portConfig);
58 // STUBS
59 extern "C" {
60 void delay(uint32_t) {}
62 bool isSerialTransmitBufferEmpty(const serialPort_t *) { return true; }
64 void systemResetToBootloader(void) {}
66 bool telemetryCheckRxPortShared(const serialPortConfig_t *) { return false; }
68 uint32_t serialRxBytesWaiting(const serialPort_t *) { return 0; }
69 uint8_t serialRead(serialPort_t *) { return 0; }
70 void serialWrite(serialPort_t *, uint8_t) {}
72 serialPort_t *usbVcpOpen(void) { return NULL; }
74 serialPort_t *uartOpen(serialPortIdentifier_e, serialReceiveCallbackPtr, void *, uint32_t, portMode_e, portOptions_e) {
75 return NULL;
78 serialPort_t *softSerialOpen(serialPortIdentifier_e, serialReceiveCallbackPtr, void *, uint32_t, portMode_e, portOptions_e) {
79 return NULL;
82 void serialSetCtrlLineStateCb(serialPort_t *, void (*)(void *, uint16_t ), void *) {}
83 void serialSetCtrlLineState(serialPort_t *, uint16_t ) {}
84 uint32_t serialTxBytesFree(const serialPort_t *) {return 1;}
86 void serialSetBaudRateCb(serialPort_t *, void (*)(serialPort_t *context, uint32_t baud), serialPort_t *) {}
88 void pinioSet(int, bool) {}