diff --git a/lib/BoardFinder/BoardFinder.h b/lib/BoardFinder/BoardFinder.h index 2361559..0167854 100644 --- a/lib/BoardFinder/BoardFinder.h +++ b/lib/BoardFinder/BoardFinder.h @@ -11,20 +11,6 @@ #include -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 &_boardConfigs; bool checkOledConfig(BoardConfig const *boardConfig, logging::Logger &logger); diff --git a/platformio.ini b/platformio.ini index af1ca28..58e7005 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 80d0cf4..440949a 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -1,3 +1,4 @@ +#ifndef UNIT_TEST #include #include @@ -188,3 +189,5 @@ void loop() { syslogSet = true; } } + +#endif diff --git a/test/test_BoardFinder/test.cpp b/test/test_BoardFinder/test.cpp new file mode 100644 index 0000000..41154bd --- /dev/null +++ b/test/test_BoardFinder/test.cpp @@ -0,0 +1,78 @@ +#include +#include + +#include + +std::list 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() { +}