Initial commit
[platform/upstream/glib2.0.git] / glib / tests / fileutils.c
1 /* Unit tests for gfileutils
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
7  *
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.
11  *
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.
20  */
21
22 #include <string.h>
23 #include <errno.h>
24 #include <glib.h>
25 #include <glib/gstdio.h>
26
27 #define S G_DIR_SEPARATOR_S
28
29 static void
30 check_string (gchar *str, gchar *expected)
31 {
32   g_assert (str != NULL);
33   g_assert_cmpstr (str, ==, expected);
34   g_free (str);
35 }
36
37 static void
38 test_build_path (void)
39 {
40 /*  check_string (g_build_path ("", NULL), "");*/
41   check_string (g_build_path ("", "", NULL), "");
42   check_string (g_build_path ("", "x", NULL), "x");
43   check_string (g_build_path ("", "x", "y",  NULL), "xy");
44   check_string (g_build_path ("", "x", "y", "z", NULL), "xyz");
45
46 /*  check_string (g_build_path (":", NULL), "");*/
47   check_string (g_build_path (":", ":", NULL), ":");
48   check_string (g_build_path (":", ":x", NULL), ":x");
49   check_string (g_build_path (":", "x:", NULL), "x:");
50   check_string (g_build_path (":", "", "x", NULL), "x");
51   check_string (g_build_path (":", "", ":x", NULL), ":x");
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", "y",  NULL), "x:y");
59   check_string (g_build_path (":", ":x", "y", NULL), ":x:y");
60   check_string (g_build_path (":", "x", "y:", NULL), "x:y:");
61   check_string (g_build_path (":", ":x:", ":y:", NULL), ":x:y:");
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", "z", NULL), "x:y:z");
67   check_string (g_build_path (":", ":x:", ":y:", ":z:", NULL), ":x:y:z:");
68   check_string (g_build_path (":", "::x::", "::y::", "::z::", NULL), "::x:y:z::");
69
70 /*  check_string (g_build_path ("::", NULL), "");*/
71   check_string (g_build_path ("::", "::", NULL), "::");
72   check_string (g_build_path ("::", ":::", NULL), ":::");
73   check_string (g_build_path ("::", "::x", NULL), "::x");
74   check_string (g_build_path ("::", "x::", NULL), "x::");
75   check_string (g_build_path ("::", "", "x", NULL), "x");
76   check_string (g_build_path ("::", "", "::x", NULL), "::x");
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
83   /* This following is weird, but keeps the definition simple */
84   check_string (g_build_path ("::", "x", ":::", NULL), "x:::::");
85   check_string (g_build_path ("::", "x", "::::", NULL), "x::::");
86   check_string (g_build_path ("::", "x", "y",  NULL), "x::y");
87   check_string (g_build_path ("::", "::x", "y", NULL), "::x::y");
88   check_string (g_build_path ("::", "x", "y::", NULL), "x::y::");
89   check_string (g_build_path ("::", "::x::", "::y::", NULL), "::x::y::");
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", "z", NULL), "x::y::z");
96   check_string (g_build_path ("::", "::x::", "::y::", "::z::", NULL), "::x::y::z::");
97   check_string (g_build_path ("::", ":::x:::", ":::y:::", ":::z:::", NULL), ":::x::::y::::z:::");
98   check_string (g_build_path ("::", "::::x::::", "::::y::::", "::::z::::", NULL), "::::x::y::z::::");
99 }
100
101 static void
102 test_build_pathv (void)
103 {
104   gchar *args[10];
105
106   args[0] = NULL;
107   check_string (g_build_pathv ("", args), "");
108   args[0] = ""; args[1] = NULL;
109   check_string (g_build_pathv ("", args), "");
110   args[0] = "x"; args[1] = NULL;
111   check_string (g_build_pathv ("", args), "x");
112   args[0] = "x"; args[1] = "y"; args[2] = NULL;
113   check_string (g_build_pathv ("", args), "xy");
114   args[0] = "x"; args[1] = "y"; args[2] = "z", args[3] = NULL;
115   check_string (g_build_pathv ("", args), "xyz");
116
117   args[0] = NULL;
118   check_string (g_build_pathv (":", args), "");
119   args[0] = ":"; args[1] = NULL;
120   check_string (g_build_pathv (":", args), ":");
121   args[0] = ":x"; args[1] = NULL;
122   check_string (g_build_pathv (":", args), ":x");
123   args[0] = "x:"; args[1] = NULL;
124   check_string (g_build_pathv (":", args), "x:");
125   args[0] = ""; args[1] = "x"; args[2] = NULL;
126   check_string (g_build_pathv (":", args), "x");
127   args[0] = ""; args[1] = ":x"; args[2] = 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] = "x"; args[1] = ""; args[2] = NULL;
134   check_string (g_build_pathv (":", args), "x");
135   args[0] = "x:"; args[1] = ""; 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] = "y"; args[2] = NULL;
142   check_string (g_build_pathv (":", args), "x:y");
143   args[0] = ":x"; args[1] = "y"; args[2] = NULL;
144   check_string (g_build_pathv (":", args), ":x:y");
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] = ""; args[2] = "y"; args[3] = NULL;
152   check_string (g_build_pathv (":", args), "x:y");
153   args[0] = "x"; args[1] = ":"; args[2] = "y"; args[3] = 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] = "y"; args[2] = "z"; args[3] = NULL;
158   check_string (g_build_pathv (":", args), "x:y:z");
159   args[0] = ":x:"; args[1] = ":y:"; args[2] = ":z:"; args[3] = NULL;
160   check_string (g_build_pathv (":", args), ":x:y:z:");
161   args[0] = "::x::"; args[1] = "::y::"; args[2] = "::z::"; args[3] = NULL;
162   check_string (g_build_pathv (":", args), "::x:y:z::");
163
164   args[0] = NULL;
165   check_string (g_build_pathv ("::", args), "");
166   args[0] = "::"; args[1] = NULL;
167   check_string (g_build_pathv ("::", args), "::");
168   args[0] = ":::"; args[1] = NULL;
169   check_string (g_build_pathv ("::", args), ":::");
170   args[0] = "::x"; args[1] = NULL;
171   check_string (g_build_pathv ("::", args), "::x");
172   args[0] = "x::"; args[1] = NULL;
173   check_string (g_build_pathv ("::", args), "x::");
174   args[0] = ""; args[1] = "x"; args[2] = NULL;
175   check_string (g_build_pathv ("::", args), "x");
176   args[0] = ""; args[1] = "::x"; args[2] = 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] = "x"; args[1] = ""; args[2] = NULL;
183   check_string (g_build_pathv ("::", args), "x");
184   args[0] = "x::"; args[1] = ""; 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   /* This following is weird, but keeps the definition simple */
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   args[0] = "x"; args[1] = "y"; args[2] = NULL;
194   check_string (g_build_pathv ("::", args), "x::y");
195   args[0] = "::x"; args[1] = "y"; args[2] = NULL;
196   check_string (g_build_pathv ("::", args), "::x::y");
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] = ""; args[2] = "y"; args[3] = NULL;
206   check_string (g_build_pathv ("::", args), "x::y");
207   args[0] = "x"; args[1] = "::"; args[2] = "y"; args[3] = 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] = "y"; args[2] = "z"; args[3] = NULL;
212   check_string (g_build_pathv ("::", args), "x::y::z");
213   args[0] = "::x::"; args[1] = "::y::"; args[2] = "::z::"; args[3] = NULL;
214   check_string (g_build_pathv ("::", args), "::x::y::z::");
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 }
220
221 static void
222 test_build_filename (void)
223 {
224 /*  check_string (g_build_filename (NULL), "");*/
225   check_string (g_build_filename (S, NULL), S);
226   check_string (g_build_filename (S"x", NULL), S"x");
227   check_string (g_build_filename ("x"S, NULL), "x"S);
228   check_string (g_build_filename ("", "x", NULL), "x");
229   check_string (g_build_filename ("", S"x", NULL), S"x");
230   check_string (g_build_filename (S, "x", NULL), S"x");
231   check_string (g_build_filename (S S, "x", NULL), S S"x");
232   check_string (g_build_filename ("x", "", NULL), "x");
233   check_string (g_build_filename ("x"S, "", NULL), "x"S);
234   check_string (g_build_filename ("x", S, NULL), "x"S);
235   check_string (g_build_filename ("x", S S, NULL), "x"S S);
236   check_string (g_build_filename ("x", "y",  NULL), "x"S"y");
237   check_string (g_build_filename (S"x", "y", NULL), S"x"S"y");
238   check_string (g_build_filename ("x", "y"S, NULL), "x"S"y"S);
239   check_string (g_build_filename (S"x"S, S"y"S, NULL), S"x"S"y"S);
240   check_string (g_build_filename (S"x"S S, S S"y"S, NULL), S"x"S"y"S);
241   check_string (g_build_filename ("x", "", "y",  NULL), "x"S"y");
242   check_string (g_build_filename ("x", S, "y",  NULL), "x"S"y");
243   check_string (g_build_filename ("x", S S, "y",  NULL), "x"S"y");
244   check_string (g_build_filename ("x", "y", "z", NULL), "x"S"y"S"z");
245   check_string (g_build_filename (S"x"S, S"y"S, S"z"S, NULL), S"x"S"y"S"z"S);
246   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);
247
248 #ifdef G_OS_WIN32
249
250   /* Test also using the slash as file name separator */
251 #define U "/"
252   check_string (g_build_filename (NULL), "");
253   check_string (g_build_filename (U, NULL), U);
254   check_string (g_build_filename (U"x", NULL), U"x");
255   check_string (g_build_filename ("x"U, NULL), "x"U);
256   check_string (g_build_filename ("", U"x", NULL), U"x");
257   check_string (g_build_filename ("", U"x", NULL), U"x");
258   check_string (g_build_filename (U, "x", NULL), U"x");
259   check_string (g_build_filename (U U, "x", NULL), U U"x");
260   check_string (g_build_filename (U S, "x", NULL), U S"x");
261   check_string (g_build_filename ("x"U, "", NULL), "x"U);
262   check_string (g_build_filename ("x"S"y", "z"U"a", NULL), "x"S"y"S"z"U"a");
263   check_string (g_build_filename ("x", U, NULL), "x"U);
264   check_string (g_build_filename ("x", U U, NULL), "x"U U);
265   check_string (g_build_filename ("x", S U, NULL), "x"S U);
266   check_string (g_build_filename (U"x", "y", NULL), U"x"U"y");
267   check_string (g_build_filename ("x", "y"U, NULL), "x"U"y"U);
268   check_string (g_build_filename (U"x"U, U"y"U, NULL), U"x"U"y"U);
269   check_string (g_build_filename (U"x"U U, U U"y"U, NULL), U"x"U"y"U);
270   check_string (g_build_filename ("x", U, "y",  NULL), "x"U"y");
271   check_string (g_build_filename ("x", U U, "y",  NULL), "x"U"y");
272   check_string (g_build_filename ("x", U S, "y",  NULL), "x"S"y");
273   check_string (g_build_filename ("x", S U, "y",  NULL), "x"U"y");
274   check_string (g_build_filename ("x", U "y", "z", NULL), "x"U"y"U"z");
275   check_string (g_build_filename ("x", S "y", "z", NULL), "x"S"y"S"z");
276   check_string (g_build_filename ("x", S "y", "z", U, "a", "b", NULL), "x"S"y"S"z"U"a"U"b");
277   check_string (g_build_filename (U"x"U, U"y"U, U"z"U, NULL), U"x"U"y"U"z"U);
278   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);
279
280 #undef U
281
282 #endif /* G_OS_WIN32 */
283
284 }
285
286 static void
287 test_build_filenamev (void)
288 {
289   gchar *args[10];
290
291   args[0] = NULL;
292   check_string (g_build_filenamev (args), "");
293   args[0] = S; args[1] = NULL;
294   check_string (g_build_filenamev (args), S);
295   args[0] = S"x"; args[1] = NULL;
296   check_string (g_build_filenamev (args), S"x");
297   args[0] = "x"S; args[1] = NULL;
298   check_string (g_build_filenamev (args), "x"S);
299   args[0] = ""; args[1] = "x"; args[2] = NULL;
300   check_string (g_build_filenamev (args), "x");
301   args[0] = ""; args[1] = S"x"; args[2] = NULL;
302   check_string (g_build_filenamev (args), S"x");
303   args[0] = S; args[1] = "x"; args[2] = NULL;
304   check_string (g_build_filenamev (args), S"x");
305   args[0] = S S; args[1] = "x"; args[2] = NULL;
306   check_string (g_build_filenamev (args), S S"x");
307   args[0] = "x"; args[1] = ""; args[2] = NULL;
308   check_string (g_build_filenamev (args), "x");
309   args[0] = "x"S; args[1] = ""; args[2] = NULL;
310   check_string (g_build_filenamev (args), "x"S);
311   args[0] = "x"; args[1] = S; args[2] = NULL;
312   check_string (g_build_filenamev (args), "x"S);
313   args[0] = "x"; args[1] = S S; args[2] = NULL;
314   check_string (g_build_filenamev (args), "x"S S);
315   args[0] = "x"; args[1] = "y"; args[2] = NULL;
316   check_string (g_build_filenamev (args), "x"S"y");
317   args[0] = S"x"; args[1] = "y"; args[2] = NULL;
318   check_string (g_build_filenamev (args), S"x"S"y");
319   args[0] = "x"; args[1] = "y"S; args[2] = NULL;
320   check_string (g_build_filenamev (args), "x"S"y"S);
321   args[0] = S"x"S; args[1] = S"y"S; args[2] = NULL;
322   check_string (g_build_filenamev (args), S"x"S"y"S);
323   args[0] = S"x"S S; args[1] = S S"y"S; args[2] = NULL;
324   check_string (g_build_filenamev (args), S"x"S"y"S);
325   args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
326   check_string (g_build_filenamev (args), "x"S"y");
327   args[0] = "x"; args[1] = S; args[2] = "y"; args[3] = NULL;
328   check_string (g_build_filenamev (args), "x"S"y");
329   args[0] = "x"; args[1] = S S; args[2] = "y"; args[3] = NULL;
330   check_string (g_build_filenamev (args), "x"S"y");
331   args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
332   check_string (g_build_filenamev (args), "x"S"y"S"z");
333   args[0] = S"x"S; args[1] = S"y"S; args[2] = S"z"S; args[3] = NULL;
334   check_string (g_build_filenamev (args), S"x"S"y"S"z"S);
335   args[0] = S S"x"S S; args[1] = S S"y"S S; args[2] = S S"z"S S; args[3] = NULL;
336   check_string (g_build_filenamev (args), S S"x"S"y"S"z"S S);
337
338 #ifdef G_OS_WIN32
339
340   /* Test also using the slash as file name separator */
341 #define U "/"
342   args[0] = NULL;
343   check_string (g_build_filenamev (args), "");
344   args[0] = U; args[1] = NULL;
345   check_string (g_build_filenamev (args), U);
346   args[0] = U"x"; args[1] = NULL;
347   check_string (g_build_filenamev (args), U"x");
348   args[0] = "x"U; args[1] = NULL;
349   check_string (g_build_filenamev (args), "x"U);
350   args[0] = ""; args[1] = U"x"; args[2] = NULL;
351   check_string (g_build_filenamev (args), U"x");
352   args[0] = ""; args[1] = U"x"; args[2] = NULL;
353   check_string (g_build_filenamev (args), U"x");
354   args[0] = U; args[1] = "x"; args[2] = NULL;
355   check_string (g_build_filenamev (args), U"x");
356   args[0] = U U; args[1] = "x"; args[2] = NULL;
357   check_string (g_build_filenamev (args), U U"x");
358   args[0] = U S; args[1] = "x"; args[2] = NULL;
359   check_string (g_build_filenamev (args), U S"x");
360   args[0] = "x"U; args[1] = ""; args[2] = NULL;
361   check_string (g_build_filenamev (args), "x"U);
362   args[0] = "x"S"y"; args[1] = "z"U"a"; args[2] = NULL;
363   check_string (g_build_filenamev (args), "x"S"y"S"z"U"a");
364   args[0] = "x"; args[1] = U; args[2] = NULL;
365   check_string (g_build_filenamev (args), "x"U);
366   args[0] = "x"; args[1] = U U; args[2] = NULL;
367   check_string (g_build_filenamev (args), "x"U U);
368   args[0] = "x"; args[1] = S U; args[2] = NULL;
369   check_string (g_build_filenamev (args), "x"S U);
370   args[0] = U"x"; args[1] = "y"; args[2] = NULL;
371   check_string (g_build_filenamev (args), U"x"U"y");
372   args[0] = "x"; args[1] = "y"U; args[2] = NULL;
373   check_string (g_build_filenamev (args), "x"U"y"U);
374   args[0] = U"x"U; args[1] = U"y"U; args[2] = NULL;
375   check_string (g_build_filenamev (args), U"x"U"y"U);
376   args[0] = U"x"U U; args[1] = U U"y"U; args[2] = NULL;
377   check_string (g_build_filenamev (args), U"x"U"y"U);
378   args[0] = "x"; args[1] = U; args[2] = "y", args[3] = NULL;
379   check_string (g_build_filenamev (args), "x"U"y");
380   args[0] = "x"; args[1] = U U; args[2] = "y", args[3] = NULL;
381   check_string (g_build_filenamev (args), "x"U"y");
382   args[0] = "x"; args[1] = U S; args[2] = "y", args[3] = NULL;
383   check_string (g_build_filenamev (args), "x"S"y");
384   args[0] = "x"; args[1] = S U; args[2] = "y", args[3] = NULL;
385   check_string (g_build_filenamev (args), "x"U"y");
386   args[0] = "x"; args[1] = U "y"; args[2] = "z", args[3] = NULL;
387   check_string (g_build_filenamev (args), "x"U"y"U"z");
388   args[0] = "x"; args[1] = S "y"; args[2] = "z", args[3] = NULL;
389   check_string (g_build_filenamev (args), "x"S"y"S"z");
390   args[0] = "x"; args[1] = S "y"; args[2] = "z", args[3] = U;
391   args[4] = "a"; args[5] = "b"; args[6] = NULL;
392   check_string (g_build_filenamev (args), "x"S"y"S"z"U"a"U"b");
393   args[0] = U"x"U; args[1] = U"y"U; args[2] = U"z"U, args[3] = NULL;
394   check_string (g_build_filenamev (args), U"x"U"y"U"z"U);
395   args[0] = U U"x"U U; args[1] = U U"y"U U; args[2] = U U"z"U U, args[3] = NULL;
396   check_string (g_build_filenamev (args), U U"x"U"y"U"z"U U);
397
398 #undef U
399
400 #endif /* G_OS_WIN32 */
401 }
402
403 #undef S
404
405 static void
406 test_mkdir_with_parents_1 (const gchar *base)
407 {
408   char *p0 = g_build_filename (base, "fum", NULL);
409   char *p1 = g_build_filename (p0, "tem", NULL);
410   char *p2 = g_build_filename (p1, "zap", NULL);
411   FILE *f;
412
413   g_remove (p2);
414   g_remove (p1);
415   g_remove (p0);
416
417   if (g_file_test (p0, G_FILE_TEST_EXISTS))
418     g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p0);
419
420   if (g_file_test (p1, G_FILE_TEST_EXISTS))
421     g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p1);
422
423   if (g_file_test (p2, G_FILE_TEST_EXISTS))
424     g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p2);
425
426   if (g_mkdir_with_parents (p2, 0777) == -1)
427     g_error ("failed, g_mkdir_with_parents(%s) failed: %s\n", p2, g_strerror (errno));
428
429   if (!g_file_test (p2, G_FILE_TEST_IS_DIR))
430     g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p2);
431
432   if (!g_file_test (p1, G_FILE_TEST_IS_DIR))
433     g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p1);
434
435   if (!g_file_test (p0, G_FILE_TEST_IS_DIR))
436     g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p0);
437
438   g_rmdir (p2);
439   if (g_file_test (p2, G_FILE_TEST_EXISTS))
440     g_error ("failed, did g_rmdir(%s), but %s is still there\n", p2, p2);
441
442   g_rmdir (p1);
443   if (g_file_test (p1, G_FILE_TEST_EXISTS))
444     g_error ("failed, did g_rmdir(%s), but %s is still there\n", p1, p1);
445
446   f = g_fopen (p1, "w");
447   if (f == NULL)
448     g_error ("failed, couldn't create file %s\n", p1);
449   fclose (f);
450
451   if (g_mkdir_with_parents (p1, 0666) == 0)
452     g_error ("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p1, p1);
453
454   if (g_mkdir_with_parents (p2, 0666) == 0)
455     g_error("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p2, p1);
456
457   g_remove (p2);
458   g_remove (p1);
459   g_remove (p0);
460 }
461
462 static void
463 test_mkdir_with_parents (void)
464 {
465   gchar *cwd;
466   if (g_test_verbose())
467     g_print ("checking g_mkdir_with_parents() in subdir ./hum/");
468   test_mkdir_with_parents_1 ("hum");
469   g_remove ("hum");
470   if (g_test_verbose())
471     g_print ("checking g_mkdir_with_parents() in subdir ./hii///haa/hee/");
472   test_mkdir_with_parents_1 ("hii///haa/hee");
473   g_remove ("hii/haa/hee");
474   g_remove ("hii/haa");
475   g_remove ("hii");
476   cwd = g_get_current_dir ();
477   if (g_test_verbose())
478     g_print ("checking g_mkdir_with_parents() in cwd: %s", cwd);
479   test_mkdir_with_parents_1 (cwd);
480   g_free (cwd);
481 }
482
483 static void
484 test_format_size_for_display (void)
485 {
486   check_string (g_format_size_for_display (0), "0 bytes");
487   check_string (g_format_size_for_display (1), "1 byte");
488   check_string (g_format_size_for_display (2), "2 bytes");
489   check_string (g_format_size_for_display (1024), "1.0 KB");
490   check_string (g_format_size_for_display (1024 * 1024), "1.0 MB");
491   check_string (g_format_size_for_display (1024 * 1024 * 1024), "1.0 GB");
492 }
493
494 int
495 main (int   argc,
496       char *argv[])
497 {
498   g_test_init (&argc, &argv, NULL);
499
500   g_test_add_func ("/fileutils/build-path", test_build_path);
501   g_test_add_func ("/fileutils/build-pathv", test_build_pathv);
502   g_test_add_func ("/fileutils/build-filename", test_build_filename);
503   g_test_add_func ("/fileutils/build-filenamev", test_build_filenamev);
504   g_test_add_func ("/fileutils/mkdir-with-parents", test_mkdir_with_parents);
505   g_test_add_func ("/fileutils/format-size-for-display", test_format_size_for_display);
506
507   return g_test_run();
508 }