]>
Commit | Line | Data |
---|---|---|
76877b46 ZJS |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2013 Zbigniew Jędrzejewski-Szmek | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
22 | #include "path-util.h" | |
23 | #include "util.h" | |
24 | #include "macro.h" | |
25 | ||
26 | ||
27 | static void test_path(void) { | |
28 | assert_se(path_equal("/goo", "/goo")); | |
29 | assert_se(path_equal("//goo", "/goo")); | |
30 | assert_se(path_equal("//goo/////", "/goo")); | |
31 | assert_se(path_equal("goo/////", "goo")); | |
32 | ||
33 | assert_se(path_equal("/goo/boo", "/goo//boo")); | |
34 | assert_se(path_equal("//goo/boo", "/goo/boo//")); | |
35 | ||
36 | assert_se(path_equal("/", "///")); | |
37 | ||
38 | assert_se(!path_equal("/x", "x/")); | |
39 | assert_se(!path_equal("x/", "/")); | |
40 | ||
41 | assert_se(!path_equal("/x/./y", "x/y")); | |
42 | assert_se(!path_equal("x/.y", "x/y")); | |
43 | ||
44 | assert_se(path_is_absolute("/")); | |
45 | assert_se(!path_is_absolute("./")); | |
46 | ||
47 | assert_se(is_path("/dir")); | |
48 | assert_se(is_path("a/b")); | |
49 | assert_se(!is_path(".")); | |
50 | ||
51 | assert_se(streq(path_get_file_name("./aa/bb/../file.da."), "file.da.")); | |
52 | assert_se(streq(path_get_file_name("/aa///.file"), ".file")); | |
53 | assert_se(streq(path_get_file_name("/aa///file..."), "file...")); | |
54 | assert_se(streq(path_get_file_name("file.../"), ".")); | |
55 | ||
56 | #define test_parent(x, y) { \ | |
57 | char *z; \ | |
58 | int r = path_get_parent(x, &z); \ | |
59 | assert_se(r==0); \ | |
60 | assert_se(streq(z, y)); \ | |
61 | } | |
62 | ||
63 | test_parent("./aa/bb/../file.da.", "./aa/bb/.."); | |
64 | test_parent("/aa///.file", "/aa///"); | |
65 | test_parent("/aa///file...", "/aa///"); | |
66 | test_parent("file.../", "file..."); | |
67 | ||
68 | assert_se(path_is_mount_point("/", true)); | |
69 | assert_se(path_is_mount_point("/", false)); | |
70 | ||
71 | { | |
72 | char p1[] = "aaa/bbb////ccc"; | |
73 | char p2[] = "//aaa/.////ccc"; | |
74 | char p3[] = "/./"; | |
75 | ||
76 | assert(path_equal(path_kill_slashes(p1), "aaa/bbb/ccc")); | |
77 | assert(path_equal(path_kill_slashes(p2), "/aaa/./ccc")); | |
78 | assert(path_equal(path_kill_slashes(p3), "/./")); | |
79 | } | |
80 | } | |
81 | ||
82 | int main(void) { | |
83 | test_path(); | |
84 | return 0; | |
85 | } |