Skip to content

Commit

Permalink
Test for null compare function
Browse files Browse the repository at this point in the history
  • Loading branch information
tronkko committed Sep 9, 2023
1 parent 1cb00d7 commit 39c1f1b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/t-scandir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -53,6 +54,7 @@ main(void)
test_versionsort();
test_large();
test_match();
test_null();

cleanup();
return EXIT_SUCCESS;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 39c1f1b

Please sign in to comment.