Mercurial > hg > octave-shane > gnulib-hg
annotate tests/test-dirname.c @ 17632:86af85d364e1 default tip
unistd: port readlink to Mac OS X 10.3.9
* lib/unistd.in.h (_GL_INCLUDING_UNISTD_H): New macro, to work
around self-include problem in Mac OS X 10.3.9 when combined with
readlink module. Problem reported by Klaus Zietler in
<http://bugs.gnu.org/16825>.
author | Paul Eggert <eggert@penguin.cs.ucla.edu> |
---|---|
date | Tue, 25 Feb 2014 11:16:27 -0800 |
parents | 344018b6e5d7 |
children |
rev | line source |
---|---|
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
1 /* Test the gnulib dirname module. |
17587 | 2 Copyright (C) 2005-2007, 2009-2014 Free Software Foundation, Inc. |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
7 (at your option) any later version. |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
8 |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
13 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
16 |
8891
633babea5f62
Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents:
8463
diff
changeset
|
17 #include <config.h> |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
18 |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
19 #include "dirname.h" |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
20 |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
21 #include <stdbool.h> |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
22 #include <stdio.h> |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
23 #include <stdlib.h> |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
24 #include <string.h> |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
25 |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
26 struct test { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
27 const char *name; /* Name under test. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
28 const char *dir; /* dir_name (name). */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
29 const char *last; /* last_component (name). */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
30 const char *base; /* base_name (name). */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
31 const char *stripped; /* name after strip_trailing_slashes (name). */ |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
32 bool modified; /* result of strip_trailing_slashes (name). */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
33 bool absolute; /* IS_ABSOLUTE_FILE_NAME (name). */ |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
34 }; |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
35 |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
36 static struct test tests[] = { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
37 {"d/f", "d", "f", "f", "d/f", false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
38 {"/d/f", "/d", "f", "f", "/d/f", false, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
39 {"d/f/", "d", "f/", "f/", "d/f", true, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
40 {"d/f//", "d", "f//", "f/", "d/f", true, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
41 {"f", ".", "f", "f", "f", false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
42 {"/", "/", "", "/", "/", false, true}, |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
43 #if DOUBLE_SLASH_IS_DISTINCT_ROOT |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
44 {"//", "//", "", "//", "//", false, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
45 {"//d", "//", "d", "d", "//d", false, true}, |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
46 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
47 {"//", "/", "", "/", "/", true, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
48 {"//d", "/", "d", "d", "//d", false, true}, |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
49 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
50 {"///", "/", "", "/", "/", true, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
51 {"///a///", "/", "a///", "a/", "///a", true, true}, |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
52 /* POSIX requires dirname("") and basename("") to both return ".", |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
53 but dir_name and base_name are defined differently. */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
54 {"", ".", "", "", "", false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
55 {".", ".", ".", ".", ".", false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
56 {"..", ".", "..", "..", "..", false, false}, |
14393
9f47f8c334f2
dirname: move m4/dos.m4 functionality into lib/dosname.h
Paul Eggert <eggert@cs.ucla.edu>
parents:
14079
diff
changeset
|
57 #if ISSLASH ('\\') |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
58 {"a\\", ".", "a\\", "a\\", "a", true, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
59 {"a\\b", "a", "b", "b", "a\\b", false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
60 {"\\", "\\", "", "\\", "\\", false, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
61 {"\\/\\", "\\", "", "\\", "\\", true, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
62 {"\\\\/", "\\", "", "\\", "\\", true, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
63 {"\\//", "\\", "", "\\", "\\", true, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
64 {"//\\", "/", "", "/", "/", true, true}, |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
65 #else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
66 {"a\\", ".", "a\\", "a\\", "a\\", false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
67 {"a\\b", ".", "a\\b", "a\\b", "a\\b", false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
68 {"\\", ".", "\\", "\\", "\\", false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
69 {"\\/\\", "\\", "\\", "\\", "\\/\\",false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
70 {"\\\\/", ".", "\\\\/","\\\\/","\\\\", true, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
71 {"\\//", ".", "\\//", "\\/", "\\", true, false}, |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
72 # if DOUBLE_SLASH_IS_DISTINCT_ROOT |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
73 {"//\\", "//", "\\", "\\", "//\\", false, true}, |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
74 # else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
75 {"//\\", "/", "\\", "\\", "//\\", false, true}, |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
76 # endif |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
77 #endif |
14393
9f47f8c334f2
dirname: move m4/dos.m4 functionality into lib/dosname.h
Paul Eggert <eggert@cs.ucla.edu>
parents:
14079
diff
changeset
|
78 #if ISSLASH ('\\') |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
79 # if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
80 {"c:", "c:", "", "c:", "c:", false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
81 {"c:/", "c:/", "", "c:/", "c:/", false, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
82 {"c://", "c:/", "", "c:/", "c:/", true, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
83 {"c:/d", "c:/", "d", "d", "c:/d", false, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
84 {"c://d", "c:/", "d", "d", "c://d",false, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
85 {"c:/d/", "c:/", "d/", "d/", "c:/d", true, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
86 {"c:/d/f", "c:/d", "f", "f", "c:/d/f",false, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
87 {"c:d", "c:.", "d", "d", "c:d", false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
88 {"c:d/", "c:.", "d/", "d/", "c:d", true, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
89 {"c:d/f", "c:d", "f", "f", "c:d/f",false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
90 {"a:b:c", "a:.", "b:c", "./b:c","a:b:c",false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
91 {"a/b:c", "a", "b:c", "./b:c","a/b:c",false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
92 {"a/b:c/", "a", "b:c/", "./b:c/","a/b:c",true, false}, |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
93 # else /* ! FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
94 {"c:", "c:", "", "c:", "c:", false, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
95 {"c:/", "c:", "", "c:", "c:", true, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
96 {"c://", "c:", "", "c:", "c:", true, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
97 {"c:/d", "c:", "d", "d", "c:/d", false, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
98 {"c://d", "c:", "d", "d", "c://d",false, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
99 {"c:/d/", "c:", "d/", "d/", "c:/d", true, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
100 {"c:/d/f", "c:/d", "f", "f", "c:/d/f",false, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
101 {"c:d", "c:", "d", "d", "c:d", false, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
102 {"c:d/", "c:", "d/", "d/", "c:d", true, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
103 {"c:d/f", "c:d", "f", "f", "c:d/f",false, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
104 {"a:b:c", "a:", "b:c", "./b:c","a:b:c",false, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
105 {"a/b:c", "a", "b:c", "./b:c","a/b:c",false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
106 {"a/b:c/", "a", "b:c/", "./b:c/","a/b:c",true, false}, |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
107 # endif |
14393
9f47f8c334f2
dirname: move m4/dos.m4 functionality into lib/dosname.h
Paul Eggert <eggert@cs.ucla.edu>
parents:
14079
diff
changeset
|
108 #else /* ! ISSLASH ('\\') */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
109 {"c:", ".", "c:", "c:", "c:", false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
110 {"c:/", ".", "c:/", "c:/", "c:", true, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
111 {"c://", ".", "c://", "c:/", "c:", true, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
112 {"c:/d", "c:", "d", "d", "c:/d", false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
113 {"c://d", "c:", "d", "d", "c://d",false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
114 {"c:/d/", "c:", "d/", "d/", "c:/d", true, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
115 {"c:/d/f", "c:/d", "f", "f", "c:/d/f",false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
116 {"c:d", ".", "c:d", "c:d", "c:d", false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
117 {"c:d/", ".", "c:d/", "c:d/", "c:d", true, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
118 {"c:d/f", "c:d", "f", "f", "c:d/f",false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
119 {"a:b:c", ".", "a:b:c","a:b:c","a:b:c",false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
120 {"a/b:c", "a", "b:c", "b:c", "a/b:c",false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
121 {"a/b:c/", "a", "b:c/", "b:c/", "a/b:c",true, false}, |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
122 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
123 {"1:", ".", "1:", "1:", "1:", false, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
124 {"1:/", ".", "1:/", "1:/", "1:", true, false}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
125 {"/:", "/", ":", ":", "/:", false, true}, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
126 {"/:/", "/", ":/", ":/", "/:", true, true}, |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
127 /* End sentinel. */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
128 {NULL, NULL, NULL, NULL, NULL, false, false} |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
129 }; |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
130 |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
131 int |
12197
e45d9bb2233e
tests: avoid several compiler warnings
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
132 main (void) |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
133 { |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
134 struct test *t; |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
135 bool ok = true; |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
136 |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
137 for (t = tests; t->name; t++) |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
138 { |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
139 char *dir = dir_name (t->name); |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
140 int dirlen = dir_len (t->name); |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
141 char *last = last_component (t->name); |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
142 char *base = base_name (t->name); |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
143 int baselen = base_len (base); |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
144 char *stripped = strdup (t->name); |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
145 bool modified = strip_trailing_slashes (stripped); |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
146 bool absolute = IS_ABSOLUTE_FILE_NAME (t->name); |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
147 if (! (strcmp (dir, t->dir) == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
148 && (dirlen == strlen (dir) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
149 || (dirlen + 1 == strlen (dir) && dir[dirlen] == '.')))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
150 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
151 ok = false; |
16234
f9b906545e2f
Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
152 printf ("dir_name '%s': got '%s' len %d," |
f9b906545e2f
Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
153 " expected '%s' len %ld\n", |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
154 t->name, dir, dirlen, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
155 t->dir, (unsigned long) strlen (t->dir)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
156 } |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
157 if (strcmp (last, t->last)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
158 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
159 ok = false; |
16234
f9b906545e2f
Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
160 printf ("last_component '%s': got '%s', expected '%s'\n", |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
161 t->name, last, t->last); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
162 } |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
163 if (! (strcmp (base, t->base) == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
164 && (baselen == strlen (base) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
165 || (baselen + 1 == strlen (base) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
166 && ISSLASH (base[baselen]))))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
167 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
168 ok = false; |
16234
f9b906545e2f
Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
169 printf ("base_name '%s': got '%s' len %d," |
f9b906545e2f
Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
170 " expected '%s' len %ld\n", |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
171 t->name, base, baselen, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
172 t->base, (unsigned long) strlen (t->base)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
173 } |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
174 if (strcmp (stripped, t->stripped) || modified != t->modified) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
175 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
176 ok = false; |
16234
f9b906545e2f
Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
177 printf ("strip_trailing_slashes '%s': got %s %s, expected %s %s\n", |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
178 t->name, stripped, modified ? "changed" : "unchanged", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
179 t->stripped, t->modified ? "changed" : "unchanged"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
180 } |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
181 if (t->absolute != absolute) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
182 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
183 ok = false; |
16234
f9b906545e2f
Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
184 printf ("'%s': got %s, expected %s\n", t->name, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
185 absolute ? "absolute" : "relative", |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
186 t->absolute ? "absolute" : "relative"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12212
diff
changeset
|
187 } |
6922
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
188 free (dir); |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
189 free (base); |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
190 free (stripped); |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
191 } |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
192 return ok ? 0 : 1; |
640106e1be97
* modules/dirname-tests: New test module.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
193 } |