From: Richard Russon Date: Mon, 29 Apr 2019 13:46:56 +0000 (+0100) Subject: test: add list tests for degenerate cases X-Git-Tag: 2019-10-25~233^2~67 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ca67e558246cf8b9060da41c8bde28090263b896;p=neomutt test: add list tests for degenerate cases --- diff --git a/test/list/mutt_list_clear.c b/test/list/mutt_list_clear.c index 3c49c4c45..f9796679e 100644 --- a/test/list/mutt_list_clear.c +++ b/test/list/mutt_list_clear.c @@ -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)"); + } } diff --git a/test/list/mutt_list_compare.c b/test/list/mutt_list_compare.c index 9ce7da224..50901a90a 100644 --- a/test/list/mutt_list_compare.c +++ b/test/list/mutt_list_compare.c @@ -28,4 +28,14 @@ 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)); + } } diff --git a/test/list/mutt_list_find.c b/test/list/mutt_list_find.c index d523bd1ec..3166f363a 100644 --- a/test/list/mutt_list_find.c +++ b/test/list/mutt_list_find.c @@ -28,4 +28,13 @@ 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)); + } } diff --git a/test/list/mutt_list_free.c b/test/list/mutt_list_free.c index 5f077e13e..faab626fc 100644 --- a/test/list/mutt_list_free.c +++ b/test/list/mutt_list_free.c @@ -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)"); + } } diff --git a/test/list/mutt_list_free_type.c b/test/list/mutt_list_free_type.c index 00253db06..8daa6886d 100644 --- a/test/list/mutt_list_free_type.c +++ b/test/list/mutt_list_free_type.c @@ -25,7 +25,23 @@ #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)"); + } } diff --git a/test/list/mutt_list_insert_after.c b/test/list/mutt_list_insert_after.c index 09fb9f5fe..d9389cc15 100644 --- a/test/list/mutt_list_insert_after.c +++ b/test/list/mutt_list_insert_after.c @@ -28,4 +28,20 @@ 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); + } } diff --git a/test/list/mutt_list_insert_head.c b/test/list/mutt_list_insert_head.c index 5169aeceb..decafd992 100644 --- a/test/list/mutt_list_insert_head.c +++ b/test/list/mutt_list_insert_head.c @@ -28,4 +28,13 @@ 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); + } } diff --git a/test/list/mutt_list_insert_tail.c b/test/list/mutt_list_insert_tail.c index 9d7fec7f1..990001701 100644 --- a/test/list/mutt_list_insert_tail.c +++ b/test/list/mutt_list_insert_tail.c @@ -28,4 +28,13 @@ 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); + } } diff --git a/test/list/mutt_list_match.c b/test/list/mutt_list_match.c index 4718c53fc..7c08bbee3 100644 --- a/test/list/mutt_list_match.c +++ b/test/list/mutt_list_match.c @@ -28,4 +28,13 @@ 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)); + } }