Skip to content

Commit

Permalink
tests: Add test for lists
Browse files Browse the repository at this point in the history
The test is checking that counting the length of a list is done
properly.
  • Loading branch information
LukasWoodtli committed Sep 23, 2024
1 parent 7d3a1e7 commit 2967734
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/core_list_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,28 @@ static void test_list_rm(void) {

static void test_list_newId(void) {
list_node_t *list = reset_list();
const uint16_t id = lwm2m_list_newId((lwm2m_list_t *)list);
const uint16_t id = LWM2M_LIST_NEW_ID(list);
CU_ASSERT_EQUAL(id, 1);
}

static void test_dynamic_allocated_nodes(void) {
list_node_t *head = lwm2m_malloc(sizeof(list_node_t));
memset(head, 0, sizeof(*head));
for (int i = 0; i < 3; ++i) {
list_node_t *node = lwm2m_malloc(sizeof(list_node_t));
memset(node, 0, sizeof(*node));
node->mID = LWM2M_LIST_NEW_ID(head);
LWM2M_LIST_ADD(head, node);
}
const size_t count = LWM2M_LIST_COUNT(head);
CU_ASSERT_EQUAL(4, count);
CU_ASSERT_PTR_NOT_NULL(LWM2M_LIST_FIND(head, 0));
CU_ASSERT_PTR_NOT_NULL(LWM2M_LIST_FIND(head, 1));
CU_ASSERT_PTR_NOT_NULL(LWM2M_LIST_FIND(head, 2));
CU_ASSERT_PTR_NOT_NULL(LWM2M_LIST_FIND(head, 3));
LWM2M_LIST_FREE(head);
}

static void test_list_malloc_free(void) {
list_node_t *list = lwm2m_malloc(sizeof(list_node_t));
memset(list, 0, sizeof(*list));
Expand All @@ -106,6 +124,7 @@ static struct TestTable table[] = {
{"test_list_not_find", test_list_not_find},
{"test_list_rm", test_list_rm},
{"test_list_newId", test_list_newId},
{"test_dynamic_allocated_nodes", test_dynamic_allocated_nodes},
{"test_list_malloc_free", test_list_malloc_free},
{NULL, NULL},
};
Expand Down

0 comments on commit 2967734

Please sign in to comment.