From d9e9f75bfc4c8949e824fdd7019eda6185ea13bf Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Mon, 8 Jan 2024 12:41:01 +0900 Subject: [PATCH] kernel: api: implement test for sys_slist_find implement test for sys_slist_find signed-off-by: Gaetan Perrot --- tests/unit/list/slist.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/unit/list/slist.c b/tests/unit/list/slist.c index 49c4b8257b..53e3ebc70a 100644 --- a/tests/unit/list/slist.c +++ b/tests/unit/list/slist.c @@ -184,7 +184,7 @@ static inline bool verify_tail_head(sys_slist_t *list, * @see sys_slist_init(), sys_slist_append(), * sys_slist_find_and_remove(), sys_slist_prepend(), * sys_slist_remove(), sys_slist_get(), sys_slist_get_not_empty(), - * sys_slist_append_list(), sys_slist_merge_list() + * sys_slist_append_list(), sys_slist_merge_list(), sys_slist_find() */ ZTEST(dlist_api, test_slist) { @@ -202,6 +202,13 @@ ZTEST(dlist_api, test_slist) &test_node_1.node, true)), "test_list head/tail are wrong"); + /* Find the node 1, previous node should be null */ + sys_snode_t *test_node_1_prev = &test_node_1.node; + + zassert_true(sys_slist_find(&test_list, &test_node_1.node, &test_node_1_prev), + "test_list did not find node "); + zassert_is_null(test_node_1_prev, "test_list previous node not null "); + /* Finding and removing node 1 */ sys_slist_find_and_remove(&test_list, &test_node_1.node); zassert_true((verify_emptyness(&test_list)), @@ -258,6 +265,14 @@ ZTEST(dlist_api, test_slist) &test_node_4.node), "test_list node links are wrong"); + /* Find the node 4 and get the previous node*/ + sys_snode_t *test_node_4_prev = NULL; + + zassert_true(sys_slist_find(&test_list, &test_node_4.node, &test_node_4_prev), + "test_list did not find node"); + zassert_equal(&test_node_2.node, test_node_4_prev, + "test_list previous node wrong "); + /* Finding and removing node 1 */ sys_slist_find_and_remove(&test_list, &test_node_1.node); zassert_true((verify_content_amount(&test_list, 3)),