File: | bld/../path_utils/path_utils_ut.c |
Location: | line 407, column 5 |
Description: | Dereference of null pointer |
1 | /* | ||||
2 | path_utils - unit tests | ||||
3 | |||||
4 | Authors: | ||||
5 | Jakub Hrozek <jhrozek@redhat.com> | ||||
6 | |||||
7 | Copyright (C) 2009 Red Hat | ||||
8 | |||||
9 | This program is free software; you can redistribute it and/or modify | ||||
10 | it under the terms of the GNU General Public License as published by | ||||
11 | the Free Software Foundation; either version 3 of the License, or | ||||
12 | (at your option) any later version. | ||||
13 | |||||
14 | This program is distributed in the hope that it will be useful, | ||||
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
17 | GNU General Public License for more details. | ||||
18 | |||||
19 | You should have received a copy of the GNU General Public License | ||||
20 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
21 | */ | ||||
22 | |||||
23 | #include "config.h" | ||||
24 | |||||
25 | #include <check.h> | ||||
26 | #include <stdlib.h> | ||||
27 | #include <stdio.h> | ||||
28 | #include <unistd.h> | ||||
29 | #include <errno(*__errno_location ()).h> | ||||
30 | |||||
31 | #include "path_utils.h" | ||||
32 | |||||
33 | #define fail_unless_str_equal(a, b)do { _fail_unless(strcmp(a, b) == 0, "../path_utils/path_utils_ut.c" , 33, "Assertion '""strcmp(a, b) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , a, b, ((void*)0)); } while(0); do { \ | ||||
34 | fail_unless(strcmp(a, b) == 0, \_fail_unless(strcmp(a, b) == 0, "../path_utils/path_utils_ut.c" , 36, "Assertion '""strcmp(a, b) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , a, b, ((void*)0)) | ||||
35 | "The strings '%s' and '%s' are different, expected same", \_fail_unless(strcmp(a, b) == 0, "../path_utils/path_utils_ut.c" , 36, "Assertion '""strcmp(a, b) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , a, b, ((void*)0)) | ||||
36 | a, b)_fail_unless(strcmp(a, b) == 0, "../path_utils/path_utils_ut.c" , 36, "Assertion '""strcmp(a, b) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , a, b, ((void*)0)); \ | ||||
37 | } while(0); | ||||
38 | |||||
39 | #define DIR_TEMPLATE"test-directory-list-dir-XXXXXX" "test-directory-list-dir-XXXXXX" | ||||
40 | #define SUBDIR"test-directory-list-subdir" "test-directory-list-subdir" | ||||
41 | #define SUBSUBDIR"test-directory-list-subsubdir" "test-directory-list-subsubdir" | ||||
42 | char *dlist_dir; | ||||
43 | char *dlist_subdir; | ||||
44 | char *dlist_subsubdir; | ||||
45 | |||||
46 | /**** get_dirname ****/ | ||||
47 | START_TEST(test_dirname)static void test_dirname (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_dirname", "../path_utils/path_utils_ut.c", 47); | ||||
48 | { | ||||
49 | char p[PATH_MAX4096]; | ||||
50 | char cwd[PATH_MAX4096]; | ||||
51 | |||||
52 | fail_unless(get_dirname(p, PATH_MAX, "/foo/bar") == SUCCESS)_fail_unless(get_dirname(p, 4096, "/foo/bar") == 0, "../path_utils/path_utils_ut.c" , 52, "Assertion '""get_dirname(p, PATH_MAX, \"/foo/bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
53 | fail_unless_str_equal(p, "/foo")do { _fail_unless(strcmp(p, "/foo") == 0, "../path_utils/path_utils_ut.c" , 53, "Assertion '""strcmp(p, \"/foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "/foo", ((void*)0)); } while(0);; | ||||
54 | |||||
55 | fail_unless(get_dirname(p, PATH_MAX, "/") == SUCCESS)_fail_unless(get_dirname(p, 4096, "/") == 0, "../path_utils/path_utils_ut.c" , 55, "Assertion '""get_dirname(p, PATH_MAX, \"/\") == SUCCESS" "' failed", ((void*)0)); | ||||
56 | fail_unless_str_equal(p, "/")do { _fail_unless(strcmp(p, "/") == 0, "../path_utils/path_utils_ut.c" , 56, "Assertion '""strcmp(p, \"/\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "/", ((void*)0)); } while(0);; | ||||
57 | |||||
58 | fail_unless(get_dirname(p, PATH_MAX, "/foo") == SUCCESS)_fail_unless(get_dirname(p, 4096, "/foo") == 0, "../path_utils/path_utils_ut.c" , 58, "Assertion '""get_dirname(p, PATH_MAX, \"/foo\") == SUCCESS" "' failed", ((void*)0)); | ||||
59 | fail_unless_str_equal(p, "/")do { _fail_unless(strcmp(p, "/") == 0, "../path_utils/path_utils_ut.c" , 59, "Assertion '""strcmp(p, \"/\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "/", ((void*)0)); } while(0);; | ||||
60 | |||||
61 | fail_unless(get_dirname(p, PATH_MAX, "//foo//bar") == SUCCESS)_fail_unless(get_dirname(p, 4096, "//foo//bar") == 0, "../path_utils/path_utils_ut.c" , 61, "Assertion '""get_dirname(p, PATH_MAX, \"//foo//bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
62 | fail_unless_str_equal(p, "//foo")do { _fail_unless(strcmp(p, "//foo") == 0, "../path_utils/path_utils_ut.c" , 62, "Assertion '""strcmp(p, \"//foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "//foo", ((void*)0)); } while(0);; | ||||
63 | |||||
64 | fail_unless(get_dirname(p, PATH_MAX, "//foo//") == SUCCESS)_fail_unless(get_dirname(p, 4096, "//foo//") == 0, "../path_utils/path_utils_ut.c" , 64, "Assertion '""get_dirname(p, PATH_MAX, \"//foo//\") == SUCCESS" "' failed", ((void*)0)); | ||||
65 | fail_unless_str_equal(p, "//")do { _fail_unless(strcmp(p, "//") == 0, "../path_utils/path_utils_ut.c" , 65, "Assertion '""strcmp(p, \"//\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "//", ((void*)0)); } while(0);; | ||||
66 | |||||
67 | fail_unless(get_dirname(p, PATH_MAX, "foo//bar") == SUCCESS)_fail_unless(get_dirname(p, 4096, "foo//bar") == 0, "../path_utils/path_utils_ut.c" , 67, "Assertion '""get_dirname(p, PATH_MAX, \"foo//bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
68 | fail_unless_str_equal(p, "foo")do { _fail_unless(strcmp(p, "foo") == 0, "../path_utils/path_utils_ut.c" , 68, "Assertion '""strcmp(p, \"foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "foo", ((void*)0)); } while(0);; | ||||
69 | |||||
70 | fail_unless(get_dirname(p, PATH_MAX, "foo//////bar") == SUCCESS)_fail_unless(get_dirname(p, 4096, "foo//////bar") == 0, "../path_utils/path_utils_ut.c" , 70, "Assertion '""get_dirname(p, PATH_MAX, \"foo//////bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
71 | fail_unless_str_equal(p, "foo")do { _fail_unless(strcmp(p, "foo") == 0, "../path_utils/path_utils_ut.c" , 71, "Assertion '""strcmp(p, \"foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "foo", ((void*)0)); } while(0);; | ||||
72 | |||||
73 | /* if pathname does not contain a slash, dirname returns cwd */ | ||||
74 | fail_if(getcwd(cwd, PATH_MAX) == NULL, "getcwd failed")_fail_unless(!(getcwd(cwd, 4096) == ((void*)0)), "../path_utils/path_utils_ut.c" , 74, "Failure '""getcwd(cwd, PATH_MAX) == NULL""' occured" , "getcwd failed", ((void*)0)); | ||||
75 | |||||
76 | fail_unless(get_dirname(p, PATH_MAX, "foo") == SUCCESS)_fail_unless(get_dirname(p, 4096, "foo") == 0, "../path_utils/path_utils_ut.c" , 76, "Assertion '""get_dirname(p, PATH_MAX, \"foo\") == SUCCESS" "' failed", ((void*)0)); | ||||
77 | fail_unless_str_equal(p, cwd)do { _fail_unless(strcmp(p, cwd) == 0, "../path_utils/path_utils_ut.c" , 77, "Assertion '""strcmp(p, cwd) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, cwd, ((void*)0)); } while(0);; | ||||
78 | |||||
79 | fail_unless(get_dirname(p, PATH_MAX, ".") == SUCCESS)_fail_unless(get_dirname(p, 4096, ".") == 0, "../path_utils/path_utils_ut.c" , 79, "Assertion '""get_dirname(p, PATH_MAX, \".\") == SUCCESS" "' failed", ((void*)0)); | ||||
80 | fail_unless_str_equal(p, cwd)do { _fail_unless(strcmp(p, cwd) == 0, "../path_utils/path_utils_ut.c" , 80, "Assertion '""strcmp(p, cwd) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, cwd, ((void*)0)); } while(0);; | ||||
81 | |||||
82 | fail_unless(get_dirname(p, PATH_MAX, "..") == SUCCESS)_fail_unless(get_dirname(p, 4096, "..") == 0, "../path_utils/path_utils_ut.c" , 82, "Assertion '""get_dirname(p, PATH_MAX, \"..\") == SUCCESS" "' failed", ((void*)0)); | ||||
83 | fail_unless_str_equal(p, cwd)do { _fail_unless(strcmp(p, cwd) == 0, "../path_utils/path_utils_ut.c" , 83, "Assertion '""strcmp(p, cwd) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, cwd, ((void*)0)); } while(0);; | ||||
84 | |||||
85 | fail_unless(get_dirname(p, PATH_MAX, "") == SUCCESS)_fail_unless(get_dirname(p, 4096, "") == 0, "../path_utils/path_utils_ut.c" , 85, "Assertion '""get_dirname(p, PATH_MAX, \"\") == SUCCESS" "' failed", ((void*)0)); | ||||
86 | fail_unless_str_equal(p, cwd)do { _fail_unless(strcmp(p, cwd) == 0, "../path_utils/path_utils_ut.c" , 86, "Assertion '""strcmp(p, cwd) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, cwd, ((void*)0)); } while(0);; | ||||
87 | } | ||||
88 | END_TEST} | ||||
89 | |||||
90 | START_TEST(test_dirname_neg)static void test_dirname_neg (int _i __attribute__ ((unused)) ){ tcase_fn_start ("""test_dirname_neg", "../path_utils/path_utils_ut.c" , 90); | ||||
91 | { | ||||
92 | char neg[3]; | ||||
93 | char p[PATH_MAX4096]; | ||||
94 | |||||
95 | fail_if(get_dirname(neg, 3, "/foo/bar") == SUCCESS)_fail_unless(!(get_dirname(neg, 3, "/foo/bar") == 0), "../path_utils/path_utils_ut.c" , 95, "Failure '""get_dirname(neg, 3, \"/foo/bar\") == SUCCESS" "' occured", ((void*)0)); | ||||
96 | fail_unless(get_dirname(p, PATH_MAX, NULL) == EINVAL)_fail_unless(get_dirname(p, 4096, ((void*)0)) == 22, "../path_utils/path_utils_ut.c" , 96, "Assertion '""get_dirname(p, PATH_MAX, NULL) == EINVAL" "' failed", ((void*)0)); | ||||
97 | } | ||||
98 | END_TEST} | ||||
99 | |||||
100 | /**** get_basename ****/ | ||||
101 | START_TEST(test_basename)static void test_basename (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_basename", "../path_utils/path_utils_ut.c", 101); | ||||
102 | { | ||||
103 | char p[PATH_MAX4096]; | ||||
104 | char cwd[PATH_MAX4096]; | ||||
105 | |||||
106 | fail_unless(get_basename(p, PATH_MAX, "/foo/bar") == SUCCESS)_fail_unless(get_basename(p, 4096, "/foo/bar") == 0, "../path_utils/path_utils_ut.c" , 106, "Assertion '""get_basename(p, PATH_MAX, \"/foo/bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
107 | fail_unless_str_equal(p, "bar")do { _fail_unless(strcmp(p, "bar") == 0, "../path_utils/path_utils_ut.c" , 107, "Assertion '""strcmp(p, \"bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "bar", ((void*)0)); } while(0);; | ||||
108 | |||||
109 | fail_unless(get_basename(p, PATH_MAX, "/foo/") == SUCCESS)_fail_unless(get_basename(p, 4096, "/foo/") == 0, "../path_utils/path_utils_ut.c" , 109, "Assertion '""get_basename(p, PATH_MAX, \"/foo/\") == SUCCESS" "' failed", ((void*)0)); | ||||
110 | fail_unless_str_equal(p, "foo")do { _fail_unless(strcmp(p, "foo") == 0, "../path_utils/path_utils_ut.c" , 110, "Assertion '""strcmp(p, \"foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "foo", ((void*)0)); } while(0);; | ||||
111 | |||||
112 | fail_unless(get_basename(p, PATH_MAX, "foo") == SUCCESS)_fail_unless(get_basename(p, 4096, "foo") == 0, "../path_utils/path_utils_ut.c" , 112, "Assertion '""get_basename(p, PATH_MAX, \"foo\") == SUCCESS" "' failed", ((void*)0)); | ||||
113 | fail_unless_str_equal(p, "foo")do { _fail_unless(strcmp(p, "foo") == 0, "../path_utils/path_utils_ut.c" , 113, "Assertion '""strcmp(p, \"foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "foo", ((void*)0)); } while(0);; | ||||
114 | |||||
115 | fail_unless(get_basename(p, PATH_MAX, "/") == SUCCESS)_fail_unless(get_basename(p, 4096, "/") == 0, "../path_utils/path_utils_ut.c" , 115, "Assertion '""get_basename(p, PATH_MAX, \"/\") == SUCCESS" "' failed", ((void*)0)); | ||||
116 | fail_unless_str_equal(p, "/")do { _fail_unless(strcmp(p, "/") == 0, "../path_utils/path_utils_ut.c" , 116, "Assertion '""strcmp(p, \"/\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "/", ((void*)0)); } while(0);; | ||||
117 | |||||
118 | fail_if(getcwd(cwd, PATH_MAX) == NULL, "getcwd failed")_fail_unless(!(getcwd(cwd, 4096) == ((void*)0)), "../path_utils/path_utils_ut.c" , 118, "Failure '""getcwd(cwd, PATH_MAX) == NULL""' occured" , "getcwd failed", ((void*)0)); | ||||
119 | |||||
120 | fail_unless(get_basename(p, PATH_MAX, ".") == SUCCESS)_fail_unless(get_basename(p, 4096, ".") == 0, "../path_utils/path_utils_ut.c" , 120, "Assertion '""get_basename(p, PATH_MAX, \".\") == SUCCESS" "' failed", ((void*)0)); | ||||
121 | fail_unless_str_equal(p, cwd)do { _fail_unless(strcmp(p, cwd) == 0, "../path_utils/path_utils_ut.c" , 121, "Assertion '""strcmp(p, cwd) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, cwd, ((void*)0)); } while(0);; | ||||
122 | |||||
123 | fail_unless(get_basename(p, PATH_MAX, "") == SUCCESS)_fail_unless(get_basename(p, 4096, "") == 0, "../path_utils/path_utils_ut.c" , 123, "Assertion '""get_basename(p, PATH_MAX, \"\") == SUCCESS" "' failed", ((void*)0)); | ||||
124 | fail_unless_str_equal(p, cwd)do { _fail_unless(strcmp(p, cwd) == 0, "../path_utils/path_utils_ut.c" , 124, "Assertion '""strcmp(p, cwd) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, cwd, ((void*)0)); } while(0);; | ||||
125 | } | ||||
126 | END_TEST} | ||||
127 | |||||
128 | START_TEST(test_basename_neg)static void test_basename_neg (int _i __attribute__ ((unused) )){ tcase_fn_start ("""test_basename_neg", "../path_utils/path_utils_ut.c" , 128); | ||||
129 | { | ||||
130 | char neg[3]; | ||||
131 | char p[PATH_MAX4096]; | ||||
132 | |||||
133 | fail_if(get_basename(neg, 3, "/foo/bar") == SUCCESS)_fail_unless(!(get_basename(neg, 3, "/foo/bar") == 0), "../path_utils/path_utils_ut.c" , 133, "Failure '""get_basename(neg, 3, \"/foo/bar\") == SUCCESS" "' occured", ((void*)0)); | ||||
134 | |||||
135 | fail_unless(get_basename(p, PATH_MAX, NULL) == EINVAL)_fail_unless(get_basename(p, 4096, ((void*)0)) == 22, "../path_utils/path_utils_ut.c" , 135, "Assertion '""get_basename(p, PATH_MAX, NULL) == EINVAL" "' failed", ((void*)0)); | ||||
136 | } | ||||
137 | END_TEST} | ||||
138 | |||||
139 | /**** is_absolute_path ****/ | ||||
140 | START_TEST(test_is_absolute_path)static void test_is_absolute_path (int _i __attribute__ ((unused ))){ tcase_fn_start ("""test_is_absolute_path", "../path_utils/path_utils_ut.c" , 140); | ||||
141 | { | ||||
142 | fail_unless(is_absolute_path("") == false)_fail_unless(is_absolute_path("") == 0, "../path_utils/path_utils_ut.c" , 142, "Assertion '""is_absolute_path(\"\") == false""' failed" , ((void*)0)); | ||||
143 | fail_unless(is_absolute_path("foo/bar") == false)_fail_unless(is_absolute_path("foo/bar") == 0, "../path_utils/path_utils_ut.c" , 143, "Assertion '""is_absolute_path(\"foo/bar\") == false""' failed" , ((void*)0)); | ||||
144 | |||||
145 | fail_unless(is_absolute_path("/foo/bar") == true)_fail_unless(is_absolute_path("/foo/bar") == 1, "../path_utils/path_utils_ut.c" , 145, "Assertion '""is_absolute_path(\"/foo/bar\") == true""' failed" , ((void*)0)); | ||||
146 | fail_unless(is_absolute_path("/foo") == true)_fail_unless(is_absolute_path("/foo") == 1, "../path_utils/path_utils_ut.c" , 146, "Assertion '""is_absolute_path(\"/foo\") == true""' failed" , ((void*)0)); | ||||
147 | fail_unless(is_absolute_path("/") == true)_fail_unless(is_absolute_path("/") == 1, "../path_utils/path_utils_ut.c" , 147, "Assertion '""is_absolute_path(\"/\") == true""' failed" , ((void*)0)); | ||||
148 | } | ||||
149 | END_TEST} | ||||
150 | |||||
151 | /**** get_dirname_and_basename ****/ | ||||
152 | /* Just a couple of basic tests - get_dirname_and_basename() | ||||
153 | * uses get_dirname() and get_basename() under the hood which | ||||
154 | * are tested enough in their specific tests | ||||
155 | */ | ||||
156 | START_TEST(test_dirname_and_basename)static void test_dirname_and_basename (int _i __attribute__ ( (unused))){ tcase_fn_start ("""test_dirname_and_basename", "../path_utils/path_utils_ut.c" , 156); | ||||
157 | { | ||||
158 | char dir[PATH_MAX4096]; | ||||
159 | char base[PATH_MAX4096]; | ||||
160 | char cwd[PATH_MAX4096]; | ||||
161 | int ret; | ||||
162 | |||||
163 | ret = get_directory_and_base_name(dir, PATH_MAX4096, base, PATH_MAX4096, "/foo/bar"); | ||||
164 | fail_unless(ret == SUCCESS)_fail_unless(ret == 0, "../path_utils/path_utils_ut.c", 164, "Assertion '" "ret == SUCCESS""' failed", ((void*)0)); | ||||
165 | fail_unless_str_equal(dir, "/foo")do { _fail_unless(strcmp(dir, "/foo") == 0, "../path_utils/path_utils_ut.c" , 165, "Assertion '""strcmp(dir, \"/foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , dir, "/foo", ((void*)0)); } while(0);; | ||||
166 | fail_unless_str_equal(base, "bar")do { _fail_unless(strcmp(base, "bar") == 0, "../path_utils/path_utils_ut.c" , 166, "Assertion '""strcmp(base, \"bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , base, "bar", ((void*)0)); } while(0);; | ||||
167 | |||||
168 | ret = get_directory_and_base_name(dir, PATH_MAX4096, base, PATH_MAX4096, "/foo"); | ||||
169 | fail_unless(ret == SUCCESS)_fail_unless(ret == 0, "../path_utils/path_utils_ut.c", 169, "Assertion '" "ret == SUCCESS""' failed", ((void*)0)); | ||||
170 | fail_unless_str_equal(dir, "/")do { _fail_unless(strcmp(dir, "/") == 0, "../path_utils/path_utils_ut.c" , 170, "Assertion '""strcmp(dir, \"/\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , dir, "/", ((void*)0)); } while(0);; | ||||
171 | fail_unless_str_equal(base, "foo")do { _fail_unless(strcmp(base, "foo") == 0, "../path_utils/path_utils_ut.c" , 171, "Assertion '""strcmp(base, \"foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , base, "foo", ((void*)0)); } while(0);; | ||||
172 | |||||
173 | ret = get_directory_and_base_name(dir, PATH_MAX4096, base, PATH_MAX4096, "/"); | ||||
174 | fail_unless(ret == SUCCESS)_fail_unless(ret == 0, "../path_utils/path_utils_ut.c", 174, "Assertion '" "ret == SUCCESS""' failed", ((void*)0)); | ||||
175 | fail_unless_str_equal(dir, "/")do { _fail_unless(strcmp(dir, "/") == 0, "../path_utils/path_utils_ut.c" , 175, "Assertion '""strcmp(dir, \"/\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , dir, "/", ((void*)0)); } while(0);; | ||||
176 | fail_unless_str_equal(base, "/")do { _fail_unless(strcmp(base, "/") == 0, "../path_utils/path_utils_ut.c" , 176, "Assertion '""strcmp(base, \"/\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , base, "/", ((void*)0)); } while(0);; | ||||
177 | |||||
178 | fail_if(getcwd(cwd, PATH_MAX) == NULL, "getcwd failed")_fail_unless(!(getcwd(cwd, 4096) == ((void*)0)), "../path_utils/path_utils_ut.c" , 178, "Failure '""getcwd(cwd, PATH_MAX) == NULL""' occured" , "getcwd failed", ((void*)0)); | ||||
179 | |||||
180 | ret = get_directory_and_base_name(dir, PATH_MAX4096, base, PATH_MAX4096, "foo"); | ||||
181 | fail_unless(ret == SUCCESS)_fail_unless(ret == 0, "../path_utils/path_utils_ut.c", 181, "Assertion '" "ret == SUCCESS""' failed", ((void*)0)); | ||||
182 | fail_unless_str_equal(dir, cwd)do { _fail_unless(strcmp(dir, cwd) == 0, "../path_utils/path_utils_ut.c" , 182, "Assertion '""strcmp(dir, cwd) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , dir, cwd, ((void*)0)); } while(0);; | ||||
183 | fail_unless_str_equal(base, "foo")do { _fail_unless(strcmp(base, "foo") == 0, "../path_utils/path_utils_ut.c" , 183, "Assertion '""strcmp(base, \"foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , base, "foo", ((void*)0)); } while(0);; | ||||
184 | |||||
185 | ret = get_directory_and_base_name(dir, PATH_MAX4096, base, PATH_MAX4096, ""); | ||||
186 | fail_unless(ret == SUCCESS)_fail_unless(ret == 0, "../path_utils/path_utils_ut.c", 186, "Assertion '" "ret == SUCCESS""' failed", ((void*)0)); | ||||
187 | fail_unless_str_equal(dir, cwd)do { _fail_unless(strcmp(dir, cwd) == 0, "../path_utils/path_utils_ut.c" , 187, "Assertion '""strcmp(dir, cwd) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , dir, cwd, ((void*)0)); } while(0);; | ||||
188 | fail_unless_str_equal(base, "")do { _fail_unless(strcmp(base, "") == 0, "../path_utils/path_utils_ut.c" , 188, "Assertion '""strcmp(base, \"\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , base, "", ((void*)0)); } while(0);; | ||||
189 | |||||
190 | ret = get_directory_and_base_name(dir, PATH_MAX4096, base, PATH_MAX4096, "."); | ||||
191 | fail_unless(ret == SUCCESS)_fail_unless(ret == 0, "../path_utils/path_utils_ut.c", 191, "Assertion '" "ret == SUCCESS""' failed", ((void*)0)); | ||||
192 | fail_unless_str_equal(dir, cwd)do { _fail_unless(strcmp(dir, cwd) == 0, "../path_utils/path_utils_ut.c" , 192, "Assertion '""strcmp(dir, cwd) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , dir, cwd, ((void*)0)); } while(0);; | ||||
193 | fail_unless_str_equal(base, "")do { _fail_unless(strcmp(base, "") == 0, "../path_utils/path_utils_ut.c" , 193, "Assertion '""strcmp(base, \"\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , base, "", ((void*)0)); } while(0);; | ||||
194 | } | ||||
195 | END_TEST} | ||||
196 | |||||
197 | START_TEST(test_dirname_and_basename_neg)static void test_dirname_and_basename_neg (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_dirname_and_basename_neg" , "../path_utils/path_utils_ut.c", 197); | ||||
198 | { | ||||
199 | char dir[PATH_MAX4096]; | ||||
200 | char base[PATH_MAX4096]; | ||||
201 | int ret; | ||||
202 | |||||
203 | ret = get_directory_and_base_name(dir, PATH_MAX4096, base, PATH_MAX4096, NULL((void*)0)); | ||||
204 | fail_unless(ret == EINVAL)_fail_unless(ret == 22, "../path_utils/path_utils_ut.c", 204, "Assertion '""ret == EINVAL""' failed", ((void*)0)); | ||||
205 | } | ||||
206 | END_TEST} | ||||
207 | |||||
208 | /**** path_concat ****/ | ||||
209 | START_TEST(test_path_concat)static void test_path_concat (int _i __attribute__ ((unused)) ){ tcase_fn_start ("""test_path_concat", "../path_utils/path_utils_ut.c" , 209); | ||||
210 | { | ||||
211 | char p[PATH_MAX4096]; | ||||
212 | char p2[9]; | ||||
213 | |||||
214 | fail_unless(path_concat(p, PATH_MAX, "/foo", "bar") == SUCCESS)_fail_unless(path_concat(p, 4096, "/foo", "bar") == 0, "../path_utils/path_utils_ut.c" , 214, "Assertion '""path_concat(p, PATH_MAX, \"/foo\", \"bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
215 | fail_unless_str_equal(p, "/foo/bar")do { _fail_unless(strcmp(p, "/foo/bar") == 0, "../path_utils/path_utils_ut.c" , 215, "Assertion '""strcmp(p, \"/foo/bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", p, "/foo/bar", ((void*)0)); } while(0);; | ||||
216 | |||||
217 | fail_unless(path_concat(p, PATH_MAX, "/foo", "/bar") == SUCCESS)_fail_unless(path_concat(p, 4096, "/foo", "/bar") == 0, "../path_utils/path_utils_ut.c" , 217, "Assertion '""path_concat(p, PATH_MAX, \"/foo\", \"/bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
218 | fail_unless_str_equal(p, "/foo/bar")do { _fail_unless(strcmp(p, "/foo/bar") == 0, "../path_utils/path_utils_ut.c" , 218, "Assertion '""strcmp(p, \"/foo/bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", p, "/foo/bar", ((void*)0)); } while(0);; | ||||
219 | |||||
220 | fail_unless(path_concat(p, PATH_MAX, "/foo/", "/bar") == SUCCESS)_fail_unless(path_concat(p, 4096, "/foo/", "/bar") == 0, "../path_utils/path_utils_ut.c" , 220, "Assertion '""path_concat(p, PATH_MAX, \"/foo/\", \"/bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
221 | fail_unless_str_equal(p, "/foo/bar")do { _fail_unless(strcmp(p, "/foo/bar") == 0, "../path_utils/path_utils_ut.c" , 221, "Assertion '""strcmp(p, \"/foo/bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", p, "/foo/bar", ((void*)0)); } while(0);; | ||||
222 | |||||
223 | fail_unless(path_concat(p, PATH_MAX, "/foo", "") == SUCCESS)_fail_unless(path_concat(p, 4096, "/foo", "") == 0, "../path_utils/path_utils_ut.c" , 223, "Assertion '""path_concat(p, PATH_MAX, \"/foo\", \"\") == SUCCESS" "' failed", ((void*)0)); | ||||
224 | fail_unless_str_equal(p, "/foo")do { _fail_unless(strcmp(p, "/foo") == 0, "../path_utils/path_utils_ut.c" , 224, "Assertion '""strcmp(p, \"/foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "/foo", ((void*)0)); } while(0);; | ||||
225 | |||||
226 | fail_unless(path_concat(p, PATH_MAX, "foo", NULL) == SUCCESS)_fail_unless(path_concat(p, 4096, "foo", ((void*)0)) == 0, "../path_utils/path_utils_ut.c" , 226, "Assertion '""path_concat(p, PATH_MAX, \"foo\", NULL) == SUCCESS" "' failed", ((void*)0)); | ||||
227 | fail_unless_str_equal(p, "foo")do { _fail_unless(strcmp(p, "foo") == 0, "../path_utils/path_utils_ut.c" , 227, "Assertion '""strcmp(p, \"foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "foo", ((void*)0)); } while(0);; | ||||
228 | |||||
229 | fail_unless(path_concat(p, PATH_MAX, "", "foo") == SUCCESS)_fail_unless(path_concat(p, 4096, "", "foo") == 0, "../path_utils/path_utils_ut.c" , 229, "Assertion '""path_concat(p, PATH_MAX, \"\", \"foo\") == SUCCESS" "' failed", ((void*)0)); | ||||
230 | fail_unless_str_equal(p, "foo")do { _fail_unless(strcmp(p, "foo") == 0, "../path_utils/path_utils_ut.c" , 230, "Assertion '""strcmp(p, \"foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "foo", ((void*)0)); } while(0);; | ||||
231 | |||||
232 | fail_unless(path_concat(p, PATH_MAX, "/", "foo") == SUCCESS)_fail_unless(path_concat(p, 4096, "/", "foo") == 0, "../path_utils/path_utils_ut.c" , 232, "Assertion '""path_concat(p, PATH_MAX, \"/\", \"foo\") == SUCCESS" "' failed", ((void*)0)); | ||||
233 | fail_unless_str_equal(p, "/foo")do { _fail_unless(strcmp(p, "/foo") == 0, "../path_utils/path_utils_ut.c" , 233, "Assertion '""strcmp(p, \"/foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "/foo", ((void*)0)); } while(0);; | ||||
234 | |||||
235 | fail_unless(path_concat(p, PATH_MAX, "/foo", "/") == SUCCESS)_fail_unless(path_concat(p, 4096, "/foo", "/") == 0, "../path_utils/path_utils_ut.c" , 235, "Assertion '""path_concat(p, PATH_MAX, \"/foo\", \"/\") == SUCCESS" "' failed", ((void*)0)); | ||||
236 | fail_unless_str_equal(p, "/foo/")do { _fail_unless(strcmp(p, "/foo/") == 0, "../path_utils/path_utils_ut.c" , 236, "Assertion '""strcmp(p, \"/foo/\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "/foo/", ((void*)0)); } while(0);; | ||||
237 | |||||
238 | fail_unless(path_concat(p, PATH_MAX, "/foo", "bar/") == SUCCESS)_fail_unless(path_concat(p, 4096, "/foo", "bar/") == 0, "../path_utils/path_utils_ut.c" , 238, "Assertion '""path_concat(p, PATH_MAX, \"/foo\", \"bar/\") == SUCCESS" "' failed", ((void*)0)); | ||||
239 | fail_unless_str_equal(p, "/foo/bar/")do { _fail_unless(strcmp(p, "/foo/bar/") == 0, "../path_utils/path_utils_ut.c" , 239, "Assertion '""strcmp(p, \"/foo/bar/\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", p , "/foo/bar/", ((void*)0)); } while(0);; | ||||
240 | |||||
241 | fail_unless(path_concat(p, PATH_MAX, NULL, "foo") == SUCCESS)_fail_unless(path_concat(p, 4096, ((void*)0), "foo") == 0, "../path_utils/path_utils_ut.c" , 241, "Assertion '""path_concat(p, PATH_MAX, NULL, \"foo\") == SUCCESS" "' failed", ((void*)0)); | ||||
242 | fail_unless_str_equal(p, "foo")do { _fail_unless(strcmp(p, "foo") == 0, "../path_utils/path_utils_ut.c" , 242, "Assertion '""strcmp(p, \"foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "foo", ((void*)0)); } while(0);; | ||||
243 | |||||
244 | /* on-by-one */ | ||||
245 | fail_unless(path_concat(p2, 9, "/foo", "bar") == SUCCESS)_fail_unless(path_concat(p2, 9, "/foo", "bar") == 0, "../path_utils/path_utils_ut.c" , 245, "Assertion '""path_concat(p2, 9, \"/foo\", \"bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
246 | fail_unless_str_equal(p2, "/foo/bar")do { _fail_unless(strcmp(p2, "/foo/bar") == 0, "../path_utils/path_utils_ut.c" , 246, "Assertion '""strcmp(p2, \"/foo/bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", p2 , "/foo/bar", ((void*)0)); } while(0);; | ||||
247 | } | ||||
248 | END_TEST} | ||||
249 | |||||
250 | START_TEST(test_path_concat_neg)static void test_path_concat_neg (int _i __attribute__ ((unused ))){ tcase_fn_start ("""test_path_concat_neg", "../path_utils/path_utils_ut.c" , 250); | ||||
251 | { | ||||
252 | char small[3]; | ||||
253 | char small2[5]; | ||||
254 | char small3[7]; | ||||
255 | char p2[10]; | ||||
256 | |||||
257 | /* these two test different conditions */ | ||||
258 | |||||
259 | /* Test if head is longer than the buffer */ | ||||
260 | fail_unless(path_concat(small, 3, "/foo", "bar") == ENOBUFS)_fail_unless(path_concat(small, 3, "/foo", "bar") == 105, "../path_utils/path_utils_ut.c" , 260, "Assertion '""path_concat(small, 3, \"/foo\", \"bar\") == ENOBUFS" "' failed", ((void*)0)); | ||||
261 | /* On ENOBUFS, path should be empty */ | ||||
262 | fail_unless_str_equal(small, "")do { _fail_unless(strcmp(small, "") == 0, "../path_utils/path_utils_ut.c" , 262, "Assertion '""strcmp(small, \"\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , small, "", ((void*)0)); } while(0);; | ||||
263 | |||||
264 | /* Test if head is the same length as the buffer */ | ||||
265 | fail_unless(path_concat(small2, 5, "/foo", "bar") == ENOBUFS)_fail_unless(path_concat(small2, 5, "/foo", "bar") == 105, "../path_utils/path_utils_ut.c" , 265, "Assertion '""path_concat(small2, 5, \"/foo\", \"bar\") == ENOBUFS" "' failed", ((void*)0)); | ||||
266 | /* On ENOBUFS, path should be empty */ | ||||
267 | fail_unless_str_equal(small2, "")do { _fail_unless(strcmp(small2, "") == 0, "../path_utils/path_utils_ut.c" , 267, "Assertion '""strcmp(small2, \"\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , small2, "", ((void*)0)); } while(0);; | ||||
268 | |||||
269 | /* Test if head+tail is the longer than the buffer */ | ||||
270 | fail_unless(path_concat(small3, 7, "/foo", "bar") == ENOBUFS)_fail_unless(path_concat(small3, 7, "/foo", "bar") == 105, "../path_utils/path_utils_ut.c" , 270, "Assertion '""path_concat(small3, 7, \"/foo\", \"bar\") == ENOBUFS" "' failed", ((void*)0)); | ||||
271 | /* On ENOBUFS, path should be empty */ | ||||
272 | fail_unless_str_equal(small3, "")do { _fail_unless(strcmp(small3, "") == 0, "../path_utils/path_utils_ut.c" , 272, "Assertion '""strcmp(small3, \"\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , small3, "", ((void*)0)); } while(0);; | ||||
273 | |||||
274 | /* off-by-one */ | ||||
275 | /* Fill with garbage data for now */ | ||||
276 | memset(p2, 'Z', 9); | ||||
277 | p2[9] = '\0'; | ||||
278 | |||||
279 | fail_unless(path_concat(p2, 8, "/foo", "bar") == ENOBUFS)_fail_unless(path_concat(p2, 8, "/foo", "bar") == 105, "../path_utils/path_utils_ut.c" , 279, "Assertion '""path_concat(p2, 8, \"/foo\", \"bar\") == ENOBUFS" "' failed", ((void*)0)); | ||||
280 | /* Make sure we don't write past the end of the buffer */ | ||||
281 | fail_unless(p2[8] == 'Z', "Got [%d]", p2[8])_fail_unless(p2[8] == 'Z', "../path_utils/path_utils_ut.c", 281 , "Assertion '""p2[8] == 'Z'""' failed" , "Got [%d]", p2[8], ( (void*)0)); | ||||
282 | /* On ENOBUFS, path should be empty */ | ||||
283 | fail_unless_str_equal(p2, "")do { _fail_unless(strcmp(p2, "") == 0, "../path_utils/path_utils_ut.c" , 283, "Assertion '""strcmp(p2, \"\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p2, "", ((void*)0)); } while(0);; | ||||
284 | } | ||||
285 | END_TEST} | ||||
286 | |||||
287 | /**** make_path_absolute ****/ | ||||
288 | START_TEST(test_make_path_absolute)static void test_make_path_absolute (int _i __attribute__ ((unused ))){ tcase_fn_start ("""test_make_path_absolute", "../path_utils/path_utils_ut.c" , 288); | ||||
289 | { | ||||
290 | char p[PATH_MAX4096]; | ||||
291 | char p2[PATH_MAX4096]; | ||||
292 | char cwd[PATH_MAX4096]; | ||||
293 | char *buf; | ||||
294 | size_t buf_len; | ||||
295 | |||||
296 | fail_unless(make_path_absolute(p, PATH_MAX, "/foo") == SUCCESS)_fail_unless(make_path_absolute(p, 4096, "/foo") == 0, "../path_utils/path_utils_ut.c" , 296, "Assertion '""make_path_absolute(p, PATH_MAX, \"/foo\") == SUCCESS" "' failed", ((void*)0)); | ||||
297 | fail_unless_str_equal(p, "/foo")do { _fail_unless(strcmp(p, "/foo") == 0, "../path_utils/path_utils_ut.c" , 297, "Assertion '""strcmp(p, \"/foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "/foo", ((void*)0)); } while(0);; | ||||
298 | |||||
299 | fail_if(getcwd(cwd, PATH_MAX) == NULL, "getcwd failed")_fail_unless(!(getcwd(cwd, 4096) == ((void*)0)), "../path_utils/path_utils_ut.c" , 299, "Failure '""getcwd(cwd, PATH_MAX) == NULL""' occured" , "getcwd failed", ((void*)0)); | ||||
300 | |||||
301 | fail_unless(make_path_absolute(p, PATH_MAX, "foo") == SUCCESS)_fail_unless(make_path_absolute(p, 4096, "foo") == 0, "../path_utils/path_utils_ut.c" , 301, "Assertion '""make_path_absolute(p, PATH_MAX, \"foo\") == SUCCESS" "' failed", ((void*)0)); | ||||
302 | snprintf(p2, PATH_MAX4096, "%s/foo", cwd); | ||||
303 | fail_unless_str_equal(p, p2)do { _fail_unless(strcmp(p, p2) == 0, "../path_utils/path_utils_ut.c" , 303, "Assertion '""strcmp(p, p2) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, p2, ((void*)0)); } while(0);; | ||||
304 | |||||
305 | fail_unless(make_path_absolute(p, PATH_MAX, "") == SUCCESS)_fail_unless(make_path_absolute(p, 4096, "") == 0, "../path_utils/path_utils_ut.c" , 305, "Assertion '""make_path_absolute(p, PATH_MAX, \"\") == SUCCESS" "' failed", ((void*)0)); | ||||
306 | fail_unless_str_equal(p, cwd)do { _fail_unless(strcmp(p, cwd) == 0, "../path_utils/path_utils_ut.c" , 306, "Assertion '""strcmp(p, cwd) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, cwd, ((void*)0)); } while(0);; | ||||
307 | |||||
308 | /* on-by-one; 2 = terminating null + path delimeter */ | ||||
309 | buf_len = strlen(cwd) + strlen("foo") + 2; | ||||
310 | buf = malloc(buf_len); | ||||
311 | fail_if(buf == NULL)_fail_unless(!(buf == ((void*)0)), "../path_utils/path_utils_ut.c" , 311, "Failure '""buf == NULL""' occured", ((void*)0)); | ||||
312 | fail_unless(make_path_absolute(buf, buf_len, "foo") == SUCCESS)_fail_unless(make_path_absolute(buf, buf_len, "foo") == 0, "../path_utils/path_utils_ut.c" , 312, "Assertion '""make_path_absolute(buf, buf_len, \"foo\") == SUCCESS" "' failed", ((void*)0)); | ||||
313 | free(buf); | ||||
314 | } | ||||
315 | END_TEST} | ||||
316 | |||||
317 | START_TEST(test_make_path_absolute_neg)static void test_make_path_absolute_neg (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_make_path_absolute_neg" , "../path_utils/path_utils_ut.c", 317); | ||||
318 | { | ||||
319 | char small[1]; | ||||
320 | char cwd[PATH_MAX4096]; | ||||
321 | char *small2; | ||||
322 | int small_len; | ||||
323 | |||||
324 | fail_unless(make_path_absolute(small, 1, "/foo") == ENOBUFS)_fail_unless(make_path_absolute(small, 1, "/foo") == 105, "../path_utils/path_utils_ut.c" , 324, "Assertion '""make_path_absolute(small, 1, \"/foo\") == ENOBUFS" "' failed", ((void*)0)); | ||||
325 | fail_unless(make_path_absolute(NULL, 1, "/foo") == ENOBUFS)_fail_unless(make_path_absolute(((void*)0), 1, "/foo") == 105 , "../path_utils/path_utils_ut.c", 325, "Assertion '""make_path_absolute(NULL, 1, \"/foo\") == ENOBUFS" "' failed", ((void*)0)); | ||||
326 | |||||
327 | /* off-by-one */ | ||||
328 | fail_if(getcwd(cwd, PATH_MAX) == NULL, "getcwd failed")_fail_unless(!(getcwd(cwd, 4096) == ((void*)0)), "../path_utils/path_utils_ut.c" , 328, "Failure '""getcwd(cwd, PATH_MAX) == NULL""' occured" , "getcwd failed", ((void*)0)); | ||||
329 | small_len = strlen(cwd) + strlen("foo") + 1; | ||||
330 | small2 = malloc(small_len); | ||||
331 | fail_if(small2 == NULL)_fail_unless(!(small2 == ((void*)0)), "../path_utils/path_utils_ut.c" , 331, "Failure '""small2 == NULL""' occured", ((void*)0)); | ||||
332 | fail_unless(make_path_absolute(small2, small_len, "foo") == ENOBUFS)_fail_unless(make_path_absolute(small2, small_len, "foo") == 105 , "../path_utils/path_utils_ut.c", 332, "Assertion '""make_path_absolute(small2, small_len, \"foo\") == ENOBUFS" "' failed", ((void*)0)); | ||||
333 | free(small2); | ||||
334 | |||||
335 | /* just enough space for cwd */ | ||||
336 | small_len = strlen(cwd) + 1; | ||||
337 | small2 = malloc(small_len); | ||||
338 | fail_if(small2 == NULL)_fail_unless(!(small2 == ((void*)0)), "../path_utils/path_utils_ut.c" , 338, "Failure '""small2 == NULL""' occured", ((void*)0)); | ||||
339 | fail_unless(make_path_absolute(small2, small_len, "foo") == ENOBUFS)_fail_unless(make_path_absolute(small2, small_len, "foo") == 105 , "../path_utils/path_utils_ut.c", 339, "Assertion '""make_path_absolute(small2, small_len, \"foo\") == ENOBUFS" "' failed", ((void*)0)); | ||||
340 | free(small2); | ||||
341 | } | ||||
342 | END_TEST} | ||||
343 | |||||
344 | /**** make_normalized_absolute_path ****/ | ||||
345 | START_TEST(test_make_normalized_absolute_path)static void test_make_normalized_absolute_path (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_make_normalized_absolute_path" , "../path_utils/path_utils_ut.c", 345); | ||||
346 | { | ||||
347 | char p[PATH_MAX4096]; | ||||
348 | char p2[PATH_MAX4096]; | ||||
349 | char cwd[PATH_MAX4096]; | ||||
350 | |||||
351 | fail_if(getcwd(cwd, PATH_MAX) == NULL, "getcwd failed")_fail_unless(!(getcwd(cwd, 4096) == ((void*)0)), "../path_utils/path_utils_ut.c" , 351, "Failure '""getcwd(cwd, PATH_MAX) == NULL""' occured" , "getcwd failed", ((void*)0)); | ||||
352 | |||||
353 | fail_unless(make_normalized_absolute_path(p, PATH_MAX, "foo/baz/../bar") == SUCCESS)_fail_unless(make_normalized_absolute_path(p, 4096, "foo/baz/../bar" ) == 0, "../path_utils/path_utils_ut.c", 353, "Assertion '""make_normalized_absolute_path(p, PATH_MAX, \"foo/baz/../bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
354 | snprintf(p2, PATH_MAX4096, "%s/foo/bar", cwd); | ||||
355 | fail_unless_str_equal(p, p2)do { _fail_unless(strcmp(p, p2) == 0, "../path_utils/path_utils_ut.c" , 355, "Assertion '""strcmp(p, p2) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, p2, ((void*)0)); } while(0);; | ||||
356 | |||||
357 | fail_unless(make_normalized_absolute_path(p, PATH_MAX, "/foo/../bar") == SUCCESS)_fail_unless(make_normalized_absolute_path(p, 4096, "/foo/../bar" ) == 0, "../path_utils/path_utils_ut.c", 357, "Assertion '""make_normalized_absolute_path(p, PATH_MAX, \"/foo/../bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
358 | fail_unless_str_equal(p, "/bar")do { _fail_unless(strcmp(p, "/bar") == 0, "../path_utils/path_utils_ut.c" , 358, "Assertion '""strcmp(p, \"/bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "/bar", ((void*)0)); } while(0);; | ||||
359 | |||||
360 | fail_unless(make_normalized_absolute_path(p, PATH_MAX, "/foo/../baz/../bar") == SUCCESS)_fail_unless(make_normalized_absolute_path(p, 4096, "/foo/../baz/../bar" ) == 0, "../path_utils/path_utils_ut.c", 360, "Assertion '""make_normalized_absolute_path(p, PATH_MAX, \"/foo/../baz/../bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
361 | fail_unless_str_equal(p, "/bar")do { _fail_unless(strcmp(p, "/bar") == 0, "../path_utils/path_utils_ut.c" , 361, "Assertion '""strcmp(p, \"/bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "/bar", ((void*)0)); } while(0);; | ||||
362 | } | ||||
363 | END_TEST} | ||||
364 | |||||
365 | START_TEST(test_make_normalized_absolute_path_neg)static void test_make_normalized_absolute_path_neg (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_make_normalized_absolute_path_neg" , "../path_utils/path_utils_ut.c", 365); | ||||
366 | { | ||||
367 | char small[1]; | ||||
368 | |||||
369 | fail_unless(make_path_absolute(small, 1, "/foo") == ENOBUFS)_fail_unless(make_path_absolute(small, 1, "/foo") == 105, "../path_utils/path_utils_ut.c" , 369, "Assertion '""make_path_absolute(small, 1, \"/foo\") == ENOBUFS" "' failed", ((void*)0)); | ||||
370 | fail_unless(make_path_absolute(NULL, 1, "/foo") == ENOBUFS)_fail_unless(make_path_absolute(((void*)0), 1, "/foo") == 105 , "../path_utils/path_utils_ut.c", 370, "Assertion '""make_path_absolute(NULL, 1, \"/foo\") == ENOBUFS" "' failed", ((void*)0)); | ||||
371 | } | ||||
372 | END_TEST} | ||||
373 | |||||
374 | /**** split_path ****/ | ||||
375 | START_TEST(test_split_path)static void test_split_path (int _i __attribute__ ((unused))) { tcase_fn_start ("""test_split_path", "../path_utils/path_utils_ut.c" , 375); | ||||
376 | { | ||||
377 | char **array; | ||||
378 | int n; | ||||
379 | |||||
380 | array = split_path("/foo/bar", &n); | ||||
381 | fail_if(array == NULL)_fail_unless(!(array == ((void*)0)), "../path_utils/path_utils_ut.c" , 381, "Failure '""array == NULL""' occured", ((void*)0)); | ||||
382 | fail_unless(n == 3)_fail_unless(n == 3, "../path_utils/path_utils_ut.c", 382, "Assertion '" "n == 3""' failed", ((void*)0)); | ||||
383 | fail_unless_str_equal(array[0], "/")do { _fail_unless(strcmp(array[0], "/") == 0, "../path_utils/path_utils_ut.c" , 383, "Assertion '""strcmp(array[0], \"/\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", array [0], "/", ((void*)0)); } while(0);; | ||||
384 | fail_unless_str_equal(array[1], "foo")do { _fail_unless(strcmp(array[1], "foo") == 0, "../path_utils/path_utils_ut.c" , 384, "Assertion '""strcmp(array[1], \"foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", array [1], "foo", ((void*)0)); } while(0);; | ||||
385 | fail_unless_str_equal(array[2], "bar")do { _fail_unless(strcmp(array[2], "bar") == 0, "../path_utils/path_utils_ut.c" , 385, "Assertion '""strcmp(array[2], \"bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", array [2], "bar", ((void*)0)); } while(0);; | ||||
386 | free(array); | ||||
387 | |||||
388 | array = split_path("/foo/../bar", &n); | ||||
389 | fail_if(array == NULL)_fail_unless(!(array == ((void*)0)), "../path_utils/path_utils_ut.c" , 389, "Failure '""array == NULL""' occured", ((void*)0)); | ||||
390 | fail_unless(n == 4)_fail_unless(n == 4, "../path_utils/path_utils_ut.c", 390, "Assertion '" "n == 4""' failed", ((void*)0)); | ||||
391 | fail_unless_str_equal(array[0], "/")do { _fail_unless(strcmp(array[0], "/") == 0, "../path_utils/path_utils_ut.c" , 391, "Assertion '""strcmp(array[0], \"/\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", array [0], "/", ((void*)0)); } while(0);; | ||||
392 | fail_unless_str_equal(array[1], "foo")do { _fail_unless(strcmp(array[1], "foo") == 0, "../path_utils/path_utils_ut.c" , 392, "Assertion '""strcmp(array[1], \"foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", array [1], "foo", ((void*)0)); } while(0);; | ||||
393 | fail_unless_str_equal(array[2], "..")do { _fail_unless(strcmp(array[2], "..") == 0, "../path_utils/path_utils_ut.c" , 393, "Assertion '""strcmp(array[2], \"..\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", array [2], "..", ((void*)0)); } while(0);; | ||||
394 | fail_unless_str_equal(array[3], "bar")do { _fail_unless(strcmp(array[3], "bar") == 0, "../path_utils/path_utils_ut.c" , 394, "Assertion '""strcmp(array[3], \"bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", array [3], "bar", ((void*)0)); } while(0);; | ||||
395 | free(array); | ||||
396 | |||||
397 | array = split_path("/foo/bar", NULL((void*)0)); | ||||
398 | fail_if(array == NULL)_fail_unless(!(array == ((void*)0)), "../path_utils/path_utils_ut.c" , 398, "Failure '""array == NULL""' occured", ((void*)0)); | ||||
399 | fail_unless_str_equal(array[0], "/")do { _fail_unless(strcmp(array[0], "/") == 0, "../path_utils/path_utils_ut.c" , 399, "Assertion '""strcmp(array[0], \"/\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", array [0], "/", ((void*)0)); } while(0);; | ||||
400 | fail_unless_str_equal(array[1], "foo")do { _fail_unless(strcmp(array[1], "foo") == 0, "../path_utils/path_utils_ut.c" , 400, "Assertion '""strcmp(array[1], \"foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", array [1], "foo", ((void*)0)); } while(0);; | ||||
401 | fail_unless_str_equal(array[2], "bar")do { _fail_unless(strcmp(array[2], "bar") == 0, "../path_utils/path_utils_ut.c" , 401, "Assertion '""strcmp(array[2], \"bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", array [2], "bar", ((void*)0)); } while(0);; | ||||
402 | free(array); | ||||
403 | |||||
404 | array = split_path("foo/bar", &n); | ||||
405 | fail_if(array == NULL)_fail_unless(!(array == ((void*)0)), "../path_utils/path_utils_ut.c" , 405, "Failure '""array == NULL""' occured", ((void*)0)); | ||||
| |||||
406 | fail_unless(n == 2)_fail_unless(n == 2, "../path_utils/path_utils_ut.c", 406, "Assertion '" "n == 2""' failed", ((void*)0)); | ||||
407 | fail_unless_str_equal(array[0], "foo")do { _fail_unless(strcmp(array[0], "foo") == 0, "../path_utils/path_utils_ut.c" , 407, "Assertion '""strcmp(array[0], \"foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", array [0], "foo", ((void*)0)); } while(0);; | ||||
| |||||
408 | fail_unless_str_equal(array[1], "bar")do { _fail_unless(strcmp(array[1], "bar") == 0, "../path_utils/path_utils_ut.c" , 408, "Assertion '""strcmp(array[1], \"bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", array [1], "bar", ((void*)0)); } while(0);; | ||||
409 | free(array); | ||||
410 | |||||
411 | array = split_path(".", &n); | ||||
412 | fail_if(array == NULL)_fail_unless(!(array == ((void*)0)), "../path_utils/path_utils_ut.c" , 412, "Failure '""array == NULL""' occured", ((void*)0)); | ||||
413 | fail_unless(n == 1)_fail_unless(n == 1, "../path_utils/path_utils_ut.c", 413, "Assertion '" "n == 1""' failed", ((void*)0)); | ||||
414 | fail_unless_str_equal(array[0], ".")do { _fail_unless(strcmp(array[0], ".") == 0, "../path_utils/path_utils_ut.c" , 414, "Assertion '""strcmp(array[0], \".\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", array [0], ".", ((void*)0)); } while(0);; | ||||
415 | free(array); | ||||
416 | |||||
417 | array = split_path("foo", &n); | ||||
418 | fail_if(array == NULL)_fail_unless(!(array == ((void*)0)), "../path_utils/path_utils_ut.c" , 418, "Failure '""array == NULL""' occured", ((void*)0)); | ||||
419 | fail_unless(n == 1)_fail_unless(n == 1, "../path_utils/path_utils_ut.c", 419, "Assertion '" "n == 1""' failed", ((void*)0)); | ||||
420 | fail_unless_str_equal(array[0], "foo")do { _fail_unless(strcmp(array[0], "foo") == 0, "../path_utils/path_utils_ut.c" , 420, "Assertion '""strcmp(array[0], \"foo\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", array [0], "foo", ((void*)0)); } while(0);; | ||||
421 | free(array); | ||||
422 | |||||
423 | /* one might expect { "" } or outright NULL, but we agreed not to | ||||
424 | * do changes beyond bugfixes at this point */ | ||||
425 | array = split_path("", &n); | ||||
426 | fail_if(array == NULL)_fail_unless(!(array == ((void*)0)), "../path_utils/path_utils_ut.c" , 426, "Failure '""array == NULL""' occured", ((void*)0)); | ||||
427 | fail_unless(n == 0)_fail_unless(n == 0, "../path_utils/path_utils_ut.c", 427, "Assertion '" "n == 0""' failed", ((void*)0)); | ||||
428 | fail_unless(array[0] == NULL)_fail_unless(array[0] == ((void*)0), "../path_utils/path_utils_ut.c" , 428, "Assertion '""array[0] == NULL""' failed", ((void*)0)); | ||||
429 | free(array); | ||||
430 | } | ||||
431 | END_TEST} | ||||
432 | |||||
433 | START_TEST(test_split_path_neg)static void test_split_path_neg (int _i __attribute__ ((unused ))){ tcase_fn_start ("""test_split_path_neg", "../path_utils/path_utils_ut.c" , 433); | ||||
434 | { | ||||
435 | char **array; | ||||
436 | int n; | ||||
437 | |||||
438 | array = split_path(NULL((void*)0), &n); | ||||
439 | fail_unless(array == NULL)_fail_unless(array == ((void*)0), "../path_utils/path_utils_ut.c" , 439, "Assertion '""array == NULL""' failed", ((void*)0)); | ||||
440 | |||||
441 | array = split_path(NULL((void*)0), NULL((void*)0)); | ||||
442 | fail_unless(array == NULL)_fail_unless(array == ((void*)0), "../path_utils/path_utils_ut.c" , 442, "Assertion '""array == NULL""' failed", ((void*)0)); | ||||
443 | } | ||||
444 | END_TEST} | ||||
445 | |||||
446 | /**** normalize_path ****/ | ||||
447 | START_TEST(test_normalize_path)static void test_normalize_path (int _i __attribute__ ((unused ))){ tcase_fn_start ("""test_normalize_path", "../path_utils/path_utils_ut.c" , 447); | ||||
448 | { | ||||
449 | char norm[PATH_MAX4096]; | ||||
450 | char small[8]; | ||||
451 | |||||
452 | fail_unless(normalize_path(norm, PATH_MAX, "/foo/../bar") == SUCCESS)_fail_unless(normalize_path(norm, 4096, "/foo/../bar") == 0, "../path_utils/path_utils_ut.c" , 452, "Assertion '""normalize_path(norm, PATH_MAX, \"/foo/../bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
453 | fail_unless_str_equal(norm, "/bar")do { _fail_unless(strcmp(norm, "/bar") == 0, "../path_utils/path_utils_ut.c" , 453, "Assertion '""strcmp(norm, \"/bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", norm , "/bar", ((void*)0)); } while(0);; | ||||
454 | |||||
455 | fail_unless(normalize_path(norm, PATH_MAX, "/foo/../baz/../bar") == SUCCESS)_fail_unless(normalize_path(norm, 4096, "/foo/../baz/../bar") == 0, "../path_utils/path_utils_ut.c", 455, "Assertion '""normalize_path(norm, PATH_MAX, \"/foo/../baz/../bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
456 | fail_unless_str_equal(norm, "/bar")do { _fail_unless(strcmp(norm, "/bar") == 0, "../path_utils/path_utils_ut.c" , 456, "Assertion '""strcmp(norm, \"/bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", norm , "/bar", ((void*)0)); } while(0);; | ||||
457 | |||||
458 | fail_unless(normalize_path(norm, PATH_MAX, "foo/baz/../bar") == SUCCESS)_fail_unless(normalize_path(norm, 4096, "foo/baz/../bar") == 0 , "../path_utils/path_utils_ut.c", 458, "Assertion '""normalize_path(norm, PATH_MAX, \"foo/baz/../bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
459 | fail_unless_str_equal(norm, "foo/bar")do { _fail_unless(strcmp(norm, "foo/bar") == 0, "../path_utils/path_utils_ut.c" , 459, "Assertion '""strcmp(norm, \"foo/bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", norm , "foo/bar", ((void*)0)); } while(0);; | ||||
460 | |||||
461 | fail_unless(normalize_path(norm, PATH_MAX, "/foo/./bar") == SUCCESS)_fail_unless(normalize_path(norm, 4096, "/foo/./bar") == 0, "../path_utils/path_utils_ut.c" , 461, "Assertion '""normalize_path(norm, PATH_MAX, \"/foo/./bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
462 | fail_unless_str_equal(norm, "/foo/bar")do { _fail_unless(strcmp(norm, "/foo/bar") == 0, "../path_utils/path_utils_ut.c" , 462, "Assertion '""strcmp(norm, \"/foo/bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", norm , "/foo/bar", ((void*)0)); } while(0);; | ||||
463 | |||||
464 | fail_unless(normalize_path(norm, PATH_MAX, "/foo//bar") == SUCCESS)_fail_unless(normalize_path(norm, 4096, "/foo//bar") == 0, "../path_utils/path_utils_ut.c" , 464, "Assertion '""normalize_path(norm, PATH_MAX, \"/foo//bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
465 | fail_unless_str_equal(norm, "/foo/bar")do { _fail_unless(strcmp(norm, "/foo/bar") == 0, "../path_utils/path_utils_ut.c" , 465, "Assertion '""strcmp(norm, \"/foo/bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", norm , "/foo/bar", ((void*)0)); } while(0);; | ||||
466 | |||||
467 | fail_unless(normalize_path(norm, PATH_MAX, "/foo//bar") == SUCCESS)_fail_unless(normalize_path(norm, 4096, "/foo//bar") == 0, "../path_utils/path_utils_ut.c" , 467, "Assertion '""normalize_path(norm, PATH_MAX, \"/foo//bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
468 | fail_unless_str_equal(norm, "/foo/bar")do { _fail_unless(strcmp(norm, "/foo/bar") == 0, "../path_utils/path_utils_ut.c" , 468, "Assertion '""strcmp(norm, \"/foo/bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", norm , "/foo/bar", ((void*)0)); } while(0);; | ||||
469 | |||||
470 | fail_unless(normalize_path(norm, PATH_MAX, "") == SUCCESS)_fail_unless(normalize_path(norm, 4096, "") == 0, "../path_utils/path_utils_ut.c" , 470, "Assertion '""normalize_path(norm, PATH_MAX, \"\") == SUCCESS" "' failed", ((void*)0)); | ||||
471 | fail_unless_str_equal(norm, ".")do { _fail_unless(strcmp(norm, ".") == 0, "../path_utils/path_utils_ut.c" , 471, "Assertion '""strcmp(norm, \".\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , norm, ".", ((void*)0)); } while(0);; | ||||
472 | |||||
473 | fail_unless(normalize_path(norm, PATH_MAX, "/../..") == SUCCESS)_fail_unless(normalize_path(norm, 4096, "/../..") == 0, "../path_utils/path_utils_ut.c" , 473, "Assertion '""normalize_path(norm, PATH_MAX, \"/../..\") == SUCCESS" "' failed", ((void*)0)); | ||||
474 | fail_unless_str_equal(norm, "/")do { _fail_unless(strcmp(norm, "/") == 0, "../path_utils/path_utils_ut.c" , 474, "Assertion '""strcmp(norm, \"/\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , norm, "/", ((void*)0)); } while(0);; | ||||
475 | |||||
476 | /* on-by-one */ | ||||
477 | fail_unless(normalize_path(small, 8, "foo/baz/../bar") == SUCCESS)_fail_unless(normalize_path(small, 8, "foo/baz/../bar") == 0, "../path_utils/path_utils_ut.c", 477, "Assertion '""normalize_path(small, 8, \"foo/baz/../bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
478 | fail_unless_str_equal(small, "foo/bar")do { _fail_unless(strcmp(small, "foo/bar") == 0, "../path_utils/path_utils_ut.c" , 478, "Assertion '""strcmp(small, \"foo/bar\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", small , "foo/bar", ((void*)0)); } while(0);; | ||||
479 | } | ||||
480 | END_TEST} | ||||
481 | |||||
482 | START_TEST(test_normalize_path_neg)static void test_normalize_path_neg (int _i __attribute__ ((unused ))){ tcase_fn_start ("""test_normalize_path_neg", "../path_utils/path_utils_ut.c" , 482); | ||||
483 | { | ||||
484 | char norm[PATH_MAX4096]; | ||||
485 | char small[4]; | ||||
486 | |||||
487 | fail_unless(normalize_path(norm, PATH_MAX, "foo/../..") == PATH_UTILS_ERROR_NOT_FULLY_NORMALIZED)_fail_unless(normalize_path(norm, 4096, "foo/../..") == (-3000 + 1), "../path_utils/path_utils_ut.c", 487, "Assertion '""normalize_path(norm, PATH_MAX, \"foo/../..\") == PATH_UTILS_ERROR_NOT_FULLY_NORMALIZED" "' failed", ((void*)0)); | ||||
488 | |||||
489 | /* with a buffer of 4 chars, this would test off-by-one error */ | ||||
490 | fail_unless(normalize_path(small, 4, "/foo/../bar") == ENOBUFS)_fail_unless(normalize_path(small, 4, "/foo/../bar") == 105, "../path_utils/path_utils_ut.c" , 490, "Assertion '""normalize_path(small, 4, \"/foo/../bar\") == ENOBUFS" "' failed", ((void*)0)); | ||||
491 | } | ||||
492 | END_TEST} | ||||
493 | |||||
494 | /**** common_path_prefix ****/ | ||||
495 | START_TEST(test_common_path_prefix)static void test_common_path_prefix (int _i __attribute__ ((unused ))){ tcase_fn_start ("""test_common_path_prefix", "../path_utils/path_utils_ut.c" , 495); | ||||
496 | { | ||||
497 | char common[PATH_MAX4096]; | ||||
498 | char small[5]; | ||||
499 | int count; | ||||
500 | |||||
501 | fail_unless(common_path_prefix(common, PATH_MAX, &count, "/usr/lib", "/usr/share") == SUCCESS)_fail_unless(common_path_prefix(common, 4096, &count, "/usr/lib" , "/usr/share") == 0, "../path_utils/path_utils_ut.c", 501, "Assertion '" "common_path_prefix(common, PATH_MAX, &count, \"/usr/lib\", \"/usr/share\") == SUCCESS" "' failed", ((void*)0)); | ||||
502 | fail_unless_str_equal(common, "/usr")do { _fail_unless(strcmp(common, "/usr") == 0, "../path_utils/path_utils_ut.c" , 502, "Assertion '""strcmp(common, \"/usr\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", common , "/usr", ((void*)0)); } while(0);; | ||||
503 | fail_unless(count == 2)_fail_unless(count == 2, "../path_utils/path_utils_ut.c", 503 , "Assertion '""count == 2""' failed", ((void*)0)); | ||||
504 | |||||
505 | fail_unless(common_path_prefix(common, PATH_MAX, NULL, "/usr/lib", "/usr/share") == SUCCESS)_fail_unless(common_path_prefix(common, 4096, ((void*)0), "/usr/lib" , "/usr/share") == 0, "../path_utils/path_utils_ut.c", 505, "Assertion '" "common_path_prefix(common, PATH_MAX, NULL, \"/usr/lib\", \"/usr/share\") == SUCCESS" "' failed", ((void*)0)); | ||||
506 | fail_unless_str_equal(common, "/usr")do { _fail_unless(strcmp(common, "/usr") == 0, "../path_utils/path_utils_ut.c" , 506, "Assertion '""strcmp(common, \"/usr\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", common , "/usr", ((void*)0)); } while(0);; | ||||
507 | |||||
508 | fail_unless(common_path_prefix(common, PATH_MAX, &count, "/usr/lib", "/usr/lab") == SUCCESS)_fail_unless(common_path_prefix(common, 4096, &count, "/usr/lib" , "/usr/lab") == 0, "../path_utils/path_utils_ut.c", 508, "Assertion '" "common_path_prefix(common, PATH_MAX, &count, \"/usr/lib\", \"/usr/lab\") == SUCCESS" "' failed", ((void*)0)); | ||||
509 | fail_unless_str_equal(common, "/usr")do { _fail_unless(strcmp(common, "/usr") == 0, "../path_utils/path_utils_ut.c" , 509, "Assertion '""strcmp(common, \"/usr\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", common , "/usr", ((void*)0)); } while(0);; | ||||
510 | fail_unless(count == 2)_fail_unless(count == 2, "../path_utils/path_utils_ut.c", 510 , "Assertion '""count == 2""' failed", ((void*)0)); | ||||
511 | |||||
512 | fail_unless(common_path_prefix(common, PATH_MAX, &count, "foo", "bar") == SUCCESS)_fail_unless(common_path_prefix(common, 4096, &count, "foo" , "bar") == 0, "../path_utils/path_utils_ut.c", 512, "Assertion '" "common_path_prefix(common, PATH_MAX, &count, \"foo\", \"bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
513 | fail_unless_str_equal(common, "")do { _fail_unless(strcmp(common, "") == 0, "../path_utils/path_utils_ut.c" , 513, "Assertion '""strcmp(common, \"\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , common, "", ((void*)0)); } while(0);; | ||||
514 | fail_unless(count == 0)_fail_unless(count == 0, "../path_utils/path_utils_ut.c", 514 , "Assertion '""count == 0""' failed", ((void*)0)); | ||||
515 | |||||
516 | fail_unless(common_path_prefix(common, PATH_MAX, &count, "/", "/") == SUCCESS)_fail_unless(common_path_prefix(common, 4096, &count, "/" , "/") == 0, "../path_utils/path_utils_ut.c", 516, "Assertion '" "common_path_prefix(common, PATH_MAX, &count, \"/\", \"/\") == SUCCESS" "' failed", ((void*)0)); | ||||
517 | fail_unless_str_equal(common, "/")do { _fail_unless(strcmp(common, "/") == 0, "../path_utils/path_utils_ut.c" , 517, "Assertion '""strcmp(common, \"/\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , common, "/", ((void*)0)); } while(0);; | ||||
518 | fail_unless(count == 1)_fail_unless(count == 1, "../path_utils/path_utils_ut.c", 518 , "Assertion '""count == 1""' failed", ((void*)0)); | ||||
519 | |||||
520 | fail_unless(common_path_prefix(common, PATH_MAX, &count, NULL, "/usr/share") == SUCCESS)_fail_unless(common_path_prefix(common, 4096, &count, ((void *)0), "/usr/share") == 0, "../path_utils/path_utils_ut.c", 520 , "Assertion '""common_path_prefix(common, PATH_MAX, &count, NULL, \"/usr/share\") == SUCCESS" "' failed", ((void*)0)); | ||||
521 | fail_unless_str_equal(common, "")do { _fail_unless(strcmp(common, "") == 0, "../path_utils/path_utils_ut.c" , 521, "Assertion '""strcmp(common, \"\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , common, "", ((void*)0)); } while(0);; | ||||
522 | fail_unless(count == 0)_fail_unless(count == 0, "../path_utils/path_utils_ut.c", 522 , "Assertion '""count == 0""' failed", ((void*)0)); | ||||
523 | |||||
524 | /* on-by-one */ | ||||
525 | fail_unless(common_path_prefix(small, 5, NULL, "/usr/lib", "/usr/share") == SUCCESS)_fail_unless(common_path_prefix(small, 5, ((void*)0), "/usr/lib" , "/usr/share") == 0, "../path_utils/path_utils_ut.c", 525, "Assertion '" "common_path_prefix(small, 5, NULL, \"/usr/lib\", \"/usr/share\") == SUCCESS" "' failed", ((void*)0)); | ||||
526 | fail_unless_str_equal(small, "/usr")do { _fail_unless(strcmp(small, "/usr") == 0, "../path_utils/path_utils_ut.c" , 526, "Assertion '""strcmp(small, \"/usr\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same", small , "/usr", ((void*)0)); } while(0);; | ||||
527 | } | ||||
528 | END_TEST} | ||||
529 | |||||
530 | START_TEST(test_common_path_prefix_neg)static void test_common_path_prefix_neg (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_common_path_prefix_neg" , "../path_utils/path_utils_ut.c", 530); | ||||
531 | { | ||||
532 | char small[1]; | ||||
533 | char small2[4]; | ||||
534 | int count; | ||||
535 | |||||
536 | fail_unless(common_path_prefix(small, 1, &count, "/usr/lib", "/usr/share") == ENOBUFS)_fail_unless(common_path_prefix(small, 1, &count, "/usr/lib" , "/usr/share") == 105, "../path_utils/path_utils_ut.c", 536, "Assertion '""common_path_prefix(small, 1, &count, \"/usr/lib\", \"/usr/share\") == ENOBUFS" "' failed", ((void*)0)); | ||||
537 | fail_unless(common_path_prefix(NULL, PATH_MAX, &count, "/usr/lib", "/usr/share") == ENOBUFS)_fail_unless(common_path_prefix(((void*)0), 4096, &count, "/usr/lib", "/usr/share") == 105, "../path_utils/path_utils_ut.c" , 537, "Assertion '""common_path_prefix(NULL, PATH_MAX, &count, \"/usr/lib\", \"/usr/share\") == ENOBUFS" "' failed", ((void*)0)); | ||||
538 | /* off-by-one */ | ||||
539 | fail_unless(common_path_prefix(small2, 4, NULL, "/usr/lib", "/usr/share") == ENOBUFS)_fail_unless(common_path_prefix(small2, 4, ((void*)0), "/usr/lib" , "/usr/share") == 105, "../path_utils/path_utils_ut.c", 539, "Assertion '""common_path_prefix(small2, 4, NULL, \"/usr/lib\", \"/usr/share\") == ENOBUFS" "' failed", ((void*)0)); | ||||
540 | } | ||||
541 | END_TEST} | ||||
542 | |||||
543 | /**** find_existing_directory_ancestor ****/ | ||||
544 | START_TEST(test_find_existing_directory_ancestor)static void test_find_existing_directory_ancestor (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_find_existing_directory_ancestor" , "../path_utils/path_utils_ut.c", 544); | ||||
545 | { | ||||
546 | char p[PATH_MAX4096]; | ||||
547 | char cwd[PATH_MAX4096]; | ||||
548 | |||||
549 | fail_unless(find_existing_directory_ancestor(p, PATH_MAX, "/etc/passwd") == SUCCESS)_fail_unless(find_existing_directory_ancestor(p, 4096, "/etc/passwd" ) == 0, "../path_utils/path_utils_ut.c", 549, "Assertion '""find_existing_directory_ancestor(p, PATH_MAX, \"/etc/passwd\") == SUCCESS" "' failed", ((void*)0)); | ||||
550 | fail_unless_str_equal(p, "/etc")do { _fail_unless(strcmp(p, "/etc") == 0, "../path_utils/path_utils_ut.c" , 550, "Assertion '""strcmp(p, \"/etc\") == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, "/etc", ((void*)0)); } while(0);; | ||||
551 | |||||
552 | /* if pathname does not contain a slash, the parent is cwd */ | ||||
553 | fail_if(getcwd(cwd, PATH_MAX) == NULL, "getcwd failed")_fail_unless(!(getcwd(cwd, 4096) == ((void*)0)), "../path_utils/path_utils_ut.c" , 553, "Failure '""getcwd(cwd, PATH_MAX) == NULL""' occured" , "getcwd failed", ((void*)0)); | ||||
554 | |||||
555 | fail_unless(find_existing_directory_ancestor(p, PATH_MAX, "foo/bar") == SUCCESS)_fail_unless(find_existing_directory_ancestor(p, 4096, "foo/bar" ) == 0, "../path_utils/path_utils_ut.c", 555, "Assertion '""find_existing_directory_ancestor(p, PATH_MAX, \"foo/bar\") == SUCCESS" "' failed", ((void*)0)); | ||||
556 | fail_unless_str_equal(p, cwd)do { _fail_unless(strcmp(p, cwd) == 0, "../path_utils/path_utils_ut.c" , 556, "Assertion '""strcmp(p, cwd) == 0""' failed" , "The strings '%s' and '%s' are different, expected same" , p, cwd, ((void*)0)); } while(0);; | ||||
557 | } | ||||
558 | END_TEST} | ||||
559 | |||||
560 | START_TEST(test_find_existing_directory_ancestor_neg)static void test_find_existing_directory_ancestor_neg (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_find_existing_directory_ancestor_neg" , "../path_utils/path_utils_ut.c", 560); | ||||
561 | { | ||||
562 | char small[4]; | ||||
563 | fail_unless(find_existing_directory_ancestor(small, 4, "/etc/passwd") == ENOBUFS)_fail_unless(find_existing_directory_ancestor(small, 4, "/etc/passwd" ) == 105, "../path_utils/path_utils_ut.c", 563, "Assertion '" "find_existing_directory_ancestor(small, 4, \"/etc/passwd\") == ENOBUFS" "' failed", ((void*)0)); | ||||
564 | fail_unless(find_existing_directory_ancestor(NULL, 4, "/etc/passwd") == ENOBUFS)_fail_unless(find_existing_directory_ancestor(((void*)0), 4, "/etc/passwd" ) == 105, "../path_utils/path_utils_ut.c", 564, "Assertion '" "find_existing_directory_ancestor(NULL, 4, \"/etc/passwd\") == ENOBUFS" "' failed", ((void*)0)); | ||||
565 | } | ||||
566 | END_TEST} | ||||
567 | |||||
568 | /**** directory_list ****/ | ||||
569 | void setup_directory_list(void) | ||||
570 | { | ||||
571 | char *s = NULL((void*)0); | ||||
572 | int ret; | ||||
573 | |||||
574 | s = strdup(DIR_TEMPLATE"test-directory-list-dir-XXXXXX"); | ||||
575 | fail_unless(s != NULL, "strdup failed\n")_fail_unless(s != ((void*)0), "../path_utils/path_utils_ut.c" , 575, "Assertion '""s != NULL""' failed" , "strdup failed\n" , ((void*)0)); | ||||
576 | dlist_dir = mkdtemp(s); | ||||
577 | fail_unless(dlist_dir != NULL, "mkstemp failed [%d][%s]", errno, strerror(errno))_fail_unless(dlist_dir != ((void*)0), "../path_utils/path_utils_ut.c" , 577, "Assertion '""dlist_dir != NULL""' failed" , "mkstemp failed [%d][%s]" , (*__errno_location ()), strerror((*__errno_location ())), ( (void*)0)); | ||||
578 | |||||
579 | ret = asprintf(&dlist_subdir, "%s/%s", dlist_dir, SUBDIR"test-directory-list-subdir"); | ||||
580 | fail_unless(ret != 1, "strdup failed\n")_fail_unless(ret != 1, "../path_utils/path_utils_ut.c", 580, "Assertion '" "ret != 1""' failed" , "strdup failed\n", ((void*)0)); | ||||
581 | ret = mkdir(dlist_subdir, 0700); | ||||
582 | fail_unless(ret != -1, "mkdir %s failed [%d][%s]", dlist_subdir, errno, strerror(errno))_fail_unless(ret != -1, "../path_utils/path_utils_ut.c", 582, "Assertion '""ret != -1""' failed" , "mkdir %s failed [%d][%s]" , dlist_subdir, (*__errno_location ()), strerror((*__errno_location ())), ((void*)0)); | ||||
583 | |||||
584 | ret = asprintf(&dlist_subsubdir, "%s/%s", dlist_subdir, SUBSUBDIR"test-directory-list-subsubdir"); | ||||
585 | fail_unless(ret != 1, "strdup failed\n")_fail_unless(ret != 1, "../path_utils/path_utils_ut.c", 585, "Assertion '" "ret != 1""' failed" , "strdup failed\n", ((void*)0)); | ||||
586 | ret = mkdir(dlist_subsubdir, 0700); | ||||
587 | fail_unless(ret != -1, "mkdir %s failed [%d][%s]", dlist_subsubdir, errno, strerror(errno))_fail_unless(ret != -1, "../path_utils/path_utils_ut.c", 587, "Assertion '""ret != -1""' failed" , "mkdir %s failed [%d][%s]" , dlist_subsubdir, (*__errno_location ()), strerror((*__errno_location ())), ((void*)0)); | ||||
588 | } | ||||
589 | |||||
590 | void teardown_directory_list(void) | ||||
591 | { | ||||
592 | int ret; | ||||
593 | |||||
594 | if (dlist_subsubdir) { | ||||
595 | ret = rmdir(dlist_subsubdir); | ||||
596 | fail_unless(ret != -1, "unlink %s failed [%d][%s]", dlist_subsubdir, errno, strerror(errno))_fail_unless(ret != -1, "../path_utils/path_utils_ut.c", 596, "Assertion '""ret != -1""' failed" , "unlink %s failed [%d][%s]" , dlist_subsubdir, (*__errno_location ()), strerror((*__errno_location ())), ((void*)0)); | ||||
597 | free(dlist_subsubdir); | ||||
598 | dlist_subsubdir = NULL((void*)0); | ||||
599 | } | ||||
600 | |||||
601 | if (dlist_subdir) { | ||||
602 | ret = rmdir(dlist_subdir); | ||||
603 | fail_unless(ret != -1, "unlink %s failed [%d][%s]", dlist_subdir, errno, strerror(errno))_fail_unless(ret != -1, "../path_utils/path_utils_ut.c", 603, "Assertion '""ret != -1""' failed" , "unlink %s failed [%d][%s]" , dlist_subdir, (*__errno_location ()), strerror((*__errno_location ())), ((void*)0)); | ||||
604 | free(dlist_subdir); | ||||
605 | dlist_subdir = NULL((void*)0); | ||||
606 | } | ||||
607 | |||||
608 | if (dlist_dir) { | ||||
609 | ret = rmdir(dlist_dir); | ||||
610 | fail_unless(ret != -1, "unlink %s failed [%d][%s]", dlist_dir, errno, strerror(errno))_fail_unless(ret != -1, "../path_utils/path_utils_ut.c", 610, "Assertion '""ret != -1""' failed" , "unlink %s failed [%d][%s]" , dlist_dir, (*__errno_location ()), strerror((*__errno_location ())), ((void*)0)); | ||||
611 | free(dlist_dir); | ||||
612 | dlist_dir = NULL((void*)0); | ||||
613 | } | ||||
614 | } | ||||
615 | |||||
616 | bool_Bool dirlist_cb_nonrecursive(const char *directory, const char *base_name, | ||||
617 | const char *path, struct stat *info, | ||||
618 | void *user_data) | ||||
619 | { | ||||
620 | int *data = (int *) user_data; | ||||
621 | |||||
622 | fail_unless_str_equal(path, dlist_subdir)do { _fail_unless(strcmp(path, dlist_subdir) == 0, "../path_utils/path_utils_ut.c" , 622, "Assertion '""strcmp(path, dlist_subdir) == 0""' failed" , "The strings '%s' and '%s' are different, expected same", path , dlist_subdir, ((void*)0)); } while(0);; | ||||
623 | fail_unless(*data == 123)_fail_unless(*data == 123, "../path_utils/path_utils_ut.c", 623 , "Assertion '""*data == 123""' failed", ((void*)0)); | ||||
624 | |||||
625 | return true1; | ||||
626 | } | ||||
627 | |||||
628 | bool_Bool dirlist_cb_recursive(const char *directory, const char *base_name, | ||||
629 | const char *path, struct stat *info, | ||||
630 | void *user_data) | ||||
631 | { | ||||
632 | bool_Bool *seen_child = (bool_Bool *) user_data; | ||||
633 | static bool_Bool seen_parent = false0; | ||||
634 | |||||
635 | if (!seen_parent) { | ||||
636 | fail_unless_str_equal(path, dlist_subdir)do { _fail_unless(strcmp(path, dlist_subdir) == 0, "../path_utils/path_utils_ut.c" , 636, "Assertion '""strcmp(path, dlist_subdir) == 0""' failed" , "The strings '%s' and '%s' are different, expected same", path , dlist_subdir, ((void*)0)); } while(0);; | ||||
637 | seen_parent = true1; | ||||
638 | } else { | ||||
639 | *seen_child = true1; | ||||
640 | fail_unless_str_equal(path, dlist_subsubdir)do { _fail_unless(strcmp(path, dlist_subsubdir) == 0, "../path_utils/path_utils_ut.c" , 640, "Assertion '""strcmp(path, dlist_subsubdir) == 0""' failed" , "The strings '%s' and '%s' are different, expected same", path , dlist_subsubdir, ((void*)0)); } while(0);; | ||||
641 | seen_parent = false0; | ||||
642 | } | ||||
643 | |||||
644 | return true1; | ||||
645 | } | ||||
646 | |||||
647 | START_TEST(test_directory_list)static void test_directory_list (int _i __attribute__ ((unused ))){ tcase_fn_start ("""test_directory_list", "../path_utils/path_utils_ut.c" , 647); | ||||
648 | { | ||||
649 | int data = 123; | ||||
650 | bool_Bool seen_child; | ||||
651 | |||||
652 | fail_unless(directory_list(dlist_dir, false, dirlist_cb_nonrecursive, &data) == SUCCESS)_fail_unless(directory_list(dlist_dir, 0, dirlist_cb_nonrecursive , &data) == 0, "../path_utils/path_utils_ut.c", 652, "Assertion '" "directory_list(dlist_dir, false, dirlist_cb_nonrecursive, &data) == SUCCESS" "' failed", ((void*)0)); | ||||
653 | |||||
654 | seen_child = false0; | ||||
655 | fail_unless(directory_list(dlist_dir, true, dirlist_cb_recursive, &seen_child) == SUCCESS)_fail_unless(directory_list(dlist_dir, 1, dirlist_cb_recursive , &seen_child) == 0, "../path_utils/path_utils_ut.c", 655 , "Assertion '""directory_list(dlist_dir, true, dirlist_cb_recursive, &seen_child) == SUCCESS" "' failed", ((void*)0)); | ||||
656 | fail_unless(seen_child == true)_fail_unless(seen_child == 1, "../path_utils/path_utils_ut.c" , 656, "Assertion '""seen_child == true""' failed", ((void*)0 )); | ||||
657 | |||||
658 | seen_child = false0; | ||||
659 | fail_unless(directory_list(dlist_dir, false, dirlist_cb_recursive, &seen_child) == SUCCESS)_fail_unless(directory_list(dlist_dir, 0, dirlist_cb_recursive , &seen_child) == 0, "../path_utils/path_utils_ut.c", 659 , "Assertion '""directory_list(dlist_dir, false, dirlist_cb_recursive, &seen_child) == SUCCESS" "' failed", ((void*)0)); | ||||
660 | fail_unless(seen_child == false)_fail_unless(seen_child == 0, "../path_utils/path_utils_ut.c" , 660, "Assertion '""seen_child == false""' failed", ((void*) 0)); | ||||
661 | } | ||||
662 | END_TEST} | ||||
663 | |||||
664 | START_TEST(test_directory_list_neg)static void test_directory_list_neg (int _i __attribute__ ((unused ))){ tcase_fn_start ("""test_directory_list_neg", "../path_utils/path_utils_ut.c" , 664); | ||||
665 | { | ||||
666 | fail_if(directory_list("/not/here", false, dirlist_cb_nonrecursive, NULL) == SUCCESS)_fail_unless(!(directory_list("/not/here", 0, dirlist_cb_nonrecursive , ((void*)0)) == 0), "../path_utils/path_utils_ut.c", 666, "Failure '" "directory_list(\"/not/here\", false, dirlist_cb_nonrecursive, NULL) == SUCCESS" "' occured", ((void*)0)); | ||||
667 | fail_if(directory_list("/etc/passwd", false, dirlist_cb_nonrecursive, NULL) == SUCCESS)_fail_unless(!(directory_list("/etc/passwd", 0, dirlist_cb_nonrecursive , ((void*)0)) == 0), "../path_utils/path_utils_ut.c", 667, "Failure '" "directory_list(\"/etc/passwd\", false, dirlist_cb_nonrecursive, NULL) == SUCCESS" "' occured", ((void*)0)); | ||||
668 | } | ||||
669 | END_TEST} | ||||
670 | |||||
671 | /**** is_ancestor_path ****/ | ||||
672 | START_TEST(test_is_ancestor_path)static void test_is_ancestor_path (int _i __attribute__ ((unused ))){ tcase_fn_start ("""test_is_ancestor_path", "../path_utils/path_utils_ut.c" , 672); | ||||
673 | { | ||||
674 | fail_unless(is_ancestor_path("/a/b/c", "/a/b/c/d") == true)_fail_unless(is_ancestor_path("/a/b/c", "/a/b/c/d") == 1, "../path_utils/path_utils_ut.c" , 674, "Assertion '""is_ancestor_path(\"/a/b/c\", \"/a/b/c/d\") == true" "' failed", ((void*)0)); | ||||
675 | /* equal, not ancestor */ | ||||
676 | fail_unless(is_ancestor_path("/a/b/c/d", "/a/b/c/d") == false)_fail_unless(is_ancestor_path("/a/b/c/d", "/a/b/c/d") == 0, "../path_utils/path_utils_ut.c" , 676, "Assertion '""is_ancestor_path(\"/a/b/c/d\", \"/a/b/c/d\") == false" "' failed", ((void*)0)); | ||||
677 | fail_unless(is_ancestor_path("/a/x/c", "/a/b/c/d") == false)_fail_unless(is_ancestor_path("/a/x/c", "/a/b/c/d") == 0, "../path_utils/path_utils_ut.c" , 677, "Assertion '""is_ancestor_path(\"/a/x/c\", \"/a/b/c/d\") == false" "' failed", ((void*)0)); | ||||
678 | fail_unless(is_ancestor_path(NULL, "/a/b/c/d") == false)_fail_unless(is_ancestor_path(((void*)0), "/a/b/c/d") == 0, "../path_utils/path_utils_ut.c" , 678, "Assertion '""is_ancestor_path(NULL, \"/a/b/c/d\") == false" "' failed", ((void*)0)); | ||||
679 | fail_unless(is_ancestor_path("/a/x/c", NULL) == false)_fail_unless(is_ancestor_path("/a/x/c", ((void*)0)) == 0, "../path_utils/path_utils_ut.c" , 679, "Assertion '""is_ancestor_path(\"/a/x/c\", NULL) == false" "' failed", ((void*)0)); | ||||
680 | fail_unless(is_ancestor_path(NULL, NULL) == false)_fail_unless(is_ancestor_path(((void*)0), ((void*)0)) == 0, "../path_utils/path_utils_ut.c" , 680, "Assertion '""is_ancestor_path(NULL, NULL) == false""' failed" , ((void*)0)); | ||||
681 | fail_unless(is_ancestor_path("", "") == false)_fail_unless(is_ancestor_path("", "") == 0, "../path_utils/path_utils_ut.c" , 681, "Assertion '""is_ancestor_path(\"\", \"\") == false""' failed" , ((void*)0)); | ||||
682 | } | ||||
683 | END_TEST} | ||||
684 | |||||
685 | |||||
686 | Suite *path_utils_suite(void) | ||||
687 | { | ||||
688 | Suite *s = suite_create("path_utils"); | ||||
689 | |||||
690 | TCase *tc_path_utils = tcase_create("path_utils"); | ||||
691 | TCase *tc_directory_list = tcase_create("path_utils_directory_list"); | ||||
692 | |||||
693 | tcase_add_test(tc_path_utils, test_dirname)_tcase_add_test((tc_path_utils),(test_dirname),"" "test_dirname" "",(0), 0, 0, 1); | ||||
694 | tcase_add_test(tc_path_utils, test_dirname_neg)_tcase_add_test((tc_path_utils),(test_dirname_neg),"" "test_dirname_neg" "",(0), 0, 0, 1); | ||||
695 | |||||
696 | tcase_add_test(tc_path_utils, test_basename)_tcase_add_test((tc_path_utils),(test_basename),"" "test_basename" "",(0), 0, 0, 1); | ||||
697 | tcase_add_test(tc_path_utils, test_basename_neg)_tcase_add_test((tc_path_utils),(test_basename_neg),"" "test_basename_neg" "",(0), 0, 0, 1); | ||||
698 | |||||
699 | tcase_add_test(tc_path_utils, test_dirname_and_basename)_tcase_add_test((tc_path_utils),(test_dirname_and_basename),"" "test_dirname_and_basename" "",(0), 0, 0, 1); | ||||
700 | tcase_add_test(tc_path_utils, test_dirname_and_basename_neg)_tcase_add_test((tc_path_utils),(test_dirname_and_basename_neg ),"" "test_dirname_and_basename_neg" "",(0), 0, 0, 1); | ||||
701 | |||||
702 | tcase_add_test(tc_path_utils, test_is_absolute_path)_tcase_add_test((tc_path_utils),(test_is_absolute_path),"" "test_is_absolute_path" "",(0), 0, 0, 1); | ||||
703 | |||||
704 | tcase_add_test(tc_path_utils, test_path_concat)_tcase_add_test((tc_path_utils),(test_path_concat),"" "test_path_concat" "",(0), 0, 0, 1); | ||||
705 | tcase_add_test(tc_path_utils, test_path_concat_neg)_tcase_add_test((tc_path_utils),(test_path_concat_neg),"" "test_path_concat_neg" "",(0), 0, 0, 1); | ||||
706 | |||||
707 | tcase_add_test(tc_path_utils, test_split_path)_tcase_add_test((tc_path_utils),(test_split_path),"" "test_split_path" "",(0), 0, 0, 1); | ||||
708 | tcase_add_test(tc_path_utils, test_split_path_neg)_tcase_add_test((tc_path_utils),(test_split_path_neg),"" "test_split_path_neg" "",(0), 0, 0, 1); | ||||
709 | |||||
710 | tcase_add_test(tc_path_utils, test_make_path_absolute)_tcase_add_test((tc_path_utils),(test_make_path_absolute),"" "test_make_path_absolute" "",(0), 0, 0, 1); | ||||
711 | tcase_add_test(tc_path_utils, test_make_path_absolute_neg)_tcase_add_test((tc_path_utils),(test_make_path_absolute_neg) ,"" "test_make_path_absolute_neg" "",(0), 0, 0, 1); | ||||
712 | |||||
713 | tcase_add_test(tc_path_utils, test_normalize_path)_tcase_add_test((tc_path_utils),(test_normalize_path),"" "test_normalize_path" "",(0), 0, 0, 1); | ||||
714 | tcase_add_test(tc_path_utils, test_normalize_path_neg)_tcase_add_test((tc_path_utils),(test_normalize_path_neg),"" "test_normalize_path_neg" "",(0), 0, 0, 1); | ||||
715 | |||||
716 | tcase_add_test(tc_path_utils, test_make_normalized_absolute_path)_tcase_add_test((tc_path_utils),(test_make_normalized_absolute_path ),"" "test_make_normalized_absolute_path" "",(0), 0, 0, 1); | ||||
717 | tcase_add_test(tc_path_utils, test_make_normalized_absolute_path_neg)_tcase_add_test((tc_path_utils),(test_make_normalized_absolute_path_neg ),"" "test_make_normalized_absolute_path_neg" "",(0), 0, 0, 1 ); | ||||
718 | |||||
719 | tcase_add_test(tc_path_utils, test_common_path_prefix)_tcase_add_test((tc_path_utils),(test_common_path_prefix),"" "test_common_path_prefix" "",(0), 0, 0, 1); | ||||
720 | tcase_add_test(tc_path_utils, test_common_path_prefix_neg)_tcase_add_test((tc_path_utils),(test_common_path_prefix_neg) ,"" "test_common_path_prefix_neg" "",(0), 0, 0, 1); | ||||
721 | |||||
722 | tcase_add_test(tc_path_utils, test_find_existing_directory_ancestor)_tcase_add_test((tc_path_utils),(test_find_existing_directory_ancestor ),"" "test_find_existing_directory_ancestor" "",(0), 0, 0, 1); | ||||
723 | tcase_add_test(tc_path_utils, test_find_existing_directory_ancestor_neg)_tcase_add_test((tc_path_utils),(test_find_existing_directory_ancestor_neg ),"" "test_find_existing_directory_ancestor_neg" "",(0), 0, 0 , 1); | ||||
724 | |||||
725 | tcase_add_test(tc_path_utils, test_is_ancestor_path)_tcase_add_test((tc_path_utils),(test_is_ancestor_path),"" "test_is_ancestor_path" "",(0), 0, 0, 1); | ||||
726 | |||||
727 | tcase_add_checked_fixture(tc_directory_list, | ||||
728 | setup_directory_list, | ||||
729 | teardown_directory_list); | ||||
730 | tcase_add_test(tc_directory_list, test_directory_list)_tcase_add_test((tc_directory_list),(test_directory_list),"" "test_directory_list" "",(0), 0, 0, 1); | ||||
731 | tcase_add_test(tc_directory_list, test_directory_list_neg)_tcase_add_test((tc_directory_list),(test_directory_list_neg) ,"" "test_directory_list_neg" "",(0), 0, 0, 1); | ||||
732 | |||||
733 | suite_add_tcase(s, tc_path_utils); | ||||
734 | suite_add_tcase(s, tc_directory_list); | ||||
735 | |||||
736 | return s; | ||||
737 | } | ||||
738 | |||||
739 | int main(void) | ||||
740 | { | ||||
741 | int number_failed; | ||||
742 | |||||
743 | Suite *s = path_utils_suite(); | ||||
744 | SRunner *sr = srunner_create(s); | ||||
745 | /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */ | ||||
746 | srunner_run_all(sr, CK_ENV); | ||||
747 | number_failed = srunner_ntests_failed(sr); | ||||
748 | srunner_free(sr); | ||||
749 | return (number_failed == 0) ? EXIT_SUCCESS0 : EXIT_FAILURE1; | ||||
750 | } | ||||
751 |