reduced verbosity and better debugging.
[gnutls.git] / gl / tests / test-symlink.h
bloba7c407945ec80531e5831ee8bafd782874bae18b
1 /* Tests of symlink.
2 Copyright (C) 2009-2012 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */
19 /* This file is designed to test both symlink(a,b) and
20 symlinkat(a,AT_FDCWD,b). FUNC is the function to test. Assumes
21 that BASE and ASSERT are already defined, and that appropriate
22 headers are already included. If PRINT, warn before skipping
23 symlink tests with status 77. */
25 static int
26 test_symlink (int (*func) (char const *, char const *), bool print)
28 if (func ("nowhere", BASE "link1"))
30 if (print)
31 fputs ("skipping test: symlinks not supported on this file system\n",
32 stderr);
33 return 77;
36 /* Some systems allow the creation of 0-length symlinks as a synonym
37 for "."; but most reject it. */
39 int status;
40 errno = 0;
41 status = func ("", BASE "link2");
42 if (status == -1)
43 ASSERT (errno == ENOENT || errno == EINVAL);
44 else
46 ASSERT (status == 0);
47 ASSERT (unlink (BASE "link2") == 0);
51 /* Sanity checks of failures. */
52 errno = 0;
53 ASSERT (func ("nowhere", "") == -1);
54 ASSERT (errno == ENOENT);
55 errno = 0;
56 ASSERT (func ("nowhere", ".") == -1);
57 ASSERT (errno == EEXIST || errno == EINVAL);
58 errno = 0;
59 ASSERT (func ("somewhere", BASE "link1") == -1);
60 ASSERT (errno == EEXIST);
61 errno = 0;
62 ASSERT (func ("nowhere", BASE "link2/") == -1);
63 ASSERT (errno == ENOTDIR || errno == ENOENT);
64 ASSERT (mkdir (BASE "dir", 0700) == 0);
65 errno = 0;
66 ASSERT (func ("nowhere", BASE "dir") == -1);
67 ASSERT (errno == EEXIST);
68 errno = 0;
69 ASSERT (func ("nowhere", BASE "dir/") == -1);
70 ASSERT (errno == EEXIST || errno == EINVAL);
71 ASSERT (close (creat (BASE "file", 0600)) == 0);
72 errno = 0;
73 ASSERT (func ("nowhere", BASE "file") == -1);
74 ASSERT (errno == EEXIST);
75 errno = 0;
76 ASSERT (func ("nowhere", BASE "file/") == -1);
77 ASSERT (errno == EEXIST || errno == ENOTDIR || errno == ENOENT);
79 /* Trailing slash must always be rejected. */
80 ASSERT (unlink (BASE "link1") == 0);
81 ASSERT (func (BASE "link2", BASE "link1") == 0);
82 errno = 0;
83 ASSERT (func (BASE "nowhere", BASE "link1/") == -1);
84 ASSERT (errno == EEXIST || errno == ENOTDIR || errno == ENOENT);
85 errno = 0;
86 ASSERT (unlink (BASE "link2") == -1);
87 ASSERT (errno == ENOENT);
89 /* Cleanup. */
90 ASSERT (rmdir (BASE "dir") == 0);
91 ASSERT (unlink (BASE "file") == 0);
92 ASSERT (unlink (BASE "link1") == 0);
94 return 0;