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)
111 check_string (g_build_pathv ("", args), "");
112 args[0] = ""; args[1] = NULL;
113 check_string (g_build_pathv ("", args), "");
114 args[0] = "x"; args[1] = NULL;
115 check_string (g_build_pathv ("", args), "x");
116 args[0] = "x"; args[1] = "y"; args[2] = NULL;
117 check_string (g_build_pathv ("", args), "xy");
118 args[0] = "x"; args[1] = "y"; args[2] = "z", args[3] = NULL;
119 check_string (g_build_pathv ("", args), "xyz");
122 check_string (g_build_pathv (":", args), "");
123 args[0] = ":"; args[1] = NULL;
124 check_string (g_build_pathv (":", args), ":");
125 args[0] = ":x"; args[1] = NULL;
126 check_string (g_build_pathv (":", args), ":x");
127 args[0] = "x:"; args[1] = NULL;
128 check_string (g_build_pathv (":", args), "x:");
129 args[0] = ""; args[1] = "x"; args[2] = NULL;
130 check_string (g_build_pathv (":", args), "x");
131 args[0] = ""; args[1] = ":x"; args[2] = NULL;
132 check_string (g_build_pathv (":", args), ":x");
133 args[0] = ":"; args[1] = "x"; args[2] = NULL;
134 check_string (g_build_pathv (":", args), ":x");
135 args[0] = "::"; args[1] = "x"; args[2] = NULL;
136 check_string (g_build_pathv (":", args), "::x");
137 args[0] = "x"; args[1] = ""; args[2] = NULL;
138 check_string (g_build_pathv (":", args), "x");
139 args[0] = "x:"; args[1] = ""; args[2] = NULL;
140 check_string (g_build_pathv (":", args), "x:");
141 args[0] = "x"; args[1] = ":"; args[2] = NULL;
142 check_string (g_build_pathv (":", args), "x:");
143 args[0] = "x"; args[1] = "::"; args[2] = NULL;
144 check_string (g_build_pathv (":", args), "x::");
145 args[0] = "x"; args[1] = "y"; args[2] = NULL;
146 check_string (g_build_pathv (":", args), "x:y");
147 args[0] = ":x"; args[1] = "y"; args[2] = NULL;
148 check_string (g_build_pathv (":", args), ":x:y");
149 args[0] = "x"; args[1] = "y:"; args[2] = NULL;
150 check_string (g_build_pathv (":", args), "x:y:");
151 args[0] = ":x:"; args[1] = ":y:"; args[2] = NULL;
152 check_string (g_build_pathv (":", args), ":x:y:");
153 args[0] = ":x::"; args[1] = "::y:"; args[2] = NULL;
154 check_string (g_build_pathv (":", args), ":x:y:");
155 args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
156 check_string (g_build_pathv (":", args), "x:y");
157 args[0] = "x"; args[1] = ":"; args[2] = "y"; args[3] = NULL;
158 check_string (g_build_pathv (":", args), "x:y");
159 args[0] = "x"; args[1] = "::"; args[2] = "y"; args[3] = NULL;
160 check_string (g_build_pathv (":", args), "x:y");
161 args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
162 check_string (g_build_pathv (":", args), "x:y:z");
163 args[0] = ":x:"; args[1] = ":y:"; args[2] = ":z:"; args[3] = NULL;
164 check_string (g_build_pathv (":", args), ":x:y:z:");
165 args[0] = "::x::"; args[1] = "::y::"; args[2] = "::z::"; args[3] = NULL;
166 check_string (g_build_pathv (":", args), "::x:y:z::");
169 check_string (g_build_pathv ("::", args), "");
170 args[0] = "::"; args[1] = NULL;
171 check_string (g_build_pathv ("::", args), "::");
172 args[0] = ":::"; args[1] = NULL;
173 check_string (g_build_pathv ("::", args), ":::");
174 args[0] = "::x"; args[1] = NULL;
175 check_string (g_build_pathv ("::", args), "::x");
176 args[0] = "x::"; args[1] = NULL;
177 check_string (g_build_pathv ("::", args), "x::");
178 args[0] = ""; args[1] = "x"; args[2] = NULL;
179 check_string (g_build_pathv ("::", args), "x");
180 args[0] = ""; args[1] = "::x"; args[2] = NULL;
181 check_string (g_build_pathv ("::", args), "::x");
182 args[0] = "::"; args[1] = "x"; args[2] = NULL;
183 check_string (g_build_pathv ("::", args), "::x");
184 args[0] = "::::"; args[1] = "x"; args[2] = NULL;
185 check_string (g_build_pathv ("::", args), "::::x");
186 args[0] = "x"; args[1] = ""; args[2] = NULL;
187 check_string (g_build_pathv ("::", args), "x");
188 args[0] = "x::"; args[1] = ""; args[2] = NULL;
189 check_string (g_build_pathv ("::", args), "x::");
190 args[0] = "x"; args[1] = "::"; args[2] = NULL;
191 check_string (g_build_pathv ("::", args), "x::");
192 /* This following is weird, but keeps the definition simple */
193 args[0] = "x"; args[1] = ":::"; args[2] = NULL;
194 check_string (g_build_pathv ("::", args), "x:::::");
195 args[0] = "x"; args[1] = "::::"; args[2] = NULL;
196 check_string (g_build_pathv ("::", args), "x::::");
197 args[0] = "x"; args[1] = "y"; args[2] = NULL;
198 check_string (g_build_pathv ("::", args), "x::y");
199 args[0] = "::x"; args[1] = "y"; args[2] = NULL;
200 check_string (g_build_pathv ("::", args), "::x::y");
201 args[0] = "x"; args[1] = "y::"; args[2] = NULL;
202 check_string (g_build_pathv ("::", args), "x::y::");
203 args[0] = "::x::"; args[1] = "::y::"; args[2] = NULL;
204 check_string (g_build_pathv ("::", args), "::x::y::");
205 args[0] = "::x:::"; args[1] = ":::y::"; args[2] = NULL;
206 check_string (g_build_pathv ("::", args), "::x::::y::");
207 args[0] = "::x::::"; args[1] = "::::y::"; args[2] = NULL;
208 check_string (g_build_pathv ("::", args), "::x::y::");
209 args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
210 check_string (g_build_pathv ("::", args), "x::y");
211 args[0] = "x"; args[1] = "::"; args[2] = "y"; args[3] = NULL;
212 check_string (g_build_pathv ("::", args), "x::y");
213 args[0] = "x"; args[1] = "::::"; args[2] = "y"; args[3] = NULL;
214 check_string (g_build_pathv ("::", args), "x::y");
215 args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
216 check_string (g_build_pathv ("::", args), "x::y::z");
217 args[0] = "::x::"; args[1] = "::y::"; args[2] = "::z::"; args[3] = NULL;
218 check_string (g_build_pathv ("::", args), "::x::y::z::");
219 args[0] = ":::x:::"; args[1] = ":::y:::"; args[2] = ":::z:::"; args[3] = NULL;
220 check_string (g_build_pathv ("::", args), ":::x::::y::::z:::");
221 args[0] = "::::x::::"; args[1] = "::::y::::"; args[2] = "::::z::::"; args[3] = NULL;
222 check_string (g_build_pathv ("::", args), "::::x::y::z::::");
226 test_build_filename (void)
228 /* check_string (g_build_filename (NULL), "");*/
229 check_string (g_build_filename (S, NULL), S);
230 check_string (g_build_filename (S"x", NULL), S"x");
231 check_string (g_build_filename ("x"S, NULL), "x"S);
232 check_string (g_build_filename ("", "x", NULL), "x");
233 check_string (g_build_filename ("", S"x", NULL), S"x");
234 check_string (g_build_filename (S, "x", NULL), S"x");
235 check_string (g_build_filename (S S, "x", NULL), S S"x");
236 check_string (g_build_filename ("x", "", NULL), "x");
237 check_string (g_build_filename ("x"S, "", NULL), "x"S);
238 check_string (g_build_filename ("x", S, NULL), "x"S);
239 check_string (g_build_filename ("x", S S, NULL), "x"S S);
240 check_string (g_build_filename ("x", "y", NULL), "x"S"y");
241 check_string (g_build_filename (S"x", "y", NULL), S"x"S"y");
242 check_string (g_build_filename ("x", "y"S, NULL), "x"S"y"S);
243 check_string (g_build_filename (S"x"S, S"y"S, NULL), S"x"S"y"S);
244 check_string (g_build_filename (S"x"S S, S S"y"S, NULL), S"x"S"y"S);
245 check_string (g_build_filename ("x", "", "y", NULL), "x"S"y");
246 check_string (g_build_filename ("x", S, "y", NULL), "x"S"y");
247 check_string (g_build_filename ("x", S S, "y", NULL), "x"S"y");
248 check_string (g_build_filename ("x", "y", "z", NULL), "x"S"y"S"z");
249 check_string (g_build_filename (S"x"S, S"y"S, S"z"S, NULL), S"x"S"y"S"z"S);
250 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);
254 /* Test also using the slash as file name separator */
256 check_string (g_build_filename (NULL), "");
257 check_string (g_build_filename (U, NULL), U);
258 check_string (g_build_filename (U"x", NULL), U"x");
259 check_string (g_build_filename ("x"U, NULL), "x"U);
260 check_string (g_build_filename ("", U"x", NULL), U"x");
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 U, "x", NULL), U U"x");
264 check_string (g_build_filename (U S, "x", NULL), U S"x");
265 check_string (g_build_filename ("x"U, "", NULL), "x"U);
266 check_string (g_build_filename ("x"S"y", "z"U"a", NULL), "x"S"y"S"z"U"a");
267 check_string (g_build_filename ("x", U, NULL), "x"U);
268 check_string (g_build_filename ("x", U U, NULL), "x"U U);
269 check_string (g_build_filename ("x", S U, NULL), "x"S U);
270 check_string (g_build_filename (U"x", "y", NULL), U"x"U"y");
271 check_string (g_build_filename ("x", "y"U, NULL), "x"U"y"U);
272 check_string (g_build_filename (U"x"U, U"y"U, NULL), U"x"U"y"U);
273 check_string (g_build_filename (U"x"U U, U U"y"U, NULL), U"x"U"y"U);
274 check_string (g_build_filename ("x", U, "y", NULL), "x"U"y");
275 check_string (g_build_filename ("x", U U, "y", NULL), "x"U"y");
276 check_string (g_build_filename ("x", U S, "y", NULL), "x"S"y");
277 check_string (g_build_filename ("x", S U, "y", NULL), "x"U"y");
278 check_string (g_build_filename ("x", U "y", "z", NULL), "x"U"y"U"z");
279 check_string (g_build_filename ("x", S "y", "z", NULL), "x"S"y"S"z");
280 check_string (g_build_filename ("x", S "y", "z", U, "a", "b", NULL), "x"S"y"S"z"U"a"U"b");
281 check_string (g_build_filename (U"x"U, U"y"U, U"z"U, NULL), U"x"U"y"U"z"U);
282 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);
286 #endif /* G_OS_WIN32 */
291 test_build_filenamev (void)
296 check_string (g_build_filenamev (args), "");
297 args[0] = S; args[1] = NULL;
298 check_string (g_build_filenamev (args), S);
299 args[0] = S"x"; args[1] = NULL;
300 check_string (g_build_filenamev (args), S"x");
301 args[0] = "x"S; args[1] = NULL;
302 check_string (g_build_filenamev (args), "x"S);
303 args[0] = ""; args[1] = "x"; args[2] = NULL;
304 check_string (g_build_filenamev (args), "x");
305 args[0] = ""; args[1] = S"x"; args[2] = NULL;
306 check_string (g_build_filenamev (args), S"x");
307 args[0] = S; args[1] = "x"; args[2] = NULL;
308 check_string (g_build_filenamev (args), S"x");
309 args[0] = S S; args[1] = "x"; args[2] = NULL;
310 check_string (g_build_filenamev (args), S S"x");
311 args[0] = "x"; args[1] = ""; args[2] = NULL;
312 check_string (g_build_filenamev (args), "x");
313 args[0] = "x"S; args[1] = ""; args[2] = NULL;
314 check_string (g_build_filenamev (args), "x"S);
315 args[0] = "x"; args[1] = S; args[2] = NULL;
316 check_string (g_build_filenamev (args), "x"S);
317 args[0] = "x"; args[1] = S S; args[2] = NULL;
318 check_string (g_build_filenamev (args), "x"S S);
319 args[0] = "x"; args[1] = "y"; args[2] = NULL;
320 check_string (g_build_filenamev (args), "x"S"y");
321 args[0] = S"x"; args[1] = "y"; args[2] = NULL;
322 check_string (g_build_filenamev (args), S"x"S"y");
323 args[0] = "x"; args[1] = "y"S; args[2] = NULL;
324 check_string (g_build_filenamev (args), "x"S"y"S);
325 args[0] = S"x"S; args[1] = S"y"S; args[2] = NULL;
326 check_string (g_build_filenamev (args), S"x"S"y"S);
327 args[0] = S"x"S S; args[1] = S S"y"S; args[2] = NULL;
328 check_string (g_build_filenamev (args), S"x"S"y"S);
329 args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
330 check_string (g_build_filenamev (args), "x"S"y");
331 args[0] = "x"; args[1] = S; args[2] = "y"; args[3] = NULL;
332 check_string (g_build_filenamev (args), "x"S"y");
333 args[0] = "x"; args[1] = S S; args[2] = "y"; args[3] = NULL;
334 check_string (g_build_filenamev (args), "x"S"y");
335 args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
336 check_string (g_build_filenamev (args), "x"S"y"S"z");
337 args[0] = S"x"S; args[1] = S"y"S; args[2] = S"z"S; args[3] = NULL;
338 check_string (g_build_filenamev (args), S"x"S"y"S"z"S);
339 args[0] = S S"x"S S; args[1] = S S"y"S S; args[2] = S S"z"S S; args[3] = NULL;
340 check_string (g_build_filenamev (args), S S"x"S"y"S"z"S S);
344 /* Test also using the slash as file name separator */
347 check_string (g_build_filenamev (args), "");
348 args[0] = U; args[1] = NULL;
349 check_string (g_build_filenamev (args), U);
350 args[0] = U"x"; args[1] = NULL;
351 check_string (g_build_filenamev (args), U"x");
352 args[0] = "x"U; args[1] = NULL;
353 check_string (g_build_filenamev (args), "x"U);
354 args[0] = ""; args[1] = U"x"; args[2] = NULL;
355 check_string (g_build_filenamev (args), U"x");
356 args[0] = ""; args[1] = U"x"; args[2] = NULL;
357 check_string (g_build_filenamev (args), U"x");
358 args[0] = U; args[1] = "x"; args[2] = NULL;
359 check_string (g_build_filenamev (args), U"x");
360 args[0] = U U; args[1] = "x"; args[2] = NULL;
361 check_string (g_build_filenamev (args), U U"x");
362 args[0] = U S; args[1] = "x"; args[2] = NULL;
363 check_string (g_build_filenamev (args), U S"x");
364 args[0] = "x"U; args[1] = ""; args[2] = NULL;
365 check_string (g_build_filenamev (args), "x"U);
366 args[0] = "x"S"y"; args[1] = "z"U"a"; args[2] = NULL;
367 check_string (g_build_filenamev (args), "x"S"y"S"z"U"a");
368 args[0] = "x"; args[1] = U; args[2] = NULL;
369 check_string (g_build_filenamev (args), "x"U);
370 args[0] = "x"; args[1] = U U; args[2] = NULL;
371 check_string (g_build_filenamev (args), "x"U U);
372 args[0] = "x"; args[1] = S U; args[2] = NULL;
373 check_string (g_build_filenamev (args), "x"S U);
374 args[0] = U"x"; args[1] = "y"; args[2] = NULL;
375 check_string (g_build_filenamev (args), U"x"U"y");
376 args[0] = "x"; args[1] = "y"U; args[2] = NULL;
377 check_string (g_build_filenamev (args), "x"U"y"U);
378 args[0] = U"x"U; args[1] = U"y"U; args[2] = NULL;
379 check_string (g_build_filenamev (args), U"x"U"y"U);
380 args[0] = U"x"U U; args[1] = U U"y"U; args[2] = NULL;
381 check_string (g_build_filenamev (args), U"x"U"y"U);
382 args[0] = "x"; args[1] = U; args[2] = "y", args[3] = NULL;
383 check_string (g_build_filenamev (args), "x"U"y");
384 args[0] = "x"; args[1] = U U; args[2] = "y", args[3] = NULL;
385 check_string (g_build_filenamev (args), "x"U"y");
386 args[0] = "x"; args[1] = U S; args[2] = "y", args[3] = NULL;
387 check_string (g_build_filenamev (args), "x"S"y");
388 args[0] = "x"; args[1] = S U; args[2] = "y", args[3] = NULL;
389 check_string (g_build_filenamev (args), "x"U"y");
390 args[0] = "x"; args[1] = U "y"; args[2] = "z", args[3] = NULL;
391 check_string (g_build_filenamev (args), "x"U"y"U"z");
392 args[0] = "x"; args[1] = S "y"; args[2] = "z", args[3] = NULL;
393 check_string (g_build_filenamev (args), "x"S"y"S"z");
394 args[0] = "x"; args[1] = S "y"; args[2] = "z", args[3] = U;
395 args[4] = "a"; args[5] = "b"; args[6] = NULL;
396 check_string (g_build_filenamev (args), "x"S"y"S"z"U"a"U"b");
397 args[0] = U"x"U; args[1] = U"y"U; args[2] = U"z"U, args[3] = NULL;
398 check_string (g_build_filenamev (args), U"x"U"y"U"z"U);
399 args[0] = U U"x"U U; args[1] = U U"y"U U; args[2] = U U"z"U U, args[3] = NULL;
400 check_string (g_build_filenamev (args), U U"x"U"y"U"z"U U);
404 #endif /* G_OS_WIN32 */
410 test_mkdir_with_parents_1 (const gchar *base)
412 char *p0 = g_build_filename (base, "fum", NULL);
413 char *p1 = g_build_filename (p0, "tem", NULL);
414 char *p2 = g_build_filename (p1, "zap", NULL);
421 if (g_file_test (p0, G_FILE_TEST_EXISTS))
422 g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p0);
424 if (g_file_test (p1, G_FILE_TEST_EXISTS))
425 g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p1);
427 if (g_file_test (p2, G_FILE_TEST_EXISTS))
428 g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p2);
430 if (g_mkdir_with_parents (p2, 0777) == -1)
431 g_error ("failed, g_mkdir_with_parents(%s) failed: %s\n", p2, g_strerror (errno));
433 if (!g_file_test (p2, G_FILE_TEST_IS_DIR))
434 g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p2);
436 if (!g_file_test (p1, G_FILE_TEST_IS_DIR))
437 g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p1);
439 if (!g_file_test (p0, G_FILE_TEST_IS_DIR))
440 g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p0);
443 if (g_file_test (p2, G_FILE_TEST_EXISTS))
444 g_error ("failed, did g_rmdir(%s), but %s is still there\n", p2, p2);
447 if (g_file_test (p1, G_FILE_TEST_EXISTS))
448 g_error ("failed, did g_rmdir(%s), but %s is still there\n", p1, p1);
450 f = g_fopen (p1, "w");
452 g_error ("failed, couldn't create file %s\n", p1);
455 if (g_mkdir_with_parents (p1, 0666) == 0)
456 g_error ("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p1, p1);
458 if (g_mkdir_with_parents (p2, 0666) == 0)
459 g_error("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p2, p1);
471 test_mkdir_with_parents (void)
474 if (g_test_verbose())
475 g_print ("checking g_mkdir_with_parents() in subdir ./hum/");
476 test_mkdir_with_parents_1 ("hum");
478 if (g_test_verbose())
479 g_print ("checking g_mkdir_with_parents() in subdir ./hii///haa/hee/");
480 test_mkdir_with_parents_1 ("hii///haa/hee");
481 g_remove ("hii/haa/hee");
482 g_remove ("hii/haa");
484 cwd = g_get_current_dir ();
485 if (g_test_verbose())
486 g_print ("checking g_mkdir_with_parents() in cwd: %s", cwd);
487 test_mkdir_with_parents_1 (cwd);
490 g_assert (g_mkdir_with_parents (NULL, 0) == -1);
491 g_assert (errno == EINVAL);
495 test_format_size_for_display (void)
497 /* nobody called setlocale(), so we should get "C" behaviour... */
498 check_string (g_format_size_for_display (0), "0 bytes");
499 check_string (g_format_size_for_display (1), "1 byte");
500 check_string (g_format_size_for_display (2), "2 bytes");
501 check_string (g_format_size_for_display (1024), "1.0 KB");
502 check_string (g_format_size_for_display (1024 * 1024), "1.0 MB");
503 check_string (g_format_size_for_display (1024 * 1024 * 1024), "1.0 GB");
505 check_string (g_format_size (0), "0 bytes");
506 check_string (g_format_size (1), "1 byte");
507 check_string (g_format_size (2), "2 bytes");
508 check_string (g_format_size (1000), "1.0 kB");
509 check_string (g_format_size (1000 * 1000), "1.0 MB");
510 check_string (g_format_size (1000 * 1000 * 1000), "1.0 GB");
512 check_string (g_format_size_full (238472938, G_FORMAT_SIZE_IEC_UNITS), "227.4 MiB");
513 check_string (g_format_size_full (238472938, G_FORMAT_SIZE_DEFAULT), "238.5 MB");
514 check_string (g_format_size_full (238472938, G_FORMAT_SIZE_LONG_FORMAT), "238.5 MB (238472938 bytes)");
521 g_test_init (&argc, &argv, NULL);
523 g_test_add_func ("/fileutils/build-path", test_build_path);
524 g_test_add_func ("/fileutils/build-pathv", test_build_pathv);
525 g_test_add_func ("/fileutils/build-filename", test_build_filename);
526 g_test_add_func ("/fileutils/build-filenamev", test_build_filenamev);
527 g_test_add_func ("/fileutils/mkdir-with-parents", test_mkdir_with_parents);
528 g_test_add_func ("/fileutils/format-size-for-display", test_format_size_for_display);