From f321991de2c2a7cd3c2d0f2b3c90ebe4ee8f6e74 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Sat, 27 Apr 2019 17:53:29 +0100 Subject: [PATCH] test: add address tests for degenerate cases --- test/address/mutt_addr_append.c | 10 ++++++++++ test/address/mutt_addr_cat.c | 19 +++++++++++++++++++ test/address/mutt_addr_cmp.c | 10 ++++++++++ test/address/mutt_addr_cmp_strict.c | 10 ++++++++++ test/address/mutt_addr_copy.c | 4 ++++ test/address/mutt_addr_copy_list.c | 4 ++++ test/address/mutt_addr_for_display.c | 4 ++++ test/address/mutt_addr_free.c | 5 +++++ test/address/mutt_addr_has_recips.c | 4 ++++ test/address/mutt_addr_is_intl.c | 4 ++++ test/address/mutt_addr_is_local.c | 4 ++++ test/address/mutt_addr_mbox_to_udomain.c | 16 ++++++++++++++++ test/address/mutt_addr_parse_list.c | 11 +++++++++++ test/address/mutt_addr_parse_list2.c | 11 +++++++++++ test/address/mutt_addr_qualify.c | 11 +++++++++++ test/address/mutt_addr_remove_from_list.c | 9 +++++++++ test/address/mutt_addr_remove_xrefs.c | 10 ++++++++++ test/address/mutt_addr_search.c | 10 ++++++++++ test/address/mutt_addr_set_intl.c | 11 +++++++++++ test/address/mutt_addr_set_local.c | 11 +++++++++++ test/address/mutt_addr_valid_msgid.c | 4 ++++ test/address/mutt_addr_write.c | 10 ++++++++++ test/address/mutt_addr_write_single.c | 12 ++++++++++++ test/address/mutt_addrlist_to_intl.c | 10 ++++++++++ test/address/mutt_addrlist_to_local.c | 4 ++++ 25 files changed, 218 insertions(+) diff --git a/test/address/mutt_addr_append.c b/test/address/mutt_addr_append.c index 225766739..fe9af1249 100644 --- a/test/address/mutt_addr_append.c +++ b/test/address/mutt_addr_append.c @@ -29,4 +29,14 @@ void test_mutt_addr_append(void) { // struct Address *mutt_addr_append(struct Address **a, struct Address *b, bool prune); + + { + struct Address addr = { 0 }; + TEST_CHECK(!mutt_addr_append(NULL, &addr, false)); + } + + { + struct Address *addr = NULL; + TEST_CHECK(!mutt_addr_append(&addr, NULL, false)); + } } diff --git a/test/address/mutt_addr_cat.c b/test/address/mutt_addr_cat.c index acae11c7b..74993458d 100644 --- a/test/address/mutt_addr_cat.c +++ b/test/address/mutt_addr_cat.c @@ -29,4 +29,23 @@ void test_mutt_addr_cat(void) { // void mutt_addr_cat(char *buf, size_t buflen, const char *value, const char *specials); + + const char MimeSpecials[] = "@.,;:<>[]\\\"()?/= \t"; + + { + mutt_addr_cat(NULL, 32, "apple", MimeSpecials); + TEST_CHECK_(1, "mutt_addr_cat(NULL, 32, \"apple\", MimeSpecials)"); + } + + { + char buf[32]; + mutt_addr_cat(buf, sizeof(buf), NULL, MimeSpecials); + TEST_CHECK_(1, "mutt_addr_cat(buf, sizeof(buf), NULL, MimeSpecials)"); + } + + { + char buf[32]; + mutt_addr_cat(buf, sizeof(buf), "apple", NULL); + TEST_CHECK_(1, "mutt_addr_cat(buf, sizeof(buf), \"apple\", NULL)"); + } } diff --git a/test/address/mutt_addr_cmp.c b/test/address/mutt_addr_cmp.c index 432ff9480..b43cb2b50 100644 --- a/test/address/mutt_addr_cmp.c +++ b/test/address/mutt_addr_cmp.c @@ -29,4 +29,14 @@ void test_mutt_addr_cmp(void) { // bool mutt_addr_cmp(struct Address *a, struct Address *b); + + { + struct Address addr = { 0 }; + TEST_CHECK(!mutt_addr_cmp(NULL, &addr)); + } + + { + struct Address addr = { 0 }; + TEST_CHECK(!mutt_addr_cmp(&addr, NULL)); + } } diff --git a/test/address/mutt_addr_cmp_strict.c b/test/address/mutt_addr_cmp_strict.c index e88e72840..651939489 100644 --- a/test/address/mutt_addr_cmp_strict.c +++ b/test/address/mutt_addr_cmp_strict.c @@ -29,4 +29,14 @@ void test_mutt_addr_cmp_strict(void) { // bool mutt_addr_cmp_strict(const struct Address *a, const struct Address *b); + + { + struct Address addr = { 0 }; + TEST_CHECK(!mutt_addr_cmp_strict(NULL, &addr)); + } + + { + struct Address addr = { 0 }; + TEST_CHECK(!mutt_addr_cmp_strict(&addr, NULL)); + } } diff --git a/test/address/mutt_addr_copy.c b/test/address/mutt_addr_copy.c index 9f600187f..12a272f40 100644 --- a/test/address/mutt_addr_copy.c +++ b/test/address/mutt_addr_copy.c @@ -29,4 +29,8 @@ void test_mutt_addr_copy(void) { // struct Address *mutt_addr_copy(struct Address *addr); + + { + TEST_CHECK(!mutt_addr_copy(NULL)); + } } diff --git a/test/address/mutt_addr_copy_list.c b/test/address/mutt_addr_copy_list.c index bf549b9ad..cae8e1c11 100644 --- a/test/address/mutt_addr_copy_list.c +++ b/test/address/mutt_addr_copy_list.c @@ -29,4 +29,8 @@ void test_mutt_addr_copy_list(void) { // struct Address *mutt_addr_copy_list(struct Address *addr, bool prune); + + { + TEST_CHECK(!mutt_addr_copy_list(NULL, false)); + } } diff --git a/test/address/mutt_addr_for_display.c b/test/address/mutt_addr_for_display.c index ca26eb5ed..71004d666 100644 --- a/test/address/mutt_addr_for_display.c +++ b/test/address/mutt_addr_for_display.c @@ -29,4 +29,8 @@ void test_mutt_addr_for_display(void) { // const char * mutt_addr_for_display(struct Address *a); + + { + TEST_CHECK(!mutt_addr_for_display(NULL)); + } } diff --git a/test/address/mutt_addr_free.c b/test/address/mutt_addr_free.c index a73e6287c..cb33e3346 100644 --- a/test/address/mutt_addr_free.c +++ b/test/address/mutt_addr_free.c @@ -29,4 +29,9 @@ void test_mutt_addr_free(void) { // void mutt_addr_free(struct Address **p); + + { + mutt_addr_free(NULL); + TEST_CHECK_(1, "mutt_addr_free(NULL)"); + } } diff --git a/test/address/mutt_addr_has_recips.c b/test/address/mutt_addr_has_recips.c index 9582f3242..30f905bdf 100644 --- a/test/address/mutt_addr_has_recips.c +++ b/test/address/mutt_addr_has_recips.c @@ -29,4 +29,8 @@ void test_mutt_addr_has_recips(void) { // int mutt_addr_has_recips(struct Address *a); + + { + TEST_CHECK(mutt_addr_has_recips(NULL) == 0); + } } diff --git a/test/address/mutt_addr_is_intl.c b/test/address/mutt_addr_is_intl.c index d7530e50d..43a512880 100644 --- a/test/address/mutt_addr_is_intl.c +++ b/test/address/mutt_addr_is_intl.c @@ -29,4 +29,8 @@ void test_mutt_addr_is_intl(void) { // bool mutt_addr_is_intl(struct Address *a); + + { + TEST_CHECK(!mutt_addr_is_intl(NULL)); + } } diff --git a/test/address/mutt_addr_is_local.c b/test/address/mutt_addr_is_local.c index c9f13f17e..2015e897f 100644 --- a/test/address/mutt_addr_is_local.c +++ b/test/address/mutt_addr_is_local.c @@ -29,4 +29,8 @@ void test_mutt_addr_is_local(void) { // bool mutt_addr_is_local(struct Address *a); + + { + TEST_CHECK(!mutt_addr_is_local(NULL)); + } } diff --git a/test/address/mutt_addr_mbox_to_udomain.c b/test/address/mutt_addr_mbox_to_udomain.c index 623d725b5..eac5b7c7d 100644 --- a/test/address/mutt_addr_mbox_to_udomain.c +++ b/test/address/mutt_addr_mbox_to_udomain.c @@ -29,4 +29,20 @@ void test_mutt_addr_mbox_to_udomain(void) { // int mutt_addr_mbox_to_udomain(const char *mbox, char **user, char **domain); + + { + char *user = NULL; + char *domain = NULL; + TEST_CHECK(mutt_addr_mbox_to_udomain(NULL, &user, &domain) == -1); + } + + { + char *domain = NULL; + TEST_CHECK(mutt_addr_mbox_to_udomain("apple", NULL, &domain) == -1); + } + + { + char *user = NULL; + TEST_CHECK(mutt_addr_mbox_to_udomain("apple", &user, NULL) == -1); + } } diff --git a/test/address/mutt_addr_parse_list.c b/test/address/mutt_addr_parse_list.c index e47e40509..ac76e7618 100644 --- a/test/address/mutt_addr_parse_list.c +++ b/test/address/mutt_addr_parse_list.c @@ -29,4 +29,15 @@ void test_mutt_addr_parse_list(void) { // struct Address *mutt_addr_parse_list(struct Address *top, const char *s); + + { + struct Address *addr = NULL; + TEST_CHECK((addr = mutt_addr_parse_list(NULL, "apple")) != NULL); + mutt_addr_free(&addr); + } + + { + struct Address addr = { 0 }; + TEST_CHECK(!mutt_addr_parse_list(&addr, NULL)); + } } diff --git a/test/address/mutt_addr_parse_list2.c b/test/address/mutt_addr_parse_list2.c index 73cff7901..241b3c759 100644 --- a/test/address/mutt_addr_parse_list2.c +++ b/test/address/mutt_addr_parse_list2.c @@ -29,4 +29,15 @@ void test_mutt_addr_parse_list2(void) { // struct Address *mutt_addr_parse_list2(struct Address *p, const char *s); + + { + struct Address *addr = NULL; + TEST_CHECK((addr = mutt_addr_parse_list2(NULL, "apple")) != NULL); + mutt_addr_free(&addr); + } + + { + struct Address addr = { 0 }; + TEST_CHECK(!mutt_addr_parse_list2(&addr, NULL)); + } } diff --git a/test/address/mutt_addr_qualify.c b/test/address/mutt_addr_qualify.c index 4b32cb459..2e724513b 100644 --- a/test/address/mutt_addr_qualify.c +++ b/test/address/mutt_addr_qualify.c @@ -29,4 +29,15 @@ void test_mutt_addr_qualify(void) { // void mutt_addr_qualify(struct Address *addr, const char *host); + + { + mutt_addr_qualify(NULL, "example.com"); + TEST_CHECK_(1, "mutt_addr_qualify(NULL, \"example.com\")"); + } + + { + struct Address addr = { 0 }; + mutt_addr_qualify(&addr, NULL); + TEST_CHECK_(1, "mutt_addr_qualify(&addr, NULL)"); + } } diff --git a/test/address/mutt_addr_remove_from_list.c b/test/address/mutt_addr_remove_from_list.c index 1cff65951..96d313afd 100644 --- a/test/address/mutt_addr_remove_from_list.c +++ b/test/address/mutt_addr_remove_from_list.c @@ -29,4 +29,13 @@ void test_mutt_addr_remove_from_list(void) { // int mutt_addr_remove_from_list(struct Address **a, const char *mailbox); + + { + TEST_CHECK(mutt_addr_remove_from_list(NULL, "apple") == -1); + } + + { + struct Address *addr = NULL; + TEST_CHECK(mutt_addr_remove_from_list(&addr, NULL) == 0); + } } diff --git a/test/address/mutt_addr_remove_xrefs.c b/test/address/mutt_addr_remove_xrefs.c index f2f177b94..1e282fcaf 100644 --- a/test/address/mutt_addr_remove_xrefs.c +++ b/test/address/mutt_addr_remove_xrefs.c @@ -29,4 +29,14 @@ void test_mutt_addr_remove_xrefs(void) { // struct Address *mutt_addr_remove_xrefs(struct Address *a, struct Address *b); + + { + struct Address addr = { 0 }; + TEST_CHECK(mutt_addr_remove_xrefs(NULL, &addr) == NULL); + } + + { + struct Address addr = { 0 }; + TEST_CHECK(mutt_addr_remove_xrefs(&addr, NULL) == NULL); + } } diff --git a/test/address/mutt_addr_search.c b/test/address/mutt_addr_search.c index cb6c2970f..52f2f56b2 100644 --- a/test/address/mutt_addr_search.c +++ b/test/address/mutt_addr_search.c @@ -29,4 +29,14 @@ void test_mutt_addr_search(void) { // bool mutt_addr_search(struct Address *a, struct Address *lst); + + { + struct Address addr = { 0 }; + TEST_CHECK(!mutt_addr_search(NULL, &addr)); + } + + { + struct Address addr = { 0 }; + TEST_CHECK(!mutt_addr_search(&addr, NULL)); + } } diff --git a/test/address/mutt_addr_set_intl.c b/test/address/mutt_addr_set_intl.c index 725410267..6765959b6 100644 --- a/test/address/mutt_addr_set_intl.c +++ b/test/address/mutt_addr_set_intl.c @@ -29,4 +29,15 @@ void test_mutt_addr_set_intl(void) { // void mutt_addr_set_intl(struct Address *a, char *intl_mailbox); + + { + mutt_addr_set_intl(NULL, "apple"); + TEST_CHECK_(1, "mutt_addr_set_intl(NULL, \"apple\")"); + } + + { + struct Address addr = { 0 }; + mutt_addr_set_intl(&addr, NULL); + TEST_CHECK_(1, "mutt_addr_set_intl(&addr, NULL)"); + } } diff --git a/test/address/mutt_addr_set_local.c b/test/address/mutt_addr_set_local.c index 9377aa618..171067328 100644 --- a/test/address/mutt_addr_set_local.c +++ b/test/address/mutt_addr_set_local.c @@ -29,4 +29,15 @@ void test_mutt_addr_set_local(void) { // void mutt_addr_set_local(struct Address *a, char *local_mailbox); + + { + mutt_addr_set_local(NULL, "apple"); + TEST_CHECK_(1, "mutt_addr_set_local(NULL, \"apple\")"); + } + + { + struct Address addr = { 0 }; + mutt_addr_set_local(&addr, NULL); + TEST_CHECK_(1, "mutt_addr_set_local(&addr, NULL)"); + } } diff --git a/test/address/mutt_addr_valid_msgid.c b/test/address/mutt_addr_valid_msgid.c index ad420b87e..036737a8c 100644 --- a/test/address/mutt_addr_valid_msgid.c +++ b/test/address/mutt_addr_valid_msgid.c @@ -29,4 +29,8 @@ void test_mutt_addr_valid_msgid(void) { // bool mutt_addr_valid_msgid(const char *msgid); + + { + TEST_CHECK(!mutt_addr_valid_msgid(NULL)); + } } diff --git a/test/address/mutt_addr_write.c b/test/address/mutt_addr_write.c index d68535851..e6d0bcb63 100644 --- a/test/address/mutt_addr_write.c +++ b/test/address/mutt_addr_write.c @@ -29,4 +29,14 @@ void test_mutt_addr_write(void) { // size_t mutt_addr_write(char *buf, size_t buflen, struct Address *addr, bool display); + + { + struct Address addr = { 0 }; + TEST_CHECK(mutt_addr_write(NULL, 32, &addr, false) == 0); + } + + { + char buf[32] = { 0 }; + TEST_CHECK(mutt_addr_write(buf, sizeof(buf), NULL, false) == 0); + } } diff --git a/test/address/mutt_addr_write_single.c b/test/address/mutt_addr_write_single.c index c7dc659e8..09cc0a0f7 100644 --- a/test/address/mutt_addr_write_single.c +++ b/test/address/mutt_addr_write_single.c @@ -29,4 +29,16 @@ void test_mutt_addr_write_single(void) { // void mutt_addr_write_single(char *buf, size_t buflen, struct Address *addr, bool display); + + { + struct Address addr = { 0 }; + mutt_addr_write_single(NULL, 32, &addr, false); + TEST_CHECK_(1, "mutt_addr_write_single(NULL, 32, &addr, false)"); + } + + { + char buf[32] = { 0 }; + mutt_addr_write_single(buf, sizeof(buf), NULL, false); + TEST_CHECK_(1, "mutt_addr_write_single(buf, sizeof(buf), NULL, false)"); + } } diff --git a/test/address/mutt_addrlist_to_intl.c b/test/address/mutt_addrlist_to_intl.c index ff7acf5a7..670c9d19c 100644 --- a/test/address/mutt_addrlist_to_intl.c +++ b/test/address/mutt_addrlist_to_intl.c @@ -29,4 +29,14 @@ void test_mutt_addrlist_to_intl(void) { // int mutt_addrlist_to_intl(struct Address *a, char **err); + + { + char *err = NULL; + TEST_CHECK(mutt_addrlist_to_intl(NULL, &err) == 0); + } + + { + struct Address addr = { 0 }; + TEST_CHECK(mutt_addrlist_to_intl(&addr, NULL) == 0); + } } diff --git a/test/address/mutt_addrlist_to_local.c b/test/address/mutt_addrlist_to_local.c index 57a99a8ad..fc213a19f 100644 --- a/test/address/mutt_addrlist_to_local.c +++ b/test/address/mutt_addrlist_to_local.c @@ -29,4 +29,8 @@ void test_mutt_addrlist_to_local(void) { // int mutt_addrlist_to_local(struct Address *a); + + { + TEST_CHECK(mutt_addrlist_to_local(NULL) == 0); + } } -- 2.40.0