summaryrefslogtreecommitdiff
path: root/tests/test-lstat.c
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-09-18 18:06:31 -0600
committerEric Blake <ebb9@byu.net>2009-09-19 13:38:41 -0600
commit3a5041b1c62c2b7c829f47bec2f1789c59844b6c (patch)
tree4bdba64a43ebe472eebfc40fde320b8641897793 /tests/test-lstat.c
parent6ca71ffe395184749d849f5bba4771d6b2fbb7d6 (diff)
downloadgnulib-3a5041b1c62c2b7c829f47bec2f1789c59844b6c.tar.gz
test-fstatat: new test, to expose Solaris 9 bugs
Share the stat and lstat tests with fstatat. * tests/test-stat.c (main): Factor guts... * tests/test-stat.h (test_stat_func): ...into new file. * tests/test-lstat.c (main): Factor guts... * tests/test-lstat.h (test_lstat_func): ...into new file. * tests/test-fstatat.c: New file. * modules/stat-tests (Files): Add test-stat.h. * modules/lstat-tests (Files): Add test-lstat.h. (Depends-on): Add stdbool. * modules/openat-tests (Depends-on): Add pathmax. (Files): Add test-lstat.h, test-stat.h, test-fstatat.c. (Makefile.am): Run new test. Signed-off-by: Eric Blake <ebb9@byu.net>
Diffstat (limited to 'tests/test-lstat.c')
-rw-r--r--tests/test-lstat.c102
1 files changed, 12 insertions, 90 deletions
diff --git a/tests/test-lstat.c b/tests/test-lstat.c
index 8182738a86..cb9963d3b5 100644
--- a/tests/test-lstat.c
+++ b/tests/test-lstat.c
@@ -22,6 +22,7 @@
#include <fcntl.h>
#include <errno.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -46,97 +47,18 @@
#define BASE "test-lstat.t"
+#include "test-lstat.h"
+
+/* Wrapper around lstat, which works even if lstat is a function-like
+ macro, where test_lstat_func(lstat) would do the wrong thing. */
+static int
+do_lstat (char const *name, struct stat *st)
+{
+ return lstat (name, st);
+}
+
int
main ()
{
- struct stat st1;
- struct stat st2;
-
- /* Remove any leftovers from a previous partial run. */
- ASSERT (system ("rm -rf " BASE "*") == 0);
-
- /* Test for common directories. */
- ASSERT (lstat (".", &st1) == 0);
- ASSERT (lstat ("./", &st2) == 0);
- ASSERT (SAME_INODE (st1, st2));
- ASSERT (S_ISDIR (st1.st_mode));
- ASSERT (S_ISDIR (st2.st_mode));
- ASSERT (lstat ("/", &st1) == 0);
- ASSERT (lstat ("///", &st2) == 0);
- ASSERT (SAME_INODE (st1, st2));
- ASSERT (S_ISDIR (st1.st_mode));
- ASSERT (S_ISDIR (st2.st_mode));
- ASSERT (lstat ("..", &st1) == 0);
- ASSERT (S_ISDIR (st1.st_mode));
-
- /* Test for error conditions. */
- errno = 0;
- ASSERT (lstat ("", &st1) == -1);
- ASSERT (errno == ENOENT);
- errno = 0;
- ASSERT (lstat ("nosuch", &st1) == -1);
- ASSERT (errno == ENOENT);
- errno = 0;
- ASSERT (lstat ("nosuch/", &st1) == -1);
- ASSERT (errno == ENOENT);
-
- ASSERT (close (creat (BASE "file", 0600)) == 0);
- ASSERT (lstat (BASE "file", &st1) == 0);
- ASSERT (S_ISREG (st1.st_mode));
- errno = 0;
- ASSERT (lstat (BASE "file/", &st1) == -1);
- ASSERT (errno == ENOTDIR);
-
- /* Now for some symlink tests, where supported. We set up:
- link1 -> directory
- link2 -> file
- link3 -> dangling
- link4 -> loop
- then test behavior both with and without trailing slash.
- */
- if (symlink (".", BASE "link1") != 0)
- {
- ASSERT (unlink (BASE "file") == 0);
- fputs ("skipping test: symlinks not supported on this filesystem\n",
- stderr);
- return 77;
- }
- ASSERT (symlink (BASE "file", BASE "link2") == 0);
- ASSERT (symlink (BASE "nosuch", BASE "link3") == 0);
- ASSERT (symlink (BASE "link4", BASE "link4") == 0);
-
- ASSERT (lstat (BASE "link1", &st1) == 0);
- ASSERT (S_ISLNK (st1.st_mode));
- ASSERT (lstat (BASE "link1/", &st1) == 0);
- ASSERT (stat (BASE "link1", &st2) == 0);
- ASSERT (S_ISDIR (st1.st_mode));
- ASSERT (S_ISDIR (st2.st_mode));
- ASSERT (SAME_INODE (st1, st2));
-
- ASSERT (lstat (BASE "link2", &st1) == 0);
- ASSERT (S_ISLNK (st1.st_mode));
- errno = 0;
- ASSERT (lstat (BASE "link2/", &st1) == -1);
- ASSERT (errno == ENOTDIR);
-
- ASSERT (lstat (BASE "link3", &st1) == 0);
- ASSERT (S_ISLNK (st1.st_mode));
- errno = 0;
- ASSERT (lstat (BASE "link3/", &st1) == -1);
- ASSERT (errno == ENOENT);
-
- ASSERT (lstat (BASE "link4", &st1) == 0);
- ASSERT (S_ISLNK (st1.st_mode));
- errno = 0;
- ASSERT (lstat (BASE "link4/", &st1) == -1);
- ASSERT (errno == ELOOP);
-
- /* Cleanup. */
- ASSERT (unlink (BASE "file") == 0);
- ASSERT (unlink (BASE "link1") == 0);
- ASSERT (unlink (BASE "link2") == 0);
- ASSERT (unlink (BASE "link3") == 0);
- ASSERT (unlink (BASE "link4") == 0);
-
- return 0;
+ return test_lstat_func (do_lstat, true);
}