Skip to content

Commit

Permalink
Add test to edgehog_device
Browse files Browse the repository at this point in the history
Add nvs get/set string test cases.
Add `edgehog_device_get_telemetry_typ` test cases.
Add `edgehog_device_get_telemetry_periodic` test cases.

Signed-off-by: Antonio Gisondi <[email protected]>
  • Loading branch information
harlem88 committed Feb 9, 2022
1 parent 67119b4 commit 3aa5011
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
9 changes: 9 additions & 0 deletions test/app_test/main/test_main.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#include <unity.h>
#include <nvs_flash.h>
#include <nvs.h>

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();
Expand Down
2 changes: 1 addition & 1 deletion test/app_test/test_edgehog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
71 changes: 69 additions & 2 deletions test/test_edgehog_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,85 @@
*/

#include "edgehog_device.h"
#include "edgehog_device.c"
#include "unity.h"
#include <astarte_credentials.h>
#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)
}

0 comments on commit 3aa5011

Please sign in to comment.