1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
4 Copyright (C) 2009-2011 Free Software Foundation, Inc.
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 /* Written by Eric Blake <ebb9@byu.net>, 2009. */
21 /* This file is designed to test both symlink(a,b) and
22 symlinkat(a,AT_FDCWD,b). FUNC is the function to test. Assumes
23 that BASE and ASSERT are already defined, and that appropriate
24 headers are already included. If PRINT, warn before skipping
25 symlink tests with status 77. */
28 test_symlink (int (*func) (char const *, char const *), bool print)
30 if (func ("nowhere", BASE "link1"))
33 fputs ("skipping test: symlinks not supported on this file system\n",
38 /* Some systems allow the creation of 0-length symlinks as a synonym
39 for "."; but most reject it. */
43 status = func ("", BASE "link2");
45 ASSERT (errno == ENOENT || errno == EINVAL);
49 ASSERT (unlink (BASE "link2") == 0);
53 /* Sanity checks of failures. */
55 ASSERT (func ("nowhere", "") == -1);
56 ASSERT (errno == ENOENT);
58 ASSERT (func ("nowhere", ".") == -1);
59 ASSERT (errno == EEXIST || errno == EINVAL);
61 ASSERT (func ("somewhere", BASE "link1") == -1);
62 ASSERT (errno == EEXIST);
64 ASSERT (func ("nowhere", BASE "link2/") == -1);
65 ASSERT (errno == ENOTDIR || errno == ENOENT);
66 ASSERT (mkdir (BASE "dir", 0700) == 0);
68 ASSERT (func ("nowhere", BASE "dir") == -1);
69 ASSERT (errno == EEXIST);
71 ASSERT (func ("nowhere", BASE "dir/") == -1);
72 ASSERT (errno == EEXIST || errno == EINVAL);
73 ASSERT (close (creat (BASE "file", 0600)) == 0);
75 ASSERT (func ("nowhere", BASE "file") == -1);
76 ASSERT (errno == EEXIST);
78 ASSERT (func ("nowhere", BASE "file/") == -1);
79 ASSERT (errno == EEXIST || errno == ENOTDIR || errno == ENOENT);
81 /* Trailing slash must always be rejected. */
82 ASSERT (unlink (BASE "link1") == 0);
83 ASSERT (func (BASE "link2", BASE "link1") == 0);
85 ASSERT (func (BASE "nowhere", BASE "link1/") == -1);
86 ASSERT (errno == EEXIST || errno == ENOTDIR || errno == ENOENT);
88 ASSERT (unlink (BASE "link2") == -1);
89 ASSERT (errno == ENOENT);
92 ASSERT (rmdir (BASE "dir") == 0);
93 ASSERT (unlink (BASE "file") == 0);
94 ASSERT (unlink (BASE "link1") == 0);