From fff13b5312d9a72d8518840e42b1b382ee96097d Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Fri, 19 Apr 2019 01:07:37 +0100 Subject: [PATCH] test: add path tests for degenerate cases --- test/path/mutt_path_abbr_folder.c | 9 +++++++++ test/path/mutt_path_basename.c | 5 +++++ test/path/mutt_path_canon.c | 4 ++++ test/path/mutt_path_concat.c | 14 ++++++++++++++ test/path/mutt_path_concatn.c | 14 ++++++++++++++ test/path/mutt_path_dirname.c | 4 ++++ test/path/mutt_path_escape.c | 4 ++++ test/path/mutt_path_getcwd.c | 5 +++++ test/path/mutt_path_parent.c | 4 ++++ test/path/mutt_path_pretty.c | 9 +++++++++ test/path/mutt_path_realpath.c | 4 ++++ test/path/mutt_path_tidy.c | 4 ++++ test/path/mutt_path_tidy_dotdot.c | 4 ++++ test/path/mutt_path_tidy_slash.c | 4 ++++ test/path/mutt_path_to_absolute.c | 8 ++++++++ 15 files changed, 96 insertions(+) diff --git a/test/path/mutt_path_abbr_folder.c b/test/path/mutt_path_abbr_folder.c index 758af4dfd..9a05439ae 100644 --- a/test/path/mutt_path_abbr_folder.c +++ b/test/path/mutt_path_abbr_folder.c @@ -28,4 +28,13 @@ void test_mutt_path_abbr_folder(void) { // bool mutt_path_abbr_folder(char *buf, size_t buflen, const char *folder); + + { + TEST_CHECK(!mutt_path_abbr_folder(NULL, 10, "apple")); + } + + { + char buf[32] = { 0 }; + TEST_CHECK(!mutt_path_abbr_folder(buf, sizeof(buf), NULL)); + } } diff --git a/test/path/mutt_path_basename.c b/test/path/mutt_path_basename.c index f8886cb40..3815796b5 100644 --- a/test/path/mutt_path_basename.c +++ b/test/path/mutt_path_basename.c @@ -28,4 +28,9 @@ void test_mutt_path_basename(void) { // const char *mutt_path_basename(const char *f); + + { + mutt_path_basename(NULL); + TEST_CHECK_(1, "mutt_path_basename(NULL)"); + } } diff --git a/test/path/mutt_path_canon.c b/test/path/mutt_path_canon.c index 89f2548fb..90b264cc6 100644 --- a/test/path/mutt_path_canon.c +++ b/test/path/mutt_path_canon.c @@ -28,4 +28,8 @@ void test_mutt_path_canon(void) { // bool mutt_path_canon(char *buf, size_t buflen, const char *homedir); + + { + TEST_CHECK(!mutt_path_canon(NULL, 10, "apple")); + } } diff --git a/test/path/mutt_path_concat.c b/test/path/mutt_path_concat.c index e5a74e6f2..14a2ec3e0 100644 --- a/test/path/mutt_path_concat.c +++ b/test/path/mutt_path_concat.c @@ -28,4 +28,18 @@ void test_mutt_path_concat(void) { // char *mutt_path_concat(char *d, const char *dir, const char *fname, size_t l); + + { + TEST_CHECK(mutt_path_concat(NULL, "apple", "banana", 5) == NULL); + } + + { + char buf[32] = { 0 }; + TEST_CHECK(mutt_path_concat(buf, NULL, "banana", 5) == NULL); + } + + { + char buf[32] = { 0 }; + TEST_CHECK(mutt_path_concat(buf, "apple", NULL, 5) == NULL); + } } diff --git a/test/path/mutt_path_concatn.c b/test/path/mutt_path_concatn.c index e866a2fe6..f8d247e01 100644 --- a/test/path/mutt_path_concatn.c +++ b/test/path/mutt_path_concatn.c @@ -28,4 +28,18 @@ void test_mutt_path_concatn(void) { // char *mutt_path_concatn(char *dst, size_t dstlen, const char *dir, size_t dirlen, const char *fname, size_t fnamelen); + + { + TEST_CHECK(mutt_path_concatn(NULL, 10, "apple", 5, "banana", 6) == NULL); + } + + { + char buf[32] = { 0 }; + TEST_CHECK(mutt_path_concatn(buf, sizeof(buf), NULL, 5, "banana", 6) == NULL); + } + + { + char buf[32] = { 0 }; + TEST_CHECK(mutt_path_concatn(buf, sizeof(buf), "apple", 5, NULL, 6) == NULL); + } } diff --git a/test/path/mutt_path_dirname.c b/test/path/mutt_path_dirname.c index 0fae79e42..2decd0c66 100644 --- a/test/path/mutt_path_dirname.c +++ b/test/path/mutt_path_dirname.c @@ -28,4 +28,8 @@ void test_mutt_path_dirname(void) { // char *mutt_path_dirname(const char *path); + + { + TEST_CHECK(mutt_path_dirname(NULL) == NULL); + } } diff --git a/test/path/mutt_path_escape.c b/test/path/mutt_path_escape.c index 99874d49e..378a134cb 100644 --- a/test/path/mutt_path_escape.c +++ b/test/path/mutt_path_escape.c @@ -28,4 +28,8 @@ void test_mutt_path_escape(void) { // char *mutt_path_escape(const char *src); + + { + TEST_CHECK(mutt_path_escape(NULL) == NULL); + } } diff --git a/test/path/mutt_path_getcwd.c b/test/path/mutt_path_getcwd.c index 3e9ac5d12..5f3e69af6 100644 --- a/test/path/mutt_path_getcwd.c +++ b/test/path/mutt_path_getcwd.c @@ -28,4 +28,9 @@ void test_mutt_path_getcwd(void) { // void mutt_path_getcwd(struct Buffer *cwd); + + { + mutt_path_getcwd(NULL); + TEST_CHECK_(1, "mutt_path_getcwd(NULL)"); + } } diff --git a/test/path/mutt_path_parent.c b/test/path/mutt_path_parent.c index 0a0468fa5..e166bdc24 100644 --- a/test/path/mutt_path_parent.c +++ b/test/path/mutt_path_parent.c @@ -28,4 +28,8 @@ void test_mutt_path_parent(void) { // bool mutt_path_parent(char *buf, size_t buflen); + + { + TEST_CHECK(!mutt_path_parent(NULL, 10)); + } } diff --git a/test/path/mutt_path_pretty.c b/test/path/mutt_path_pretty.c index 8b2f817a4..a37f92566 100644 --- a/test/path/mutt_path_pretty.c +++ b/test/path/mutt_path_pretty.c @@ -28,4 +28,13 @@ void test_mutt_path_pretty(void) { // bool mutt_path_pretty(char *buf, size_t buflen, const char *homedir); + + { + TEST_CHECK(!mutt_path_pretty(NULL, 10, "apple")); + } + + { + char buf[32] = { 0 }; + TEST_CHECK(!mutt_path_pretty(buf, sizeof(buf), NULL)); + } } diff --git a/test/path/mutt_path_realpath.c b/test/path/mutt_path_realpath.c index 165d8c363..ecd69bd56 100644 --- a/test/path/mutt_path_realpath.c +++ b/test/path/mutt_path_realpath.c @@ -28,4 +28,8 @@ void test_mutt_path_realpath(void) { // size_t mutt_path_realpath(char *buf); + + { + TEST_CHECK(mutt_path_realpath(NULL) == 0); + } } diff --git a/test/path/mutt_path_tidy.c b/test/path/mutt_path_tidy.c index 562a936a4..061b3aadb 100644 --- a/test/path/mutt_path_tidy.c +++ b/test/path/mutt_path_tidy.c @@ -28,4 +28,8 @@ void test_mutt_path_tidy(void) { // bool mutt_path_tidy(char *buf); + + { + TEST_CHECK(!mutt_path_tidy(NULL)); + } } diff --git a/test/path/mutt_path_tidy_dotdot.c b/test/path/mutt_path_tidy_dotdot.c index de0822fb1..afdbe23c5 100644 --- a/test/path/mutt_path_tidy_dotdot.c +++ b/test/path/mutt_path_tidy_dotdot.c @@ -28,4 +28,8 @@ void test_mutt_path_tidy_dotdot(void) { // bool mutt_path_tidy_dotdot(char *buf); + + { + TEST_CHECK(!mutt_path_tidy_dotdot(NULL)); + } } diff --git a/test/path/mutt_path_tidy_slash.c b/test/path/mutt_path_tidy_slash.c index 3ace0e84c..c02338aef 100644 --- a/test/path/mutt_path_tidy_slash.c +++ b/test/path/mutt_path_tidy_slash.c @@ -28,4 +28,8 @@ void test_mutt_path_tidy_slash(void) { // bool mutt_path_tidy_slash(char *buf); + + { + TEST_CHECK(!mutt_path_tidy_slash(NULL)); + } } diff --git a/test/path/mutt_path_to_absolute.c b/test/path/mutt_path_to_absolute.c index 06d38a9a3..d29d06b9d 100644 --- a/test/path/mutt_path_to_absolute.c +++ b/test/path/mutt_path_to_absolute.c @@ -28,4 +28,12 @@ void test_mutt_path_to_absolute(void) { // int mutt_path_to_absolute(char *path, const char *reference); + + { + TEST_CHECK(!mutt_path_to_absolute(NULL, "apple")); + } + + { + TEST_CHECK(!mutt_path_to_absolute("apple", NULL)); + } } -- 2.40.0