diff --git a/components/esp_netif/test_app/CMakeLists.txt b/components/esp_netif/test_app/CMakeLists.txt new file mode 100644 index 0000000000..46cdffa89e --- /dev/null +++ b/components/esp_netif/test_app/CMakeLists.txt @@ -0,0 +1,5 @@ +# This is the project CMakeLists.txt file for the test subproject +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(esp_netif_test) diff --git a/components/esp_netif/test_app/main/CMakeLists.txt b/components/esp_netif/test_app/main/CMakeLists.txt new file mode 100644 index 0000000000..3f50694172 --- /dev/null +++ b/components/esp_netif/test_app/main/CMakeLists.txt @@ -0,0 +1,4 @@ +idf_component_register(SRCS "esp_netif_test.c" + INCLUDE_DIRS "." + PRIV_INCLUDE_DIRS "../../private_include" "." + PRIV_REQUIRES unity esp_netif nvs_flash) diff --git a/components/esp_netif/test_app/main/esp_netif_test.c b/components/esp_netif/test_app/main/esp_netif_test.c new file mode 100644 index 0000000000..bb635e6629 --- /dev/null +++ b/components/esp_netif/test_app/main/esp_netif_test.c @@ -0,0 +1,286 @@ +#include +#include +#include "unity.h" +#include "unity_fixture.h" +#include "esp_netif.h" +#include "esp_wifi.h" +#include "nvs_flash.h" +#include "esp_wifi_netif.h" + +/* Fixme: re-add test_utils.h */ +static void test_case_uses_tcpip(void) {} + + +TEST_GROUP(esp_netif); + +TEST_SETUP(esp_netif) +{ +} + +TEST_TEAR_DOWN(esp_netif) +{ +} + +TEST(esp_netif, init_and_destroy) +{ + esp_netif_config_t cfg = ESP_NETIF_DEFAULT_WIFI_STA(); + esp_netif_t *esp_netif = esp_netif_new(NULL); + + TEST_ASSERT_EQUAL(NULL, esp_netif); + esp_netif = esp_netif_new(&cfg); + TEST_ASSERT_NOT_EQUAL(NULL, esp_netif); + + esp_netif_destroy(esp_netif); +} + + +TEST(esp_netif, get_from_if_key) +{ + // init default netif + esp_netif_config_t cfg = ESP_NETIF_DEFAULT_WIFI_STA(); + esp_netif_t *esp_netif = esp_netif_new(&cfg); + TEST_ASSERT_NOT_NULL(esp_netif); + + // check it's accessible by key + TEST_ASSERT_EQUAL(esp_netif, esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")); + + // destroy it + esp_netif_destroy(esp_netif); + + // check it's also destroyed in list + TEST_ASSERT_EQUAL(NULL, esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")); + +} + + +TEST(esp_netif, create_delete_multiple_netifs) +{ + // interface key has to be a unique identifier + const char* if_keys[] = { "if1", "if2", "if3", "if4", "if5", "if6", "if7", "if8", "if9" }; + const int nr_of_netifs = sizeof(if_keys)/sizeof(char*); + esp_netif_t *netifs[nr_of_netifs]; + + // create 10 wifi stations + for (int i=0; i