]> granicus.if.org Git - neomutt/commitdiff
test: improve test_mutt_list_insert_head()
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_head.c

index 5b37da595b398b6c5b47cff6b07298f93dd616d0..1eef3d4ed2da3a30bf6e5b313a931edf56e47479 100644 (file)
@@ -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)
 {
index a3c31300fad9c3a9ba807fdaee39a0ead1282813..1590f51184bb6a45a95b73d1b78e9c08a1b1cc2c 100644 (file)
@@ -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);
+  }
 }