From 39c1f1bc98ef3326237d03006f35d7dd44620e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20R=C3=B6nkk=C3=B6?= Date: Sat, 9 Sep 2023 13:09:28 +0300 Subject: [PATCH] Test for null compare function --- tests/t-scandir.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/t-scandir.c b/tests/t-scandir.c index 26c7003..30698ff 100644 --- a/tests/t-scandir.c +++ b/tests/t-scandir.c @@ -33,6 +33,7 @@ static void test_enotdir(void); static void test_versionsort(void); static void test_large(void); static void test_match(void); +static void test_null(void); static int only_readme(const struct dirent *entry); static int no_directories(const struct dirent *entry); static int reverse_alpha(const struct dirent **a, const struct dirent **b); @@ -53,6 +54,7 @@ main(void) test_versionsort(); test_large(); test_match(); + test_null(); cleanup(); return EXIT_SUCCESS; @@ -336,6 +338,21 @@ test_match(void) assert(match("abb", "a*?") == 0); } +static void +test_null(void) +{ + /* Scandir can be used with null filter and compare functions */ + struct dirent **files = NULL; + int n = scandir("tests/3", &files, NULL, NULL); + assert(n == 13); + + /* Release file names */ + for (int i = 0; i < n; i++) { + free(files[i]); + } + free(files); +} + /* Only pass README.txt file */ static int only_readme(const struct dirent *entry)