1 /* Unit tests for gfileutils
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This work is provided "as is"; redistribution and modification
5 * in whole or in part, in any medium, physical or electronic is
6 * permitted without restriction.
8 * This work is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * In no event shall the authors or contributors be liable for any
13 * direct, indirect, incidental, special, exemplary, or consequential
14 * damages (including, but not limited to, procurement of substitute
15 * goods or services; loss of use, data, or profits; or business
16 * interruption) however caused and on any theory of liability, whether
17 * in contract, strict liability, or tort (including negligence or
18 * otherwise) arising in any way out of the use of this software, even
19 * if advised of the possibility of such damage.
25 /* We are testing some deprecated APIs here */
26 #define GLIB_DISABLE_DEPRECATION_WARNINGS
29 #include <glib/gstdio.h>
31 #define S G_DIR_SEPARATOR_S
34 check_string (gchar *str, gchar *expected)
36 g_assert (str != NULL);
37 g_assert_cmpstr (str, ==, expected);
42 test_build_path (void)
44 /* check_string (g_build_path ("", NULL), "");*/
45 check_string (g_build_path ("", "", NULL), "");
46 check_string (g_build_path ("", "x", NULL), "x");
47 check_string (g_build_path ("", "x", "y", NULL), "xy");
48 check_string (g_build_path ("", "x", "y", "z", NULL), "xyz");
50 /* check_string (g_build_path (":", NULL), "");*/
51 check_string (g_build_path (":", ":", NULL), ":");
52 check_string (g_build_path (":", ":x", NULL), ":x");
53 check_string (g_build_path (":", "x:", NULL), "x:");
54 check_string (g_build_path (":", "", "x", NULL), "x");
55 check_string (g_build_path (":", "", ":x", NULL), ":x");
56 check_string (g_build_path (":", ":", "x", NULL), ":x");
57 check_string (g_build_path (":", "::", "x", NULL), "::x");
58 check_string (g_build_path (":", "x", "", NULL), "x");
59 check_string (g_build_path (":", "x:", "", NULL), "x:");
60 check_string (g_build_path (":", "x", ":", NULL), "x:");
61 check_string (g_build_path (":", "x", "::", NULL), "x::");
62 check_string (g_build_path (":", "x", "y", NULL), "x:y");
63 check_string (g_build_path (":", ":x", "y", NULL), ":x:y");
64 check_string (g_build_path (":", "x", "y:", NULL), "x:y:");
65 check_string (g_build_path (":", ":x:", ":y:", NULL), ":x:y:");
66 check_string (g_build_path (":", ":x::", "::y:", NULL), ":x:y:");
67 check_string (g_build_path (":", "x", "","y", NULL), "x:y");
68 check_string (g_build_path (":", "x", ":", "y", NULL), "x:y");
69 check_string (g_build_path (":", "x", "::", "y", NULL), "x:y");
70 check_string (g_build_path (":", "x", "y", "z", NULL), "x:y:z");
71 check_string (g_build_path (":", ":x:", ":y:", ":z:", NULL), ":x:y:z:");
72 check_string (g_build_path (":", "::x::", "::y::", "::z::", NULL), "::x:y:z::");
74 /* check_string (g_build_path ("::", NULL), "");*/
75 check_string (g_build_path ("::", "::", NULL), "::");
76 check_string (g_build_path ("::", ":::", NULL), ":::");
77 check_string (g_build_path ("::", "::x", NULL), "::x");
78 check_string (g_build_path ("::", "x::", NULL), "x::");
79 check_string (g_build_path ("::", "", "x", NULL), "x");
80 check_string (g_build_path ("::", "", "::x", NULL), "::x");
81 check_string (g_build_path ("::", "::", "x", NULL), "::x");
82 check_string (g_build_path ("::", "::::", "x", NULL), "::::x");
83 check_string (g_build_path ("::", "x", "", NULL), "x");
84 check_string (g_build_path ("::", "x::", "", NULL), "x::");
85 check_string (g_build_path ("::", "x", "::", NULL), "x::");
87 /* This following is weird, but keeps the definition simple */
88 check_string (g_build_path ("::", "x", ":::", NULL), "x:::::");
89 check_string (g_build_path ("::", "x", "::::", NULL), "x::::");
90 check_string (g_build_path ("::", "x", "y", NULL), "x::y");
91 check_string (g_build_path ("::", "::x", "y", NULL), "::x::y");
92 check_string (g_build_path ("::", "x", "y::", NULL), "x::y::");
93 check_string (g_build_path ("::", "::x::", "::y::", NULL), "::x::y::");
94 check_string (g_build_path ("::", "::x:::", ":::y::", NULL), "::x::::y::");
95 check_string (g_build_path ("::", "::x::::", "::::y::", NULL), "::x::y::");
96 check_string (g_build_path ("::", "x", "", "y", NULL), "x::y");
97 check_string (g_build_path ("::", "x", "::", "y", NULL), "x::y");
98 check_string (g_build_path ("::", "x", "::::", "y", NULL), "x::y");
99 check_string (g_build_path ("::", "x", "y", "z", NULL), "x::y::z");
100 check_string (g_build_path ("::", "::x::", "::y::", "::z::", NULL), "::x::y::z::");
101 check_string (g_build_path ("::", ":::x:::", ":::y:::", ":::z:::", NULL), ":::x::::y::::z:::");
102 check_string (g_build_path ("::", "::::x::::", "::::y::::", "::::z::::", NULL), "::::x::y::z::::");
106 test_build_pathv (void)
110 g_assert (g_build_pathv ("", NULL) == NULL);
112 check_string (g_build_pathv ("", args), "");
113 args[0] = ""; args[1] = NULL;
114 check_string (g_build_pathv ("", args), "");
115 args[0] = "x"; args[1] = NULL;
116 check_string (g_build_pathv ("", args), "x");
117 args[0] = "x"; args[1] = "y"; args[2] = NULL;
118 check_string (g_build_pathv ("", args), "xy");
119 args[0] = "x"; args[1] = "y"; args[2] = "z", args[3] = NULL;
120 check_string (g_build_pathv ("", args), "xyz");
123 check_string (g_build_pathv (":", args), "");
124 args[0] = ":"; args[1] = NULL;
125 check_string (g_build_pathv (":", args), ":");
126 args[0] = ":x"; args[1] = NULL;
127 check_string (g_build_pathv (":", args), ":x");
128 args[0] = "x:"; args[1] = NULL;
129 check_string (g_build_pathv (":", args), "x:");
130 args[0] = ""; args[1] = "x"; args[2] = NULL;
131 check_string (g_build_pathv (":", args), "x");
132 args[0] = ""; args[1] = ":x"; args[2] = NULL;
133 check_string (g_build_pathv (":", args), ":x");
134 args[0] = ":"; args[1] = "x"; args[2] = NULL;
135 check_string (g_build_pathv (":", args), ":x");
136 args[0] = "::"; args[1] = "x"; args[2] = NULL;
137 check_string (g_build_pathv (":", args), "::x");
138 args[0] = "x"; args[1] = ""; args[2] = NULL;
139 check_string (g_build_pathv (":", args), "x");
140 args[0] = "x:"; args[1] = ""; args[2] = NULL;
141 check_string (g_build_pathv (":", args), "x:");
142 args[0] = "x"; args[1] = ":"; args[2] = NULL;
143 check_string (g_build_pathv (":", args), "x:");
144 args[0] = "x"; args[1] = "::"; args[2] = NULL;
145 check_string (g_build_pathv (":", args), "x::");
146 args[0] = "x"; args[1] = "y"; args[2] = NULL;
147 check_string (g_build_pathv (":", args), "x:y");
148 args[0] = ":x"; args[1] = "y"; args[2] = NULL;
149 check_string (g_build_pathv (":", args), ":x:y");
150 args[0] = "x"; args[1] = "y:"; args[2] = NULL;
151 check_string (g_build_pathv (":", args), "x:y:");
152 args[0] = ":x:"; args[1] = ":y:"; args[2] = NULL;
153 check_string (g_build_pathv (":", args), ":x:y:");
154 args[0] = ":x::"; args[1] = "::y:"; args[2] = NULL;
155 check_string (g_build_pathv (":", args), ":x:y:");
156 args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
157 check_string (g_build_pathv (":", args), "x:y");
158 args[0] = "x"; args[1] = ":"; args[2] = "y"; args[3] = NULL;
159 check_string (g_build_pathv (":", args), "x:y");
160 args[0] = "x"; args[1] = "::"; args[2] = "y"; args[3] = NULL;
161 check_string (g_build_pathv (":", args), "x:y");
162 args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
163 check_string (g_build_pathv (":", args), "x:y:z");
164 args[0] = ":x:"; args[1] = ":y:"; args[2] = ":z:"; args[3] = NULL;
165 check_string (g_build_pathv (":", args), ":x:y:z:");
166 args[0] = "::x::"; args[1] = "::y::"; args[2] = "::z::"; args[3] = NULL;
167 check_string (g_build_pathv (":", args), "::x:y:z::");
170 check_string (g_build_pathv ("::", args), "");
171 args[0] = "::"; args[1] = NULL;
172 check_string (g_build_pathv ("::", args), "::");
173 args[0] = ":::"; args[1] = NULL;
174 check_string (g_build_pathv ("::", args), ":::");
175 args[0] = "::x"; args[1] = NULL;
176 check_string (g_build_pathv ("::", args), "::x");
177 args[0] = "x::"; args[1] = NULL;
178 check_string (g_build_pathv ("::", args), "x::");
179 args[0] = ""; args[1] = "x"; args[2] = NULL;
180 check_string (g_build_pathv ("::", args), "x");
181 args[0] = ""; args[1] = "::x"; args[2] = NULL;
182 check_string (g_build_pathv ("::", args), "::x");
183 args[0] = "::"; args[1] = "x"; args[2] = NULL;
184 check_string (g_build_pathv ("::", args), "::x");
185 args[0] = "::::"; args[1] = "x"; args[2] = NULL;
186 check_string (g_build_pathv ("::", args), "::::x");
187 args[0] = "x"; args[1] = ""; args[2] = NULL;
188 check_string (g_build_pathv ("::", args), "x");
189 args[0] = "x::"; args[1] = ""; args[2] = NULL;
190 check_string (g_build_pathv ("::", args), "x::");
191 args[0] = "x"; args[1] = "::"; args[2] = NULL;
192 check_string (g_build_pathv ("::", args), "x::");
193 /* This following is weird, but keeps the definition simple */
194 args[0] = "x"; args[1] = ":::"; args[2] = NULL;
195 check_string (g_build_pathv ("::", args), "x:::::");
196 args[0] = "x"; args[1] = "::::"; args[2] = NULL;
197 check_string (g_build_pathv ("::", args), "x::::");
198 args[0] = "x"; args[1] = "y"; args[2] = NULL;
199 check_string (g_build_pathv ("::", args), "x::y");
200 args[0] = "::x"; args[1] = "y"; args[2] = NULL;
201 check_string (g_build_pathv ("::", args), "::x::y");
202 args[0] = "x"; args[1] = "y::"; args[2] = NULL;
203 check_string (g_build_pathv ("::", args), "x::y::");
204 args[0] = "::x::"; args[1] = "::y::"; args[2] = NULL;
205 check_string (g_build_pathv ("::", args), "::x::y::");
206 args[0] = "::x:::"; args[1] = ":::y::"; args[2] = NULL;
207 check_string (g_build_pathv ("::", args), "::x::::y::");
208 args[0] = "::x::::"; args[1] = "::::y::"; args[2] = NULL;
209 check_string (g_build_pathv ("::", args), "::x::y::");
210 args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
211 check_string (g_build_pathv ("::", args), "x::y");
212 args[0] = "x"; args[1] = "::"; args[2] = "y"; args[3] = NULL;
213 check_string (g_build_pathv ("::", args), "x::y");
214 args[0] = "x"; args[1] = "::::"; args[2] = "y"; args[3] = NULL;
215 check_string (g_build_pathv ("::", args), "x::y");
216 args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
217 check_string (g_build_pathv ("::", args), "x::y::z");
218 args[0] = "::x::"; args[1] = "::y::"; args[2] = "::z::"; args[3] = NULL;
219 check_string (g_build_pathv ("::", args), "::x::y::z::");
220 args[0] = ":::x:::"; args[1] = ":::y:::"; args[2] = ":::z:::"; args[3] = NULL;
221 check_string (g_build_pathv ("::", args), ":::x::::y::::z:::");
222 args[0] = "::::x::::"; args[1] = "::::y::::"; args[2] = "::::z::::"; args[3] = NULL;
223 check_string (g_build_pathv ("::", args), "::::x::y::z::::");
227 test_build_filename (void)
229 /* check_string (g_build_filename (NULL), "");*/
230 check_string (g_build_filename (S, NULL), S);
231 check_string (g_build_filename (S"x", NULL), S"x");
232 check_string (g_build_filename ("x"S, NULL), "x"S);
233 check_string (g_build_filename ("", "x", NULL), "x");
234 check_string (g_build_filename ("", S"x", NULL), S"x");
235 check_string (g_build_filename (S, "x", NULL), S"x");
236 check_string (g_build_filename (S S, "x", NULL), S S"x");
237 check_string (g_build_filename ("x", "", NULL), "x");
238 check_string (g_build_filename ("x"S, "", NULL), "x"S);
239 check_string (g_build_filename ("x", S, NULL), "x"S);
240 check_string (g_build_filename ("x", S S, NULL), "x"S S);
241 check_string (g_build_filename ("x", "y", NULL), "x"S"y");
242 check_string (g_build_filename (S"x", "y", NULL), S"x"S"y");
243 check_string (g_build_filename ("x", "y"S, NULL), "x"S"y"S);
244 check_string (g_build_filename (S"x"S, S"y"S, NULL), S"x"S"y"S);
245 check_string (g_build_filename (S"x"S S, S S"y"S, NULL), S"x"S"y"S);
246 check_string (g_build_filename ("x", "", "y", NULL), "x"S"y");
247 check_string (g_build_filename ("x", S, "y", NULL), "x"S"y");
248 check_string (g_build_filename ("x", S S, "y", NULL), "x"S"y");
249 check_string (g_build_filename ("x", "y", "z", NULL), "x"S"y"S"z");
250 check_string (g_build_filename (S"x"S, S"y"S, S"z"S, NULL), S"x"S"y"S"z"S);
251 check_string (g_build_filename (S S"x"S S, S S"y"S S, S S"z"S S, NULL), S S"x"S"y"S"z"S S);
255 /* Test also using the slash as file name separator */
257 check_string (g_build_filename (NULL), "");
258 check_string (g_build_filename (U, NULL), U);
259 check_string (g_build_filename (U"x", NULL), U"x");
260 check_string (g_build_filename ("x"U, NULL), "x"U);
261 check_string (g_build_filename ("", U"x", NULL), U"x");
262 check_string (g_build_filename ("", U"x", NULL), U"x");
263 check_string (g_build_filename (U, "x", NULL), U"x");
264 check_string (g_build_filename (U U, "x", NULL), U U"x");
265 check_string (g_build_filename (U S, "x", NULL), U S"x");
266 check_string (g_build_filename ("x"U, "", NULL), "x"U);
267 check_string (g_build_filename ("x"S"y", "z"U"a", NULL), "x"S"y"S"z"U"a");
268 check_string (g_build_filename ("x", U, NULL), "x"U);
269 check_string (g_build_filename ("x", U U, NULL), "x"U U);
270 check_string (g_build_filename ("x", S U, NULL), "x"S U);
271 check_string (g_build_filename (U"x", "y", NULL), U"x"U"y");
272 check_string (g_build_filename ("x", "y"U, NULL), "x"U"y"U);
273 check_string (g_build_filename (U"x"U, U"y"U, NULL), U"x"U"y"U);
274 check_string (g_build_filename (U"x"U U, U U"y"U, NULL), U"x"U"y"U);
275 check_string (g_build_filename ("x", U, "y", NULL), "x"U"y");
276 check_string (g_build_filename ("x", U U, "y", NULL), "x"U"y");
277 check_string (g_build_filename ("x", U S, "y", NULL), "x"S"y");
278 check_string (g_build_filename ("x", S U, "y", NULL), "x"U"y");
279 check_string (g_build_filename ("x", U "y", "z", NULL), "x"U"y"U"z");
280 check_string (g_build_filename ("x", S "y", "z", NULL), "x"S"y"S"z");
281 check_string (g_build_filename ("x", S "y", "z", U, "a", "b", NULL), "x"S"y"S"z"U"a"U"b");
282 check_string (g_build_filename (U"x"U, U"y"U, U"z"U, NULL), U"x"U"y"U"z"U);
283 check_string (g_build_filename (U U"x"U U, U U"y"U U, U U"z"U U, NULL), U U"x"U"y"U"z"U U);
287 #endif /* G_OS_WIN32 */
292 test_build_filenamev (void)
297 check_string (g_build_filenamev (args), "");
298 args[0] = S; args[1] = NULL;
299 check_string (g_build_filenamev (args), S);
300 args[0] = S"x"; args[1] = NULL;
301 check_string (g_build_filenamev (args), S"x");
302 args[0] = "x"S; args[1] = NULL;
303 check_string (g_build_filenamev (args), "x"S);
304 args[0] = ""; args[1] = "x"; args[2] = NULL;
305 check_string (g_build_filenamev (args), "x");
306 args[0] = ""; args[1] = S"x"; args[2] = NULL;
307 check_string (g_build_filenamev (args), S"x");
308 args[0] = S; args[1] = "x"; args[2] = NULL;
309 check_string (g_build_filenamev (args), S"x");
310 args[0] = S S; args[1] = "x"; args[2] = NULL;
311 check_string (g_build_filenamev (args), S S"x");
312 args[0] = "x"; args[1] = ""; args[2] = NULL;
313 check_string (g_build_filenamev (args), "x");
314 args[0] = "x"S; args[1] = ""; args[2] = NULL;
315 check_string (g_build_filenamev (args), "x"S);
316 args[0] = "x"; args[1] = S; args[2] = NULL;
317 check_string (g_build_filenamev (args), "x"S);
318 args[0] = "x"; args[1] = S S; args[2] = NULL;
319 check_string (g_build_filenamev (args), "x"S S);
320 args[0] = "x"; args[1] = "y"; args[2] = NULL;
321 check_string (g_build_filenamev (args), "x"S"y");
322 args[0] = S"x"; args[1] = "y"; args[2] = NULL;
323 check_string (g_build_filenamev (args), S"x"S"y");
324 args[0] = "x"; args[1] = "y"S; args[2] = NULL;
325 check_string (g_build_filenamev (args), "x"S"y"S);
326 args[0] = S"x"S; args[1] = S"y"S; args[2] = NULL;
327 check_string (g_build_filenamev (args), S"x"S"y"S);
328 args[0] = S"x"S S; args[1] = S S"y"S; args[2] = NULL;
329 check_string (g_build_filenamev (args), S"x"S"y"S);
330 args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
331 check_string (g_build_filenamev (args), "x"S"y");
332 args[0] = "x"; args[1] = S; args[2] = "y"; args[3] = NULL;
333 check_string (g_build_filenamev (args), "x"S"y");
334 args[0] = "x"; args[1] = S S; args[2] = "y"; args[3] = NULL;
335 check_string (g_build_filenamev (args), "x"S"y");
336 args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
337 check_string (g_build_filenamev (args), "x"S"y"S"z");
338 args[0] = S"x"S; args[1] = S"y"S; args[2] = S"z"S; args[3] = NULL;
339 check_string (g_build_filenamev (args), S"x"S"y"S"z"S);
340 args[0] = S S"x"S S; args[1] = S S"y"S S; args[2] = S S"z"S S; args[3] = NULL;
341 check_string (g_build_filenamev (args), S S"x"S"y"S"z"S S);
345 /* Test also using the slash as file name separator */
348 check_string (g_build_filenamev (args), "");
349 args[0] = U; args[1] = NULL;
350 check_string (g_build_filenamev (args), U);
351 args[0] = U"x"; args[1] = NULL;
352 check_string (g_build_filenamev (args), U"x");
353 args[0] = "x"U; args[1] = NULL;
354 check_string (g_build_filenamev (args), "x"U);
355 args[0] = ""; args[1] = U"x"; args[2] = NULL;
356 check_string (g_build_filenamev (args), U"x");
357 args[0] = ""; args[1] = U"x"; args[2] = NULL;
358 check_string (g_build_filenamev (args), U"x");
359 args[0] = U; args[1] = "x"; args[2] = NULL;
360 check_string (g_build_filenamev (args), U"x");
361 args[0] = U U; args[1] = "x"; args[2] = NULL;
362 check_string (g_build_filenamev (args), U U"x");
363 args[0] = U S; args[1] = "x"; args[2] = NULL;
364 check_string (g_build_filenamev (args), U S"x");
365 args[0] = "x"U; args[1] = ""; args[2] = NULL;
366 check_string (g_build_filenamev (args), "x"U);
367 args[0] = "x"S"y"; args[1] = "z"U"a"; args[2] = NULL;
368 check_string (g_build_filenamev (args), "x"S"y"S"z"U"a");
369 args[0] = "x"; args[1] = U; args[2] = NULL;
370 check_string (g_build_filenamev (args), "x"U);
371 args[0] = "x"; args[1] = U U; args[2] = NULL;
372 check_string (g_build_filenamev (args), "x"U U);
373 args[0] = "x"; args[1] = S U; args[2] = NULL;
374 check_string (g_build_filenamev (args), "x"S U);
375 args[0] = U"x"; args[1] = "y"; args[2] = NULL;
376 check_string (g_build_filenamev (args), U"x"U"y");
377 args[0] = "x"; args[1] = "y"U; args[2] = NULL;
378 check_string (g_build_filenamev (args), "x"U"y"U);
379 args[0] = U"x"U; args[1] = U"y"U; args[2] = NULL;
380 check_string (g_build_filenamev (args), U"x"U"y"U);
381 args[0] = U"x"U U; args[1] = U U"y"U; args[2] = NULL;
382 check_string (g_build_filenamev (args), U"x"U"y"U);
383 args[0] = "x"; args[1] = U; args[2] = "y", args[3] = NULL;
384 check_string (g_build_filenamev (args), "x"U"y");
385 args[0] = "x"; args[1] = U U; args[2] = "y", args[3] = NULL;
386 check_string (g_build_filenamev (args), "x"U"y");
387 args[0] = "x"; args[1] = U S; args[2] = "y", args[3] = NULL;
388 check_string (g_build_filenamev (args), "x"S"y");
389 args[0] = "x"; args[1] = S U; args[2] = "y", args[3] = NULL;
390 check_string (g_build_filenamev (args), "x"U"y");
391 args[0] = "x"; args[1] = U "y"; args[2] = "z", args[3] = NULL;
392 check_string (g_build_filenamev (args), "x"U"y"U"z");
393 args[0] = "x"; args[1] = S "y"; args[2] = "z", args[3] = NULL;
394 check_string (g_build_filenamev (args), "x"S"y"S"z");
395 args[0] = "x"; args[1] = S "y"; args[2] = "z", args[3] = U;
396 args[4] = "a"; args[5] = "b"; args[6] = NULL;
397 check_string (g_build_filenamev (args), "x"S"y"S"z"U"a"U"b");
398 args[0] = U"x"U; args[1] = U"y"U; args[2] = U"z"U, args[3] = NULL;
399 check_string (g_build_filenamev (args), U"x"U"y"U"z"U);
400 args[0] = U U"x"U U; args[1] = U U"y"U U; args[2] = U U"z"U U, args[3] = NULL;
401 check_string (g_build_filenamev (args), U U"x"U"y"U"z"U U);
405 #endif /* G_OS_WIN32 */
411 test_mkdir_with_parents_1 (const gchar *base)
413 char *p0 = g_build_filename (base, "fum", NULL);
414 char *p1 = g_build_filename (p0, "tem", NULL);
415 char *p2 = g_build_filename (p1, "zap", NULL);
422 if (g_file_test (p0, G_FILE_TEST_EXISTS))
423 g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p0);
425 if (g_file_test (p1, G_FILE_TEST_EXISTS))
426 g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p1);
428 if (g_file_test (p2, G_FILE_TEST_EXISTS))
429 g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p2);
431 if (g_mkdir_with_parents (p2, 0777) == -1)
432 g_error ("failed, g_mkdir_with_parents(%s) failed: %s\n", p2, g_strerror (errno));
434 if (!g_file_test (p2, G_FILE_TEST_IS_DIR))
435 g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p2);
437 if (!g_file_test (p1, G_FILE_TEST_IS_DIR))
438 g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p1);
440 if (!g_file_test (p0, G_FILE_TEST_IS_DIR))
441 g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p0);
444 if (g_file_test (p2, G_FILE_TEST_EXISTS))
445 g_error ("failed, did g_rmdir(%s), but %s is still there\n", p2, p2);
448 if (g_file_test (p1, G_FILE_TEST_EXISTS))
449 g_error ("failed, did g_rmdir(%s), but %s is still there\n", p1, p1);
451 f = g_fopen (p1, "w");
453 g_error ("failed, couldn't create file %s\n", p1);
456 if (g_mkdir_with_parents (p1, 0666) == 0)
457 g_error ("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p1, p1);
459 if (g_mkdir_with_parents (p2, 0666) == 0)
460 g_error("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p2, p1);
472 test_mkdir_with_parents (void)
475 if (g_test_verbose())
476 g_print ("checking g_mkdir_with_parents() in subdir ./hum/");
477 test_mkdir_with_parents_1 ("hum");
479 if (g_test_verbose())
480 g_print ("checking g_mkdir_with_parents() in subdir ./hii///haa/hee/");
481 test_mkdir_with_parents_1 ("hii///haa/hee");
482 g_remove ("hii/haa/hee");
483 g_remove ("hii/haa");
485 cwd = g_get_current_dir ();
486 if (g_test_verbose())
487 g_print ("checking g_mkdir_with_parents() in cwd: %s", cwd);
488 test_mkdir_with_parents_1 (cwd);
491 g_assert (g_mkdir_with_parents (NULL, 0) == -1);
492 g_assert (errno == EINVAL);
496 test_format_size_for_display (void)
498 /* nobody called setlocale(), so we should get "C" behaviour... */
499 check_string (g_format_size_for_display (0), "0 bytes");
500 check_string (g_format_size_for_display (1), "1 byte");
501 check_string (g_format_size_for_display (2), "2 bytes");
502 check_string (g_format_size_for_display (1024), "1.0 KB");
503 check_string (g_format_size_for_display (1024 * 1024), "1.0 MB");
504 check_string (g_format_size_for_display (1024 * 1024 * 1024), "1.0 GB");
506 check_string (g_format_size (0), "0 bytes");
507 check_string (g_format_size (1), "1 byte");
508 check_string (g_format_size (2), "2 bytes");
509 check_string (g_format_size (1000ULL), "1.0 kB");
510 check_string (g_format_size (1000ULL * 1000), "1.0 MB");
511 check_string (g_format_size (1000ULL * 1000 * 1000), "1.0 GB");
512 check_string (g_format_size (1000ULL * 1000 * 1000 * 1000), "1.0 TB");
513 check_string (g_format_size (1000ULL * 1000 * 1000 * 1000 * 1000), "1.0 PB");
514 check_string (g_format_size (1000ULL * 1000 * 1000 * 1000 * 1000 * 1000), "1.0 EB");
516 check_string (g_format_size_full (0, G_FORMAT_SIZE_IEC_UNITS), "0 bytes");
517 check_string (g_format_size_full (1, G_FORMAT_SIZE_IEC_UNITS), "1 byte");
518 check_string (g_format_size_full (2, G_FORMAT_SIZE_IEC_UNITS), "2 bytes");
520 check_string (g_format_size_full (2048ULL, G_FORMAT_SIZE_IEC_UNITS), "2.0 KiB");
521 check_string (g_format_size_full (2048ULL * 1024, G_FORMAT_SIZE_IEC_UNITS), "2.0 MiB");
522 check_string (g_format_size_full (2048ULL * 1024 * 1024, G_FORMAT_SIZE_IEC_UNITS), "2.0 GiB");
523 check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024, G_FORMAT_SIZE_IEC_UNITS), "2.0 TiB");
524 check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024 * 1024, G_FORMAT_SIZE_IEC_UNITS), "2.0 PiB");
525 check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024 * 1024 * 1024, G_FORMAT_SIZE_IEC_UNITS), "2.0 EiB");
527 check_string (g_format_size_full (238472938, G_FORMAT_SIZE_IEC_UNITS), "227.4 MiB");
528 check_string (g_format_size_full (238472938, G_FORMAT_SIZE_DEFAULT), "238.5 MB");
529 check_string (g_format_size_full (238472938, G_FORMAT_SIZE_LONG_FORMAT), "238.5 MB (238472938 bytes)");
533 test_file_errors (void)
536 g_assert (g_file_error_from_errno (EEXIST) == G_FILE_ERROR_EXIST);
539 g_assert (g_file_error_from_errno (EISDIR) == G_FILE_ERROR_ISDIR);
542 g_assert (g_file_error_from_errno (EACCES) == G_FILE_ERROR_ACCES);
545 g_assert (g_file_error_from_errno (ENAMETOOLONG) == G_FILE_ERROR_NAMETOOLONG);
548 g_assert (g_file_error_from_errno (ENOENT) == G_FILE_ERROR_NOENT);
551 g_assert (g_file_error_from_errno (ENOTDIR) == G_FILE_ERROR_NOTDIR);
554 g_assert (g_file_error_from_errno (ENXIO) == G_FILE_ERROR_NXIO);
557 g_assert (g_file_error_from_errno (ENODEV) == G_FILE_ERROR_NODEV);
560 g_assert (g_file_error_from_errno (EROFS) == G_FILE_ERROR_ROFS);
563 g_assert (g_file_error_from_errno (ETXTBSY) == G_FILE_ERROR_TXTBSY);
566 g_assert (g_file_error_from_errno (EFAULT) == G_FILE_ERROR_FAULT);
569 g_assert (g_file_error_from_errno (ELOOP) == G_FILE_ERROR_LOOP);
572 g_assert (g_file_error_from_errno (ENOSPC) == G_FILE_ERROR_NOSPC);
575 g_assert (g_file_error_from_errno (ENOMEM) == G_FILE_ERROR_NOMEM);
578 g_assert (g_file_error_from_errno (EMFILE) == G_FILE_ERROR_MFILE);
581 g_assert (g_file_error_from_errno (ENFILE) == G_FILE_ERROR_NFILE);
584 g_assert (g_file_error_from_errno (EBADF) == G_FILE_ERROR_BADF);
587 g_assert (g_file_error_from_errno (EINVAL) == G_FILE_ERROR_INVAL);
590 g_assert (g_file_error_from_errno (EPIPE) == G_FILE_ERROR_PIPE);
593 g_assert (g_file_error_from_errno (EAGAIN) == G_FILE_ERROR_AGAIN);
596 g_assert (g_file_error_from_errno (EINTR) == G_FILE_ERROR_INTR);
599 g_assert (g_file_error_from_errno (EIO) == G_FILE_ERROR_IO);
602 g_assert (g_file_error_from_errno (EPERM) == G_FILE_ERROR_PERM);
605 g_assert (g_file_error_from_errno (ENOSYS) == G_FILE_ERROR_NOSYS);
614 b = g_path_get_basename ("");
615 g_assert_cmpstr (b, ==, ".");
618 b = g_path_get_basename ("///");
619 g_assert_cmpstr (b, ==, "/");
622 b = g_path_get_basename ("/a/b/c/d");
623 g_assert_cmpstr (b, ==, "d");
631 g_test_init (&argc, &argv, NULL);
633 g_test_add_func ("/fileutils/build-path", test_build_path);
634 g_test_add_func ("/fileutils/build-pathv", test_build_pathv);
635 g_test_add_func ("/fileutils/build-filename", test_build_filename);
636 g_test_add_func ("/fileutils/build-filenamev", test_build_filenamev);
637 g_test_add_func ("/fileutils/mkdir-with-parents", test_mkdir_with_parents);
638 g_test_add_func ("/fileutils/format-size-for-display", test_format_size_for_display);
639 g_test_add_func ("/fileutils/errors", test_file_errors);
640 g_test_add_func ("/fileutils/basename", test_basename);