Commit | Line | Data |
---|---|---|
c68d8eba | 1 | |
b90f122b RK |
2 | /* |
3 | * This file is part of DisOrder. | |
4 | * Copyright (C) 2005, 2007, 2008 Richard Kettlewell | |
5 | * | |
e7eb3a27 | 6 | * This program is free software: you can redistribute it and/or modify |
b90f122b | 7 | * it under the terms of the GNU General Public License as published by |
e7eb3a27 | 8 | * the Free Software Foundation, either version 3 of the License, or |
b90f122b | 9 | * (at your option) any later version. |
e7eb3a27 RK |
10 | * |
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. | |
15 | * | |
b90f122b | 16 | * You should have received a copy of the GNU General Public License |
e7eb3a27 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
b90f122b RK |
18 | */ |
19 | #include "test.h" | |
20 | ||
2257512d RK |
21 | #define check_filepart(PATH, DIR, BASE) do { \ |
22 | char *d = d_dirname(PATH), *b = d_basename(PATH); \ | |
23 | \ | |
24 | if(strcmp(d, DIR)) { \ | |
25 | fprintf(stderr, "%s:%d: d_dirname failed:\n" \ | |
26 | " path: %s\n" \ | |
27 | " got: %s\n" \ | |
28 | "expected: %s\n", \ | |
29 | __FILE__, __LINE__, \ | |
30 | PATH, d, DIR); \ | |
31 | count_error(); \ | |
32 | } \ | |
33 | if(strcmp(b, BASE)) { \ | |
34 | fprintf(stderr, "%s:%d: d_basename failed:\n" \ | |
35 | " path: %s\n" \ | |
36 | " got: %s\n" \ | |
37 | "expected: %s\n", \ | |
38 | __FILE__, __LINE__, \ | |
39 | PATH, d, DIR); \ | |
40 | count_error(); \ | |
41 | } \ | |
42 | } while(0) | |
43 | ||
c68d8eba | 44 | static void test_filepart(void) { |
2257512d RK |
45 | check_filepart("", "", ""); |
46 | check_filepart("/", "/", "/"); | |
47 | check_filepart("////", "/", "/"); | |
48 | check_filepart("/spong", "/", "spong"); | |
49 | check_filepart("/spong/", "/", "spong"); | |
50 | check_filepart("/spong//", "/", "spong"); | |
51 | check_filepart("////spong", "/", "spong"); | |
52 | check_filepart("/foo/bar", "/foo", "bar"); | |
53 | check_filepart("/foo/bar/", "/foo", "bar"); | |
54 | check_filepart("////foo/////bar", "////foo", "bar"); | |
55 | check_filepart("./bar", ".", "bar"); | |
56 | check_filepart(".//bar", ".", "bar"); | |
57 | check_filepart(".", ".", "."); | |
58 | check_filepart("..", ".", ".."); | |
59 | check_filepart("../blat", "..", "blat"); | |
60 | check_filepart("..//blat", "..", "blat"); | |
61 | check_filepart("wibble", ".", "wibble"); | |
b90f122b RK |
62 | check_string(extension("foo.c"), ".c"); |
63 | check_string(extension(".c"), ".c"); | |
64 | check_string(extension("."), "."); | |
65 | check_string(extension("foo"), ""); | |
66 | check_string(extension("./foo"), ""); | |
67 | check_string(extension("./foo.c"), ".c"); | |
68 | check_string(strip_extension("foo.c"), "foo"); | |
69 | check_string(strip_extension("foo.mp3"), "foo"); | |
70 | check_string(strip_extension("foo.---"), "foo.---"); | |
71 | check_string(strip_extension("foo.---xyz"), "foo.---xyz"); | |
72 | check_string(strip_extension("foo.bar/wibble.spong"), "foo.bar/wibble"); | |
73 | } | |
74 | ||
c68d8eba RK |
75 | TEST(filepart); |
76 | ||
b90f122b RK |
77 | /* |
78 | Local Variables: | |
79 | c-basic-offset:2 | |
80 | comment-column:40 | |
81 | fill-column:79 | |
82 | indent-tabs-mode:nil | |
83 | End: | |
84 | */ |