1 /* Test program for dirname function a la XPG.
2 Copyright (C) 1996-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
26 test (const char *input
, const char *result
)
32 retval
= strcmp (cp
, result
);
34 printf ("dirname(\"%s\") should be \"%s\", but is \"%s\"\n",
44 /* These are the examples given in XPG4.2. */
45 result
|= test ("/usr/lib", "/usr");
46 result
|= test ("/usr/", "/");
47 result
|= test ("usr", ".");
48 result
|= test ("/", "/");
49 result
|= test (".", ".");
50 result
|= test ("..", ".");
52 /* Some more tests. */
53 result
|= test ("/usr/lib/", "/usr");
54 result
|= test ("/usr", "/");
55 result
|= test ("a//", ".");
56 result
|= test ("a////", ".");
57 result
|= test ("////usr", "/");
58 result
|= test ("////usr//", "/");
59 result
|= test ("//usr", "//");
60 result
|= test ("//usr//", "//");
61 result
|= test ("//", "//");
63 /* Other Unix implementations behave like this. */
64 result
|= test ("x///y", "x");
65 result
|= test ("x/////y", "x");
70 #define TEST_FUNCTION do_test ()
71 #include "../test-skeleton.c"