annotate tests/test-symlinkat.c @ 17530:8981b79e1271

error: make the module depend on vfprintf-posix * modules/error (Depends-on): Add vfprintf-posix, since error calls vfprintf unconditionally, via error_tail.
author Jim Meyering <meyering@fb.com>
date Sat, 12 Oct 2013 19:28:40 -0700
parents 3a09cc104f4c
children 344018b6e5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13539
56e31af9a41e readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents: 12842
diff changeset
1 /* Tests of symlinkat.
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16201
diff changeset
2 Copyright (C) 2009-2013 Free Software Foundation, Inc.
11956
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
3
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 (at your option) any later version.
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
8
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12 GNU General Public License for more details.
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
19 #include <config.h>
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
21 #include <unistd.h>
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
22
12489
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
23 #include "signature.h"
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
24 SIGNATURE_CHECK (symlinkat, int, (char const *, int, char const *));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
25
11956
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
26 #include <fcntl.h>
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
27 #include <errno.h>
12061
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
28 #include <stdbool.h>
11956
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
29 #include <stdio.h>
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
30 #include <stdlib.h>
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
31 #include <string.h>
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
32 #include <sys/stat.h>
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
33
12842
b2bf8684a2db tests: silence warning about system return
Eric Blake <ebb9@byu.net>
parents: 12559
diff changeset
34 #include "ignore-value.h"
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12489
diff changeset
35 #include "macros.h"
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12489
diff changeset
36
11956
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
37 #ifndef HAVE_SYMLINK
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
38 # define HAVE_SYMLINK 0
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
39 #endif
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
40
12061
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
41 #define BASE "test-symlinkat.t"
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
42
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
43 #include "test-symlink.h"
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
44
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
45 static int dfd = AT_FDCWD;
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
46
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
47 static int
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
48 do_symlink (char const *contents, char const *name)
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
49 {
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
50 return symlinkat (contents, dfd, name);
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
51 }
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
52
11956
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
53 int
12197
e45d9bb2233e tests: avoid several compiler warnings
Eric Blake <ebb9@byu.net>
parents: 12146
diff changeset
54 main (void)
11956
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
55 {
12061
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
56 int result;
11956
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
57
12061
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
58 /* Remove any leftovers from a previous partial run. */
12842
b2bf8684a2db tests: silence warning about system return
Eric Blake <ebb9@byu.net>
parents: 12559
diff changeset
59 ignore_value (system ("rm -rf " BASE "*"));
11956
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
60
15704
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
61 /* Test behaviour for invalid file descriptors. */
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
62 {
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
63 errno = 0;
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
64 ASSERT (symlinkat ("foo", -1, "bar") == -1);
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
65 ASSERT (errno == EBADF
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
66 || errno == ENOSYS /* seen on mingw */
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
67 );
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
68 }
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
69 {
17295
3a09cc104f4c tests: don't assume fd 99 is closed
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
70 close (99);
15704
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
71 errno = 0;
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
72 ASSERT (symlinkat ("foo", 99, "bar") == -1);
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
73 ASSERT (errno == EBADF
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
74 || errno == ENOSYS /* seen on mingw */
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
75 );
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
76 }
17eaeb48cbef symlinkat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
77
12061
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
78 /* Perform same checks as counterpart functions. */
13539
56e31af9a41e readlinkat: split into its own module
Eric Blake <eblake@redhat.com>
parents: 12842
diff changeset
79 result = test_symlink (do_symlink, false);
12061
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
80 dfd = openat (AT_FDCWD, ".", O_RDONLY);
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
81 ASSERT (0 <= dfd);
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
82 ASSERT (test_symlink (do_symlink, false) == result);
11956
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
83
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
84 ASSERT (close (dfd) == 0);
12061
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
85 if (result == 77)
12146
e076a06bae48 maint: prefer 'file system' over 'filesystem'
Eric Blake <ebb9@byu.net>
parents: 12061
diff changeset
86 fputs ("skipping test: symlinks not supported on this file system\n",
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12197
diff changeset
87 stderr);
12061
c47da311af77 test-symlinkat: enhance test
Eric Blake <ebb9@byu.net>
parents: 11956
diff changeset
88 return result;
11956
55cb5282dd84 symlinkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
89 }