From 713fcd0af5304f99d3f35f718ae58ed7cfddc382 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Wed, 29 May 2019 17:00:53 +0100 Subject: [PATCH] test: improve test_mutt_list_insert_head() --- mutt/list.c | 2 ++ test/list/mutt_list_insert_head.c | 36 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/mutt/list.c b/mutt/list.c index 5b37da595..1eef3d4ed 100644 --- a/mutt/list.c +++ b/mutt/list.c @@ -40,6 +40,8 @@ * @param h Head of the List * @param s String to insert * @retval ptr Newly inserted ListNode containing the string + * + * @note The inserted string isn't strdup()d */ struct ListNode *mutt_list_insert_head(struct ListHead *h, char *s) { diff --git a/test/list/mutt_list_insert_head.c b/test/list/mutt_list_insert_head.c index a3c31300f..1590f5118 100644 --- a/test/list/mutt_list_insert_head.c +++ b/test/list/mutt_list_insert_head.c @@ -24,6 +24,7 @@ #include "acutest.h" #include "config.h" #include "mutt/mutt.h" +#include "common.h" void test_mutt_list_insert_head(void) { @@ -39,4 +40,39 @@ void test_mutt_list_insert_head(void) TEST_CHECK((newnode = mutt_list_insert_head(&listhead, NULL)) != NULL); FREE(&newnode); } + + { + static const char *start_names[] = { "Amy", "Beth", "Cathy", NULL }; + static const char *expected_names[] = { "Zelda", "Amy", "Beth", "Cathy", NULL }; + char *insert = "Zelda"; + struct ListHead start = test_list_create(start_names, false); + struct ListHead expected = test_list_create(expected_names, false); + TEST_CHECK(mutt_list_insert_head(&start, insert) != NULL); + TEST_CHECK(mutt_list_compare(&start, &expected) == true); + mutt_list_clear(&start); + mutt_list_clear(&expected); + } + + { + static const char *expected_names[] = { "Zelda", NULL }; + char *insert = "Zelda"; + struct ListHead start = STAILQ_HEAD_INITIALIZER(start); + struct ListHead expected = test_list_create(expected_names, false); + TEST_CHECK(mutt_list_insert_head(&start, insert) != NULL); + TEST_CHECK(mutt_list_compare(&start, &expected) == true); + mutt_list_clear(&start); + mutt_list_clear(&expected); + } + + { + static const char *start_names[] = { "Amy", "Beth", "Cathy", NULL }; + static const char *expected_names[] = { "Zelda", "Amy", "Beth", "Cathy", NULL }; + char *insert = "Zelda"; + struct ListHead start = test_list_create(start_names, false); + struct ListHead expected = test_list_create(expected_names, false); + TEST_CHECK(mutt_list_insert_head(&start, insert) != NULL); + TEST_CHECK(mutt_list_compare(&start, &expected) == true); + mutt_list_clear(&start); + mutt_list_clear(&expected); + } } -- 2.40.0