From: Richard Russon Date: Mon, 29 Apr 2019 13:46:56 +0000 (+0100) Subject: test: add file tests for degenerate cases X-Git-Tag: 2019-10-25~233^2~73 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3ab313c3028f8f0ed5fc3c0fe10eedfa78e19091;p=neomutt test: add file tests for degenerate cases --- diff --git a/test/file/mutt_file_check_empty.c b/test/file/mutt_file_check_empty.c index 6f23ff4d7..000db0193 100644 --- a/test/file/mutt_file_check_empty.c +++ b/test/file/mutt_file_check_empty.c @@ -28,4 +28,8 @@ void test_mutt_file_check_empty(void) { // int mutt_file_check_empty(const char *path); + + { + TEST_CHECK(mutt_file_check_empty(NULL) != 0); + } } diff --git a/test/file/mutt_file_chmod.c b/test/file/mutt_file_chmod.c index aefde7e9f..f193bfeb2 100644 --- a/test/file/mutt_file_chmod.c +++ b/test/file/mutt_file_chmod.c @@ -28,4 +28,8 @@ void test_mutt_file_chmod(void) { // int mutt_file_chmod(const char *path, mode_t mode); + + { + TEST_CHECK(mutt_file_chmod(NULL, 0) != 0); + } } diff --git a/test/file/mutt_file_chmod_add.c b/test/file/mutt_file_chmod_add.c index 0dbfda710..ddbaec5f3 100644 --- a/test/file/mutt_file_chmod_add.c +++ b/test/file/mutt_file_chmod_add.c @@ -28,4 +28,8 @@ void test_mutt_file_chmod_add(void) { // int mutt_file_chmod_add(const char *path, mode_t mode); + + { + TEST_CHECK(mutt_file_chmod_add(NULL, 0) != 0); + } } diff --git a/test/file/mutt_file_chmod_add_stat.c b/test/file/mutt_file_chmod_add_stat.c index a1cebc906..567b9e876 100644 --- a/test/file/mutt_file_chmod_add_stat.c +++ b/test/file/mutt_file_chmod_add_stat.c @@ -28,4 +28,13 @@ void test_mutt_file_chmod_add_stat(void) { // int mutt_file_chmod_add_stat(const char *path, mode_t mode, struct stat *st); + + { + struct stat stat = { 0 }; + TEST_CHECK(mutt_file_chmod_add_stat(NULL, 0, &stat) != 0); + } + + { + TEST_CHECK(mutt_file_chmod_add_stat("apple", 0, NULL) != 0); + } } diff --git a/test/file/mutt_file_chmod_rm.c b/test/file/mutt_file_chmod_rm.c index 61ea9c7a4..99d7e46ec 100644 --- a/test/file/mutt_file_chmod_rm.c +++ b/test/file/mutt_file_chmod_rm.c @@ -28,4 +28,8 @@ void test_mutt_file_chmod_rm(void) { // int mutt_file_chmod_rm(const char *path, mode_t mode); + + { + TEST_CHECK(mutt_file_chmod_rm(NULL, 0) != 0); + } } diff --git a/test/file/mutt_file_chmod_rm_stat.c b/test/file/mutt_file_chmod_rm_stat.c index 84183969f..ff261e81a 100644 --- a/test/file/mutt_file_chmod_rm_stat.c +++ b/test/file/mutt_file_chmod_rm_stat.c @@ -28,4 +28,13 @@ void test_mutt_file_chmod_rm_stat(void) { // int mutt_file_chmod_rm_stat(const char *path, mode_t mode, struct stat *st); + + { + struct stat stat = { 0 }; + TEST_CHECK(mutt_file_chmod_rm_stat(NULL, 0, &stat) != 0); + } + + { + TEST_CHECK(mutt_file_chmod_rm_stat("apple", 0, NULL) != 0); + } } diff --git a/test/file/mutt_file_copy_bytes.c b/test/file/mutt_file_copy_bytes.c index 2426e3166..a7595f1ad 100644 --- a/test/file/mutt_file_copy_bytes.c +++ b/test/file/mutt_file_copy_bytes.c @@ -28,4 +28,14 @@ void test_mutt_file_copy_bytes(void) { // int mutt_file_copy_bytes(FILE *fp_in, FILE *fp_out, size_t size); + + { + FILE fp = { 0 }; + TEST_CHECK(mutt_file_copy_bytes(NULL, &fp, 10) != 0); + } + + { + FILE fp = { 0 }; + TEST_CHECK(mutt_file_copy_bytes(&fp, NULL, 10) != 0); + } } diff --git a/test/file/mutt_file_copy_stream.c b/test/file/mutt_file_copy_stream.c index d75fee9b4..bef791744 100644 --- a/test/file/mutt_file_copy_stream.c +++ b/test/file/mutt_file_copy_stream.c @@ -28,4 +28,14 @@ void test_mutt_file_copy_stream(void) { // int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out); + + { + FILE fp = { 0 }; + TEST_CHECK(mutt_file_copy_stream(NULL, &fp) != 0); + } + + { + FILE fp = { 0 }; + TEST_CHECK(mutt_file_copy_stream(&fp, NULL) != 0); + } } diff --git a/test/file/mutt_file_decrease_mtime.c b/test/file/mutt_file_decrease_mtime.c index 07a538937..8d4ddab1e 100644 --- a/test/file/mutt_file_decrease_mtime.c +++ b/test/file/mutt_file_decrease_mtime.c @@ -28,4 +28,13 @@ void test_mutt_file_decrease_mtime(void) { // time_t mutt_file_decrease_mtime(const char *fp, struct stat *st); + + { + struct stat stat = { 0 }; + TEST_CHECK(mutt_file_decrease_mtime(NULL, &stat) != 0); + } + + { + TEST_CHECK(mutt_file_decrease_mtime("apple", NULL) != 0); + } } diff --git a/test/file/mutt_file_expand_fmt.c b/test/file/mutt_file_expand_fmt.c index 90671fcf2..c30188355 100644 --- a/test/file/mutt_file_expand_fmt.c +++ b/test/file/mutt_file_expand_fmt.c @@ -28,4 +28,21 @@ void test_mutt_file_expand_fmt(void) { // void mutt_file_expand_fmt(char *dest, size_t destlen, const char *fmt, const char *src); + + { + mutt_file_expand_fmt(NULL, 10, "apple", "banana"); + TEST_CHECK_(1, "mutt_file_expand_fmt(NULL, 10, \"apple\", \"banana\")"); + } + + { + char buf[32] = { 0 }; + mutt_file_expand_fmt(buf, sizeof(buf), NULL, "banana"); + TEST_CHECK_(1, "mutt_file_expand_fmt(&buf, sizeof(buf), NULL, \"banana\")"); + } + + { + char buf[32] = { 0 }; + mutt_file_expand_fmt(buf, sizeof(buf), "apple", NULL); + TEST_CHECK_(1, "mutt_file_expand_fmt(&buf, sizeof(buf), \"apple\", NULL)"); + } } diff --git a/test/file/mutt_file_expand_fmt_quote.c b/test/file/mutt_file_expand_fmt_quote.c index c6354b070..19d4332ea 100644 --- a/test/file/mutt_file_expand_fmt_quote.c +++ b/test/file/mutt_file_expand_fmt_quote.c @@ -28,4 +28,21 @@ void test_mutt_file_expand_fmt_quote(void) { // void mutt_file_expand_fmt_quote(char *dest, size_t destlen, const char *fmt, const char *src); + + { + mutt_file_expand_fmt_quote(NULL, 10, "apple", "banana"); + TEST_CHECK_(1, "mutt_file_expand_fmt_quote(NULL, 10, \"apple\", \"banana\")"); + } + + { + char buf[32] = { 0 }; + mutt_file_expand_fmt_quote(buf, sizeof(buf), NULL, "banana"); + TEST_CHECK_(1, "mutt_file_expand_fmt_quote(&buf, sizeof(buf), NULL, \"banana\")"); + } + + { + char buf[32] = { 0 }; + mutt_file_expand_fmt_quote(buf, sizeof(buf), "apple", NULL); + TEST_CHECK_(1, "mutt_file_expand_fmt_quote(&buf, sizeof(buf), \"apple\", NULL)"); + } } diff --git a/test/file/mutt_file_fclose.c b/test/file/mutt_file_fclose.c index 61484be99..448a4ea3d 100644 --- a/test/file/mutt_file_fclose.c +++ b/test/file/mutt_file_fclose.c @@ -28,4 +28,13 @@ void test_mutt_file_fclose(void) { // int mutt_file_fclose(FILE **fp); + + { + TEST_CHECK(mutt_file_fclose(NULL) == 0); + } + + { + FILE *fp = NULL; + TEST_CHECK(mutt_file_fclose(&fp) == 0); + } } diff --git a/test/file/mutt_file_fopen.c b/test/file/mutt_file_fopen.c index 68de754b6..75b056cbe 100644 --- a/test/file/mutt_file_fopen.c +++ b/test/file/mutt_file_fopen.c @@ -28,4 +28,12 @@ void test_mutt_file_fopen(void) { // FILE *mutt_file_fopen(const char *path, const char *mode); + + { + TEST_CHECK(!mutt_file_fopen(NULL, "banana")); + } + + { + TEST_CHECK(!mutt_file_fopen("apple", NULL)); + } } diff --git a/test/file/mutt_file_fsync_close.c b/test/file/mutt_file_fsync_close.c index 2025ca55c..7b5d12065 100644 --- a/test/file/mutt_file_fsync_close.c +++ b/test/file/mutt_file_fsync_close.c @@ -28,4 +28,13 @@ void test_mutt_file_fsync_close(void) { // int mutt_file_fsync_close(FILE **fp); + + { + TEST_CHECK(mutt_file_fsync_close(NULL) == 0); + } + + { + FILE *fp = NULL; + TEST_CHECK(mutt_file_fsync_close(&fp) == 0); + } } diff --git a/test/file/mutt_file_get_size.c b/test/file/mutt_file_get_size.c index 63899778f..dd2b2e49a 100644 --- a/test/file/mutt_file_get_size.c +++ b/test/file/mutt_file_get_size.c @@ -28,4 +28,8 @@ void test_mutt_file_get_size(void) { // long mutt_file_get_size(const char *path); + + { + TEST_CHECK(mutt_file_get_size(NULL) == 0); + } } diff --git a/test/file/mutt_file_get_stat_timespec.c b/test/file/mutt_file_get_stat_timespec.c index d32d1ae24..f5caa21c0 100644 --- a/test/file/mutt_file_get_stat_timespec.c +++ b/test/file/mutt_file_get_stat_timespec.c @@ -28,4 +28,16 @@ void test_mutt_file_get_stat_timespec(void) { // void mutt_file_get_stat_timespec(struct timespec *dest, struct stat *sb, enum MuttStatType type); + + { + struct stat stat = { 0 }; + mutt_file_get_stat_timespec(NULL, &stat, 0); + TEST_CHECK_(1, "mutt_file_get_stat_timespec(NULL, &stat, 0)"); + } + + { + struct timespec timespec = { 0 }; + mutt_file_get_stat_timespec(×pec, NULL, 0); + TEST_CHECK_(1, "mutt_file_get_stat_timespec(×pec, NULL, 0)"); + } } diff --git a/test/file/mutt_file_iter_line.c b/test/file/mutt_file_iter_line.c index 1149c6035..439c74211 100644 --- a/test/file/mutt_file_iter_line.c +++ b/test/file/mutt_file_iter_line.c @@ -28,4 +28,14 @@ void test_mutt_file_iter_line(void) { // bool mutt_file_iter_line(struct MuttFileIter *iter, FILE *fp, int flags); + + { + FILE fp = { 0 }; + TEST_CHECK(!mutt_file_iter_line(NULL, &fp, 0)); + } + + { + struct MuttFileIter muttfileiter = { 0 }; + TEST_CHECK(!mutt_file_iter_line(&muttfileiter, NULL, 0)); + } } diff --git a/test/file/mutt_file_map_lines.c b/test/file/mutt_file_map_lines.c index b67586eb0..98475caf2 100644 --- a/test/file/mutt_file_map_lines.c +++ b/test/file/mutt_file_map_lines.c @@ -25,7 +25,29 @@ #include "config.h" #include "mutt/mutt.h" +bool map_dummy(char *line, int line_num, void *user_data) +{ + return false; +} + void test_mutt_file_map_lines(void) { // bool mutt_file_map_lines(mutt_file_map_t func, void *user_data, FILE *fp, int flags); + + { + FILE fp = { 0 }; + TEST_CHECK(!mutt_file_map_lines(NULL, "apple", &fp, 0)); + } + + { + mutt_file_map_t map = map_dummy; + FILE *fp = fopen("/dev/null", "r"); + TEST_CHECK(mutt_file_map_lines(map, NULL, fp, 0)); + fclose(fp); + } + + { + mutt_file_map_t map = map_dummy; + TEST_CHECK(!mutt_file_map_lines(map, "apple", NULL, 0)); + } } diff --git a/test/file/mutt_file_mkdir.c b/test/file/mutt_file_mkdir.c index e8b3f7aac..73de581a1 100644 --- a/test/file/mutt_file_mkdir.c +++ b/test/file/mutt_file_mkdir.c @@ -28,4 +28,8 @@ void test_mutt_file_mkdir(void) { // int mutt_file_mkdir(const char *path, mode_t mode); + + { + TEST_CHECK(mutt_file_mkdir(NULL, 0) != 0); + } } diff --git a/test/file/mutt_file_mkstemp_full.c b/test/file/mutt_file_mkstemp_full.c index 81a36cd33..44c14d9d6 100644 --- a/test/file/mutt_file_mkstemp_full.c +++ b/test/file/mutt_file_mkstemp_full.c @@ -28,4 +28,14 @@ void test_mutt_file_mkstemp_full(void) { // FILE *mutt_file_mkstemp_full(const char *file, int line, const char *func); + + C_Tmpdir = "/tmp"; + + { + TEST_CHECK(mutt_file_mkstemp_full(NULL, 0, "apple") != NULL); + } + + { + TEST_CHECK(mutt_file_mkstemp_full("apple", 0, NULL) != NULL); + } } diff --git a/test/file/mutt_file_open.c b/test/file/mutt_file_open.c index 6c015506d..e150dfd50 100644 --- a/test/file/mutt_file_open.c +++ b/test/file/mutt_file_open.c @@ -28,4 +28,8 @@ void test_mutt_file_open(void) { // int mutt_file_open(const char *path, int flags); + + { + TEST_CHECK(mutt_file_open(NULL, 0) != 0); + } } diff --git a/test/file/mutt_file_quote_filename.c b/test/file/mutt_file_quote_filename.c index 2e7114d00..58d62e379 100644 --- a/test/file/mutt_file_quote_filename.c +++ b/test/file/mutt_file_quote_filename.c @@ -28,4 +28,13 @@ void test_mutt_file_quote_filename(void) { // size_t mutt_file_quote_filename(const char *filename, char *buf, size_t buflen); + + { + char buf[32] = { 0 }; + TEST_CHECK(mutt_file_quote_filename(NULL, buf, sizeof(buf)) == 0); + } + + { + TEST_CHECK(mutt_file_quote_filename("apple", NULL, 10) == 0); + } } diff --git a/test/file/mutt_file_read_keyword.c b/test/file/mutt_file_read_keyword.c index fb73152df..c71d6a470 100644 --- a/test/file/mutt_file_read_keyword.c +++ b/test/file/mutt_file_read_keyword.c @@ -28,4 +28,13 @@ void test_mutt_file_read_keyword(void) { // char *mutt_file_read_keyword(const char *file, char *buf, size_t buflen); + + { + char buf[32] = { 0 }; + TEST_CHECK(!mutt_file_read_keyword(NULL, buf, sizeof(buf))); + } + + { + TEST_CHECK(!mutt_file_read_keyword("apple", NULL, 10)); + } } diff --git a/test/file/mutt_file_read_line.c b/test/file/mutt_file_read_line.c index a2a431fc4..04fbe3e5f 100644 --- a/test/file/mutt_file_read_line.c +++ b/test/file/mutt_file_read_line.c @@ -28,4 +28,35 @@ void test_mutt_file_read_line(void) { // char *mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, int flags); + + { + size_t size = 0; + FILE *fp = fopen("/dev/null", "r"); + int line_num = 0; + TEST_CHECK(!mutt_file_read_line(NULL, &size, fp, &line_num, 0)); + fclose(fp); + } + + { + FILE fp = { 0 }; + char *line = strdup("apple"); + int line_num = 0; + TEST_CHECK(!mutt_file_read_line(line, NULL, &fp, &line_num, 0)); + free(line); + } + + { + size_t size = 0; + char *line = strdup("apple"); + int line_num = 0; + TEST_CHECK(!mutt_file_read_line(line, &size, NULL, &line_num, 0)); + free(line); + } + + { + size_t size = 0; + char *line = strdup("apple"); + FILE fp = { 0 }; + TEST_CHECK(!mutt_file_read_line(line, &size, &fp, NULL, 0)); + } } diff --git a/test/file/mutt_file_rename.c b/test/file/mutt_file_rename.c index febbbbf36..33cebc9f8 100644 --- a/test/file/mutt_file_rename.c +++ b/test/file/mutt_file_rename.c @@ -28,4 +28,12 @@ void test_mutt_file_rename(void) { // int mutt_file_rename(const char *oldfile, const char *newfile); + + { + TEST_CHECK(mutt_file_rename(NULL, "apple") != 0); + } + + { + TEST_CHECK(mutt_file_rename("apple", NULL) != 0); + } } diff --git a/test/file/mutt_file_rmtree.c b/test/file/mutt_file_rmtree.c index 0252de09f..11e4b2f8f 100644 --- a/test/file/mutt_file_rmtree.c +++ b/test/file/mutt_file_rmtree.c @@ -28,4 +28,8 @@ void test_mutt_file_rmtree(void) { // int mutt_file_rmtree(const char *path); + + { + TEST_CHECK(mutt_file_rmtree(NULL) != 0); + } } diff --git a/test/file/mutt_file_safe_rename.c b/test/file/mutt_file_safe_rename.c index c3b76e279..505fe5be3 100644 --- a/test/file/mutt_file_safe_rename.c +++ b/test/file/mutt_file_safe_rename.c @@ -28,4 +28,12 @@ void test_mutt_file_safe_rename(void) { // int mutt_file_safe_rename(const char *src, const char *target); + + { + TEST_CHECK(mutt_file_safe_rename(NULL, "apple") != 0); + } + + { + TEST_CHECK(mutt_file_safe_rename("apple", NULL) != 0); + } } diff --git a/test/file/mutt_file_sanitize_filename.c b/test/file/mutt_file_sanitize_filename.c index 5e6592928..1f71e778e 100644 --- a/test/file/mutt_file_sanitize_filename.c +++ b/test/file/mutt_file_sanitize_filename.c @@ -28,4 +28,9 @@ void test_mutt_file_sanitize_filename(void) { // void mutt_file_sanitize_filename(char *fp, bool slash); + + { + mutt_file_sanitize_filename(NULL, false); + TEST_CHECK_(1, "mutt_file_sanitize_filename(NULL, false)"); + } } diff --git a/test/file/mutt_file_sanitize_regex.c b/test/file/mutt_file_sanitize_regex.c index 41a22832a..d67c0d7e9 100644 --- a/test/file/mutt_file_sanitize_regex.c +++ b/test/file/mutt_file_sanitize_regex.c @@ -28,4 +28,13 @@ void test_mutt_file_sanitize_regex(void) { // int mutt_file_sanitize_regex(struct Buffer *dest, const char *src); + + { + TEST_CHECK(mutt_file_sanitize_regex(NULL, "apple") != 0); + } + + { + struct Buffer buf = { 0 }; + TEST_CHECK(mutt_file_sanitize_regex(&buf, NULL) != 0); + } } diff --git a/test/file/mutt_file_set_mtime.c b/test/file/mutt_file_set_mtime.c index 9f8315d59..d5dfd9be3 100644 --- a/test/file/mutt_file_set_mtime.c +++ b/test/file/mutt_file_set_mtime.c @@ -28,4 +28,14 @@ void test_mutt_file_set_mtime(void) { // void mutt_file_set_mtime(const char *from, const char *to); + + { + mutt_file_set_mtime(NULL, "apple"); + TEST_CHECK_(1, "mutt_file_set_mtime(NULL, \"apple\")"); + } + + { + mutt_file_set_mtime("apple", NULL); + TEST_CHECK_(1, "mutt_file_set_mtime(\"apple\", NULL)"); + } } diff --git a/test/file/mutt_file_stat_compare.c b/test/file/mutt_file_stat_compare.c index 1e5a87916..bfdbd8678 100644 --- a/test/file/mutt_file_stat_compare.c +++ b/test/file/mutt_file_stat_compare.c @@ -28,4 +28,14 @@ void test_mutt_file_stat_compare(void) { // int mutt_file_stat_compare(struct stat *sba, enum MuttStatType sba_type, struct stat *sbb, enum MuttStatType sbb_type); + + { + struct stat stat = { 0 }; + TEST_CHECK(mutt_file_stat_compare(NULL, 0, &stat, 0) == 0); + } + + { + struct stat stat = { 0 }; + TEST_CHECK(mutt_file_stat_compare(&stat, 0, NULL, 0) == 0); + } } diff --git a/test/file/mutt_file_stat_timespec_compare.c b/test/file/mutt_file_stat_timespec_compare.c index 2d94daab2..0431998ab 100644 --- a/test/file/mutt_file_stat_timespec_compare.c +++ b/test/file/mutt_file_stat_timespec_compare.c @@ -28,4 +28,14 @@ void test_mutt_file_stat_timespec_compare(void) { // int mutt_file_stat_timespec_compare(struct stat *sba, enum MuttStatType type, struct timespec *b); + + { + struct timespec timespec = { 0 }; + TEST_CHECK(mutt_file_stat_timespec_compare(NULL, 0, ×pec) == 0); + } + + { + struct stat stat = { 0 }; + TEST_CHECK(mutt_file_stat_timespec_compare(&stat, 0, NULL) == 0); + } } diff --git a/test/file/mutt_file_symlink.c b/test/file/mutt_file_symlink.c index aa36ce268..425f08b3f 100644 --- a/test/file/mutt_file_symlink.c +++ b/test/file/mutt_file_symlink.c @@ -28,4 +28,12 @@ void test_mutt_file_symlink(void) { // int mutt_file_symlink(const char *oldpath, const char *newpath); + + { + TEST_CHECK(mutt_file_symlink(NULL, "apple") != 0); + } + + { + TEST_CHECK(mutt_file_symlink("apple", NULL) != 0); + } } diff --git a/test/file/mutt_file_timespec_compare.c b/test/file/mutt_file_timespec_compare.c index 0bf7b4078..60b003596 100644 --- a/test/file/mutt_file_timespec_compare.c +++ b/test/file/mutt_file_timespec_compare.c @@ -28,4 +28,14 @@ void test_mutt_file_timespec_compare(void) { // int mutt_file_timespec_compare(struct timespec *a, struct timespec *b); + + { + struct timespec timespec = { 0 }; + TEST_CHECK(mutt_file_timespec_compare(NULL, ×pec) == 0); + } + + { + struct timespec timespec = { 0 }; + TEST_CHECK(mutt_file_timespec_compare(×pec, NULL) == 0); + } } diff --git a/test/file/mutt_file_unlink.c b/test/file/mutt_file_unlink.c index 44f380dc4..cadc413c4 100644 --- a/test/file/mutt_file_unlink.c +++ b/test/file/mutt_file_unlink.c @@ -28,4 +28,9 @@ void test_mutt_file_unlink(void) { // void mutt_file_unlink(const char *s); + + { + mutt_file_unlink(NULL); + TEST_CHECK_(1, "mutt_file_unlink(NULL)"); + } } diff --git a/test/file/mutt_file_unlink_empty.c b/test/file/mutt_file_unlink_empty.c index b115ee1c7..edc0a9c31 100644 --- a/test/file/mutt_file_unlink_empty.c +++ b/test/file/mutt_file_unlink_empty.c @@ -28,4 +28,9 @@ void test_mutt_file_unlink_empty(void) { // void mutt_file_unlink_empty(const char *path); + + { + mutt_file_unlink_empty(NULL); + TEST_CHECK_(1, "mutt_file_unlink_empty(NULL)"); + } }