diff --git a/tests/other/test_unlink.cpp b/tests/other/test_unlink.cpp index d0e40f18411db..f03ec270e2276 100644 --- a/tests/other/test_unlink.cpp +++ b/tests/other/test_unlink.cpp @@ -3,8 +3,11 @@ // University of Illinois/NCSA Open Source License. Both these licenses can be // found in the LICENSE file. +#include +#include #include #include +#include #include #include @@ -13,13 +16,10 @@ int main() { const char *dirname = "test"; // Create a file - FILE *f = fopen(filename, "wb"); + FILE* f = fopen(filename, "w+"); if (f == NULL) { return 1; } - if (fclose(f)) { - return 1; - } // Check it exists if (access(filename, F_OK) != 0) { return 1; @@ -32,9 +32,30 @@ int main() { if (access(filename, F_OK) != -1) { return 1; } + // Check that we can still write to it + if (fwrite("hello", 1, 5, f) != 5) { + return 1; + } + // And seek in it. + if (fseek(f, 0, SEEK_SET) != 0) { + return 1; + } + // And read from it. + char buf[6] = {0}; + if (fread(buf, 1, 5, f) != 5 || strcmp("hello", buf) != 0) { + return 1; + } + if (fclose(f)) { + return 1; + } // Create a directory - if (mkdir(dirname, 0700)) { + if (mkdir(dirname, 0700) != 0) { + return 1; + } + // Open the directory + DIR* d = opendir(dirname); + if (d == NULL) { return 1; } // Delete the directory @@ -45,6 +66,17 @@ int main() { if (access(dirname, F_OK) != -1) { return 1; } + // Check that we can still read the directory, but that it is empty. + errno = 0; + if (readdir(d) != NULL || errno != 0) { + return 1; + } + // Check that we *cannot* create a child + if (openat(dirfd(d), filename, O_CREAT | O_WRONLY, S_IRWXU) != -1) { + return 1; + } + + closedir(d); printf("ok\n");