link: LoadLibrary is not needed.
[gnulib.git] / tests / test-stat.h
1 /* Tests of stat.
2    Copyright (C) 2009 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>.  */
16
17 /* Written by Eric Blake <ebb9@byu.net>, 2009.  */
18
19 /* This file is designed to test both stat(n,buf) and
20    fstatat(AT_FDCWD,n,buf,0).  FUNC is the function to test.  Assumes
21    that BASE and ASSERT are already defined, and that appropriate
22    headers are already included.  */
23
24 static int
25 test_stat_func (int (*func) (char const *, struct stat *))
26 {
27   struct stat st1;
28   struct stat st2;
29   char cwd[PATH_MAX];
30
31   ASSERT (getcwd (cwd, PATH_MAX) == cwd);
32   ASSERT (func (".", &st1) == 0);
33   ASSERT (func ("./", &st2) == 0);
34   ASSERT (SAME_INODE (st1, st2));
35   ASSERT (func (cwd, &st2) == 0);
36   ASSERT (SAME_INODE (st1, st2));
37   ASSERT (func ("/", &st1) == 0);
38   ASSERT (func ("///", &st2) == 0);
39   ASSERT (SAME_INODE (st1, st2));
40
41   errno = 0;
42   ASSERT (func ("", &st1) == -1);
43   ASSERT (errno == ENOENT);
44   errno = 0;
45   ASSERT (func ("nosuch", &st1) == -1);
46   ASSERT (errno == ENOENT);
47   errno = 0;
48   ASSERT (func ("nosuch/", &st1) == -1);
49   ASSERT (errno == ENOENT);
50
51   ASSERT (close (creat (BASE "file", 0600)) == 0);
52   ASSERT (func (BASE "file", &st1) == 0);
53   errno = 0;
54   ASSERT (func (BASE "file/", &st1) == -1);
55   ASSERT (errno == ENOTDIR);
56   ASSERT (unlink (BASE "file") == 0);
57
58   return 0;
59 }