3 * This file is part of DisOrder.
4 * Copyright (C) 2005, 2007, 2008 Richard Kettlewell
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #define check_filepart(PATH, DIR, BASE) do { \
22 char *d = d_dirname(PATH), *b = d_basename(PATH); \
24 if(strcmp(d, DIR)) { \
25 fprintf(stderr, "%s:%d: d_dirname failed:\n" \
33 if(strcmp(b, BASE)) { \
34 fprintf(stderr, "%s:%d: d_basename failed:\n" \
44 static void test_filepart(void) {
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");
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");