diff --git a/test/app_test/main/test_main.c b/test/app_test/main/test_main.c index 2366e3e..e6104b8 100644 --- a/test/app_test/main/test_main.c +++ b/test/app_test/main/test_main.c @@ -1,7 +1,16 @@ #include +#include +#include void app_main(void) { + esp_err_t err = nvs_flash_init(); + if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) { + ESP_ERROR_CHECK(nvs_flash_erase()); + err = nvs_flash_init(); + } + ESP_ERROR_CHECK( err ); + UNITY_BEGIN(); unity_run_all_tests(); UNITY_END(); diff --git a/test/app_test/test_edgehog.py b/test/app_test/test_edgehog.py index 33f0060..1430b4b 100644 --- a/test/app_test/test_edgehog.py +++ b/test/app_test/test_edgehog.py @@ -2,6 +2,6 @@ def test_edgehog_device(dut, redirect): dut.expect_unity_test_output() - assert len(dut.testsuite.testcases) == 5 + assert len(dut.testsuite.testcases) == 14 assert dut.testsuite.attrs['failures'] == 0 assert dut.testsuite.attrs['errors'] == 0 diff --git a/test/test_edgehog_device.c b/test/test_edgehog_device.c index cbd2fd4..6f76ae4 100644 --- a/test/test_edgehog_device.c +++ b/test/test_edgehog_device.c @@ -17,18 +17,85 @@ */ #include "edgehog_device.h" +#include "edgehog_device.c" #include "unity.h" #include +#include "edgehog_device_private.h" -TEST_CASE("edgehog_device_1", "create an edgehog_device with NULL edgehog_conf") +TEST_CASE("edgehog_device_01", "create an edgehog_device with NULL edgehog_conf") { edgehog_device_handle_t edgehog_device = edgehog_device_new(NULL); TEST_ASSERT(!edgehog_device); } -TEST_CASE("edgehog_device_2", "create an edgehog_device with NULL astarte device in edgehog_conf") +TEST_CASE("edgehog_device_02", "create an edgehog_device with NULL astarte device in edgehog_conf") { edgehog_device_config_t edgehog_conf = { .astarte_device = NULL, .partition_label = "nvs" }; edgehog_device_handle_t edgehog_device = edgehog_device_new(&edgehog_conf); TEST_ASSERT(!edgehog_device); } + +TEST_CASE("edgehog_device_03", "edgehog_nvs_set_str wrong partition returns != ESP_OK") +{ + esp_err_t result = edgehog_nvs_set_str("nvs_bad", "", NULL); + TEST_ASSERT(result != ESP_OK); +} + +TEST_CASE("edgehog_device_04", "edgehog_nvs_get_string returns NULL") +{ + const char* value_returned = edgehog_nvs_get_string("nvs", "key2"); + TEST_ASSERT(!value_returned) +} + +TEST_CASE("edgehog_device_05", "edgehog_nvs_set_string set value returns ESP_OK") +{ + char *value_expected = "value"; + esp_err_t result = edgehog_nvs_set_str("nvs", "key1", value_expected); + TEST_ASSERT(result == ESP_OK) + edgehog_nvs_set_str("nvs", "key1", ""); +} + +TEST_CASE("edgehog_device_06", "edgehog_nvs_get_string get value returns ESP_OK") +{ + char *value_expected = "value"; + esp_err_t result = edgehog_nvs_set_str("nvs", "key1", value_expected); + TEST_ASSERT(result == ESP_OK); + char* value_returned = edgehog_nvs_get_string("nvs", "key1"); + TEST_ASSERT(value_returned) + TEST_ASSERT(strcmp(value_expected, value_returned) == 0) + free(value_returned); +} + +TEST_CASE("edgehog_device_07", "edgehog_device_get_telemetry_periodic returns publish_device_hardware_info function") +{ + telemetry_periodic telemetry_periodic_expected = publish_device_hardware_info; + telemetry_periodic telemetry_periodic_fn = edgehog_device_get_telemetry_periodic(EDGEHOG_TELEMETRY_HW_INFO); + TEST_ASSERT(telemetry_periodic_fn) + TEST_ASSERT(telemetry_periodic_fn == telemetry_periodic_expected) +} + +TEST_CASE("edgehog_device_08", "edgehog_device_get_telemetry_periodic doesn't publish_device_hardware_info function") +{ + telemetry_periodic telemetry_periodic_expected = scan_wifi_ap; + telemetry_periodic telemetry_periodic_fn = edgehog_device_get_telemetry_periodic(EDGEHOG_TELEMETRY_HW_INFO); + TEST_ASSERT(telemetry_periodic_fn) + TEST_ASSERT(telemetry_periodic_fn != telemetry_periodic_expected) +} + +TEST_CASE("edgehog_device_09", "edgehog_device_get_telemetry_periodic returns NULL") +{ + telemetry_periodic telemetry_periodic_fn = edgehog_device_get_telemetry_periodic(EDGEHOG_TELEMETRY_INVALID); + TEST_ASSERT(!telemetry_periodic_fn) +} + +TEST_CASE("edgehog_device_10", "edgehog_device_get_telemetry_type returns EDGEHOG_TELEMETRY_INVALID") +{ + telemetry_type_t telemetry_type = edgehog_device_get_telemetry_type(""); + TEST_ASSERT(telemetry_type == EDGEHOG_TELEMETRY_INVALID) +} + +TEST_CASE("edgehog_device_11", "edgehog_device_get_telemetry_type returns EDGEHOG_TELEMETRY_HW_INFO") +{ + telemetry_type_t telemetry_type = edgehog_device_get_telemetry_type(hardware_info_interface.name); + TEST_ASSERT(telemetry_type == EDGEHOG_TELEMETRY_HW_INFO) +}