]> granicus.if.org Git - neomutt/commitdiff
test: improve test_mutt_list_insert_tail()
authorRichard Russon <rich@flatcap.org>
Wed, 29 May 2019 16:00:53 +0000 (17:00 +0100)
committerRichard Russon <rich@flatcap.org>
Wed, 29 May 2019 16:02:54 +0000 (17:02 +0100)
mutt/list.c
test/list/mutt_list_insert_tail.c

index 1eef3d4ed2da3a30bf6e5b313a931edf56e47479..f6275f19fc60749c3f5bff86b1571582afe736b1 100644 (file)
@@ -59,6 +59,8 @@ struct ListNode *mutt_list_insert_head(struct ListHead *h, char *s)
  * @param h Head of the List
  * @param s String to insert
  * @retval ptr Newly appended ListNode containing the string
+ *
+ * @note The inserted string isn't strdup()d
  */
 struct ListNode *mutt_list_insert_tail(struct ListHead *h, char *s)
 {
index e533d378e2f0a753beef2d86b52ddb3073f0638f..fcab59e3de3b2092fc5fc27b22d1cdced54bea69 100644 (file)
@@ -24,6 +24,7 @@
 #include "acutest.h"
 #include "config.h"
 #include "mutt/mutt.h"
+#include "common.h"
 
 void test_mutt_list_insert_tail(void)
 {
@@ -39,4 +40,27 @@ void test_mutt_list_insert_tail(void)
     TEST_CHECK((newnode = mutt_list_insert_tail(&listhead, NULL)) != NULL);
     FREE(&newnode);
   }
+
+  {
+    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_tail(&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[] = { "Amy", "Beth", "Cathy", "Zelda", 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_tail(&start, insert) != NULL);
+    TEST_CHECK(mutt_list_compare(&start, &expected) == true);
+    mutt_list_clear(&start);
+    mutt_list_clear(&expected);
+  }
 }