]> granicus.if.org Git - neomutt/commitdiff
test: add list tests for degenerate cases
authorRichard Russon <rich@flatcap.org>
Mon, 29 Apr 2019 13:46:56 +0000 (14:46 +0100)
committerRichard Russon <rich@flatcap.org>
Tue, 30 Apr 2019 10:22:02 +0000 (11:22 +0100)
test/list/mutt_list_clear.c
test/list/mutt_list_compare.c
test/list/mutt_list_find.c
test/list/mutt_list_free.c
test/list/mutt_list_free_type.c
test/list/mutt_list_insert_after.c
test/list/mutt_list_insert_head.c
test/list/mutt_list_insert_tail.c
test/list/mutt_list_match.c

index 3c49c4c45f2fa016f9783318cfc21647e0214278..f9796679e683e9ec54c3d2e705313e19d247fc68 100644 (file)
@@ -28,4 +28,9 @@
 void test_mutt_list_clear(void)
 {
   // void mutt_list_clear(struct ListHead *h);
+
+  {
+    mutt_list_clear(NULL);
+    TEST_CHECK_(1, "mutt_list_clear(NULL)");
+  }
 }
index 9ce7da224b152e814591526999fbe53da1bc6d47..50901a90a0d388644191ccf1a6d1855227b763ee 100644 (file)
 void test_mutt_list_compare(void)
 {
   // bool mutt_list_compare(const struct ListHead *ah, const struct ListHead *bh);
+
+  {
+    struct ListHead listhead = { 0 };
+    TEST_CHECK(!mutt_list_compare(NULL, &listhead));
+  }
+
+  {
+    struct ListHead listhead = { 0 };
+    TEST_CHECK(!mutt_list_compare(&listhead, NULL));
+  }
 }
index d523bd1ec00375a1cf5a0cd0f0df76af5067b02a..3166f363afb933a0fb8d60325324055fcecbf329 100644 (file)
 void test_mutt_list_find(void)
 {
   // struct ListNode *mutt_list_find(const struct ListHead *h, const char *data);
+
+  {
+    TEST_CHECK(!mutt_list_find(NULL, "apple"));
+  }
+
+  {
+    struct ListHead listhead = { 0 };
+    TEST_CHECK(!mutt_list_find(&listhead, NULL));
+  }
 }
index 5f077e13e752a85b9982585a83c62f2440147d51..faab626fc0f7bb54e6e1a63a752832e7c68eb988 100644 (file)
@@ -28,4 +28,9 @@
 void test_mutt_list_free(void)
 {
   // void mutt_list_free(struct ListHead *h);
+
+  {
+    mutt_list_free(NULL);
+    TEST_CHECK_(1, "mutt_list_free(NULL)");
+  }
 }
index 00253db069ceb6a3e1347cff2837ab96fd8b8c4e..8daa6886d6a610942d22b2592a70ab60b400ebd3 100644 (file)
 #include "config.h"
 #include "mutt/mutt.h"
 
+void dummy_free(void **ptr)
+{
+}
+
 void test_mutt_list_free_type(void)
 {
   // void mutt_list_free_type(struct ListHead *h, list_free_t fn);
+
+  {
+    list_free_t fn = dummy_free;
+    mutt_list_free_type(NULL, fn);
+    TEST_CHECK_(1, "mutt_list_free_type(NULL, fn)");
+  }
+
+  {
+    struct ListHead listhead = { 0 };
+    mutt_list_free_type(&listhead, NULL);
+    TEST_CHECK_(1, "mutt_list_free_type(&listhead, NULL)");
+  }
 }
index 09fb9f5fe3d881f5fbb756f0201fe043accd794c..d9389cc15e67b35b8fa4393198d97702d6a3ec95 100644 (file)
 void test_mutt_list_insert_after(void)
 {
   // struct ListNode *mutt_list_insert_after(struct ListHead *h, struct ListNode *n, char *s);
+
+  {
+    struct ListNode listnode = { 0 };
+    TEST_CHECK(!mutt_list_insert_after(NULL, &listnode, "apple"));
+  }
+
+  {
+    struct ListHead listhead = { 0 };
+    TEST_CHECK(!mutt_list_insert_after(&listhead, NULL, "apple"));
+  }
+
+  {
+    struct ListHead listhead = STAILQ_HEAD_INITIALIZER(listhead);
+    struct ListNode listnode = { 0 };
+    TEST_CHECK(mutt_list_insert_after(&listhead, &listnode, NULL) != NULL);
+  }
 }
index 5169aeceb6769a4b70609fa1d9b594419b0999b0..decafd9926809f4525c18c2884f8e65709eb1d8e 100644 (file)
 void test_mutt_list_insert_head(void)
 {
   // struct ListNode *mutt_list_insert_head(struct ListHead *h, char *s);
+
+  {
+    TEST_CHECK(!mutt_list_insert_head(NULL, "apple"));
+  }
+
+  {
+    struct ListHead listhead = STAILQ_HEAD_INITIALIZER(listhead);
+    TEST_CHECK(mutt_list_insert_head(&listhead, NULL) != NULL);
+  }
 }
index 9d7fec7f1d6c73a039e16bc219c623f9ecefd85c..990001701d2827b18ab9a10e9d0aea2fb3cfe784 100644 (file)
 void test_mutt_list_insert_tail(void)
 {
   // struct ListNode *mutt_list_insert_tail(struct ListHead *h, char *s);
+
+  {
+    TEST_CHECK(!mutt_list_insert_tail(NULL, "apple"));
+  }
+
+  {
+    struct ListHead listhead = STAILQ_HEAD_INITIALIZER(listhead);
+    TEST_CHECK(mutt_list_insert_tail(&listhead, NULL) != NULL);
+  }
 }
index 4718c53fc18ec0818a17c11c8abd2dc19ffad18d..7c08bbee3b9857aceb44760bdd2ffa3f7a946ed6 100644 (file)
 void test_mutt_list_match(void)
 {
   // bool mutt_list_match(const char *s, struct ListHead *h);
+
+  {
+    struct ListHead listhead = { 0 };
+    TEST_CHECK(!mutt_list_match(NULL, &listhead));
+  }
+
+  {
+    TEST_CHECK(!mutt_list_match("apple", NULL));
+  }
 }