From ab6e81997cf8c5bcf7d1778bb32d8e01425b13f1 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Thu, 22 Dec 2016 20:48:33 +0100 Subject: common: utils: added bc_slist_pop() --- tests/common/check_utils.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/common') diff --git a/tests/common/check_utils.c b/tests/common/check_utils.c index dc1eadd..4a4ee2b 100644 --- a/tests/common/check_utils.c +++ b/tests/common/check_utils.c @@ -86,6 +86,38 @@ test_slist_length(void **state) } +static void +test_slist_pop(void **state) +{ + bc_slist_t *l = NULL; + l = bc_slist_append(l, (void*) bc_strdup("bola")); + l = bc_slist_append(l, (void*) bc_strdup("guda")); + l = bc_slist_append(l, (void*) bc_strdup("chula")); + char *v = NULL; + l = bc_slist_pop(l, &v); + assert_string_equal(v, "bola"); + assert_non_null(l); + assert_string_equal(l->data, "guda"); + assert_string_equal(l->next->data, "chula"); + assert_null(l->next->next); + free(v); + l = bc_slist_pop(l, &v); + assert_string_equal(v, "guda"); + assert_non_null(l); + assert_string_equal(l->data, "chula"); + assert_null(l->next); + free(v); + l = bc_slist_pop(l, &v); + assert_string_equal(v, "chula"); + assert_null(l); + free(v); + v = NULL; + l = bc_slist_pop(l, &v); + assert_null(v); + assert_null(l); +} + + static void test_strdup(void **state) { @@ -1026,6 +1058,7 @@ main(void) unit_test(test_slist_prepend), unit_test(test_slist_free), unit_test(test_slist_length), + unit_test(test_slist_pop), // strfuncs unit_test(test_strdup), -- cgit v1.2.3-18-g5258