1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
27 #undef G_DISABLE_ASSERT
36 static gboolean any_failed = FALSE;
37 static gboolean failed = FALSE;
39 #define TEST(m,cond) G_STMT_START { failed = !(cond); \
42 g_print ("(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
44 g_print ("(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), m ? (gchar*)m : ""); \
50 #define TEST_FAILED(message) \
51 G_STMT_START { g_print ("Error: "); g_print message; g_print ("\n"); any_failed = TRUE; } G_STMT_END
53 #define GLIB_TEST_STRING "el dorado "
56 strv_check (gchar **strv, ...)
62 va_start (list, strv);
65 const gchar *str = va_arg (list, const char *);
73 else if (strcmp (strv[i], str) != 0)
85 str_check (gchar *str,
88 gboolean ok = (strcmp (str, expected) == 0);
96 strchomp_check (gchar *str,
99 gchar *tmp = strdup (str);
103 ok = (strcmp (tmp, expected) == 0);
109 #define FOR_ALL_CTYPE(macro) \
122 #define DEFINE_CALL_CTYPE(function) \
124 call_##function (int c) \
126 return function (c); \
129 #define DEFINE_CALL_G_ASCII_CTYPE(function) \
131 call_g_ascii_##function (gchar c) \
133 return g_ascii_##function (c); \
136 FOR_ALL_CTYPE (DEFINE_CALL_CTYPE)
137 FOR_ALL_CTYPE (DEFINE_CALL_G_ASCII_CTYPE)
140 test_is_function (const char *name,
141 gboolean (* ascii_function) (gchar),
142 int (* c_library_function) (int),
143 gboolean (* unicode_function) (gunichar))
147 for (c = 0; c <= 0x7F; c++)
149 gboolean ascii_result = ascii_function ((gchar)c);
150 gboolean c_library_result = c_library_function (c) != 0;
151 gboolean unicode_result = unicode_function ((gunichar) c);
152 if (ascii_result != c_library_result && c != '\v')
153 TEST_FAILED (("g_ascii_%s returned %d and %s returned %d for 0x%X",
154 name, ascii_result, name, c_library_result, c));
155 if (ascii_result != unicode_result)
156 TEST_FAILED (("g_ascii_%s returned %d and g_unichar_%s returned %d for 0x%X",
157 name, ascii_result, name, unicode_result, c));
159 for (c = 0x80; c <= 0xFF; c++)
161 gboolean ascii_result = ascii_function ((gchar)c);
163 TEST_FAILED (("g_ascii_%s returned TRUE for 0x%X",
169 test_to_function (const char *name,
170 gchar (* ascii_function) (gchar),
171 int (* c_library_function) (int),
172 gunichar (* unicode_function) (gunichar))
176 for (c = 0; c <= 0x7F; c++)
178 int ascii_result = (guchar) ascii_function ((gchar) c);
179 int c_library_result = c_library_function (c);
180 int unicode_result = unicode_function ((gunichar) c);
181 if (ascii_result != c_library_result)
182 TEST_FAILED (("g_ascii_%s returned 0x%X and %s returned 0x%X for 0x%X",
183 name, ascii_result, name, c_library_result, c));
184 if (ascii_result != unicode_result)
185 TEST_FAILED (("g_ascii_%s returned 0x%X and g_unichar_%s returned 0x%X for 0x%X",
186 name, ascii_result, name, unicode_result, c));
188 for (c = 0x80; c <= 0xFF; c++)
190 int ascii_result = (guchar) ascii_function ((gchar) c);
191 if (ascii_result != c)
192 TEST_FAILED (("g_ascii_%s returned 0x%X for 0x%X",
193 name, ascii_result, c));
198 test_digit_function (const char *name,
199 int (* ascii_function) (gchar),
200 int (* unicode_function) (gunichar))
204 for (c = 0; c <= 0x7F; c++)
206 int ascii_result = ascii_function ((gchar) c);
207 int unicode_result = unicode_function ((gunichar) c);
208 if (ascii_result != unicode_result)
209 TEST_FAILED (("g_ascii_%s_value returned %d and g_unichar_%s_value returned %d for 0x%X",
210 name, ascii_result, name, unicode_result, c));
212 for (c = 0x80; c <= 0xFF; c++)
214 int ascii_result = ascii_function ((gchar) c);
215 if (ascii_result != -1)
216 TEST_FAILED (("g_ascii_%s_value returned %d for 0x%X",
217 name, ascii_result, c));
226 gchar *vec[] = { "Foo", "Bar", NULL };
229 TEST (NULL, g_ascii_strcasecmp ("FroboZZ", "frobozz") == 0);
230 TEST (NULL, g_ascii_strcasecmp ("frobozz", "frobozz") == 0);
231 TEST (NULL, g_ascii_strcasecmp ("frobozz", "FROBOZZ") == 0);
232 TEST (NULL, g_ascii_strcasecmp ("FROBOZZ", "froboz") != 0);
233 TEST (NULL, g_ascii_strcasecmp ("", "") == 0);
234 TEST (NULL, g_ascii_strcasecmp ("!#%&/()", "!#%&/()") == 0);
235 TEST (NULL, g_ascii_strcasecmp ("a", "b") < 0);
236 TEST (NULL, g_ascii_strcasecmp ("a", "B") < 0);
237 TEST (NULL, g_ascii_strcasecmp ("A", "b") < 0);
238 TEST (NULL, g_ascii_strcasecmp ("A", "B") < 0);
239 TEST (NULL, g_ascii_strcasecmp ("b", "a") > 0);
240 TEST (NULL, g_ascii_strcasecmp ("b", "A") > 0);
241 TEST (NULL, g_ascii_strcasecmp ("B", "a") > 0);
242 TEST (NULL, g_ascii_strcasecmp ("B", "A") > 0);
244 TEST (NULL, g_strdup (NULL) == NULL);
245 string = g_strdup (GLIB_TEST_STRING);
246 TEST (NULL, string != NULL);
247 TEST (NULL, strcmp (string, GLIB_TEST_STRING) == 0);
250 string = g_strconcat (GLIB_TEST_STRING, NULL);
251 TEST (NULL, string != NULL);
252 TEST (NULL, strcmp (string, GLIB_TEST_STRING) == 0);
255 string = g_strconcat (GLIB_TEST_STRING, GLIB_TEST_STRING,
256 GLIB_TEST_STRING, NULL);
257 TEST (NULL, string != NULL);
258 TEST (NULL, strcmp (string, GLIB_TEST_STRING GLIB_TEST_STRING
259 GLIB_TEST_STRING) == 0);
262 string = g_strdup_printf ("%05d %-5s", 21, "test");
263 TEST (NULL, string != NULL);
264 TEST (NULL, strcmp(string, "00021 test ") == 0);
268 (g_strcompress ("abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313\\12345z"),
269 "abc\\\"\b\f\n\r\t\003\177\234\313\12345z") == 0);
270 TEST (NULL, strcmp (g_strescape("abc\\\"\b\f\n\r\t\003\177\234\313", NULL),
271 "abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313") == 0);
272 TEST (NULL, strcmp(g_strescape("abc\\\"\b\f\n\r\t\003\177\234\313",
273 "\b\f\001\002\003\004"),
274 "abc\\\\\\\"\b\f\\n\\r\\t\003\\177\\234\\313") == 0);
276 copy = g_strdupv (vec);
277 TEST (NULL, strcmp (copy[0], "Foo") == 0);
278 TEST (NULL, strcmp (copy[1], "Bar") == 0);
279 TEST (NULL, copy[2] == NULL);
282 TEST (NULL, strcmp (g_strstr_len ("FooBarFooBarFoo", 6, "Bar"),
283 "BarFooBarFoo") == 0);
284 TEST (NULL, strcmp (g_strrstr ("FooBarFooBarFoo", "Bar"),
286 TEST (NULL, strcmp (g_strrstr_len ("FooBarFooBarFoo", 14, "BarFoo"),
287 "BarFooBarFoo") == 0);
289 /* Test g_strsplit() */
290 TEST (NULL, strv_check (g_strsplit ("", ",", 0), NULL));
291 TEST (NULL, strv_check (g_strsplit ("x", ",", 0), "x", NULL));
292 TEST (NULL, strv_check (g_strsplit ("x,y", ",", 0), "x", "y", NULL));
293 TEST (NULL, strv_check (g_strsplit ("x,y,", ",", 0), "x", "y", "", NULL));
294 TEST (NULL, strv_check (g_strsplit (",x,y", ",", 0), "", "x", "y", NULL));
295 TEST (NULL, strv_check (g_strsplit (",x,y,", ",", 0), "", "x", "y", "", NULL));
296 TEST (NULL, strv_check (g_strsplit ("x,y,z", ",", 0), "x", "y", "z", NULL));
297 TEST (NULL, strv_check (g_strsplit ("x,y,z,", ",", 0), "x", "y", "z", "", NULL));
298 TEST (NULL, strv_check (g_strsplit (",x,y,z", ",", 0), "", "x", "y", "z", NULL));
299 TEST (NULL, strv_check (g_strsplit (",x,y,z,", ",", 0), "", "x", "y", "z", "", NULL));
300 TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",", 0), "", "", "x", "", "y", "", "z", "", "", NULL));
301 TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",,", 0), "", "x", "y", "z", "", NULL));
303 TEST (NULL, strv_check (g_strsplit ("", ",", 1), NULL));
304 TEST (NULL, strv_check (g_strsplit ("x", ",", 1), "x", NULL));
305 TEST (NULL, strv_check (g_strsplit ("x,y", ",", 1), "x,y", NULL));
306 TEST (NULL, strv_check (g_strsplit ("x,y,", ",", 1), "x,y,", NULL));
307 TEST (NULL, strv_check (g_strsplit (",x,y", ",", 1), ",x,y", NULL));
308 TEST (NULL, strv_check (g_strsplit (",x,y,", ",", 1), ",x,y,", NULL));
309 TEST (NULL, strv_check (g_strsplit ("x,y,z", ",", 1), "x,y,z", NULL));
310 TEST (NULL, strv_check (g_strsplit ("x,y,z,", ",", 1), "x,y,z,", NULL));
311 TEST (NULL, strv_check (g_strsplit (",x,y,z", ",", 1), ",x,y,z", NULL));
312 TEST (NULL, strv_check (g_strsplit (",x,y,z,", ",", 1), ",x,y,z,", NULL));
313 TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",", 1), ",,x,,y,,z,,", NULL));
314 TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",,", 1), ",,x,,y,,z,,", NULL));
316 TEST (NULL, strv_check (g_strsplit ("", ",", 2), NULL));
317 TEST (NULL, strv_check (g_strsplit ("x", ",", 2), "x", NULL));
318 TEST (NULL, strv_check (g_strsplit ("x,y", ",", 2), "x", "y", NULL));
319 TEST (NULL, strv_check (g_strsplit ("x,y,", ",", 2), "x", "y,", NULL));
320 TEST (NULL, strv_check (g_strsplit (",x,y", ",", 2), "", "x,y", NULL));
321 TEST (NULL, strv_check (g_strsplit (",x,y,", ",", 2), "", "x,y,", NULL));
322 TEST (NULL, strv_check (g_strsplit ("x,y,z", ",", 2), "x", "y,z", NULL));
323 TEST (NULL, strv_check (g_strsplit ("x,y,z,", ",", 2), "x", "y,z,", NULL));
324 TEST (NULL, strv_check (g_strsplit (",x,y,z", ",", 2), "", "x,y,z", NULL));
325 TEST (NULL, strv_check (g_strsplit (",x,y,z,", ",", 2), "", "x,y,z,", NULL));
326 TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",", 2), "", ",x,,y,,z,,", NULL));
327 TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",,", 2), "", "x,,y,,z,,", NULL));
329 /* Test g_strsplit_set() */
330 TEST (NULL, strv_check (g_strsplit_set ("", ",/", 0), NULL));
331 TEST (NULL, strv_check (g_strsplit_set (":def/ghi:", ":/", -1), "", "def", "ghi", "", NULL));
332 TEST (NULL, strv_check (g_strsplit_set ("abc:def/ghi", ":/", -1), "abc", "def", "ghi", NULL));
333 TEST (NULL, strv_check (g_strsplit_set (",;,;,;,;", ",;", -1), "", "", "", "", "", "", "", "", "", NULL));
334 TEST (NULL, strv_check (g_strsplit_set (",,abc.def", ".,", -1), "", "", "abc", "def", NULL));
336 TEST (NULL, strv_check (g_strsplit_set (",x.y", ",.", 0), "", "x", "y", NULL));
337 TEST (NULL, strv_check (g_strsplit_set (".x,y,", ",.", 0), "", "x", "y", "", NULL));
338 TEST (NULL, strv_check (g_strsplit_set ("x,y.z", ",.", 0), "x", "y", "z", NULL));
339 TEST (NULL, strv_check (g_strsplit_set ("x.y,z,", ",.", 0), "x", "y", "z", "", NULL));
340 TEST (NULL, strv_check (g_strsplit_set (",x.y,z", ",.", 0), "", "x", "y", "z", NULL));
341 TEST (NULL, strv_check (g_strsplit_set (",x,y,z,", ",.", 0), "", "x", "y", "z", "", NULL));
342 TEST (NULL, strv_check (g_strsplit_set (",.x,,y,;z..", ".,;", 0), "", "", "x", "", "y", "", "z", "", "", NULL));
343 TEST (NULL, strv_check (g_strsplit_set (",,x,,y,,z,,", ",,", 0), "", "", "x", "", "y", "", "z", "", "", NULL));
345 TEST (NULL, strv_check (g_strsplit_set ("x,y.z", ",.", 1), "x,y.z", NULL));
346 TEST (NULL, strv_check (g_strsplit_set ("x.y,z,", ",.", 1), "x.y,z,", NULL));
347 TEST (NULL, strv_check (g_strsplit_set (",x,y,z", ",.", 1), ",x,y,z", NULL));
348 TEST (NULL, strv_check (g_strsplit_set (",x,y.z,", ",.", 1), ",x,y.z,", NULL));
349 TEST (NULL, strv_check (g_strsplit_set (",,x,.y,,z,,", ",.", 1), ",,x,.y,,z,,", NULL));
350 TEST (NULL, strv_check (g_strsplit_set (",.x,,y,,z,,", ",,..", 1), ",.x,,y,,z,,", NULL));
352 TEST (NULL, strv_check (g_strsplit_set ("", ",", 0), NULL));
353 TEST (NULL, strv_check (g_strsplit_set ("x", ",", 0), "x", NULL));
354 TEST (NULL, strv_check (g_strsplit_set ("x,y", ",", 0), "x", "y", NULL));
355 TEST (NULL, strv_check (g_strsplit_set ("x,y,", ",", 0), "x", "y", "", NULL));
356 TEST (NULL, strv_check (g_strsplit_set (",x,y", ",", 0), "", "x", "y", NULL));
357 TEST (NULL, strv_check (g_strsplit_set (",x,y,", ",", 0), "", "x", "y", "", NULL));
358 TEST (NULL, strv_check (g_strsplit_set ("x,y,z", ",", 0), "x", "y", "z", NULL));
359 TEST (NULL, strv_check (g_strsplit_set ("x,y,z,", ",", 0), "x", "y", "z", "", NULL));
360 TEST (NULL, strv_check (g_strsplit_set (",x,y,z", ",", 0), "", "x", "y", "z", NULL));
361 TEST (NULL, strv_check (g_strsplit_set (",x,y,z,", ",", 0), "", "x", "y", "z", "", NULL));
362 TEST (NULL, strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 0), "", "", "x", "", "y", "", "z", "", "", NULL));
364 TEST (NULL, strv_check (g_strsplit_set ("", ",", 1), NULL));
365 TEST (NULL, strv_check (g_strsplit_set ("x", ",", 1), "x", NULL));
366 TEST (NULL, strv_check (g_strsplit_set ("x,y", ",", 1), "x,y", NULL));
367 TEST (NULL, strv_check (g_strsplit_set ("x,y,", ",", 1), "x,y,", NULL));
368 TEST (NULL, strv_check (g_strsplit_set (",x,y", ",", 1), ",x,y", NULL));
369 TEST (NULL, strv_check (g_strsplit_set (",x,y,", ",", 1), ",x,y,", NULL));
370 TEST (NULL, strv_check (g_strsplit_set ("x,y,z", ",", 1), "x,y,z", NULL));
371 TEST (NULL, strv_check (g_strsplit_set ("x,y,z,", ",", 1), "x,y,z,", NULL));
372 TEST (NULL, strv_check (g_strsplit_set (",x,y,z", ",", 1), ",x,y,z", NULL));
373 TEST (NULL, strv_check (g_strsplit_set (",x,y,z,", ",", 1), ",x,y,z,", NULL));
374 TEST (NULL, strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 1), ",,x,,y,,z,,", NULL));
375 TEST (NULL, strv_check (g_strsplit_set (",,x,,y,,z,,", ",,", 1), ",,x,,y,,z,,", NULL));
377 TEST (NULL, strv_check (g_strsplit_set ("", ",", 2), NULL));
378 TEST (NULL, strv_check (g_strsplit_set ("x", ",", 2), "x", NULL));
379 TEST (NULL, strv_check (g_strsplit_set ("x,y", ",", 2), "x", "y", NULL));
380 TEST (NULL, strv_check (g_strsplit_set ("x,y,", ",", 2), "x", "y,", NULL));
381 TEST (NULL, strv_check (g_strsplit_set (",x,y", ",", 2), "", "x,y", NULL));
382 TEST (NULL, strv_check (g_strsplit_set (",x,y,", ",", 2), "", "x,y,", NULL));
383 TEST (NULL, strv_check (g_strsplit_set ("x,y,z", ",", 2), "x", "y,z", NULL));
384 TEST (NULL, strv_check (g_strsplit_set ("x,y,z,", ",", 2), "x", "y,z,", NULL));
385 TEST (NULL, strv_check (g_strsplit_set (",x,y,z", ",", 2), "", "x,y,z", NULL));
386 TEST (NULL, strv_check (g_strsplit_set (",x,y,z,", ",", 2), "", "x,y,z,", NULL));
387 TEST (NULL, strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 2), "", ",x,,y,,z,,", NULL));
389 TEST (NULL, strv_check (g_strsplit_set (",,x,.y,..z,,", ",.", 3), "", "", "x,.y,..z,,", NULL));
393 #define TEST_IS(name) test_is_function (#name, call_g_ascii_##name, call_##name, g_unichar_##name);
395 FOR_ALL_CTYPE(TEST_IS)
399 #define TEST_TO(name) test_to_function (#name, g_ascii_##name, name, g_unichar_##name)
406 #define TEST_DIGIT(name) test_digit_function (#name, g_ascii_##name##_value, g_unichar_##name##_value)
413 /* Tests for strchomp () */
414 TEST (NULL, strchomp_check ("", ""));
415 TEST (NULL, strchomp_check (" ", ""));
416 TEST (NULL, strchomp_check (" \t\r\n", ""));
417 TEST (NULL, strchomp_check ("a ", "a"));
418 TEST (NULL, strchomp_check ("a ", "a"));
419 TEST (NULL, strchomp_check ("a a", "a a"));
420 TEST (NULL, strchomp_check ("a a ", "a a"));
422 /* Tests for g_build_path, g_build_filename */
424 TEST (NULL, str_check (g_build_path ("", NULL), ""));
425 TEST (NULL, str_check (g_build_path ("", "", NULL), ""));
426 TEST (NULL, str_check (g_build_path ("", "x", NULL), "x"));
427 TEST (NULL, str_check (g_build_path ("", "x", "y", NULL), "xy"));
428 TEST (NULL, str_check (g_build_path ("", "x", "y", "z", NULL), "xyz"));
430 TEST (NULL, str_check (g_build_path (":", NULL), ""));
431 TEST (NULL, str_check (g_build_path (":", ":", NULL), ":"));
432 TEST (NULL, str_check (g_build_path (":", ":x", NULL), ":x"));
433 TEST (NULL, str_check (g_build_path (":", "x:", NULL), "x:"));
434 TEST (NULL, str_check (g_build_path (":", "", "x", NULL), "x"));
435 TEST (NULL, str_check (g_build_path (":", "", ":x", NULL), ":x"));
436 TEST (NULL, str_check (g_build_path (":", ":", "x", NULL), ":x"));
437 TEST (NULL, str_check (g_build_path (":", "::", "x", NULL), "::x"));
438 TEST (NULL, str_check (g_build_path (":", "x", "", NULL), "x"));
439 TEST (NULL, str_check (g_build_path (":", "x:", "", NULL), "x:"));
440 TEST (NULL, str_check (g_build_path (":", "x", ":", NULL), "x:"));
441 TEST (NULL, str_check (g_build_path (":", "x", "::", NULL), "x::"));
442 TEST (NULL, str_check (g_build_path (":", "x", "y", NULL), "x:y"));
443 TEST (NULL, str_check (g_build_path (":", ":x", "y", NULL), ":x:y"));
444 TEST (NULL, str_check (g_build_path (":", "x", "y:", NULL), "x:y:"));
445 TEST (NULL, str_check (g_build_path (":", ":x:", ":y:", NULL), ":x:y:"));
446 TEST (NULL, str_check (g_build_path (":", ":x::", "::y:", NULL), ":x:y:"));
447 TEST (NULL, str_check (g_build_path (":", "x", "","y", NULL), "x:y"));
448 TEST (NULL, str_check (g_build_path (":", "x", ":", "y", NULL), "x:y"));
449 TEST (NULL, str_check (g_build_path (":", "x", "::", "y", NULL), "x:y"));
450 TEST (NULL, str_check (g_build_path (":", "x", "y", "z", NULL), "x:y:z"));
451 TEST (NULL, str_check (g_build_path (":", ":x:", ":y:", ":z:", NULL), ":x:y:z:"));
452 TEST (NULL, str_check (g_build_path (":", "::x::", "::y::", "::z::", NULL), "::x:y:z::"));
454 TEST (NULL, str_check (g_build_path ("::", NULL), ""));
455 TEST (NULL, str_check (g_build_path ("::", "::", NULL), "::"));
456 TEST (NULL, str_check (g_build_path ("::", ":::", NULL), ":::"));
457 TEST (NULL, str_check (g_build_path ("::", "::x", NULL), "::x"));
458 TEST (NULL, str_check (g_build_path ("::", "x::", NULL), "x::"));
459 TEST (NULL, str_check (g_build_path ("::", "", "x", NULL), "x"));
460 TEST (NULL, str_check (g_build_path ("::", "", "::x", NULL), "::x"));
461 TEST (NULL, str_check (g_build_path ("::", "::", "x", NULL), "::x"));
462 TEST (NULL, str_check (g_build_path ("::", "::::", "x", NULL), "::::x"));
463 TEST (NULL, str_check (g_build_path ("::", "x", "", NULL), "x"));
464 TEST (NULL, str_check (g_build_path ("::", "x::", "", NULL), "x::"));
465 TEST (NULL, str_check (g_build_path ("::", "x", "::", NULL), "x::"));
466 /* This following is weird, but keeps the definition simple */
467 TEST (NULL, str_check (g_build_path ("::", "x", ":::", NULL), "x:::::"));
468 TEST (NULL, str_check (g_build_path ("::", "x", "::::", NULL), "x::::"));
469 TEST (NULL, str_check (g_build_path ("::", "x", "y", NULL), "x::y"));
470 TEST (NULL, str_check (g_build_path ("::", "::x", "y", NULL), "::x::y"));
471 TEST (NULL, str_check (g_build_path ("::", "x", "y::", NULL), "x::y::"));
472 TEST (NULL, str_check (g_build_path ("::", "::x::", "::y::", NULL), "::x::y::"));
473 TEST (NULL, str_check (g_build_path ("::", "::x:::", ":::y::", NULL), "::x::::y::"));
474 TEST (NULL, str_check (g_build_path ("::", "::x::::", "::::y::", NULL), "::x::y::"));
475 TEST (NULL, str_check (g_build_path ("::", "x", "", "y", NULL), "x::y"));
476 TEST (NULL, str_check (g_build_path ("::", "x", "::", "y", NULL), "x::y"));
477 TEST (NULL, str_check (g_build_path ("::", "x", "::::", "y", NULL), "x::y"));
478 TEST (NULL, str_check (g_build_path ("::", "x", "y", "z", NULL), "x::y::z"));
479 TEST (NULL, str_check (g_build_path ("::", "::x::", "::y::", "::z::", NULL), "::x::y::z::"));
480 TEST (NULL, str_check (g_build_path ("::", ":::x:::", ":::y:::", ":::z:::", NULL), ":::x::::y::::z:::"));
481 TEST (NULL, str_check (g_build_path ("::", "::::x::::", "::::y::::", "::::z::::", NULL), "::::x::y::z::::"));
483 #define S G_DIR_SEPARATOR_S
485 TEST (NULL, str_check (g_build_filename (NULL), ""));
486 TEST (NULL, str_check (g_build_filename (S, NULL), S));
487 TEST (NULL, str_check (g_build_filename (S"x", NULL), S"x"));
488 TEST (NULL, str_check (g_build_filename ("x"S, NULL), "x"S));
489 TEST (NULL, str_check (g_build_filename ("", "x", NULL), "x"));
490 TEST (NULL, str_check (g_build_filename ("", S"x", NULL), S"x"));
491 TEST (NULL, str_check (g_build_filename (S, "x", NULL), S"x"));
492 TEST (NULL, str_check (g_build_filename (S S, "x", NULL), S S"x"));
493 TEST (NULL, str_check (g_build_filename ("x", "", NULL), "x"));
494 TEST (NULL, str_check (g_build_filename ("x"S, "", NULL), "x"S));
495 TEST (NULL, str_check (g_build_filename ("x", S, NULL), "x"S));
496 TEST (NULL, str_check (g_build_filename ("x", S S, NULL), "x"S S));
497 TEST (NULL, str_check (g_build_filename ("x", "y", NULL), "x"S"y"));
498 TEST (NULL, str_check (g_build_filename (S"x", "y", NULL), S"x"S"y"));
499 TEST (NULL, str_check (g_build_filename ("x", "y"S, NULL), "x"S"y"S));
500 TEST (NULL, str_check (g_build_filename (S"x"S, S"y"S, NULL), S"x"S"y"S));
501 TEST (NULL, str_check (g_build_filename (S"x"S S, S S"y"S, NULL), S"x"S"y"S));
502 TEST (NULL, str_check (g_build_filename ("x", "", "y", NULL), "x"S"y"));
503 TEST (NULL, str_check (g_build_filename ("x", S, "y", NULL), "x"S"y"));
504 TEST (NULL, str_check (g_build_filename ("x", S S, "y", NULL), "x"S"y"));
505 TEST (NULL, str_check (g_build_filename ("x", "y", "z", NULL), "x"S"y"S"z"));
506 TEST (NULL, str_check (g_build_filename (S"x"S, S"y"S, S"z"S, NULL), S"x"S"y"S"z"S));
507 TEST (NULL, str_check (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));
511 /* Test also using the slash as file name separator */
513 TEST (NULL, str_check (g_build_filename (NULL), ""));
514 TEST (NULL, str_check (g_build_filename (U, NULL), U));
515 TEST (NULL, str_check (g_build_filename (U"x", NULL), U"x"));
516 TEST (NULL, str_check (g_build_filename ("x"U, NULL), "x"U));
517 TEST (NULL, str_check (g_build_filename ("", U"x", NULL), U"x"));
518 TEST (NULL, str_check (g_build_filename ("", U"x", NULL), U"x"));
519 TEST (NULL, str_check (g_build_filename (U, "x", NULL), U"x"));
520 TEST (NULL, str_check (g_build_filename (U U, "x", NULL), U U"x"));
521 TEST (NULL, str_check (g_build_filename (U S, "x", NULL), U S"x"));
522 TEST (NULL, str_check (g_build_filename ("x"U, "", NULL), "x"U));
523 TEST (NULL, str_check (g_build_filename ("x"S"y", "z"U"a", NULL), "x"S"y"S"z"U"a"));
524 TEST (NULL, str_check (g_build_filename ("x", U, NULL), "x"U));
525 TEST (NULL, str_check (g_build_filename ("x", U U, NULL), "x"U U));
526 TEST (NULL, str_check (g_build_filename ("x", S U, NULL), "x"S U));
527 TEST (NULL, str_check (g_build_filename (U"x", "y", NULL), U"x"U"y"));
528 TEST (NULL, str_check (g_build_filename ("x", "y"U, NULL), "x"U"y"U));
529 TEST (NULL, str_check (g_build_filename (U"x"U, U"y"U, NULL), U"x"U"y"U));
530 TEST (NULL, str_check (g_build_filename (U"x"U U, U U"y"U, NULL), U"x"U"y"U));
531 TEST (NULL, str_check (g_build_filename ("x", U, "y", NULL), "x"U"y"));
532 TEST (NULL, str_check (g_build_filename ("x", U U, "y", NULL), "x"U"y"));
533 TEST (NULL, str_check (g_build_filename ("x", U S, "y", NULL), "x"S"y"));
534 TEST (NULL, str_check (g_build_filename ("x", S U, "y", NULL), "x"U"y"));
535 TEST (NULL, str_check (g_build_filename ("x", U "y", "z", NULL), "x"U"y"U"z"));
536 TEST (NULL, str_check (g_build_filename ("x", S "y", "z", NULL), "x"S"y"S"z"));
537 TEST (NULL, str_check (g_build_filename ("x", S "y", "z", U, "a", "b", NULL), "x"S"y"S"z"U"a"U"b"));
538 TEST (NULL, str_check (g_build_filename (U"x"U, U"y"U, U"z"U, NULL), U"x"U"y"U"z"U));
539 TEST (NULL, str_check (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));
540 #endif /* G_OS_WIN32 */
547 TEST (NULL, 3 == g_snprintf (buf, 0, "%s", "abc"));
548 TEST (NULL, 3 == g_snprintf (NULL,0, "%s", "abc"));
549 TEST (NULL, 3 == g_snprintf (buf, 5, "%s", "abc"));
550 TEST (NULL, 4 == g_snprintf (buf, 5, "%s", "abcd"));
551 TEST (NULL, 9 == g_snprintf (buf, 5, "%s", "abcdefghi"));
554 TEST (NULL, g_strv_length (g_strsplit ("1,2,3,4", ",", -1)) == 4);