1 /* Unit tests for gstrfuncs
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * SPDX-License-Identifier: LicenseRef-old-glib-tests
6 * This work is provided "as is"; redistribution and modification
7 * in whole or in part, in any medium, physical or electronic is
8 * permitted without restriction.
10 * This work is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * In no event shall the authors or contributors be liable for any
15 * direct, indirect, incidental, special, exemplary, or consequential
16 * damages (including, but not limited to, procurement of substitute
17 * goods or services; loss of use, data, or profits; or business
18 * interruption) however caused and on any theory of liability, whether
19 * in contract, strict liability, or tort (including negligence or
20 * otherwise) arising in any way out of the use of this software, even
21 * if advised of the possibility of such damage.
24 #ifndef GLIB_DISABLE_DEPRECATION_WARNINGS
25 #define GLIB_DISABLE_DEPRECATION_WARNINGS
28 #define _XOPEN_SOURCE 600
39 #if defined (_MSC_VER) && (_MSC_VER <= 1800)
40 #define isnan(x) _isnan(x)
43 static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
44 #define NAN (*(const float *) __nan)
48 #define INFINITY HUGE_VAL
53 #define GLIB_TEST_STRING "el dorado "
55 #define FOR_ALL_CTYPE(macro) \
68 #define DEFINE_CALL_CTYPE(function) \
70 call_##function (int c) \
72 return function (c); \
75 #define DEFINE_CALL_G_ASCII_CTYPE(function) \
77 call_g_ascii_##function (gchar c) \
79 return g_ascii_##function (c); \
82 FOR_ALL_CTYPE (DEFINE_CALL_CTYPE)
83 FOR_ALL_CTYPE (DEFINE_CALL_G_ASCII_CTYPE)
86 test_is_function (const char *name,
87 gboolean (* ascii_function) (gchar),
88 int (* c_library_function) (int),
89 gboolean (* unicode_function) (gunichar))
93 for (c = 0; c <= 0x7F; c++)
95 gboolean ascii_result = ascii_function ((gchar)c);
96 gboolean c_library_result = c_library_function (c) != 0;
97 gboolean unicode_result = unicode_function ((gunichar) c);
98 if (ascii_result != c_library_result && c != '\v')
100 g_error ("g_ascii_%s returned %d and %s returned %d for 0x%X",
101 name, ascii_result, name, c_library_result, c);
103 if (ascii_result != unicode_result)
105 g_error ("g_ascii_%s returned %d and g_unichar_%s returned %d for 0x%X",
106 name, ascii_result, name, unicode_result, c);
109 for (c = 0x80; c <= 0xFF; c++)
111 gboolean ascii_result = ascii_function ((gchar)c);
114 g_error ("g_ascii_%s returned TRUE for 0x%X", name, c);
120 test_to_function (const char *name,
121 gchar (* ascii_function) (gchar),
122 int (* c_library_function) (int),
123 gunichar (* unicode_function) (gunichar))
127 for (c = 0; c <= 0x7F; c++)
129 int ascii_result = (guchar) ascii_function ((gchar) c);
130 int c_library_result = c_library_function (c);
131 int unicode_result = unicode_function ((gunichar) c);
132 if (ascii_result != c_library_result)
134 g_error ("g_ascii_%s returned 0x%X and %s returned 0x%X for 0x%X",
135 name, ascii_result, name, c_library_result, c);
137 if (ascii_result != unicode_result)
139 g_error ("g_ascii_%s returned 0x%X and g_unichar_%s returned 0x%X for 0x%X",
140 name, ascii_result, name, unicode_result, c);
143 for (c = 0x80; c <= 0xFF; c++)
145 int ascii_result = (guchar) ascii_function ((gchar) c);
146 if (ascii_result != c)
148 g_error ("g_ascii_%s returned 0x%X for 0x%X",
149 name, ascii_result, c);
155 test_digit_function (const char *name,
156 int (* ascii_function) (gchar),
157 int (* unicode_function) (gunichar))
161 for (c = 0; c <= 0x7F; c++)
163 int ascii_result = ascii_function ((gchar) c);
164 int unicode_result = unicode_function ((gunichar) c);
165 if (ascii_result != unicode_result)
167 g_error ("g_ascii_%s_value returned %d and g_unichar_%s_value returned %d for 0x%X",
168 name, ascii_result, name, unicode_result, c);
171 for (c = 0x80; c <= 0xFF; c++)
173 int ascii_result = ascii_function ((gchar) c);
174 if (ascii_result != -1)
176 g_error ("g_ascii_%s_value returned %d for 0x%X",
177 name, ascii_result, c);
183 test_is_to_digit (void)
185 #define TEST_IS(name) test_is_function (#name, call_g_ascii_##name, call_##name, g_unichar_##name);
187 FOR_ALL_CTYPE(TEST_IS)
191 #define TEST_TO(name) test_to_function (#name, g_ascii_##name, name, g_unichar_##name)
198 #define TEST_DIGIT(name) test_digit_function (#name, g_ascii_##name##_value, g_unichar_##name##_value)
206 /* Testing g_memdup() function with various positive and negative cases */
210 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
212 gchar *str_dup = NULL;
213 const gchar *str = "The quick brown fox jumps over the lazy dog";
215 /* Testing negative cases */
216 g_assert_null (g_memdup (NULL, 1024));
217 g_assert_null (g_memdup (str, 0));
218 g_assert_null (g_memdup (NULL, 0));
220 /* Testing normal usage cases */
221 str_dup = g_memdup (str, strlen (str) + 1);
222 g_assert_nonnull (str_dup);
223 g_assert_cmpstr (str, ==, str_dup);
227 G_GNUC_END_IGNORE_DEPRECATIONS
230 /* Testing g_memdup2() function with various positive and negative cases */
234 gchar *str_dup = NULL;
235 const gchar *str = "The quick brown fox jumps over the lazy dog";
237 /* Testing negative cases */
238 g_assert_null (g_memdup2 (NULL, 1024));
239 g_assert_null (g_memdup2 (str, 0));
240 g_assert_null (g_memdup2 (NULL, 0));
242 /* Testing normal usage cases */
243 str_dup = g_memdup2 (str, strlen (str) + 1);
244 g_assert_nonnull (str_dup);
245 g_assert_cmpstr (str, ==, str_dup);
250 /* Testing g_strpcpy() function with various positive and negative cases */
254 gchar *str = "The quick brown fox jumps over the lazy dog";
255 gchar str_cpy[45], *str_cpy_end = NULL;
257 if (g_test_undefined ())
259 /* Testing degenerated cases */
260 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
261 "*assertion*!= NULL*");
262 str_cpy_end = g_stpcpy (str_cpy, NULL);
263 g_test_assert_expected_messages ();
265 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
266 "*assertion*!= NULL*");
267 str_cpy_end = g_stpcpy (NULL, str);
268 g_test_assert_expected_messages ();
271 /* Testing normal usage cases */
272 str_cpy_end = g_stpcpy (str_cpy, str);
273 g_assert_nonnull (str_cpy);
274 g_assert_true (str_cpy + strlen (str) == str_cpy_end);
275 g_assert_cmpstr (str, ==, str_cpy);
276 g_assert_cmpstr (str, ==, str_cpy_end - strlen (str));
279 /* Testing g_strlcpy() function with various positive and negative cases */
283 gchar *str = "The quick brown fox jumps over the lazy dog";
285 gsize str_cpy_size = 0;
287 if (g_test_undefined ())
289 /* Testing degenerated cases */
290 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
291 "*assertion*!= NULL*");
292 str_cpy_size = g_strlcpy (str_cpy, NULL, 0);
293 g_test_assert_expected_messages ();
294 /* Returned 0 because g_strlcpy() failed */
295 g_assert_cmpint (str_cpy_size, ==, 0);
297 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
298 "*assertion*!= NULL*");
299 str_cpy_size = g_strlcpy (NULL, str, 0);
300 g_test_assert_expected_messages ();
301 /* Returned 0 because g_strlcpy() failed */
302 g_assert_cmpint (str_cpy_size, ==, 0);
305 str_cpy_size = g_strlcpy (str_cpy, "", 0);
306 g_assert_cmpint (str_cpy_size, ==, strlen (""));
308 /* Testing normal usage cases.
309 * Note that the @dest_size argument to g_strlcpy() is normally meant to be
310 * set to `sizeof (dest)`. We set it to various values `≤ sizeof (str_cpy)`
311 * for testing purposes. */
312 str_cpy_size = g_strlcpy (str_cpy, str, strlen (str) + 1);
313 g_assert_nonnull (str_cpy);
314 g_assert_cmpstr (str, ==, str_cpy);
315 g_assert_cmpint (str_cpy_size, ==, strlen (str));
317 str_cpy_size = g_strlcpy (str_cpy, str, strlen (str));
318 g_assert_nonnull (str_cpy);
319 g_assert_cmpstr ("The quick brown fox jumps over the lazy do", ==, str_cpy);
320 g_assert_cmpint (str_cpy_size, ==, strlen (str));
322 str_cpy_size = g_strlcpy (str_cpy, str, strlen (str) - 15);
323 g_assert_nonnull (str_cpy);
324 g_assert_cmpstr ("The quick brown fox jumps o", ==, str_cpy);
325 g_assert_cmpint (str_cpy_size, ==, strlen (str));
327 str_cpy_size = g_strlcpy (str_cpy, str, 0);
328 g_assert_nonnull (str_cpy);
329 g_assert_cmpstr ("The quick brown fox jumps o", ==, str_cpy);
330 g_assert_cmpint (str_cpy_size, ==, strlen (str));
332 str_cpy_size = g_strlcpy (str_cpy, str, strlen (str) + 15);
333 g_assert_nonnull (str_cpy);
334 g_assert_cmpstr (str, ==, str_cpy);
335 g_assert_cmpint (str_cpy_size, ==, strlen (str));
338 /* Testing g_strlcat() function with various positive and negative cases */
342 gchar *str = "The quick brown fox jumps over the lazy dog";
343 gchar str_cpy[60] = { 0 };
344 gsize str_cpy_size = 0;
346 if (g_test_undefined ())
348 /* Testing degenerated cases */
349 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
350 "*assertion*!= NULL*");
351 str_cpy_size = g_strlcat (str_cpy, NULL, 0);
352 g_test_assert_expected_messages ();
353 /* Returned 0 because g_strlcpy() failed */
354 g_assert_cmpint (str_cpy_size, ==, 0);
356 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
357 "*assertion*!= NULL*");
358 str_cpy_size = g_strlcat (NULL, str, 0);
359 g_test_assert_expected_messages ();
360 /* Returned 0 because g_strlcpy() failed */
361 g_assert_cmpint (str_cpy_size, ==, 0);
364 str_cpy_size = g_strlcat (str_cpy, "", 0);
365 g_assert_cmpint (str_cpy_size, ==, strlen (""));
367 /* Testing normal usage cases.
368 * Note that the @dest_size argument to g_strlcat() is normally meant to be
369 * set to `sizeof (dest)`. We set it to various values `≤ sizeof (str_cpy)`
370 * for testing purposes. */
371 g_assert_cmpuint (strlen (str) + 1, <=, sizeof (str_cpy));
372 str_cpy_size = g_strlcat (str_cpy, str, strlen (str) + 1);
373 g_assert_cmpstr (str, ==, str_cpy);
374 g_assert_cmpint (str_cpy_size, ==, strlen (str));
376 g_assert_cmpuint (strlen (str), <=, sizeof (str_cpy));
377 str_cpy_size = g_strlcat (str_cpy, str, strlen (str));
378 g_assert_cmpstr (str, ==, str_cpy);
379 g_assert_cmpint (str_cpy_size, ==, 2 * strlen (str));
381 g_assert_cmpuint (strlen (str) - 15, <=, sizeof (str_cpy));
382 str_cpy_size = g_strlcat (str_cpy, str, strlen (str) - 15);
383 g_assert_cmpstr (str, ==, str_cpy);
384 g_assert_cmpint (str_cpy_size, ==, 2 * strlen (str) - 15);
386 g_assert_cmpuint (0, <=, sizeof (str_cpy));
387 str_cpy_size = g_strlcat (str_cpy, str, 0);
388 g_assert_cmpstr (str, ==, str_cpy);
389 g_assert_cmpint (str_cpy_size, ==, strlen (str));
391 g_assert_cmpuint (strlen (str) + 15, <=, sizeof (str_cpy));
392 str_cpy_size = g_strlcat (str_cpy, str, strlen (str) + 15);
393 g_assert_cmpstr ("The quick brown fox jumps over the lazy dogThe quick brow",
395 g_assert_cmpint (str_cpy_size, ==, 2 * strlen (str));
398 /* Testing g_ascii_strdown() function with various positive and negative cases */
400 test_ascii_strdown (void)
402 const gchar *str_down = "the quick brown fox jumps over the lazy dog.";
403 const gchar *str_up = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.";
406 if (g_test_undefined ())
408 /* Testing degenerated cases */
409 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
410 "*assertion*!= NULL*");
411 str = g_ascii_strdown (NULL, 0);
412 g_test_assert_expected_messages ();
415 str = g_ascii_strdown ("", 0);
416 g_assert_nonnull (str);
417 g_assert_cmpstr (str, ==, "");
420 str = g_ascii_strdown ("", -1);
421 g_assert_nonnull (str);
422 g_assert_cmpstr (str, ==, "");
425 /* Testing normal usage cases */
426 str = g_ascii_strdown (str_down, strlen (str_down));
427 g_assert_nonnull (str);
428 g_assert_cmpstr (str, ==, str_down);
431 str = g_ascii_strdown (str_up, strlen (str_up));
432 g_assert_nonnull (str);
433 g_assert_cmpstr (str, ==, str_down);
436 str = g_ascii_strdown (str_up, -1);
437 g_assert_nonnull (str);
438 g_assert_cmpstr (str, ==, str_down);
441 str = g_ascii_strdown (str_up, 0);
442 g_assert_nonnull (str);
443 g_assert_cmpstr (str, ==, "");
447 /* Testing g_ascii_strup() function with various positive and negative cases */
449 test_ascii_strup (void)
451 const gchar *str_down = "the quick brown fox jumps over the lazy dog.";
452 const gchar *str_up = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.";
455 if (g_test_undefined ())
457 /* Testing degenerated cases */
458 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
459 "*assertion*!= NULL*");
460 str = g_ascii_strup (NULL, 0);
461 g_test_assert_expected_messages ();
464 str = g_ascii_strup ("", 0);
465 g_assert_nonnull (str);
466 g_assert_cmpstr (str, ==, "");
469 str = g_ascii_strup ("", -1);
470 g_assert_nonnull (str);
471 g_assert_cmpstr (str, ==, "");
474 /* Testing normal usage cases */
475 str = g_ascii_strup (str_up, strlen (str_up));
476 g_assert_nonnull (str);
477 g_assert_cmpstr (str, ==, str_up);
480 str = g_ascii_strup (str_down, strlen (str_down));
481 g_assert_nonnull (str);
482 g_assert_cmpstr (str, ==, str_up);
485 str = g_ascii_strup (str_down, -1);
486 g_assert_nonnull (str);
487 g_assert_cmpstr (str, ==, str_up);
490 str = g_ascii_strup (str_down, 0);
491 g_assert_nonnull (str);
492 g_assert_cmpstr (str, ==, "");
496 /* Testing g_strdup() function with various positive and negative cases */
502 g_assert_null ((g_strdup) (NULL));
504 str = (g_strdup) (GLIB_TEST_STRING);
505 g_assert_nonnull (str);
506 g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
508 char *other_str = (g_strdup) (str);
511 g_assert_nonnull (other_str);
512 g_assert_cmpstr (other_str, ==, GLIB_TEST_STRING);
513 g_clear_pointer (&other_str, g_free);
515 str = (g_strdup) ("");
516 g_assert_cmpint (str[0], ==, '\0');
517 g_assert_cmpstr (str, ==, "");
518 g_clear_pointer (&str, g_free);
522 test_strdup_inline (void)
526 #if G_GNUC_CHECK_VERSION (2, 0)
528 #error g_strdup() should be defined as a macro in this platform!
531 g_test_incomplete ("g_strdup() is not inlined in this platform");
534 /* Testing inline version of g_strdup() function with various positive and
537 g_assert_null (g_strdup (NULL));
539 str = g_strdup (GLIB_TEST_STRING);
540 g_assert_nonnull (str);
541 g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
543 char *other_str = g_strdup (str);
544 g_clear_pointer (&str, g_free);
546 g_assert_nonnull (other_str);
547 g_assert_cmpstr (other_str, ==, GLIB_TEST_STRING);
548 g_clear_pointer (&other_str, g_free);
551 g_assert_cmpint (str[0], ==, '\0');
552 g_assert_cmpstr (str, ==, "");
553 g_clear_pointer (&str, g_free);
556 /* Testing g_strndup() function with various positive and negative cases */
562 str = g_strndup (NULL, 3);
565 str = g_strndup ("aaaa", 5);
566 g_assert_nonnull (str);
567 g_assert_cmpstr (str, ==, "aaaa");
570 str = g_strndup ("aaaa", 2);
571 g_assert_nonnull (str);
572 g_assert_cmpstr (str, ==, "aa");
576 /* Testing g_strdup_printf() function with various positive and negative cases */
578 test_strdup_printf (void)
582 str = g_strdup_printf ("%05d %-5s", 21, "test");
583 g_assert_nonnull (str);
584 g_assert_cmpstr (str, ==, "00021 test ");
588 /* Testing g_strdupv() function with various positive and negative cases */
592 gchar *vec[] = { "Foo", "Bar", NULL };
595 copy = g_strdupv (NULL);
596 g_assert_null (copy);
598 copy = g_strdupv (vec);
599 g_assert_nonnull (copy);
600 g_assert_cmpstrv (copy, vec);
604 /* Testing g_strfill() function with various positive and negative cases */
610 str = g_strnfill (0, 'a');
611 g_assert_nonnull (str);
612 g_assert_true (*str == '\0');
615 str = g_strnfill (5, 'a');
616 g_assert_nonnull (str);
617 g_assert_cmpstr (str, ==, "aaaaa");
621 /* Testing g_strconcat() function with various positive and negative cases */
623 test_strconcat (void)
627 str = g_strconcat (GLIB_TEST_STRING, NULL);
628 g_assert_nonnull (str);
629 g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
632 str = g_strconcat (GLIB_TEST_STRING,
636 g_assert_nonnull (str);
637 g_assert_cmpstr (str, ==, GLIB_TEST_STRING GLIB_TEST_STRING GLIB_TEST_STRING);
640 g_assert_null (g_strconcat (NULL, "bla", NULL));
643 /* Testing g_strjoinv() function with various positive and negative cases */
647 gchar *strings[] = { "string1", "string2", NULL };
648 gchar *empty_strings[] = { NULL };
651 if (g_test_undefined ())
653 /* Testing degenerated cases */
654 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
655 "*assertion*!= NULL*");
656 str = g_strjoinv (NULL, NULL);
657 g_test_assert_expected_messages ();
660 str = g_strjoinv (":", strings);
661 g_assert_nonnull (str);
662 g_assert_cmpstr (str, ==, "string1:string2");
665 str = g_strjoinv (NULL, strings);
666 g_assert_nonnull (str);
667 g_assert_cmpstr (str, ==, "string1string2");
670 str = g_strjoinv (NULL, empty_strings);
671 g_assert_nonnull (str);
672 g_assert_cmpstr (str, ==, "");
676 /* Testing g_strjoin() function with various positive and negative cases */
682 str = g_strjoin (NULL, NULL);
683 g_assert_nonnull (str);
684 g_assert_true (*str == '\0');
687 str = g_strjoin (":", NULL);
688 g_assert_nonnull (str);
689 g_assert_true (*str == '\0');
692 str = g_strjoin (NULL, GLIB_TEST_STRING, NULL);
693 g_assert_nonnull (str);
694 g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
697 str = g_strjoin (NULL,
702 g_assert_nonnull (str);
703 g_assert_cmpstr (str, ==, GLIB_TEST_STRING GLIB_TEST_STRING GLIB_TEST_STRING);
706 str = g_strjoin (":",
711 g_assert_nonnull (str);
712 g_assert_cmpstr (str, ==, GLIB_TEST_STRING ":" GLIB_TEST_STRING ":" GLIB_TEST_STRING);
716 /* Testing g_strcanon() function with various positive and negative cases */
722 if (g_test_undefined ())
726 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
727 "*assertion*!= NULL*");
728 str = g_strcanon (NULL, "ab", 'y');
729 g_test_assert_expected_messages ();
732 str = g_strdup ("abxabxab");
733 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
734 "*assertion*!= NULL*");
735 ret = g_strcanon (str, NULL, 'y');
736 g_test_assert_expected_messages ();
741 str = g_strdup ("abxabxab");
742 str = g_strcanon (str, "ab", 'y');
743 g_assert_nonnull (str);
744 g_assert_cmpstr (str, ==, "abyabyab");
748 /* Testing g_strcompress() and g_strescape() functions with various cases */
750 test_strcompress_strescape (void)
756 if (g_test_undefined ())
758 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
759 "*assertion*!= NULL*");
760 str = g_strcompress (NULL);
761 g_test_assert_expected_messages ();
764 /* trailing slashes are not allowed */
765 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
767 str = g_strcompress ("abc\\");
768 g_test_assert_expected_messages ();
769 g_assert_cmpstr (str, ==, "abc");
773 str = g_strcompress ("abc\\\\\\\"\\b\\f\\n\\r\\t\\v\\003\\177\\234\\313\\12345z");
774 g_assert_nonnull (str);
775 g_assert_cmpstr (str, ==, "abc\\\"\b\f\n\r\t\v\003\177\234\313\12345z");
779 if (g_test_undefined ())
781 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
782 "*assertion*!= NULL*");
783 str = g_strescape (NULL, NULL);
784 g_test_assert_expected_messages ();
788 str = g_strescape ("abc\\\"\b\f\n\r\t\v\003\177\234\313", NULL);
789 g_assert_nonnull (str);
790 g_assert_cmpstr (str, ==, "abc\\\\\\\"\\b\\f\\n\\r\\t\\v\\003\\177\\234\\313");
793 str = g_strescape ("abc\\\"\b\f\n\r\t\v\003\177\234\313",
794 "\b\f\001\002\003\004");
795 g_assert_nonnull (str);
796 g_assert_cmpstr (str, ==, "abc\\\\\\\"\b\f\\n\\r\\t\\v\003\\177\\234\\313");
800 tmp = g_strescape ("abc\\\"\b\f\n\r\t\v\003\177\234\313", NULL);
801 str = g_strcompress (tmp);
802 g_assert_nonnull (str);
803 g_assert_cmpstr (str, ==, "abc\\\"\b\f\n\r\t\v\003\177\234\313");
807 /* Unicode round trip */
808 str = g_strescape ("héllø there⸘", NULL);
809 g_assert_nonnull (str);
810 g_assert_cmpstr (str, ==, "h\\303\\251ll\\303\\270 there\\342\\270\\230");
811 tmp = g_strcompress (str);
812 g_assert_nonnull (tmp);
813 g_assert_cmpstr (tmp, ==, "héllø there⸘");
817 /* Test expanding invalid escapes */
818 str = g_strcompress ("\\11/ \\118 \\8aa \\19");
819 g_assert_nonnull (str);
820 g_assert_cmpstr (str, ==, "\t/ \t8 8aa \0019");
824 /* Testing g_ascii_strcasecmp() and g_ascii_strncasecmp() */
826 test_ascii_strcasecmp (void)
830 if (g_test_undefined ())
832 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
833 "*assertion*!= NULL*");
834 res = g_ascii_strcasecmp ("foo", NULL);
835 g_test_assert_expected_messages ();
836 g_assert_false (res);
838 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
839 "*assertion*!= NULL*");
840 res = g_ascii_strcasecmp (NULL, "foo");
841 g_test_assert_expected_messages ();
842 g_assert_false (res);
844 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
845 "*assertion*!= NULL*");
846 res = g_ascii_strncasecmp ("foo", NULL, 0);
847 g_test_assert_expected_messages ();
848 g_assert_false (res);
850 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
851 "*assertion*!= NULL*");
852 res = g_ascii_strncasecmp (NULL, "foo", 0);
853 g_test_assert_expected_messages ();
854 g_assert_false (res);
857 res = g_ascii_strcasecmp ("FroboZZ", "frobozz");
858 g_assert_cmpint (res, ==, 0);
860 res = g_ascii_strcasecmp ("frobozz", "frobozz");
861 g_assert_cmpint (res, ==, 0);
863 res = g_ascii_strcasecmp ("frobozz", "FROBOZZ");
864 g_assert_cmpint (res, ==, 0);
866 res = g_ascii_strcasecmp ("FROBOZZ", "froboz");
867 g_assert_cmpint (res, !=, 0);
869 res = g_ascii_strcasecmp ("", "");
870 g_assert_cmpint (res, ==, 0);
872 res = g_ascii_strcasecmp ("!#%&/()", "!#%&/()");
873 g_assert_cmpint (res, ==, 0);
875 res = g_ascii_strcasecmp ("a", "b");
876 g_assert_cmpint (res, <, 0);
878 res = g_ascii_strcasecmp ("a", "B");
879 g_assert_cmpint (res, <, 0);
881 res = g_ascii_strcasecmp ("A", "b");
882 g_assert_cmpint (res, <, 0);
884 res = g_ascii_strcasecmp ("A", "B");
885 g_assert_cmpint (res, <, 0);
887 res = g_ascii_strcasecmp ("b", "a");
888 g_assert_cmpint (res, >, 0);
890 res = g_ascii_strcasecmp ("b", "A");
891 g_assert_cmpint (res, >, 0);
893 res = g_ascii_strcasecmp ("B", "a");
894 g_assert_cmpint (res, >, 0);
896 res = g_ascii_strcasecmp ("B", "A");
897 g_assert_cmpint (res, >, 0);
899 /* g_ascii_strncasecmp() */
900 res = g_ascii_strncasecmp ("", "", 10);
901 g_assert_cmpint (res, ==, 0);
903 res = g_ascii_strncasecmp ("Frob0ZZ", "frob0zz", strlen ("frobozz"));
904 g_assert_cmpint (res, ==, 0);
906 res = g_ascii_strncasecmp ("Frob0ZZ", "frobozz", strlen ("frobozz"));
907 g_assert_cmpint (res, !=, 0);
909 res = g_ascii_strncasecmp ("frob0ZZ", "FroB0zz", strlen ("frobozz"));
910 g_assert_cmpint (res, ==, 0);
912 res = g_ascii_strncasecmp ("Frob0ZZ", "froB0zz", strlen ("frobozz") - 5);
913 g_assert_cmpint (res, ==, 0);
915 res = g_ascii_strncasecmp ("Frob0ZZ", "froB0zz", strlen ("frobozz") + 5);
916 g_assert_cmpint (res, ==, 0);
920 do_test_strchug (const gchar *str, const gchar *expected)
925 tmp = g_strdup (str);
928 res = (strcmp (tmp, expected) == 0);
931 g_assert_cmpint (res, ==, TRUE);
934 /* Testing g_strchug() function with various positive and negative cases */
938 if (g_test_undefined ())
940 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
941 "*assertion*!= NULL*");
943 g_test_assert_expected_messages ();
946 do_test_strchug ("", "");
947 do_test_strchug (" ", "");
948 do_test_strchug ("\t\r\n ", "");
949 do_test_strchug (" a", "a");
950 do_test_strchug (" a", "a");
951 do_test_strchug ("a a", "a a");
952 do_test_strchug (" a a", "a a");
956 do_test_strchomp (const gchar *str, const gchar *expected)
961 tmp = g_strdup (str);
964 res = (strcmp (tmp, expected) == 0);
967 g_assert_cmpint (res, ==, TRUE);
970 /* Testing g_strchomp() function with various positive and negative cases */
974 if (g_test_undefined ())
976 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
977 "*assertion*!= NULL*");
979 g_test_assert_expected_messages ();
982 do_test_strchomp ("", "");
983 do_test_strchomp (" ", "");
984 do_test_strchomp (" \t\r\n", "");
985 do_test_strchomp ("a ", "a");
986 do_test_strchomp ("a ", "a");
987 do_test_strchomp ("a a", "a a");
988 do_test_strchomp ("a a ", "a a");
991 /* Testing g_str_tokenize_and_fold() functions */
993 test_str_tokenize_and_fold (void)
995 const gchar *local_str = "en_GB";
996 const gchar *sample = "The quick brown fox¸ jumps over the lazy dog.";
997 const gchar *special_cases = "quıck QUİCK QUİı QUıİ İıck ıİCK àìøş";
998 gchar **tokens, **alternates;
1000 *expected_tokens[] = \
1001 {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog", NULL},
1002 *expected_tokens_alt[] = \
1003 { "quick", "quick", "quii", "quii", "iick", "iick", "àìøş", NULL};
1005 if (g_test_undefined ())
1007 /* Testing degenerated cases */
1008 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1009 "*assertion*!= NULL*");
1010 tokens = g_str_tokenize_and_fold (NULL, local_str, NULL);
1011 g_test_assert_expected_messages ();
1014 tokens = g_str_tokenize_and_fold (special_cases, local_str, &alternates);
1015 g_assert_cmpint (g_strv_length (tokens), ==,
1016 g_strv_length (expected_tokens_alt));
1017 g_assert_true (g_strv_equal ((const gchar * const *) tokens,
1018 (const gchar * const *) expected_tokens_alt));
1019 g_strfreev (tokens);
1020 g_strfreev (alternates);
1022 tokens = g_str_tokenize_and_fold (sample, local_str, &alternates);
1023 g_assert_cmpint (g_strv_length (tokens), ==, g_strv_length (expected_tokens));
1024 g_assert_true (g_strv_equal ((const gchar * const *) tokens,
1025 (const gchar * const *) expected_tokens));
1026 g_strfreev (tokens);
1027 g_strfreev (alternates);
1029 tokens = g_str_tokenize_and_fold (sample, local_str, NULL);
1030 g_assert_cmpint (g_strv_length (tokens), ==, g_strv_length (expected_tokens));
1031 g_assert_true (g_strv_equal ((const gchar * const *) tokens,
1032 (const gchar * const *) expected_tokens));
1033 g_strfreev (tokens);
1035 tokens = g_str_tokenize_and_fold (sample, NULL, &alternates);
1036 g_assert_cmpint (g_strv_length (tokens), ==, g_strv_length (expected_tokens));
1037 g_assert_true (g_strv_equal ((const gchar * const *) tokens,
1038 (const gchar * const *) expected_tokens));
1039 g_strfreev (tokens);
1040 g_strfreev (alternates);
1043 /* Testing g_strreverse() function with various positive and negative cases */
1045 test_strreverse (void)
1050 if (g_test_undefined ())
1052 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1053 "*assertion*!= NULL*");
1054 str = g_strreverse (NULL);
1055 g_test_assert_expected_messages ();
1056 g_assert_null (str);
1059 str = p = g_strdup ("abcde");
1060 str = g_strreverse (str);
1061 g_assert_nonnull (str);
1062 g_assert_true (p == str);
1063 g_assert_cmpstr (str, ==, "edcba");
1067 /* Testing g_strncasecmp() functions */
1069 test_strncasecmp (void)
1071 g_assert_cmpint (g_strncasecmp ("abc1", "ABC2", 3), ==, 0);
1072 g_assert_cmpint (g_strncasecmp ("abc1", "ABC2", 4), !=, 0);
1081 haystack = g_strdup ("FooBarFooBarFoo");
1083 if (g_test_undefined ())
1085 /* Testing degenerated cases */
1086 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1087 "*assertion*!= NULL*");
1088 res = g_strstr_len (NULL, 0, "xxx");
1089 g_test_assert_expected_messages ();
1091 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1092 "*assertion*!= NULL*");
1093 res = g_strstr_len ("xxx", 0, NULL);
1094 g_test_assert_expected_messages ();
1098 res = g_strstr_len (haystack, 6, "xxx");
1099 g_assert_null (res);
1101 res = g_strstr_len (haystack, 6, "FooBarFooBarFooBar");
1102 g_assert_null (res);
1104 res = g_strstr_len (haystack, 3, "Bar");
1105 g_assert_null (res);
1107 res = g_strstr_len (haystack, 6, "");
1108 g_assert_true (res == haystack);
1109 g_assert_cmpstr (res, ==, "FooBarFooBarFoo");
1111 res = g_strstr_len (haystack, 6, "Bar");
1112 g_assert_true (res == haystack + 3);
1113 g_assert_cmpstr (res, ==, "BarFooBarFoo");
1115 res = g_strstr_len (haystack, -1, "Bar");
1116 g_assert_true (res == haystack + 3);
1117 g_assert_cmpstr (res, ==, "BarFooBarFoo");
1120 if (g_test_undefined ())
1122 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1123 "*assertion*!= NULL*");
1124 res = g_strrstr (NULL, "xxx");
1125 g_test_assert_expected_messages ();
1127 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1128 "*assertion*!= NULL*");
1129 res = g_strrstr ("xxx", NULL);
1130 g_test_assert_expected_messages ();
1133 res = g_strrstr (haystack, "xxx");
1134 g_assert_null (res);
1136 res = g_strrstr (haystack, "FooBarFooBarFooBar");
1137 g_assert_null (res);
1139 res = g_strrstr (haystack, "");
1140 g_assert_true (res == haystack);
1141 g_assert_cmpstr (res, ==, "FooBarFooBarFoo");
1143 res = g_strrstr (haystack, "Bar");
1144 g_assert_true (res == haystack + 9);
1145 g_assert_cmpstr (res, ==, "BarFoo");
1148 if (g_test_undefined ())
1150 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1151 "*assertion*!= NULL*");
1152 res = g_strrstr_len (NULL, 14, "xxx");
1153 g_test_assert_expected_messages ();
1155 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1156 "*assertion*!= NULL*");
1157 res = g_strrstr_len ("xxx", 14, NULL);
1158 g_test_assert_expected_messages ();
1161 res = g_strrstr_len (haystack, 14, "xxx");
1162 g_assert_null (res);
1164 res = g_strrstr_len (haystack, 14, "FooBarFooBarFooBar");
1165 g_assert_null (res);
1167 res = g_strrstr_len (haystack, 3, "Bar");
1168 g_assert_null (res);
1170 res = g_strrstr_len (haystack, 14, "BarFoo");
1171 g_assert_true (res == haystack + 3);
1172 g_assert_cmpstr (res, ==, "BarFooBarFoo");
1174 res = g_strrstr_len (haystack, 15, "BarFoo");
1175 g_assert_true (res == haystack + 9);
1176 g_assert_cmpstr (res, ==, "BarFoo");
1178 res = g_strrstr_len (haystack, -1, "BarFoo");
1179 g_assert_true (res == haystack + 9);
1180 g_assert_cmpstr (res, ==, "BarFoo");
1182 /* test case for strings with \0 in the middle */
1183 *(haystack + 7) = '\0';
1184 res = g_strstr_len (haystack, 15, "BarFoo");
1185 g_assert_null (res);
1190 /* Testing g_strtod() function with various positive and negative cases */
1194 gchar *str_end = NULL;
1196 const double gold_ratio = 1.61803398874989484;
1197 const gchar *gold_ratio_str = "1.61803398874989484";
1198 const gchar *minus_gold_ratio_str = "-1.61803398874989484";
1200 if (g_test_undefined ())
1202 /* Testing degenerated cases */
1203 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1204 "*assertion*!= NULL*");
1205 value = g_strtod (NULL, NULL);
1206 g_test_assert_expected_messages ();
1207 g_assert_cmpfloat (value, ==, 0.0);
1210 g_assert_cmpfloat (g_strtod ("\x00\x00\x00\x00", NULL), ==, 0.0);
1211 g_assert_cmpfloat (g_strtod ("\x00\x00\x00\x00", &str_end), ==, 0.0);
1212 g_assert_cmpstr (str_end, ==, "");
1213 g_assert_cmpfloat (g_strtod ("\xff\xff\xff\xff", NULL), ==, 0.0);
1214 g_assert_cmpfloat (g_strtod ("\xff\xff\xff\xff", &str_end), ==, 0.0);
1215 g_assert_cmpstr (str_end, ==, "\xff\xff\xff\xff");
1217 /* Testing normal usage cases */
1218 g_assert_cmpfloat (g_strtod (gold_ratio_str, NULL), ==, gold_ratio);
1219 g_assert_cmpfloat (g_strtod (gold_ratio_str, &str_end), ==, gold_ratio);
1220 g_assert_true (str_end == gold_ratio_str + strlen (gold_ratio_str));
1221 g_assert_cmpfloat (g_strtod (minus_gold_ratio_str, NULL), ==, -gold_ratio);
1222 g_assert_cmpfloat (g_strtod (minus_gold_ratio_str, &str_end), ==, -gold_ratio);
1223 g_assert_true (str_end == minus_gold_ratio_str + strlen (minus_gold_ratio_str));
1226 /* Testing g_strdelimit() function */
1228 test_strdelimit (void)
1230 const gchar *const_string = "ABCDE<*>Q";
1233 if (g_test_undefined ())
1235 /* Testing degenerated cases */
1236 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1237 "*assertion*!= NULL*");
1238 string = g_strdelimit (NULL, "ABCDE", 'N');
1239 g_test_assert_expected_messages ();
1242 string = g_strdelimit (g_strdup (const_string), "<>", '?');
1243 g_assert_cmpstr (string, ==, "ABCDE?*?Q");
1246 string = g_strdelimit (g_strdup (const_string), NULL, '?');
1247 g_assert_cmpstr (string, ==, "ABCDE?*?Q");
1251 /* Testing g_str_has_prefix() function avoiding the optimizing macro */
1253 test_has_prefix (void)
1255 if (g_test_undefined ())
1257 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1258 "*assertion*!= NULL*");
1259 g_assert_false ((g_str_has_prefix) ("foo", NULL));
1260 g_test_assert_expected_messages ();
1262 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1263 "*assertion*!= NULL*");
1264 g_assert_false ((g_str_has_prefix) (NULL, "foo"));
1265 g_test_assert_expected_messages ();
1268 /* Having a string smaller than the prefix */
1269 g_assert_false ((g_str_has_prefix) ("aa", "aaa"));
1271 /* Negative tests */
1272 g_assert_false ((g_str_has_prefix) ("foo", "bar"));
1273 g_assert_false ((g_str_has_prefix) ("foo", "foobar"));
1274 g_assert_false ((g_str_has_prefix) ("foobar", "bar"));
1276 /* Positive tests */
1277 g_assert_true ((g_str_has_prefix) ("foobar", "foo"));
1278 g_assert_true ((g_str_has_prefix) ("foo", ""));
1279 g_assert_true ((g_str_has_prefix) ("foo", "foo"));
1280 g_assert_true ((g_str_has_prefix) ("", ""));
1283 /* Testing g_str_has_prefix() optimized macro */
1285 test_has_prefix_macro (void)
1287 #if G_GNUC_CHECK_VERSION (2, 0)
1288 #ifndef g_str_has_prefix
1289 #error g_str_has_prefix() should be defined as a macro in this platform!
1292 g_test_incomplete ("g_str_has_prefix() is not inlined in this platform");
1295 if (g_test_undefined ())
1297 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1298 "*assertion*!= NULL*");
1299 g_assert_false (g_str_has_prefix ("foo", NULL));
1300 g_test_assert_expected_messages ();
1302 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1303 "*assertion*!= NULL*");
1304 g_assert_false (g_str_has_prefix (NULL, "foo"));
1305 g_test_assert_expected_messages ();
1308 /* Having a string smaller than the prefix */
1309 g_assert_false (g_str_has_prefix ("aa", "aaa"));
1311 /* Negative tests */
1312 g_assert_false (g_str_has_prefix ("foo", "bar"));
1313 g_assert_false (g_str_has_prefix ("foo", "foobar"));
1314 g_assert_false (g_str_has_prefix ("foobar", "bar"));
1316 /* Positive tests */
1317 g_assert_true (g_str_has_prefix ("foobar", "foo"));
1318 g_assert_true (g_str_has_prefix ("foo", ""));
1319 g_assert_true (g_str_has_prefix ("foo", "foo"));
1320 g_assert_true (g_str_has_prefix ("", ""));
1322 /* Testing the nested G_UNLIKELY */
1323 g_assert_false (G_UNLIKELY (g_str_has_prefix ("foo", "aaa")));
1326 /* Testing g_str_has_suffix() function avoiding the optimizing macro */
1328 test_has_suffix (void)
1330 if (g_test_undefined ())
1332 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1333 "*assertion*!= NULL*");
1334 g_assert_false ((g_str_has_suffix) ("foo", NULL));
1335 g_test_assert_expected_messages ();
1337 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1338 "*assertion*!= NULL*");
1339 g_assert_false ((g_str_has_suffix) (NULL, "foo"));
1340 g_test_assert_expected_messages ();
1343 /* Having a string smaller than the suffix */
1344 g_assert_false ((g_str_has_suffix) ("aa", "aaa"));
1346 /* Negative tests */
1347 g_assert_false ((g_str_has_suffix) ("foo", "bar"));
1348 g_assert_false ((g_str_has_suffix) ("bar", "foobar"));
1349 g_assert_false ((g_str_has_suffix) ("foobar", "foo"));
1351 /* Positive tests */
1352 g_assert_true ((g_str_has_suffix) ("foobar", "bar"));
1353 g_assert_true ((g_str_has_suffix) ("foo", ""));
1354 g_assert_true ((g_str_has_suffix) ("foo", "foo"));
1355 g_assert_true ((g_str_has_suffix) ("", ""));
1358 /* Testing g_str_has_prefix() optimized macro */
1360 test_has_suffix_macro (void)
1362 #if G_GNUC_CHECK_VERSION (2, 0)
1363 #ifndef g_str_has_suffix
1364 #error g_str_has_suffix() should be defined as a macro in this platform!
1367 g_test_incomplete ("g_str_has_suffix() is not inlined in this platform");
1370 if (g_test_undefined ())
1372 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1373 "*assertion*!= NULL*");
1374 g_assert_false (g_str_has_suffix ("foo", NULL));
1375 g_test_assert_expected_messages ();
1377 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1378 "*assertion*!= NULL*");
1379 g_assert_false (g_str_has_suffix (NULL, "foo"));
1380 g_test_assert_expected_messages ();
1383 /* Having a string smaller than the suffix */
1384 g_assert_false (g_str_has_suffix ("aa", "aaa"));
1386 /* Negative tests */
1387 g_assert_false (g_str_has_suffix ("foo", "bar"));
1388 g_assert_false (g_str_has_suffix ("bar", "foobar"));
1389 g_assert_false (g_str_has_suffix ("foobar", "foo"));
1391 /* Positive tests */
1392 g_assert_true (g_str_has_suffix ("foobar", "bar"));
1393 g_assert_true (g_str_has_suffix ("foo", ""));
1394 g_assert_true (g_str_has_suffix ("foo", "foo"));
1395 g_assert_true (g_str_has_suffix ("", ""));
1399 strv_check (gchar **strv, ...)
1405 va_start (list, strv);
1408 const gchar *str = va_arg (list, const char *);
1409 if (strv[i] == NULL)
1411 g_assert_null (str);
1420 g_assert_cmpstr (strv[i], ==, str);
1429 /* Testing g_strsplit() function with various positive and negative cases */
1431 test_strsplit (void)
1433 gchar **string = NULL;
1435 if (g_test_undefined ())
1437 /* Testing degenerated cases */
1438 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1439 "*assertion*!= NULL*");
1440 string = g_strsplit (NULL, ",", 0);
1441 g_test_assert_expected_messages ();
1442 g_assert_null (string);
1444 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1445 "*assertion*!= NULL*");
1446 string = g_strsplit ("x", NULL, 0);
1447 g_test_assert_expected_messages ();
1448 g_assert_null (string);
1450 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1451 "*assertion \'delimiter[0] != \'\\0\'*");
1452 string = g_strsplit ("x", "", 0);
1453 g_test_assert_expected_messages ();
1454 g_assert_null (string);
1457 strv_check (g_strsplit ("", ",", 0), NULL);
1458 strv_check (g_strsplit ("x", ",", 0), "x", NULL);
1459 strv_check (g_strsplit ("x,y", ",", 0), "x", "y", NULL);
1460 strv_check (g_strsplit ("x,y,", ",", 0), "x", "y", "", NULL);
1461 strv_check (g_strsplit (",x,y", ",", 0), "", "x", "y", NULL);
1462 strv_check (g_strsplit (",x,y,", ",", 0), "", "x", "y", "", NULL);
1463 strv_check (g_strsplit ("x,y,z", ",", 0), "x", "y", "z", NULL);
1464 strv_check (g_strsplit ("x,y,z,", ",", 0), "x", "y", "z", "", NULL);
1465 strv_check (g_strsplit (",x,y,z", ",", 0), "", "x", "y", "z", NULL);
1466 strv_check (g_strsplit (",x,y,z,", ",", 0), "", "x", "y", "z", "", NULL);
1467 strv_check (g_strsplit (",,x,,y,,z,,", ",", 0), "", "", "x", "", "y", "", "z", "", "", NULL);
1468 strv_check (g_strsplit (",,x,,y,,z,,", ",,", 0), "", "x", "y", "z", "", NULL);
1470 strv_check (g_strsplit ("", ",", 1), NULL);
1471 strv_check (g_strsplit ("x", ",", 1), "x", NULL);
1472 strv_check (g_strsplit ("x,y", ",", 1), "x,y", NULL);
1473 strv_check (g_strsplit ("x,y,", ",", 1), "x,y,", NULL);
1474 strv_check (g_strsplit (",x,y", ",", 1), ",x,y", NULL);
1475 strv_check (g_strsplit (",x,y,", ",", 1), ",x,y,", NULL);
1476 strv_check (g_strsplit ("x,y,z", ",", 1), "x,y,z", NULL);
1477 strv_check (g_strsplit ("x,y,z,", ",", 1), "x,y,z,", NULL);
1478 strv_check (g_strsplit (",x,y,z", ",", 1), ",x,y,z", NULL);
1479 strv_check (g_strsplit (",x,y,z,", ",", 1), ",x,y,z,", NULL);
1480 strv_check (g_strsplit (",,x,,y,,z,,", ",", 1), ",,x,,y,,z,,", NULL);
1481 strv_check (g_strsplit (",,x,,y,,z,,", ",,", 1), ",,x,,y,,z,,", NULL);
1483 strv_check (g_strsplit ("", ",", 2), NULL);
1484 strv_check (g_strsplit ("x", ",", 2), "x", NULL);
1485 strv_check (g_strsplit ("x,y", ",", 2), "x", "y", NULL);
1486 strv_check (g_strsplit ("x,y,", ",", 2), "x", "y,", NULL);
1487 strv_check (g_strsplit (",x,y", ",", 2), "", "x,y", NULL);
1488 strv_check (g_strsplit (",x,y,", ",", 2), "", "x,y,", NULL);
1489 strv_check (g_strsplit ("x,y,z", ",", 2), "x", "y,z", NULL);
1490 strv_check (g_strsplit ("x,y,z,", ",", 2), "x", "y,z,", NULL);
1491 strv_check (g_strsplit (",x,y,z", ",", 2), "", "x,y,z", NULL);
1492 strv_check (g_strsplit (",x,y,z,", ",", 2), "", "x,y,z,", NULL);
1493 strv_check (g_strsplit (",,x,,y,,z,,", ",", 2), "", ",x,,y,,z,,", NULL);
1494 strv_check (g_strsplit (",,x,,y,,z,,", ",,", 2), "", "x,,y,,z,,", NULL);
1497 /* Testing function g_strsplit_set() */
1499 test_strsplit_set (void)
1501 gchar **string = NULL;
1503 if (g_test_undefined ())
1505 /* Testing degenerated cases */
1506 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1507 "*assertion*!= NULL*");
1508 string = g_strsplit_set (NULL, ",/", 0);
1509 g_test_assert_expected_messages ();
1510 g_assert_null (string);
1512 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1513 "*assertion*!= NULL*");
1514 string = g_strsplit_set ("", NULL, 0);
1515 g_test_assert_expected_messages ();
1516 g_assert_null (string);
1519 strv_check (g_strsplit_set ("", ",/", 0), NULL);
1520 strv_check (g_strsplit_set (":def/ghi:", ":/", -1), "", "def", "ghi", "", NULL);
1521 strv_check (g_strsplit_set ("abc:def/ghi", ":/", -1), "abc", "def", "ghi", NULL);
1522 strv_check (g_strsplit_set (",;,;,;,;", ",;", -1), "", "", "", "", "", "", "", "", "", NULL);
1523 strv_check (g_strsplit_set (",,abc.def", ".,", -1), "", "", "abc", "def", NULL);
1525 strv_check (g_strsplit_set (",x.y", ",.", 0), "", "x", "y", NULL);
1526 strv_check (g_strsplit_set (".x,y,", ",.", 0), "", "x", "y", "", NULL);
1527 strv_check (g_strsplit_set ("x,y.z", ",.", 0), "x", "y", "z", NULL);
1528 strv_check (g_strsplit_set ("x.y,z,", ",.", 0), "x", "y", "z", "", NULL);
1529 strv_check (g_strsplit_set (",x.y,z", ",.", 0), "", "x", "y", "z", NULL);
1530 strv_check (g_strsplit_set (",x,y,z,", ",.", 0), "", "x", "y", "z", "", NULL);
1531 strv_check (g_strsplit_set (",.x,,y,;z..", ".,;", 0), "", "", "x", "", "y", "", "z", "", "", NULL);
1532 strv_check (g_strsplit_set (",,x,,y,,z,,", ",,", 0), "", "", "x", "", "y", "", "z", "", "", NULL);
1534 strv_check (g_strsplit_set ("x,y.z", ",.", 1), "x,y.z", NULL);
1535 strv_check (g_strsplit_set ("x.y,z,", ",.", 1), "x.y,z,", NULL);
1536 strv_check (g_strsplit_set (",x,y,z", ",.", 1), ",x,y,z", NULL);
1537 strv_check (g_strsplit_set (",x,y.z,", ",.", 1), ",x,y.z,", NULL);
1538 strv_check (g_strsplit_set (",,x,.y,,z,,", ",.", 1), ",,x,.y,,z,,", NULL);
1539 strv_check (g_strsplit_set (",.x,,y,,z,,", ",,..", 1), ",.x,,y,,z,,", NULL);
1541 strv_check (g_strsplit_set ("", ",", 0), NULL);
1542 strv_check (g_strsplit_set ("x", ",", 0), "x", NULL);
1543 strv_check (g_strsplit_set ("x,y", ",", 0), "x", "y", NULL);
1544 strv_check (g_strsplit_set ("x,y,", ",", 0), "x", "y", "", NULL);
1545 strv_check (g_strsplit_set (",x,y", ",", 0), "", "x", "y", NULL);
1546 strv_check (g_strsplit_set (",x,y,", ",", 0), "", "x", "y", "", NULL);
1547 strv_check (g_strsplit_set ("x,y,z", ",", 0), "x", "y", "z", NULL);
1548 strv_check (g_strsplit_set ("x,y,z,", ",", 0), "x", "y", "z", "", NULL);
1549 strv_check (g_strsplit_set (",x,y,z", ",", 0), "", "x", "y", "z", NULL);
1550 strv_check (g_strsplit_set (",x,y,z,", ",", 0), "", "x", "y", "z", "", NULL);
1551 strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 0), "", "", "x", "", "y", "", "z", "", "", NULL);
1553 strv_check (g_strsplit_set ("", ",", 1), NULL);
1554 strv_check (g_strsplit_set ("x", ",", 1), "x", NULL);
1555 strv_check (g_strsplit_set ("x,y", ",", 1), "x,y", NULL);
1556 strv_check (g_strsplit_set ("x,y,", ",", 1), "x,y,", NULL);
1557 strv_check (g_strsplit_set (",x,y", ",", 1), ",x,y", NULL);
1558 strv_check (g_strsplit_set (",x,y,", ",", 1), ",x,y,", NULL);
1559 strv_check (g_strsplit_set ("x,y,z", ",", 1), "x,y,z", NULL);
1560 strv_check (g_strsplit_set ("x,y,z,", ",", 1), "x,y,z,", NULL);
1561 strv_check (g_strsplit_set (",x,y,z", ",", 1), ",x,y,z", NULL);
1562 strv_check (g_strsplit_set (",x,y,z,", ",", 1), ",x,y,z,", NULL);
1563 strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 1), ",,x,,y,,z,,", NULL);
1564 strv_check (g_strsplit_set (",,x,,y,,z,,", ",,", 1), ",,x,,y,,z,,", NULL);
1566 strv_check (g_strsplit_set ("", ",", 2), NULL);
1567 strv_check (g_strsplit_set ("x", ",", 2), "x", NULL);
1568 strv_check (g_strsplit_set ("x,y", ",", 2), "x", "y", NULL);
1569 strv_check (g_strsplit_set ("x,y,", ",", 2), "x", "y,", NULL);
1570 strv_check (g_strsplit_set (",x,y", ",", 2), "", "x,y", NULL);
1571 strv_check (g_strsplit_set (",x,y,", ",", 2), "", "x,y,", NULL);
1572 strv_check (g_strsplit_set ("x,y,z", ",", 2), "x", "y,z", NULL);
1573 strv_check (g_strsplit_set ("x,y,z,", ",", 2), "x", "y,z,", NULL);
1574 strv_check (g_strsplit_set (",x,y,z", ",", 2), "", "x,y,z", NULL);
1575 strv_check (g_strsplit_set (",x,y,z,", ",", 2), "", "x,y,z,", NULL);
1576 strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 2), "", ",x,,y,,z,,", NULL);
1578 strv_check (g_strsplit_set (",,x,.y,..z,,", ",.", 3), "", "", "x,.y,..z,,", NULL);
1581 /* Testing g_strv_length() function with various positive and negative cases */
1583 test_strv_length (void)
1588 if (g_test_undefined ())
1590 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1591 "*assertion*!= NULL*");
1592 l = g_strv_length (NULL);
1593 g_test_assert_expected_messages ();
1594 g_assert_cmpint (l, ==, 0);
1597 strv = g_strsplit ("1,2,3,4", ",", -1);
1598 l = g_strv_length (strv);
1599 g_assert_cmpuint (l, ==, 4);
1603 static char *locales[] = {"sv_SE", "en_US", "fa_IR", "C", "ru_RU"};
1606 check_strtod_string (gchar *number,
1615 /* we try a copy of number, with some free space for malloc before that.
1616 * This is supposed to smash the some wrong pointer calculations. */
1618 dummy = g_malloc (100000);
1619 number = g_strdup (number);
1622 for (l = 0; l < G_N_ELEMENTS (locales); l++)
1624 gchar *end = "(unset)";
1626 setlocale (LC_NUMERIC, locales[l]);
1627 d = g_ascii_strtod (number, &end);
1628 g_assert_true (isnan (res) ? isnan (d) : (d == res));
1629 g_assert_true ((gsize) (end - number) ==
1630 (check_end ? correct_len : strlen (number)));
1637 check_strtod_number (gdouble num, gchar *fmt, gchar *str)
1640 gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
1642 for (l = 0; l < G_N_ELEMENTS (locales); l++)
1644 setlocale (LC_ALL, locales[l]);
1645 g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, fmt, num);
1646 g_assert_cmpstr (buf, ==, str);
1650 /* Testing g_ascii_strtod() function with various positive and negative cases */
1652 test_ascii_strtod (void)
1654 gdouble d, our_nan, our_inf;
1655 char buffer[G_ASCII_DTOSTR_BUF_SIZE];
1660 /* Do this before any call to setlocale. */
1661 our_nan = atof ("NaN");
1663 g_assert_true (isnan (our_nan));
1668 our_inf = atof ("Infinity");
1670 g_assert_true (our_inf > 1 && our_inf == our_inf / 2);
1672 /* Testing degenerated cases */
1673 if (g_test_undefined ())
1675 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1676 "*assertion*!= NULL*");
1677 d = g_ascii_strtod (NULL, NULL);
1678 g_test_assert_expected_messages ();
1681 /* Testing normal cases */
1682 check_strtod_string ("123.123", 123.123, FALSE, 0);
1683 check_strtod_string ("123.123e2", 123.123e2, FALSE, 0);
1684 check_strtod_string ("123.123e-2", 123.123e-2, FALSE, 0);
1685 check_strtod_string ("-123.123", -123.123, FALSE, 0);
1686 check_strtod_string ("-123.123e2", -123.123e2, FALSE, 0);
1687 check_strtod_string ("-123.123e-2", -123.123e-2, FALSE, 0);
1688 check_strtod_string ("5.4", 5.4, TRUE, 3);
1689 check_strtod_string ("5.4,5.5", 5.4, TRUE, 3);
1690 check_strtod_string ("5,4", 5.0, TRUE, 1);
1692 /* hex strings for strtod() is a C99 feature which Visual C++ does not support */
1693 check_strtod_string ("0xa.b", 10.6875, TRUE, 5);
1694 check_strtod_string ("0xa.bP3", 85.5, TRUE, 7);
1695 check_strtod_string ("0xa.bp+3", 85.5, TRUE, 8);
1696 check_strtod_string ("0xa.bp-2", 2.671875, TRUE, 8);
1697 check_strtod_string ("0xA.BG", 10.6875, TRUE, 5);
1699 /* the following are for #156421 */
1700 check_strtod_string ("1e1", 1e1, FALSE, 0);
1702 /* NAN/-nan/INF/-infinity strings for strtod() are C99 features which Visual C++ does not support */
1703 check_strtod_string ("NAN", our_nan, FALSE, 0);
1704 check_strtod_string ("-nan", -our_nan, FALSE, 0);
1705 check_strtod_string ("INF", our_inf, FALSE, 0);
1706 check_strtod_string ("-infinity", -our_inf, FALSE, 0);
1708 check_strtod_string ("-.75,0", -0.75, TRUE, 4);
1711 /* the values of d in the following 2 tests generate a C1064 compiler limit error */
1712 d = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
1713 g_assert_true (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
1715 d = -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
1716 g_assert_true (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
1719 d = pow (2.0, -1024.1);
1720 g_assert_true (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
1722 d = -pow (2.0, -1024.1);
1723 g_assert_true (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
1726 check_strtod_string (" 0.75", 0.75, FALSE, 0);
1727 check_strtod_string (" +0.75", 0.75, FALSE, 0);
1728 check_strtod_string (" -0.75", -0.75, FALSE, 0);
1729 check_strtod_string ("\f0.75", 0.75, FALSE, 0);
1730 check_strtod_string ("\n0.75", 0.75, FALSE, 0);
1731 check_strtod_string ("\r0.75", 0.75, FALSE, 0);
1732 check_strtod_string ("\t0.75", 0.75, FALSE, 0);
1735 /* g_ascii_isspace() returns FALSE for vertical tab, see #59388 */
1736 check_strtod_string ("\v0.75", 0.75, FALSE, 0);
1740 check_strtod_number (0.75, "%0.2f", "0.75");
1741 check_strtod_number (0.75, "%5.2f", " 0.75");
1742 check_strtod_number (-0.75, "%0.2f", "-0.75");
1743 check_strtod_number (-0.75, "%5.2f", "-0.75");
1744 check_strtod_number (1e99, "%.0e", "1e+99");
1748 check_uint64 (const gchar *str,
1755 gchar *endptr = NULL;
1759 actual = g_ascii_strtoull (str, &endptr, base);
1762 g_assert_true (actual == result);
1763 g_assert_cmpstr (end, ==, endptr);
1764 g_assert_true (err == error);
1768 check_int64 (const gchar *str,
1775 gchar *endptr = NULL;
1779 actual = g_ascii_strtoll (str, &endptr, base);
1782 g_assert_true (actual == result);
1783 g_assert_cmpstr (end, ==, endptr);
1784 g_assert_true (err == error);
1790 check_uint64 ("0", "", 10, 0, 0);
1791 check_uint64 ("+0", "", 10, 0, 0);
1792 check_uint64 ("-0", "", 10, 0, 0);
1793 check_uint64 ("18446744073709551615", "", 10, G_MAXUINT64, 0);
1794 check_uint64 ("18446744073709551616", "", 10, G_MAXUINT64, ERANGE);
1795 check_uint64 ("20xyz", "xyz", 10, 20, 0);
1796 check_uint64 ("-1", "", 10, G_MAXUINT64, 0);
1797 check_uint64 ("-FF4", "", 16, -((guint64) 0xFF4), 0);
1799 check_int64 ("0", "", 10, 0, 0);
1800 check_int64 ("9223372036854775807", "", 10, G_MAXINT64, 0);
1801 check_int64 ("9223372036854775808", "", 10, G_MAXINT64, ERANGE);
1802 check_int64 ("-9223372036854775808", "", 10, G_MININT64, 0);
1803 check_int64 ("-9223372036854775809", "", 10, G_MININT64, ERANGE);
1804 check_int64 ("32768", "", 10, 32768, 0);
1805 check_int64 ("-32768", "", 10, -32768, 0);
1806 check_int64 ("001", "", 10, 1, 0);
1807 check_int64 ("-001", "", 10, -1, 0);
1810 /* Testing g_str_match_string() function with various cases */
1812 test_str_match_string (void)
1814 gboolean result = TRUE;
1815 const gchar *str = "The quick brown fox¸ jumps over the lazy dog.";
1817 if (g_test_undefined ())
1819 /* Testing degenerated cases */
1820 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1821 "*assertion*!= NULL*");
1822 result = g_str_match_string (NULL, "AAA", TRUE);
1823 g_test_assert_expected_messages ();
1824 g_assert_false (result);
1826 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
1827 "*assertion*!= NULL*");
1828 result = g_str_match_string (str, NULL, TRUE);
1829 g_test_assert_expected_messages ();
1830 g_assert_false (result);
1833 g_assert_false (g_str_match_string (str, "AAA", TRUE));
1834 g_assert_false (g_str_match_string (str, "AAA", FALSE));
1837 /* Testing functions bounds */
1841 GMappedFile *file, *before, *after;
1846 const char * const strjoinv_0[] = { NULL };
1847 const char * const strjoinv_1[] = { "foo", NULL };
1849 /* if we allocate the file between two others and then free those
1850 * other two, then hopefully we end up with unmapped memory on either
1853 before = g_mapped_file_new ("4096-random-bytes", TRUE, NULL);
1855 /* quick workaround until #549783 can be fixed */
1859 file = g_mapped_file_new ("4096-random-bytes", TRUE, NULL);
1860 after = g_mapped_file_new ("4096-random-bytes", TRUE, NULL);
1861 g_mapped_file_unref (before);
1862 g_mapped_file_unref (after);
1864 g_assert_nonnull (file);
1865 g_assert_cmpint (g_mapped_file_get_length (file), ==, 4096);
1866 string = g_mapped_file_get_contents (file);
1868 /* ensure they're all non-nul */
1869 g_assert_null (memchr (string, '\0', 4096));
1871 /* test set 1: ensure that nothing goes past its maximum length, even in
1872 * light of a missing nul terminator.
1874 * we try to test all of the 'n' functions here.
1876 tmp = g_strndup (string, 4096);
1877 g_assert_cmpint (strlen (tmp), ==, 4096);
1880 /* found no bugs in gnome, i hope :) */
1881 g_assert_null (g_strstr_len (string, 4096, "BUGS"));
1882 g_strstr_len (string, 4096, "B");
1883 g_strstr_len (string, 4096, ".");
1884 g_strstr_len (string, 4096, "");
1886 g_strrstr_len (string, 4096, "BUGS");
1887 g_strrstr_len (string, 4096, "B");
1888 g_strrstr_len (string, 4096, ".");
1889 g_strrstr_len (string, 4096, "");
1891 tmp = g_ascii_strup (string, 4096);
1892 tmp2 = g_ascii_strup (tmp, 4096);
1893 g_assert_cmpint (g_ascii_strncasecmp (string, tmp, 4096), ==, 0);
1894 g_assert_cmpint (g_ascii_strncasecmp (string, tmp2, 4096), ==, 0);
1895 g_assert_cmpint (g_ascii_strncasecmp (tmp, tmp2, 4096), ==, 0);
1899 tmp = g_ascii_strdown (string, 4096);
1900 tmp2 = g_ascii_strdown (tmp, 4096);
1901 g_assert_cmpint (g_ascii_strncasecmp (string, tmp, 4096), ==, 0);
1902 g_assert_cmpint (g_ascii_strncasecmp (string, tmp2, 4096), ==, 0);
1903 g_assert_cmpint (g_ascii_strncasecmp (tmp, tmp2, 4096), ==, 0);
1907 tmp = g_markup_escape_text (string, 4096);
1910 /* test set 2: ensure that nothing reads even one byte past a '\0'.
1912 g_assert_cmpint (string[4095], ==, '\n');
1913 string[4095] = '\0';
1915 tmp = g_strdup (string);
1916 g_assert_cmpint (strlen (tmp), ==, 4095);
1919 tmp = g_strndup (string, 10000);
1920 g_assert_cmpint (strlen (tmp), ==, 4095);
1923 g_stpcpy (buffer, string);
1924 g_assert_cmpint (strlen (buffer), ==, 4095);
1926 g_strstr_len (string, 10000, "BUGS");
1927 g_strstr_len (string, 10000, "B");
1928 g_strstr_len (string, 10000, ".");
1929 g_strstr_len (string, 10000, "");
1931 g_strrstr (string, "BUGS");
1932 g_strrstr (string, "B");
1933 g_strrstr (string, ".");
1934 g_strrstr (string, "");
1936 g_strrstr_len (string, 10000, "BUGS");
1937 g_strrstr_len (string, 10000, "B");
1938 g_strrstr_len (string, 10000, ".");
1939 g_strrstr_len (string, 10000, "");
1941 g_str_has_prefix (string, "this won't do very much...");
1942 g_str_has_suffix (string, "but maybe this will...");
1943 g_str_has_suffix (string, "HMMMM.");
1944 g_str_has_suffix (string, "MMMM.");
1945 g_str_has_suffix (string, "M.");
1947 g_strlcpy (buffer, string, sizeof buffer);
1948 g_assert_cmpint (strlen (buffer), ==, 4095);
1949 g_strlcpy (buffer, string, sizeof buffer);
1951 g_strlcat (buffer, string, sizeof buffer);
1952 g_assert_cmpint (strlen (buffer), ==, 4095);
1954 tmp = g_strdup_printf ("<%s>", string);
1955 g_assert_cmpint (strlen (tmp), ==, 4095 + 2);
1958 tmp = g_ascii_strdown (string, -1);
1959 tmp2 = g_ascii_strdown (tmp, -1);
1960 g_assert_cmpint (strlen (tmp), ==, strlen (tmp2));
1961 g_assert_cmpint (strlen (string), ==, strlen (tmp));
1962 g_assert_cmpint (g_ascii_strncasecmp (string, tmp, -1), ==, 0);
1963 g_assert_cmpint (g_ascii_strncasecmp (string, tmp2, -1), ==, 0);
1964 g_assert_cmpint (g_ascii_strncasecmp (tmp, tmp2, -1), ==, 0);
1968 tmp = g_ascii_strup (string, -1);
1969 tmp2 = g_ascii_strup (string, -1);
1970 g_assert_cmpint (strlen (tmp), ==, strlen (tmp2));
1971 g_assert_cmpint (strlen (string), ==, strlen (tmp));
1972 g_assert_cmpint (g_ascii_strncasecmp (string, tmp, -1), ==, 0);
1973 g_assert_cmpint (g_ascii_strncasecmp (string, tmp2, -1), ==, 0);
1974 g_assert_cmpint (g_ascii_strncasecmp (tmp, tmp2, -1), ==, 0);
1978 g_ascii_strcasecmp (string, string);
1979 g_ascii_strncasecmp (string, string, 10000);
1981 g_strreverse (string);
1982 g_strreverse (string);
1984 g_strchomp (string);
1985 g_strstrip (string);
1986 g_assert_cmpint (strlen (string), ==, 4095);
1988 g_strdelimit (string, "M", 'N');
1989 g_strcanon (string, " N.", ':');
1990 g_assert_cmpint (strlen (string), ==, 4095);
1992 array = g_strsplit (string, ".", -1);
1993 tmp = g_strjoinv (".", array);
1996 g_assert_cmpmem (tmp, strlen (tmp), string, 4095);
1999 tmp = g_strjoinv ("/", (char **) strjoinv_0);
2000 g_assert_cmpstr (tmp, ==, "");
2003 tmp = g_strjoinv ("/", (char **) strjoinv_1);
2004 g_assert_cmpstr (tmp, ==, "foo");
2007 tmp = g_strconcat (string, string, string, NULL);
2008 g_assert_cmpint (strlen (tmp), ==, 4095 * 3);
2011 tmp = g_strjoin ("!", string, string, NULL);
2012 g_assert_cmpint (strlen (tmp), ==, 4095 + 1 + 4095);
2015 tmp = g_markup_escape_text (string, -1);
2018 tmp = g_markup_printf_escaped ("%s", string);
2021 tmp = g_strescape (string, NULL);
2022 tmp2 = g_strcompress (tmp);
2023 g_assert_cmpstr (string, ==, tmp2);
2027 g_mapped_file_unref (file);
2030 /* Testing g_strip_context() function with various cases */
2032 test_strip_context (void)
2035 const gchar *msgval;
2040 s = g_strip_context (msgid, msgval);
2041 g_assert_true (s == msgval);
2043 msgid = msgval = "blabla";
2044 s = g_strip_context (msgid, msgval);
2045 g_assert_true (s == msgval);
2047 msgid = msgval = "blabla|foo";
2048 s = g_strip_context (msgid, msgval);
2049 g_assert_true (s == msgval + 7);
2051 msgid = msgval = "blabla||bar";
2052 s = g_strip_context (msgid, msgval);
2053 g_assert_true (s == msgval + 7);
2056 /* Test the strings returned by g_strerror() are valid and unique. On Windows,
2057 * fewer than 200 error numbers are used, so we expect some strings to
2058 * return a generic ‘unknown error code’ message. */
2060 test_strerror (void)
2064 const gchar *str, *unknown_str;
2066 setlocale (LC_ALL, "C");
2068 unknown_str = g_strerror (-1);
2069 strs = g_hash_table_new (g_str_hash, g_str_equal);
2070 for (i = 1; i < 200; i++)
2072 gboolean is_unknown;
2073 str = g_strerror (i);
2074 is_unknown = (strcmp (str, unknown_str) == 0);
2075 g_assert_nonnull (str);
2076 g_assert_true (g_utf8_validate (str, -1, NULL));
2077 g_assert_true (!g_hash_table_contains (strs, str) || is_unknown);
2078 g_hash_table_add (strs, (gpointer) str);
2081 g_hash_table_unref (strs);
2084 /* Testing g_strsignal() function with various cases */
2086 test_strsignal (void)
2091 for (i = 1; i < 20; i++)
2093 str = g_strsignal (i);
2094 g_assert_nonnull (str);
2095 g_assert_true (g_utf8_validate (str, -1, NULL));
2099 /* Testing g_strup(), g_strdown() and g_strcasecmp() */
2105 if (g_test_undefined ())
2107 /* Testing degenerated cases */
2108 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2109 "*assertion*!= NULL*");
2111 g_test_assert_expected_messages ();
2113 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2114 "*assertion*!= NULL*");
2115 s = g_strdown (NULL);
2116 g_test_assert_expected_messages ();
2118 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2119 "*assertion*!= NULL*");
2120 g_strcasecmp (NULL, "ABCD");
2121 g_test_assert_expected_messages ();
2123 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2124 "*assertion*!= NULL*");
2125 g_strcasecmp ("abcd", NULL);
2126 g_test_assert_expected_messages ();
2129 s = g_strdup ("lower UPPER");
2130 g_assert_cmpstr (g_strup (s), ==, "LOWER UPPER");
2131 g_assert_cmpstr (g_strdown (s), ==, "lower upper");
2132 g_assert_true (g_strcasecmp ("lower", "LOWER") == 0);
2136 /* Testing g_str_to_ascii() function with various cases */
2138 test_transliteration (void)
2142 /* ...to test the defaults */
2143 setlocale (LC_ALL, "C");
2145 /* Test something trivial */
2146 out = g_str_to_ascii ("hello", NULL);
2147 g_assert_cmpstr (out, ==, "hello");
2150 /* Test something above 0xffff */
2151 out = g_str_to_ascii ("𝐀𝐀𝐀", NULL);
2152 g_assert_cmpstr (out, ==, "AAA");
2155 /* Test something with no good match */
2156 out = g_str_to_ascii ("a ∧ ¬a", NULL);
2157 g_assert_cmpstr (out, ==, "a ? ?a");
2160 /* Make sure 'ö' is handled differently per locale */
2161 out = g_str_to_ascii ("ö", NULL);
2162 g_assert_cmpstr (out, ==, "o");
2165 out = g_str_to_ascii ("ö", "sv");
2166 g_assert_cmpstr (out, ==, "o");
2169 out = g_str_to_ascii ("ö", "de");
2170 g_assert_cmpstr (out, ==, "oe");
2173 /* Make sure we can find a locale by a wide range of names */
2174 out = g_str_to_ascii ("ö", "de_DE");
2175 g_assert_cmpstr (out, ==, "oe");
2178 out = g_str_to_ascii ("ö", "de_DE.UTF-8");
2179 g_assert_cmpstr (out, ==, "oe");
2182 out = g_str_to_ascii ("ö", "de_DE.UTF-8@euro");
2183 g_assert_cmpstr (out, ==, "oe");
2186 out = g_str_to_ascii ("ö", "de@euro");
2187 g_assert_cmpstr (out, ==, "oe");
2190 /* Test some invalid locale names */
2191 out = g_str_to_ascii ("ö", "de_DE@euro.UTF-8");
2192 g_assert_cmpstr (out, ==, "o");
2195 out = g_str_to_ascii ("ö", "de@DE@euro");
2196 g_assert_cmpstr (out, ==, "o");
2199 out = g_str_to_ascii ("ö", "doesnotexist");
2200 g_assert_cmpstr (out, ==, "o");
2203 out = g_str_to_ascii ("ö", "thislocalenameistoolong");
2204 g_assert_cmpstr (out, ==, "o");
2207 /* Try a lookup of a locale with a variant */
2208 out = g_str_to_ascii ("б", "sr_RS");
2209 g_assert_cmpstr (out, ==, "b");
2212 out = g_str_to_ascii ("б", "sr_RS@latin");
2213 g_assert_cmpstr (out, ==, "?");
2216 /* Ukrainian contains the only multi-character mappings.
2217 * Try a string that contains one ('зг') along with a partial
2218 * sequence ('з') at the end.
2220 out = g_str_to_ascii ("Зліва направо, згори вниз", "uk");
2221 g_assert_cmpstr (out, ==, "Zliva napravo, zghory vnyz");
2224 /* Try out the other combinations */
2225 out = g_str_to_ascii ("Зг", "uk");
2226 g_assert_cmpstr (out, ==, "Zgh");
2229 out = g_str_to_ascii ("зГ", "uk");
2230 g_assert_cmpstr (out, ==, "zGH");
2233 out = g_str_to_ascii ("ЗГ", "uk");
2234 g_assert_cmpstr (out, ==, "ZGH");
2237 /* And a non-combination */
2238 out = g_str_to_ascii ("зя", "uk");
2239 g_assert_cmpstr (out, ==, "zya");
2244 test_str_equal (void)
2246 const guchar *unsigned_a = (const guchar *) "a";
2248 g_test_summary ("Test macro and function forms of g_str_equal()");
2250 /* Test function form. */
2251 g_assert_true ((g_str_equal) ("a", "a"));
2252 g_assert_false ((g_str_equal) ("a", "b"));
2254 /* Test macro form. */
2255 g_assert_true (g_str_equal ("a", "a"));
2256 g_assert_false (g_str_equal ("a", "b"));
2258 /* As g_str_equal() is defined for use with GHashTable, it takes gconstpointer
2259 * arguments, so can historically accept unsigned arguments. We need to
2260 * continue to support that. */
2261 g_assert_true ((g_str_equal) (unsigned_a, "a"));
2262 g_assert_false ((g_str_equal) (unsigned_a, "b"));
2264 g_assert_true (g_str_equal (unsigned_a, "a"));
2265 g_assert_false (g_str_equal (unsigned_a, "b"));
2268 /* Testing g_strv_contains() function with various cases */
2270 test_strv_contains (void)
2272 gboolean result = TRUE;
2273 const gchar *strv_simple[] = { "hello", "there", NULL };
2274 const gchar *strv_dupe[] = { "dupe", "dupe", NULL };
2275 const gchar *strv_empty[] = { NULL };
2277 if (g_test_undefined ())
2279 /* Testing degenerated cases */
2280 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2281 "*assertion*!= NULL*");
2282 result = g_strv_contains (NULL, "hello");
2283 g_test_assert_expected_messages ();
2284 g_assert_false (result);
2286 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2287 "*assertion*!= NULL*");
2288 result = g_strv_contains (strv_simple, NULL);
2289 g_test_assert_expected_messages ();
2290 g_assert_false (result);
2293 g_assert_true (g_strv_contains (strv_simple, "hello"));
2294 g_assert_true (g_strv_contains (strv_simple, "there"));
2295 g_assert_false (g_strv_contains (strv_simple, "non-existent"));
2296 g_assert_false (g_strv_contains (strv_simple, ""));
2298 g_assert_true (g_strv_contains (strv_dupe, "dupe"));
2300 g_assert_false (g_strv_contains (strv_empty, "empty!"));
2301 g_assert_false (g_strv_contains (strv_empty, ""));
2304 /* Test g_strv_equal() works for various inputs. */
2306 test_strv_equal (void)
2308 gboolean result = TRUE;
2309 const gchar *strv_empty[] = { NULL };
2310 const gchar *strv_empty2[] = { NULL };
2311 const gchar *strv_simple[] = { "hello", "you", NULL };
2312 const gchar *strv_simple2[] = { "hello", "you", NULL };
2313 const gchar *strv_simple_reordered[] = { "you", "hello", NULL };
2314 const gchar *strv_simple_superset[] = { "hello", "you", "again", NULL };
2315 const gchar *strv_another[] = { "not", "a", "coded", "message", NULL };
2317 if (g_test_undefined ())
2319 /* Testing degenerated cases */
2320 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2321 "*assertion*!= NULL*");
2322 result = g_strv_equal (NULL, strv_simple2);
2323 g_test_assert_expected_messages ();
2324 g_assert_false (result);
2326 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2327 "*assertion*!= NULL*");
2328 result = g_strv_equal (strv_simple, NULL);
2329 g_test_assert_expected_messages ();
2330 g_assert_false (result);
2333 g_assert_true (g_strv_equal (strv_empty, strv_empty));
2334 g_assert_true (g_strv_equal (strv_empty, strv_empty2));
2335 g_assert_true (g_strv_equal (strv_empty2, strv_empty));
2336 g_assert_false (g_strv_equal (strv_empty, strv_simple));
2337 g_assert_false (g_strv_equal (strv_simple, strv_empty));
2338 g_assert_true (g_strv_equal (strv_simple, strv_simple));
2339 g_assert_true (g_strv_equal (strv_simple, strv_simple2));
2340 g_assert_true (g_strv_equal (strv_simple2, strv_simple));
2341 g_assert_false (g_strv_equal (strv_simple, strv_simple_reordered));
2342 g_assert_false (g_strv_equal (strv_simple_reordered, strv_simple));
2343 g_assert_false (g_strv_equal (strv_simple, strv_simple_superset));
2344 g_assert_false (g_strv_equal (strv_simple_superset, strv_simple));
2345 g_assert_false (g_strv_equal (strv_simple, strv_another));
2346 g_assert_false (g_strv_equal (strv_another, strv_simple));
2363 gboolean should_fail;
2364 GNumberParserError error_code;
2367 const TestData test_data[] = {
2368 /* typical cases for signed */
2369 { "0", SIGNED, 10, -2, 2, 0, FALSE, 0 },
2370 { "+0", SIGNED, 10, -2, 2, 0, FALSE, 0 },
2371 { "-0", SIGNED, 10, -2, 2, 0, FALSE, 0 },
2372 { "-2", SIGNED, 10, -2, 2, -2, FALSE, 0 },
2373 {"-02", SIGNED, 10, -2, 2, -2, FALSE, 0 },
2374 { "2", SIGNED, 10, -2, 2, 2, FALSE, 0 },
2375 { "02", SIGNED, 10, -2, 2, 2, FALSE, 0 },
2376 { "+2", SIGNED, 10, -2, 2, 2, FALSE, 0 },
2377 {"+02", SIGNED, 10, -2, 2, 2, FALSE, 0 },
2378 { "3", SIGNED, 10, -2, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS },
2379 { "+3", SIGNED, 10, -2, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS },
2380 { "-3", SIGNED, 10, -2, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS },
2382 /* typical cases for unsigned */
2383 { "-1", UNSIGNED, 10, 0, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2384 { "1", UNSIGNED, 10, 0, 2, 1, FALSE, 0 },
2385 { "+1", UNSIGNED, 10, 0, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2386 { "0", UNSIGNED, 10, 0, 2, 0, FALSE, 0 },
2387 { "+0", UNSIGNED, 10, 0, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2388 { "-0", UNSIGNED, 10, 0, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2389 { "2", UNSIGNED, 10, 0, 2, 2, FALSE, 0 },
2390 { "+2", UNSIGNED, 10, 0, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2391 { "3", UNSIGNED, 10, 0, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS },
2392 { "+3", UNSIGNED, 10, 0, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2394 /* min == max cases for signed */
2395 { "-2", SIGNED, 10, -2, -2, -2, FALSE, 0 },
2396 { "-1", SIGNED, 10, -2, -2, 0, TRUE, G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS },
2397 { "-3", SIGNED, 10, -2, -2, 0, TRUE, G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS },
2399 /* min == max cases for unsigned */
2400 { "2", UNSIGNED, 10, 2, 2, 2, FALSE, 0 },
2401 { "3", UNSIGNED, 10, 2, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS },
2402 { "1", UNSIGNED, 10, 2, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS },
2404 /* invalid inputs */
2405 { "", SIGNED, 10, -2, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2406 { "", UNSIGNED, 10, 0, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2407 { "a", SIGNED, 10, -2, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2408 { "a", UNSIGNED, 10, 0, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2409 { "1a", SIGNED, 10, -2, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2410 { "1a", UNSIGNED, 10, 0, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2411 { "- 1", SIGNED, 10, -2, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2413 /* leading/trailing whitespace */
2414 { " 1", SIGNED, 10, -2, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2415 { " 1", UNSIGNED, 10, 0, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2416 { "1 ", SIGNED, 10, -2, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2417 { "1 ", UNSIGNED, 10, 0, 2, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2419 /* hexadecimal numbers */
2420 { "a", SIGNED, 16, 0, 15, 10, FALSE, 0 },
2421 { "a", UNSIGNED, 16, 0, 15, 10, FALSE, 0 },
2422 { "0a", UNSIGNED, 16, 0, 15, 10, FALSE, 0 },
2423 { "0xa", SIGNED, 16, 0, 15, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2424 { "0xa", UNSIGNED, 16, 0, 15, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2425 { "-0xa", SIGNED, 16, -15, 15, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2426 { "-0xa", UNSIGNED, 16, 0, 15, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2427 { "+0xa", SIGNED, 16, 0, 15, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2428 { "+0xa", UNSIGNED, 16, 0, 15, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2429 { "- 0xa", SIGNED, 16, -15, 15, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2430 { "- 0xa", UNSIGNED, 16, 0, 15, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2431 { "+ 0xa", SIGNED, 16, -15, 15, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2432 { "+ 0xa", UNSIGNED, 16, 0, 15, 0, TRUE, G_NUMBER_PARSER_ERROR_INVALID },
2435 /* Testing g_ascii_string_to_signed() and g_ascii_string_to_unsigned() functions */
2437 test_ascii_string_to_number_usual (void)
2441 GError *error = NULL;
2442 const TestData *data;
2445 guint64 valueu64 = 0;
2447 /*** g_ascii_string_to_signed() ***/
2448 data = &test_data[0]; /* Setting data to signed data */
2450 if (g_test_undefined ())
2452 /* Testing degenerated cases */
2453 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2454 "*assertion*!= NULL*");
2455 result = g_ascii_string_to_signed (NULL,
2461 g_test_assert_expected_messages ();
2462 g_assert_false (result);
2464 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2465 "*assertion \'base >= 2 && base <= 36\'*");
2466 result = g_ascii_string_to_signed (data->str,
2472 g_test_assert_expected_messages ();
2473 g_assert_false (result);
2475 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2476 "*assertion \'base >= 2 && base <= 36\'*");
2477 result = g_ascii_string_to_signed (data->str,
2483 g_test_assert_expected_messages ();
2484 g_assert_false (result);
2486 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2487 "*assertion \'min <= max\'*");
2488 result = g_ascii_string_to_signed (data->str,
2494 g_test_assert_expected_messages ();
2495 g_assert_false (result);
2498 /* Catching first part of (error == NULL || *error == NULL) */
2499 result = g_ascii_string_to_signed (data->str,
2505 g_assert_true (result);
2507 /*** g_ascii_string_to_unsigned() ***/
2508 data = &test_data[12]; /* Setting data to unsigned data */
2510 if (g_test_undefined ())
2512 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2513 "*assertion*!= NULL*");
2514 result = g_ascii_string_to_unsigned (NULL,
2520 g_test_assert_expected_messages ();
2521 g_assert_false (result);
2523 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2524 "*assertion \'base >= 2 && base <= 36\'*");
2525 result = g_ascii_string_to_unsigned (data->str,
2531 g_test_assert_expected_messages ();
2532 g_assert_false (result);
2534 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2535 "*assertion \'base >= 2 && base <= 36\'*");
2536 result = g_ascii_string_to_unsigned (data->str,
2542 g_test_assert_expected_messages ();
2543 g_assert_false (result);
2545 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
2546 "*assertion \'min <= max\'*");
2547 result = g_ascii_string_to_unsigned (data->str,
2553 g_test_assert_expected_messages ();
2554 g_assert_false (result);
2557 /* Catching first part of (error == NULL || *error == NULL) */
2558 result = g_ascii_string_to_unsigned (data->str,
2564 g_assert_false (result);
2566 /* Testing usual cases */
2567 for (idx = 0; idx < G_N_ELEMENTS (test_data); ++idx)
2569 data = &test_data[idx];
2571 switch (data->sign_type)
2575 result = g_ascii_string_to_signed (data->str,
2582 g_assert_cmpint (value, ==, value64);
2588 result = g_ascii_string_to_unsigned (data->str,
2595 g_assert_cmpint (value, ==, valueu64);
2600 g_assert_not_reached ();
2603 if (data->should_fail)
2605 g_assert_false (result);
2606 g_assert_error (error, G_NUMBER_PARSER_ERROR, (gint) data->error_code);
2607 g_clear_error (&error);
2611 g_assert_true (result);
2612 g_assert_no_error (error);
2613 g_assert_cmpint (value, ==, data->expected);
2618 /* Testing pathological cases for g_ascii_string_to_(un)signed() */
2620 test_ascii_string_to_number_pathological (void)
2622 GError *error = NULL;
2623 const gchar *crazy_high = "999999999999999999999999999999999999";
2624 const gchar *crazy_low = "-999999999999999999999999999999999999";
2625 const gchar *max_uint64 = "18446744073709551615";
2626 const gchar *max_int64 = "9223372036854775807";
2627 const gchar *min_int64 = "-9223372036854775808";
2631 g_assert_false (g_ascii_string_to_unsigned (crazy_high,
2637 g_assert_error (error, G_NUMBER_PARSER_ERROR, G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS);
2638 g_clear_error (&error);
2639 g_assert_false (g_ascii_string_to_unsigned (crazy_low,
2645 // crazy_low is a signed number so it is not a valid unsigned number
2646 g_assert_error (error, G_NUMBER_PARSER_ERROR, G_NUMBER_PARSER_ERROR_INVALID);
2647 g_clear_error (&error);
2649 g_assert_false (g_ascii_string_to_signed (crazy_high,
2655 g_assert_error (error, G_NUMBER_PARSER_ERROR, G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS);
2656 g_clear_error (&error);
2657 g_assert_false (g_ascii_string_to_signed (crazy_low,
2663 g_assert_error (error, G_NUMBER_PARSER_ERROR, G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS);
2664 g_clear_error (&error);
2666 g_assert_true (g_ascii_string_to_unsigned (max_uint64,
2672 g_assert_no_error (error);
2673 g_assert_cmpint (uvalue, ==, G_MAXUINT64);
2675 g_assert_true (g_ascii_string_to_signed (max_int64,
2681 g_assert_no_error (error);
2682 g_assert_cmpint (svalue, ==, G_MAXINT64);
2684 g_assert_true (g_ascii_string_to_signed (min_int64,
2690 g_assert_no_error (error);
2691 g_assert_cmpint (svalue, ==, G_MININT64);
2698 const char *empty_str = "";
2700 g_assert_false (g_set_str (&str, NULL));
2701 g_assert_null (str);
2703 g_assert_true (g_set_str (&str, empty_str));
2704 g_assert_false (g_set_str (&str, empty_str));
2705 g_assert_nonnull (str);
2706 g_assert_true ((gpointer)str != (gpointer)empty_str);
2707 g_assert_cmpstr (str, ==, empty_str);
2709 g_assert_true (g_set_str (&str, NULL));
2710 g_assert_null (str);
2712 g_assert_true (g_set_str (&str, empty_str));
2713 g_assert_true (g_set_str (&str, "test"));
2714 g_assert_cmpstr (str, ==, "test");
2716 g_assert_true (g_set_str (&str, &str[2]));
2717 g_assert_cmpstr (str, ==, "st");
2726 g_test_init (&argc, &argv, NULL);
2728 g_test_add_func ("/strfuncs/ascii-strcasecmp", test_ascii_strcasecmp);
2729 g_test_add_func ("/strfuncs/ascii-string-to-num/pathological", test_ascii_string_to_number_pathological);
2730 g_test_add_func ("/strfuncs/ascii-string-to-num/usual", test_ascii_string_to_number_usual);
2731 g_test_add_func ("/strfuncs/ascii_strdown", test_ascii_strdown);
2732 g_test_add_func ("/strfuncs/ascii_strdup", test_ascii_strup);
2733 g_test_add_func ("/strfuncs/ascii_strtod", test_ascii_strtod);
2734 g_test_add_func ("/strfuncs/bounds-check", test_bounds);
2735 g_test_add_func ("/strfuncs/has-prefix", test_has_prefix);
2736 g_test_add_func ("/strfuncs/has-prefix-macro", test_has_prefix_macro);
2737 g_test_add_func ("/strfuncs/has-suffix", test_has_suffix);
2738 g_test_add_func ("/strfuncs/has-suffix-macro", test_has_suffix_macro);
2739 g_test_add_func ("/strfuncs/memdup", test_memdup);
2740 g_test_add_func ("/strfuncs/memdup2", test_memdup2);
2741 g_test_add_func ("/strfuncs/set_str", test_set_str);
2742 g_test_add_func ("/strfuncs/stpcpy", test_stpcpy);
2743 g_test_add_func ("/strfuncs/str_match_string", test_str_match_string);
2744 g_test_add_func ("/strfuncs/str_tokenize_and_fold", test_str_tokenize_and_fold);
2745 g_test_add_func ("/strfuncs/strcanon", test_strcanon);
2746 g_test_add_func ("/strfuncs/strchomp", test_strchomp);
2747 g_test_add_func ("/strfuncs/strchug", test_strchug);
2748 g_test_add_func ("/strfuncs/strcompress-strescape", test_strcompress_strescape);
2749 g_test_add_func ("/strfuncs/strconcat", test_strconcat);
2750 g_test_add_func ("/strfuncs/strdelimit", test_strdelimit);
2751 g_test_add_func ("/strfuncs/strdup", test_strdup);
2752 g_test_add_func ("/strfuncs/strdup/inline", test_strdup_inline);
2753 g_test_add_func ("/strfuncs/strdup-printf", test_strdup_printf);
2754 g_test_add_func ("/strfuncs/strdupv", test_strdupv);
2755 g_test_add_func ("/strfuncs/strerror", test_strerror);
2756 g_test_add_func ("/strfuncs/strip-context", test_strip_context);
2757 g_test_add_func ("/strfuncs/strjoin", test_strjoin);
2758 g_test_add_func ("/strfuncs/strjoinv", test_strjoinv);
2759 g_test_add_func ("/strfuncs/strlcat", test_strlcat);
2760 g_test_add_func ("/strfuncs/strlcpy", test_strlcpy);
2761 g_test_add_func ("/strfuncs/strncasecmp", test_strncasecmp);
2762 g_test_add_func ("/strfuncs/strndup", test_strndup);
2763 g_test_add_func ("/strfuncs/strnfill", test_strnfill);
2764 g_test_add_func ("/strfuncs/strreverse", test_strreverse);
2765 g_test_add_func ("/strfuncs/strsignal", test_strsignal);
2766 g_test_add_func ("/strfuncs/strsplit", test_strsplit);
2767 g_test_add_func ("/strfuncs/strsplit-set", test_strsplit_set);
2768 g_test_add_func ("/strfuncs/strstr", test_strstr);
2769 g_test_add_func ("/strfuncs/strtod", test_strtod);
2770 g_test_add_func ("/strfuncs/strtoull-strtoll", test_strtoll);
2771 g_test_add_func ("/strfuncs/strup", test_strup);
2772 g_test_add_func ("/strfuncs/strv-contains", test_strv_contains);
2773 g_test_add_func ("/strfuncs/strv-equal", test_strv_equal);
2774 g_test_add_func ("/strfuncs/strv-length", test_strv_length);
2775 g_test_add_func ("/strfuncs/test-is-to-digit", test_is_to_digit);
2776 g_test_add_func ("/strfuncs/transliteration", test_transliteration);
2777 g_test_add_func ("/strfuncs/str-equal", test_str_equal);
2779 return g_test_run();