From 61e874adb17778722af02dc66ee558fdfa5b8f45 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Mon, 29 Apr 2019 14:46:56 +0100 Subject: [PATCH] test: add parse tests for degenerate cases --- test/parse/mutt_auto_subscribe.c | 5 +++++ test/parse/mutt_check_encoding.c | 4 ++++ test/parse/mutt_check_mime_type.c | 4 ++++ test/parse/mutt_extract_message_id.c | 9 +++++++++ test/parse/mutt_is_message_type.c | 4 ++++ test/parse/mutt_matches_ignore.c | 4 ++++ test/parse/mutt_parse_content_type.c | 11 +++++++++++ test/parse/mutt_parse_mailto.c | 16 ++++++++++++++++ test/parse/mutt_parse_multipart.c | 9 +++++++++ test/parse/mutt_parse_part.c | 12 ++++++++++++ test/parse/mutt_read_mime_header.c | 4 ++++ test/parse/mutt_rfc822_parse_line.c | 22 ++++++++++++++++++++++ test/parse/mutt_rfc822_parse_message.c | 10 ++++++++++ test/parse/mutt_rfc822_read_header.c | 11 +++++++++++ test/parse/mutt_rfc822_read_line.c | 16 ++++++++++++++++ 15 files changed, 141 insertions(+) diff --git a/test/parse/mutt_auto_subscribe.c b/test/parse/mutt_auto_subscribe.c index 296f9c0a1..b8d7b010c 100644 --- a/test/parse/mutt_auto_subscribe.c +++ b/test/parse/mutt_auto_subscribe.c @@ -30,4 +30,9 @@ void test_mutt_auto_subscribe(void) { // void mutt_auto_subscribe(const char *mailto); + + { + mutt_auto_subscribe(NULL); + TEST_CHECK_(1, "mutt_auto_subscribe(NULL)"); + } } diff --git a/test/parse/mutt_check_encoding.c b/test/parse/mutt_check_encoding.c index e02a972af..6c4bde512 100644 --- a/test/parse/mutt_check_encoding.c +++ b/test/parse/mutt_check_encoding.c @@ -30,4 +30,8 @@ void test_mutt_check_encoding(void) { // int mutt_check_encoding(const char *c); + + { + TEST_CHECK(mutt_check_encoding(NULL) == 0); + } } diff --git a/test/parse/mutt_check_mime_type.c b/test/parse/mutt_check_mime_type.c index 925569ad0..f42b56ae1 100644 --- a/test/parse/mutt_check_mime_type.c +++ b/test/parse/mutt_check_mime_type.c @@ -30,4 +30,8 @@ void test_mutt_check_mime_type(void) { // int mutt_check_mime_type(const char *s); + + { + TEST_CHECK(mutt_check_mime_type(NULL) == 0); + } } diff --git a/test/parse/mutt_extract_message_id.c b/test/parse/mutt_extract_message_id.c index 0f244ac4d..078ae44e8 100644 --- a/test/parse/mutt_extract_message_id.c +++ b/test/parse/mutt_extract_message_id.c @@ -30,4 +30,13 @@ void test_mutt_extract_message_id(void) { // char *mutt_extract_message_id(const char *s, const char **saveptr); + + { + const char *saveptr = NULL; + TEST_CHECK(!mutt_extract_message_id(NULL, &saveptr)); + } + + { + TEST_CHECK(!mutt_extract_message_id("apple", NULL)); + } } diff --git a/test/parse/mutt_is_message_type.c b/test/parse/mutt_is_message_type.c index 5271d1c40..a34967e03 100644 --- a/test/parse/mutt_is_message_type.c +++ b/test/parse/mutt_is_message_type.c @@ -30,4 +30,8 @@ void test_mutt_is_message_type(void) { // bool mutt_is_message_type(int type, const char *subtype); + + { + TEST_CHECK(!mutt_is_message_type(0, NULL)); + } } diff --git a/test/parse/mutt_matches_ignore.c b/test/parse/mutt_matches_ignore.c index dcf63cfac..44755a865 100644 --- a/test/parse/mutt_matches_ignore.c +++ b/test/parse/mutt_matches_ignore.c @@ -30,4 +30,8 @@ void test_mutt_matches_ignore(void) { // bool mutt_matches_ignore(const char *s); + + { + TEST_CHECK(!mutt_matches_ignore(NULL)); + } } diff --git a/test/parse/mutt_parse_content_type.c b/test/parse/mutt_parse_content_type.c index c675b332c..66820a740 100644 --- a/test/parse/mutt_parse_content_type.c +++ b/test/parse/mutt_parse_content_type.c @@ -30,4 +30,15 @@ void test_mutt_parse_content_type(void) { // void mutt_parse_content_type(const char *s, struct Body *ct); + + { + struct Body body = { 0 }; + mutt_parse_content_type(NULL, &body); + TEST_CHECK_(1, "mutt_parse_content_type(NULL, &body)"); + } + + { + mutt_parse_content_type("apple", NULL); + TEST_CHECK_(1, "mutt_parse_content_type(\"apple\", NULL)"); + } } diff --git a/test/parse/mutt_parse_mailto.c b/test/parse/mutt_parse_mailto.c index 44b534afb..27b5daccd 100644 --- a/test/parse/mutt_parse_mailto.c +++ b/test/parse/mutt_parse_mailto.c @@ -30,4 +30,20 @@ void test_mutt_parse_mailto(void) { // int mutt_parse_mailto(struct Envelope *e, char **body, const char *src); + + { + char *body = NULL; + TEST_CHECK(mutt_parse_mailto(NULL, &body, "apple") != 0); + } + + { + struct Envelope envelope = { 0 }; + TEST_CHECK(mutt_parse_mailto(&envelope, NULL, "apple") != 0); + } + + { + struct Envelope envelope = { 0 }; + char *body = NULL; + TEST_CHECK(mutt_parse_mailto(&envelope, &body, NULL) != 0); + } } diff --git a/test/parse/mutt_parse_multipart.c b/test/parse/mutt_parse_multipart.c index 5dceffbcf..2fede9691 100644 --- a/test/parse/mutt_parse_multipart.c +++ b/test/parse/mutt_parse_multipart.c @@ -30,4 +30,13 @@ void test_mutt_parse_multipart(void) { // struct Body *mutt_parse_multipart(FILE *fp, const char *boundary, off_t end_off, bool digest); + + { + TEST_CHECK(!mutt_parse_multipart(NULL, "apple", 0, false)); + } + + { + FILE fp = { 0 }; + TEST_CHECK(!mutt_parse_multipart(&fp, NULL, 0, false)); + } } diff --git a/test/parse/mutt_parse_part.c b/test/parse/mutt_parse_part.c index 4941208d0..0340c7ca2 100644 --- a/test/parse/mutt_parse_part.c +++ b/test/parse/mutt_parse_part.c @@ -30,4 +30,16 @@ void test_mutt_parse_part(void) { // void mutt_parse_part(FILE *fp, struct Body *b); + + { + struct Body body = { 0 }; + mutt_parse_part(NULL, &body); + TEST_CHECK_(1, "mutt_parse_part(NULL, &body)"); + } + + { + FILE fp = { 0 }; + mutt_parse_part(&fp, NULL); + TEST_CHECK_(1, "mutt_parse_part(&fp, NULL)"); + } } diff --git a/test/parse/mutt_read_mime_header.c b/test/parse/mutt_read_mime_header.c index 8c1f30650..5d46e20f9 100644 --- a/test/parse/mutt_read_mime_header.c +++ b/test/parse/mutt_read_mime_header.c @@ -30,4 +30,8 @@ void test_mutt_read_mime_header(void) { // struct Body *mutt_read_mime_header(FILE *fp, bool digest); + + { + TEST_CHECK(!mutt_read_mime_header(NULL, false)); + } } diff --git a/test/parse/mutt_rfc822_parse_line.c b/test/parse/mutt_rfc822_parse_line.c index d47084156..d3040c39c 100644 --- a/test/parse/mutt_rfc822_parse_line.c +++ b/test/parse/mutt_rfc822_parse_line.c @@ -30,4 +30,26 @@ void test_mutt_rfc822_parse_line(void) { // int mutt_rfc822_parse_line(struct Envelope *env, struct Email *e, char *line, char *p, bool user_hdrs, bool weed, bool do_2047); + + { + struct Email email = { 0 }; + TEST_CHECK(mutt_rfc822_parse_line(NULL, &email, "apple", "banana", false, false, false) == 0); + } + + { + struct Envelope envelope = { 0 }; + TEST_CHECK(mutt_rfc822_parse_line(&envelope, NULL, "apple", "banana", false, false, false) == 0); + } + + { + struct Envelope envelope = { 0 }; + struct Email email = { 0 }; + TEST_CHECK(mutt_rfc822_parse_line(&envelope, &email, NULL, "banana", false, false, false) == 0); + } + + { + struct Envelope envelope = { 0 }; + struct Email email = { 0 }; + TEST_CHECK(mutt_rfc822_parse_line(&envelope, &email, "apple", NULL, false, false, false) == 0); + } } diff --git a/test/parse/mutt_rfc822_parse_message.c b/test/parse/mutt_rfc822_parse_message.c index 3b6b6ae0a..f71e8c260 100644 --- a/test/parse/mutt_rfc822_parse_message.c +++ b/test/parse/mutt_rfc822_parse_message.c @@ -30,4 +30,14 @@ void test_mutt_rfc822_parse_message(void) { // struct Body *mutt_rfc822_parse_message(FILE *fp, struct Body *parent); + + { + struct Body body = { 0 }; + TEST_CHECK(!mutt_rfc822_parse_message(NULL, &body)); + } + + { + FILE fp = { 0 }; + TEST_CHECK(!mutt_rfc822_parse_message(&fp, NULL)); + } } diff --git a/test/parse/mutt_rfc822_read_header.c b/test/parse/mutt_rfc822_read_header.c index ed744990a..59a8406c8 100644 --- a/test/parse/mutt_rfc822_read_header.c +++ b/test/parse/mutt_rfc822_read_header.c @@ -30,4 +30,15 @@ void test_mutt_rfc822_read_header(void) { // struct Envelope *mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed); + + { + struct Email email = { 0 }; + TEST_CHECK(!mutt_rfc822_read_header(NULL, &email, false, false)); + } + + { + FILE *fp = fopen("/dev/null", "r"); + TEST_CHECK(mutt_rfc822_read_header(fp, NULL, false, false) != NULL); + fclose(fp); + } } diff --git a/test/parse/mutt_rfc822_read_line.c b/test/parse/mutt_rfc822_read_line.c index 8bdb5a521..da6455087 100644 --- a/test/parse/mutt_rfc822_read_line.c +++ b/test/parse/mutt_rfc822_read_line.c @@ -30,4 +30,20 @@ void test_mutt_rfc822_read_line(void) { // char *mutt_rfc822_read_line(FILE *fp, char *line, size_t *linelen); + + { + size_t linelen = 0; + TEST_CHECK(!mutt_rfc822_read_line(NULL, "apple", &linelen)); + } + + { + FILE fp = { 0 }; + size_t linelen = 0; + TEST_CHECK(!mutt_rfc822_read_line(&fp, NULL, &linelen)); + } + + { + FILE fp = { 0 }; + TEST_CHECK(!mutt_rfc822_read_line(&fp, "apple", NULL)); + } } -- 2.49.0