add first unittest

pull/269/head
Peter Buchegger 2023-02-18 11:51:39 +01:00
rodzic 3cab03ab7e
commit 7067813e6f
4 zmienionych plików z 100 dodań i 16 usunięć

Wyświetl plik

@ -11,20 +11,6 @@
#include <logger.h>
enum BoardType {
eHELTEC_WIFI_LORA_32_V1,
eHELTEC_WIFI_LORA_32_V2,
eTTGO_LORA32_V1,
eTTGO_LORA32_V2,
eTTGO_T_Beam_V0_7,
eTTGO_T_Beam_V1_0,
eLILYGO_POE_ETH_BOARD,
eWT32_ETH_BOARD,
eTRACKERD,
eGUALTHERIUS_LORAHAM_v100,
eGUALTHERIUS_LORAHAM_v106
};
class OledPins {
public:
explicit OledPins(int8_t sda, int8_t scl, int8_t reset = -1, int8_t addr = 0x3C);
@ -80,6 +66,20 @@ public:
int8_t Pin;
};
enum BoardType {
eHELTEC_WIFI_LORA_32_V1,
eHELTEC_WIFI_LORA_32_V2,
eTTGO_LORA32_V1,
eTTGO_LORA32_V2,
eTTGO_T_Beam_V0_7,
eTTGO_T_Beam_V1_0,
eLILYGO_POE_ETH_BOARD,
eWT32_ETH_BOARD,
eTRACKERD,
eGUALTHERIUS_LORAHAM_v100,
eGUALTHERIUS_LORAHAM_v106
};
class BoardConfig {
public:
explicit BoardConfig(String name, BoardType type, OledPins oled, LoraPins lora, GpsPins gps = GpsPins(), EthernetPins ethernet = EthernetPins(), ButtonPins button = ButtonPins(), bool needcheckpowerchip = false, bool powercheckstatus = false);
@ -106,7 +106,9 @@ public:
BoardConfig const *getBoardConfig(String name);
#ifndef UNIT_TEST
private:
#endif
const std::list<BoardConfig const *> &_boardConfigs;
bool checkOledConfig(BoardConfig const *boardConfig, logging::Logger &logger);

Wyświetl plik

@ -21,6 +21,7 @@ check_tool = cppcheck
check_flags =
cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK --force lib -ilib/TimeLib -ilib/LoRa -ilib/NTPClient
check_skip_packages = yes
test_build_src = yes
#monitor_flags = --raw
# activate for OTA Update, use the CALLSIGN from is-cfg.json as upload_port:
#upload_protocol = espota
@ -28,10 +29,10 @@ check_skip_packages = yes
[env:lora_board]
board = esp32doit-devkit-v1
build_flags = -Werror -Wall
build_flags = -Werror -Wall -DUNITY_INCLUDE_PRINT_FORMATTED
[env:lora_board_debug]
board = esp32doit-devkit-v1
build_flags = -Werror -Wall -DCORE_DEBUG_LEVEL=5
build_flags = -Werror -Wall -DCORE_DEBUG_LEVEL=5 -DUNITY_INCLUDE_PRINT_FORMATTED
build_type = debug
monitor_filters = esp32_exception_decoder

Wyświetl plik

@ -1,3 +1,4 @@
#ifndef UNIT_TEST
#include <map>
#include <APRS-IS.h>
@ -188,3 +189,5 @@ void loop() {
syslogSet = true;
}
}
#endif

Wyświetl plik

@ -0,0 +1,78 @@
#include <Arduino.h>
#include <unity.h>
#include <BoardFinder.h>
std::list<BoardConfig const *> boardConfigs;
logging::Logger logger;
BoardFinder *finder = 0;
void setUp(void) {
boardConfigs.push_back(&TTGO_LORA32_V1);
boardConfigs.push_back(&TTGO_LORA32_V2);
boardConfigs.push_back(&TTGO_T_Beam_V1_0);
boardConfigs.push_back(&LILYGO_POE_ETH_BOARD);
boardConfigs.push_back(&HELTEC_WIFI_LORA_32_V1);
boardConfigs.push_back(&HELTEC_WIFI_LORA_32_V2);
finder = new BoardFinder(boardConfigs);
logger.setSerial(&Serial);
}
void tearDown(void) {
delete finder;
finder = 0;
}
void test_oled_found(void) {
bool found = false;
for (auto boardConfig : boardConfigs) {
if (finder->checkOledConfig(boardConfig, logger)) {
TEST_PRINTF("found: %s", boardConfig->Name.c_str());
found = true;
break;
}
}
TEST_ASSERT_TRUE(found);
}
void test_modem_found(void) {
bool found = false;
for (auto boardConfig : boardConfigs) {
if (finder->checkModemConfig(boardConfig)) {
TEST_PRINTF("found: %s", boardConfig->Name.c_str());
found = true;
break;
}
}
TEST_ASSERT_TRUE(found);
}
void test_search_board_config(void) {
BoardConfig const *boardConfig = finder->searchBoardConfig(logger);
TEST_ASSERT_NOT_NULL(boardConfig);
}
void test_get_board_config(void) {
BoardConfig const *boardConfig = finder->getBoardConfig("LILYGO_POE_ETH_BOARD");
TEST_ASSERT_NOT_NULL(boardConfig);
}
void test_get_board_config_negative(void) {
BoardConfig const *boardConfig = finder->getBoardConfig("NO BOARD");
TEST_ASSERT_NULL(boardConfig);
}
void setup() {
UNITY_BEGIN();
RUN_TEST(test_oled_found);
RUN_TEST(test_modem_found);
RUN_TEST(test_search_board_config);
RUN_TEST(test_get_board_config);
RUN_TEST(test_get_board_config_negative);
UNITY_END();
}
void loop() {
}