From: Richard Russon Date: Mon, 29 Apr 2019 13:46:56 +0000 (+0100) Subject: test: add charset tests for degenerate cases X-Git-Tag: 2019-10-25~233^2~79 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=be201d58595ba6d6841b33d1fa86839c0a864cd3;p=neomutt test: add charset tests for degenerate cases --- diff --git a/test/charset/mutt_ch_canonical_charset.c b/test/charset/mutt_ch_canonical_charset.c index d818fef1f..3ff47271e 100644 --- a/test/charset/mutt_ch_canonical_charset.c +++ b/test/charset/mutt_ch_canonical_charset.c @@ -28,4 +28,15 @@ void test_mutt_ch_canonical_charset(void) { // void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name); + + { + mutt_ch_canonical_charset(NULL, 10, "apple"); + TEST_CHECK_(1, "mutt_ch_canonical_charset(NULL, 10, \"apple\")"); + } + + { + char buf[32] = { 0 }; + mutt_ch_canonical_charset(buf, sizeof(buf), NULL); + TEST_CHECK_(1, "mutt_ch_canonical_charset(&buf, sizeof(buf), NULL)"); + } } diff --git a/test/charset/mutt_ch_charset_lookup.c b/test/charset/mutt_ch_charset_lookup.c index 169d04ed7..ef372d34d 100644 --- a/test/charset/mutt_ch_charset_lookup.c +++ b/test/charset/mutt_ch_charset_lookup.c @@ -28,4 +28,8 @@ void test_mutt_ch_charset_lookup(void) { // const char *mutt_ch_charset_lookup(const char *chs); + + { + TEST_CHECK(!mutt_ch_charset_lookup(NULL)); + } } diff --git a/test/charset/mutt_ch_check.c b/test/charset/mutt_ch_check.c index 2c5b9c21d..5ad211504 100644 --- a/test/charset/mutt_ch_check.c +++ b/test/charset/mutt_ch_check.c @@ -28,4 +28,18 @@ void test_mutt_ch_check(void) { // int mutt_ch_check(const char *s, size_t slen, const char *from, const char *to); + + { + TEST_CHECK(mutt_ch_check(NULL, 10, "apple", "banana") != 0); + } + + { + char buf[32] = { 0 }; + TEST_CHECK(mutt_ch_check(buf, sizeof(buf), NULL, "banana") != 0); + } + + { + char buf[32] = { 0 }; + TEST_CHECK(mutt_ch_check(buf, sizeof(buf), "apple", NULL) != 0); + } } diff --git a/test/charset/mutt_ch_check_charset.c b/test/charset/mutt_ch_check_charset.c index 7882352aa..43e525a19 100644 --- a/test/charset/mutt_ch_check_charset.c +++ b/test/charset/mutt_ch_check_charset.c @@ -28,4 +28,8 @@ void test_mutt_ch_check_charset(void) { // bool mutt_ch_check_charset(const char *cs, bool strict); + + { + TEST_CHECK(!mutt_ch_check_charset(NULL, false)); + } } diff --git a/test/charset/mutt_ch_choose.c b/test/charset/mutt_ch_choose.c index 2e4dac3e8..9b0577edc 100644 --- a/test/charset/mutt_ch_choose.c +++ b/test/charset/mutt_ch_choose.c @@ -28,4 +28,36 @@ void test_mutt_ch_choose(void) { // char *mutt_ch_choose(const char *fromcode, const char *charsets, const char *u, size_t ulen, char **d, size_t *dlen); + + { + char buf_in[32] = { 0 }; + char *buf_out = NULL; + size_t buflen = 0; + TEST_CHECK(mutt_ch_choose(NULL, "banana", buf_in, sizeof(buf_in), &buf_out, &buflen) != NULL); + } + + { + char buf_in[32] = { 0 }; + char *buf_out = NULL; + size_t buflen = 0; + TEST_CHECK(!mutt_ch_choose("apple", NULL, buf_in, sizeof(buf_in), &buf_out, &buflen)); + } + + { + char *buf_out = NULL; + size_t buflen = 0; + TEST_CHECK(mutt_ch_choose("apple", "banana", NULL, 10, &buf_out, &buflen) != NULL); + } + + { + char buf_in[32] = { 0 }; + size_t buflen = 0; + TEST_CHECK(!mutt_ch_choose("apple", "banana", buf_in, sizeof(buf_in), NULL, &buflen)); + } + + { + char buf_in[32] = { 0 }; + char *buf_out = NULL; + TEST_CHECK(mutt_ch_choose("apple", "banana", buf_in, sizeof(buf_in), &buf_out, NULL) != NULL); + } } diff --git a/test/charset/mutt_ch_chscmp.c b/test/charset/mutt_ch_chscmp.c index 6f9a5718d..2a5840921 100644 --- a/test/charset/mutt_ch_chscmp.c +++ b/test/charset/mutt_ch_chscmp.c @@ -28,4 +28,12 @@ void test_mutt_ch_chscmp(void) { // bool mutt_ch_chscmp(const char *cs1, const char *cs2); + + { + TEST_CHECK(!mutt_ch_chscmp(NULL, "banana")); + } + + { + TEST_CHECK(!mutt_ch_chscmp("apple", NULL)); + } } diff --git a/test/charset/mutt_ch_convert_nonmime_string.c b/test/charset/mutt_ch_convert_nonmime_string.c index 8a4d5024a..4fe661f17 100644 --- a/test/charset/mutt_ch_convert_nonmime_string.c +++ b/test/charset/mutt_ch_convert_nonmime_string.c @@ -28,4 +28,8 @@ void test_mutt_ch_convert_nonmime_string(void) { // int mutt_ch_convert_nonmime_string(char **ps); + + { + TEST_CHECK(mutt_ch_convert_nonmime_string(NULL) != 0); + } } diff --git a/test/charset/mutt_ch_convert_string.c b/test/charset/mutt_ch_convert_string.c index 1b1a9dff4..33f7f179e 100644 --- a/test/charset/mutt_ch_convert_string.c +++ b/test/charset/mutt_ch_convert_string.c @@ -28,4 +28,27 @@ void test_mutt_ch_convert_string(void) { // int mutt_ch_convert_string(char **ps, const char *from, const char *to, int flags); + + { + char *ps = strdup("apple"); + TEST_CHECK(mutt_ch_convert_string(NULL, "apple", "banana", 0) != 0); + free(ps); + } + + { + char *ps = NULL; + TEST_CHECK(mutt_ch_convert_string(&ps, "apple", "banana", 0) == 0); + } + + { + char *ps = strdup("apple"); + TEST_CHECK(mutt_ch_convert_string(&ps, NULL, "banana", 0) != 0); + free(ps); + } + + { + char *ps = strdup("apple"); + TEST_CHECK(mutt_ch_convert_string(&ps, "apple", NULL, 0) != 0); + free(ps); + } } diff --git a/test/charset/mutt_ch_fgetconv.c b/test/charset/mutt_ch_fgetconv.c index 437b1edb6..806ea0076 100644 --- a/test/charset/mutt_ch_fgetconv.c +++ b/test/charset/mutt_ch_fgetconv.c @@ -28,4 +28,8 @@ void test_mutt_ch_fgetconv(void) { // int mutt_ch_fgetconv(struct FgetConv *fc); + + { + TEST_CHECK(mutt_ch_fgetconv(NULL) == EOF); + } } diff --git a/test/charset/mutt_ch_fgetconv_close.c b/test/charset/mutt_ch_fgetconv_close.c index caca33bb1..c7018ee47 100644 --- a/test/charset/mutt_ch_fgetconv_close.c +++ b/test/charset/mutt_ch_fgetconv_close.c @@ -28,4 +28,15 @@ void test_mutt_ch_fgetconv_close(void) { // void mutt_ch_fgetconv_close(struct FgetConv **fc); + + { + mutt_ch_fgetconv_close(NULL); + TEST_CHECK_(1, "mutt_ch_fgetconv_close(NULL)"); + } + + { + struct FgetConv *fgetconv = NULL; + mutt_ch_fgetconv_close(&fgetconv); + TEST_CHECK_(1, "mutt_ch_fgetconv_close(&fgetconv)"); + } } diff --git a/test/charset/mutt_ch_fgetconv_open.c b/test/charset/mutt_ch_fgetconv_open.c index 714393bd1..6fb079644 100644 --- a/test/charset/mutt_ch_fgetconv_open.c +++ b/test/charset/mutt_ch_fgetconv_open.c @@ -28,4 +28,18 @@ void test_mutt_ch_fgetconv_open(void) { // struct FgetConv *mutt_ch_fgetconv_open(FILE *fp, const char *from, const char *to, int flags); + + { + TEST_CHECK(mutt_ch_fgetconv_open(NULL, "apple", "banana", 0) != NULL); + } + + { + FILE fp = { 0 }; + TEST_CHECK(mutt_ch_fgetconv_open(&fp, NULL, "banana", 0) != NULL); + } + + { + FILE fp = { 0 }; + TEST_CHECK(mutt_ch_fgetconv_open(&fp, "apple", NULL, 0) != NULL); + } } diff --git a/test/charset/mutt_ch_fgetconvs.c b/test/charset/mutt_ch_fgetconvs.c index 879113bd0..313638b4e 100644 --- a/test/charset/mutt_ch_fgetconvs.c +++ b/test/charset/mutt_ch_fgetconvs.c @@ -28,4 +28,14 @@ void test_mutt_ch_fgetconvs(void) { // char *mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc); + + { + struct FgetConv fgetconv = { 0 }; + TEST_CHECK(!mutt_ch_fgetconvs(NULL, 10, &fgetconv)); + } + + { + char buf[32] = { 0 }; + TEST_CHECK(!mutt_ch_fgetconvs(buf, sizeof(buf), NULL)); + } } diff --git a/test/charset/mutt_ch_iconv_lookup.c b/test/charset/mutt_ch_iconv_lookup.c index fcc26f61e..48e2d627b 100644 --- a/test/charset/mutt_ch_iconv_lookup.c +++ b/test/charset/mutt_ch_iconv_lookup.c @@ -28,4 +28,8 @@ void test_mutt_ch_iconv_lookup(void) { // const char *mutt_ch_iconv_lookup(const char *chs); + + { + TEST_CHECK(!mutt_ch_iconv_lookup(NULL)); + } } diff --git a/test/charset/mutt_ch_iconv_open.c b/test/charset/mutt_ch_iconv_open.c index 9a245cee9..6f426bb37 100644 --- a/test/charset/mutt_ch_iconv_open.c +++ b/test/charset/mutt_ch_iconv_open.c @@ -28,4 +28,12 @@ void test_mutt_ch_iconv_open(void) { // iconv_t mutt_ch_iconv_open(const char *tocode, const char *fromcode, int flags); + + { + TEST_CHECK(mutt_ch_iconv_open(NULL, "banana", 0) != NULL); + } + + { + TEST_CHECK(mutt_ch_iconv_open("apple", NULL, 0) != NULL); + } } diff --git a/test/charset/mutt_ch_lookup_add.c b/test/charset/mutt_ch_lookup_add.c index 77672757e..f3d4ecfd4 100644 --- a/test/charset/mutt_ch_lookup_add.c +++ b/test/charset/mutt_ch_lookup_add.c @@ -28,4 +28,18 @@ void test_mutt_ch_lookup_add(void) { // bool mutt_ch_lookup_add(enum LookupType type, const char *pat, const char *replace, struct Buffer *err); + + { + struct Buffer buf = { 0 }; + TEST_CHECK(!mutt_ch_lookup_add(0, NULL, "banana", &buf)); + } + + { + struct Buffer buf = { 0 }; + TEST_CHECK(!mutt_ch_lookup_add(0, "apple", NULL, &buf)); + } + + { + TEST_CHECK(mutt_ch_lookup_add(0, "apple", "banana", NULL)); + } } diff --git a/test/charset/mutt_ch_set_charset.c b/test/charset/mutt_ch_set_charset.c index 26bb05343..de069d417 100644 --- a/test/charset/mutt_ch_set_charset.c +++ b/test/charset/mutt_ch_set_charset.c @@ -28,4 +28,9 @@ void test_mutt_ch_set_charset(void) { // void mutt_ch_set_charset(const char *charset); + + { + mutt_ch_set_charset(NULL); + TEST_CHECK_(1, "mutt_ch_set_charset(NULL)"); + } }