various tests: do not provoke SIGTRAP with -m no-undefined
[glib.git] / glib / tests / strfuncs.c
blob3387734571d079bebd42766ea5aef9d7afabc8a7
1 /* Unit tests for gstrfuncs
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This work is provided "as is"; redistribution and modification
5 * in whole or in part, in any medium, physical or electronic is
6 * permitted without restriction.
8 * This work is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * In no event shall the authors or contributors be liable for any
13 * direct, indirect, incidental, special, exemplary, or consequential
14 * damages (including, but not limited to, procurement of substitute
15 * goods or services; loss of use, data, or profits; or business
16 * interruption) however caused and on any theory of liability, whether
17 * in contract, strict liability, or tort (including negligence or
18 * otherwise) arising in any way out of the use of this software, even
19 * if advised of the possibility of such damage.
22 #define GLIB_DISABLE_DEPRECATION_WARNINGS
24 #define _XOPEN_SOURCE 600
25 #include <ctype.h>
26 #include <errno.h>
27 #include <locale.h>
28 #include <math.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include "glib.h"
35 #define GLIB_TEST_STRING "el dorado "
37 #define FOR_ALL_CTYPE(macro) \
38 macro(isalnum) \
39 macro(isalpha) \
40 macro(iscntrl) \
41 macro(isdigit) \
42 macro(isgraph) \
43 macro(islower) \
44 macro(isprint) \
45 macro(ispunct) \
46 macro(isspace) \
47 macro(isupper) \
48 macro(isxdigit)
50 #define DEFINE_CALL_CTYPE(function) \
51 static int \
52 call_##function (int c) \
53 { \
54 return function (c); \
57 #define DEFINE_CALL_G_ASCII_CTYPE(function) \
58 static gboolean \
59 call_g_ascii_##function (gchar c) \
60 { \
61 return g_ascii_##function (c); \
64 FOR_ALL_CTYPE (DEFINE_CALL_CTYPE)
65 FOR_ALL_CTYPE (DEFINE_CALL_G_ASCII_CTYPE)
67 static void
68 test_is_function (const char *name,
69 gboolean (* ascii_function) (gchar),
70 int (* c_library_function) (int),
71 gboolean (* unicode_function) (gunichar))
73 int c;
75 for (c = 0; c <= 0x7F; c++)
77 gboolean ascii_result = ascii_function ((gchar)c);
78 gboolean c_library_result = c_library_function (c) != 0;
79 gboolean unicode_result = unicode_function ((gunichar) c);
80 if (ascii_result != c_library_result && c != '\v')
82 g_error ("g_ascii_%s returned %d and %s returned %d for 0x%X",
83 name, ascii_result, name, c_library_result, c);
85 if (ascii_result != unicode_result)
87 g_error ("g_ascii_%s returned %d and g_unichar_%s returned %d for 0x%X",
88 name, ascii_result, name, unicode_result, c);
91 for (c = 0x80; c <= 0xFF; c++)
93 gboolean ascii_result = ascii_function ((gchar)c);
94 if (ascii_result)
96 g_error ("g_ascii_%s returned TRUE for 0x%X", name, c);
101 static void
102 test_to_function (const char *name,
103 gchar (* ascii_function) (gchar),
104 int (* c_library_function) (int),
105 gunichar (* unicode_function) (gunichar))
107 int c;
109 for (c = 0; c <= 0x7F; c++)
111 int ascii_result = (guchar) ascii_function ((gchar) c);
112 int c_library_result = c_library_function (c);
113 int unicode_result = unicode_function ((gunichar) c);
114 if (ascii_result != c_library_result)
116 g_error ("g_ascii_%s returned 0x%X and %s returned 0x%X for 0x%X",
117 name, ascii_result, name, c_library_result, c);
119 if (ascii_result != unicode_result)
121 g_error ("g_ascii_%s returned 0x%X and g_unichar_%s returned 0x%X for 0x%X",
122 name, ascii_result, name, unicode_result, c);
125 for (c = 0x80; c <= 0xFF; c++)
127 int ascii_result = (guchar) ascii_function ((gchar) c);
128 if (ascii_result != c)
130 g_error ("g_ascii_%s returned 0x%X for 0x%X",
131 name, ascii_result, c);
136 static void
137 test_digit_function (const char *name,
138 int (* ascii_function) (gchar),
139 int (* unicode_function) (gunichar))
141 int c;
143 for (c = 0; c <= 0x7F; c++)
145 int ascii_result = ascii_function ((gchar) c);
146 int unicode_result = unicode_function ((gunichar) c);
147 if (ascii_result != unicode_result)
149 g_error ("g_ascii_%s_value returned %d and g_unichar_%s_value returned %d for 0x%X",
150 name, ascii_result, name, unicode_result, c);
153 for (c = 0x80; c <= 0xFF; c++)
155 int ascii_result = ascii_function ((gchar) c);
156 if (ascii_result != -1)
158 g_error ("g_ascii_%s_value returned %d for 0x%X",
159 name, ascii_result, c);
164 static void
165 test_is_to_digit (void)
167 #define TEST_IS(name) test_is_function (#name, call_g_ascii_##name, call_##name, g_unichar_##name);
169 FOR_ALL_CTYPE(TEST_IS)
171 #undef TEST_IS
173 #define TEST_TO(name) test_to_function (#name, g_ascii_##name, name, g_unichar_##name)
175 TEST_TO (tolower);
176 TEST_TO (toupper);
178 #undef TEST_TO
180 #define TEST_DIGIT(name) test_digit_function (#name, g_ascii_##name##_value, g_unichar_##name##_value)
182 TEST_DIGIT (digit);
183 TEST_DIGIT (xdigit);
185 #undef TEST_DIGIT
188 static void
189 test_strdup (void)
191 gchar *str;
193 str = g_strdup (NULL);
194 g_assert (str == NULL);
196 str = g_strdup (GLIB_TEST_STRING);
197 g_assert (str != NULL);
198 g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
199 g_free (str);
202 static void
203 test_strndup (void)
205 gchar *str;
207 str = g_strndup (NULL, 3);
208 g_assert (str == NULL);
210 str = g_strndup ("aaaa", 5);
211 g_assert (str != NULL);
212 g_assert_cmpstr (str, ==, "aaaa");
213 g_free (str);
215 str = g_strndup ("aaaa", 2);
216 g_assert (str != NULL);
217 g_assert_cmpstr (str, ==, "aa");
218 g_free (str);
221 static void
222 test_strdup_printf (void)
224 gchar *str;
226 str = g_strdup_printf ("%05d %-5s", 21, "test");
227 g_assert (str != NULL);
228 g_assert_cmpstr (str, ==, "00021 test ");
229 g_free (str);
232 static void
233 test_strdupv (void)
235 gchar *vec[] = { "Foo", "Bar", NULL };
236 gchar **copy;
238 copy = g_strdupv (NULL);
239 g_assert (copy == NULL);
241 copy = g_strdupv (vec);
242 g_assert (copy != NULL);
243 g_assert_cmpstr (copy[0], ==, "Foo");
244 g_assert_cmpstr (copy[1], ==, "Bar");
245 g_assert (copy[2] == NULL);
246 g_strfreev (copy);
249 static void
250 test_strnfill (void)
252 gchar *str;
254 str = g_strnfill (0, 'a');
255 g_assert (str != NULL);
256 g_assert (*str == '\0');
257 g_free (str);
259 str = g_strnfill (5, 'a');
260 g_assert (str != NULL);
261 g_assert_cmpstr (str, ==, "aaaaa");
262 g_free (str);
265 static void
266 test_strconcat (void)
268 gchar *str;
270 str = g_strconcat (GLIB_TEST_STRING, NULL);
271 g_assert (str != NULL);
272 g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
273 g_free (str);
275 str = g_strconcat (GLIB_TEST_STRING,
276 GLIB_TEST_STRING,
277 GLIB_TEST_STRING,
278 NULL);
279 g_assert (str != NULL);
280 g_assert_cmpstr (str, ==, GLIB_TEST_STRING GLIB_TEST_STRING GLIB_TEST_STRING);
281 g_free (str);
283 g_assert (g_strconcat (NULL, "bla", NULL) == NULL);
286 static void
287 test_strjoin (void)
289 gchar *str;
291 str = g_strjoin (NULL, NULL);
292 g_assert (str != NULL);
293 g_assert (*str == '\0');
294 g_free (str);
296 str = g_strjoin (":", NULL);
297 g_assert (str != NULL);
298 g_assert (*str == '\0');
299 g_free (str);
301 str = g_strjoin (NULL, GLIB_TEST_STRING, NULL);
302 g_assert (str != NULL);
303 g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
304 g_free (str);
306 str = g_strjoin (NULL,
307 GLIB_TEST_STRING,
308 GLIB_TEST_STRING,
309 GLIB_TEST_STRING,
310 NULL);
311 g_assert (str != NULL);
312 g_assert_cmpstr (str, ==, GLIB_TEST_STRING GLIB_TEST_STRING GLIB_TEST_STRING);
313 g_free (str);
315 str = g_strjoin (":",
316 GLIB_TEST_STRING,
317 GLIB_TEST_STRING,
318 GLIB_TEST_STRING,
319 NULL);
320 g_assert (str != NULL);
321 g_assert_cmpstr (str, ==, GLIB_TEST_STRING ":" GLIB_TEST_STRING ":" GLIB_TEST_STRING);
322 g_free (str);
325 static void
326 test_strcanon (void)
328 gchar *str;
330 if (g_test_undefined ())
332 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
334 str = g_strcanon (NULL, "ab", 'y');
336 g_test_trap_assert_failed ();
338 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
340 str = g_strdup ("abxabxab");
341 str = g_strcanon (str, NULL, 'y');
342 g_free (str);
344 g_test_trap_assert_failed ();
347 str = g_strdup ("abxabxab");
348 str = g_strcanon (str, "ab", 'y');
349 g_assert (str != NULL);
350 g_assert_cmpstr (str, ==, "abyabyab");
351 g_free (str);
354 static void
355 test_strcompress_strescape (void)
357 gchar *str;
358 gchar *tmp;
360 /* test compress */
361 if (g_test_undefined ())
363 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
365 str = g_strcompress (NULL);
367 g_test_trap_assert_failed ();
369 /* trailing slashes are not allowed */
370 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
372 str = g_strcompress ("abc\\");
374 g_test_trap_assert_failed ();
377 str = g_strcompress ("abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313\\12345z");
378 g_assert (str != NULL);
379 g_assert_cmpstr (str, ==, "abc\\\"\b\f\n\r\t\003\177\234\313\12345z");
380 g_free (str);
382 /* test escape */
383 if (g_test_undefined ())
385 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
387 str = g_strescape (NULL, NULL);
389 g_test_trap_assert_failed ();
392 str = g_strescape ("abc\\\"\b\f\n\r\t\003\177\234\313", NULL);
393 g_assert (str != NULL);
394 g_assert_cmpstr (str, ==, "abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313");
395 g_free (str);
397 str = g_strescape ("abc\\\"\b\f\n\r\t\003\177\234\313",
398 "\b\f\001\002\003\004");
399 g_assert (str != NULL);
400 g_assert_cmpstr (str, ==, "abc\\\\\\\"\b\f\\n\\r\\t\003\\177\\234\\313");
401 g_free (str);
403 /* round trip */
404 tmp = g_strescape ("abc\\\"\b\f\n\r\t\003\177\234\313", NULL);
405 str = g_strcompress (tmp);
406 g_assert (str != NULL);
407 g_assert_cmpstr (str, ==, "abc\\\"\b\f\n\r\t\003\177\234\313");
408 g_free (str);
409 g_free (tmp);
412 static void
413 test_ascii_strcasecmp (void)
415 gboolean res;
417 if (g_test_undefined ())
419 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
421 res = g_ascii_strcasecmp ("foo", NULL);
423 g_test_trap_assert_failed ();
425 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
427 res = g_ascii_strcasecmp (NULL, "foo");
429 g_test_trap_assert_failed ();
432 res = g_ascii_strcasecmp ("FroboZZ", "frobozz");
433 g_assert_cmpint (res, ==, 0);
435 res = g_ascii_strcasecmp ("frobozz", "frobozz");
436 g_assert_cmpint (res, ==, 0);
438 res = g_ascii_strcasecmp ("frobozz", "FROBOZZ");
439 g_assert_cmpint (res, ==, 0);
441 res = g_ascii_strcasecmp ("FROBOZZ", "froboz");
442 g_assert_cmpint (res, !=, 0);
444 res = g_ascii_strcasecmp ("", "");
445 g_assert_cmpint (res, ==, 0);
447 res = g_ascii_strcasecmp ("!#%&/()", "!#%&/()");
448 g_assert_cmpint (res, ==, 0);
450 res = g_ascii_strcasecmp ("a", "b");
451 g_assert_cmpint (res, <, 0);
453 res = g_ascii_strcasecmp ("a", "B");
454 g_assert_cmpint (res, <, 0);
456 res = g_ascii_strcasecmp ("A", "b");
457 g_assert_cmpint (res, <, 0);
459 res = g_ascii_strcasecmp ("A", "B");
460 g_assert_cmpint (res, <, 0);
462 res = g_ascii_strcasecmp ("b", "a");
463 g_assert_cmpint (res, >, 0);
465 res = g_ascii_strcasecmp ("b", "A");
466 g_assert_cmpint (res, >, 0);
468 res = g_ascii_strcasecmp ("B", "a");
469 g_assert_cmpint (res, >, 0);
471 res = g_ascii_strcasecmp ("B", "A");
472 g_assert_cmpint (res, >, 0);
475 static void
476 do_test_strchug (const gchar *str, const gchar *expected)
478 gchar *tmp;
479 gboolean res;
481 tmp = g_strdup (str);
483 g_strchug (tmp);
484 res = (strcmp (tmp, expected) == 0);
485 g_free (tmp);
487 g_assert_cmpint (res, ==, TRUE);
490 static void
491 test_strchug (void)
493 if (g_test_undefined ())
495 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
497 g_strchug (NULL);
499 g_test_trap_assert_failed ();
502 do_test_strchug ("", "");
503 do_test_strchug (" ", "");
504 do_test_strchug ("\t\r\n ", "");
505 do_test_strchug (" a", "a");
506 do_test_strchug (" a", "a");
507 do_test_strchug ("a a", "a a");
508 do_test_strchug (" a a", "a a");
511 static void
512 do_test_strchomp (const gchar *str, const gchar *expected)
514 gchar *tmp;
515 gboolean res;
517 tmp = g_strdup (str);
519 g_strchomp (tmp);
520 res = (strcmp (tmp, expected) == 0);
521 g_free (tmp);
523 g_assert_cmpint (res, ==, TRUE);
526 static void
527 test_strchomp (void)
529 if (g_test_undefined ())
531 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
533 g_strchomp (NULL);
535 g_test_trap_assert_failed ();
538 do_test_strchomp ("", "");
539 do_test_strchomp (" ", "");
540 do_test_strchomp (" \t\r\n", "");
541 do_test_strchomp ("a ", "a");
542 do_test_strchomp ("a ", "a");
543 do_test_strchomp ("a a", "a a");
544 do_test_strchomp ("a a ", "a a");
547 static void
548 test_strreverse (void)
550 gchar *str;
551 gchar *p;
553 if (g_test_undefined ())
555 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
557 str = g_strreverse (NULL);
559 g_test_trap_assert_failed ();
562 str = p = g_strdup ("abcde");
563 str = g_strreverse (str);
564 g_assert (str != NULL);
565 g_assert (p == str);
566 g_assert_cmpstr (str, ==, "edcba");
567 g_free (str);
570 static void
571 test_strstr (void)
573 gchar *haystack;
574 gchar *res;
576 haystack = g_strdup ("FooBarFooBarFoo");
578 /* strstr_len */
579 res = g_strstr_len (haystack, 6, "xxx");
580 g_assert (res == NULL);
582 res = g_strstr_len (haystack, 6, "FooBarFooBarFooBar");
583 g_assert (res == NULL);
585 res = g_strstr_len (haystack, 3, "Bar");
586 g_assert (res == NULL);
588 res = g_strstr_len (haystack, 6, "");
589 g_assert (res == haystack);
590 g_assert_cmpstr (res, ==, "FooBarFooBarFoo");
592 res = g_strstr_len (haystack, 6, "Bar");
593 g_assert (res == haystack + 3);
594 g_assert_cmpstr (res, ==, "BarFooBarFoo");
596 res = g_strstr_len (haystack, -1, "Bar");
597 g_assert (res == haystack + 3);
598 g_assert_cmpstr (res, ==, "BarFooBarFoo");
600 /* strrstr */
601 res = g_strrstr (haystack, "xxx");
602 g_assert (res == NULL);
604 res = g_strrstr (haystack, "FooBarFooBarFooBar");
605 g_assert (res == NULL);
607 res = g_strrstr (haystack, "");
608 g_assert (res == haystack);
609 g_assert_cmpstr (res, ==, "FooBarFooBarFoo");
611 res = g_strrstr (haystack, "Bar");
612 g_assert (res == haystack + 9);
613 g_assert_cmpstr (res, ==, "BarFoo");
615 /* strrstr_len */
616 res = g_strrstr_len (haystack, 14, "xxx");
617 g_assert (res == NULL);
619 res = g_strrstr_len (haystack, 14, "FooBarFooBarFooBar");
620 g_assert (res == NULL);
622 res = g_strrstr_len (haystack, 3, "Bar");
623 g_assert (res == NULL);
625 res = g_strrstr_len (haystack, 14, "BarFoo");
626 g_assert (res == haystack + 3);
627 g_assert_cmpstr (res, ==, "BarFooBarFoo");
629 res = g_strrstr_len (haystack, 15, "BarFoo");
630 g_assert (res == haystack + 9);
631 g_assert_cmpstr (res, ==, "BarFoo");
633 res = g_strrstr_len (haystack, -1, "BarFoo");
634 g_assert (res == haystack + 9);
635 g_assert_cmpstr (res, ==, "BarFoo");
637 /* test case for strings with \0 in the middle */
638 *(haystack + 7) = '\0';
639 res = g_strstr_len (haystack, 15, "BarFoo");
640 g_assert (res == NULL);
642 g_free (haystack);
645 static void
646 test_has_prefix (void)
648 gboolean res;
650 if (g_test_undefined ())
652 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
654 res = g_str_has_prefix ("foo", NULL);
656 g_test_trap_assert_failed ();
658 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
660 res = g_str_has_prefix (NULL, "foo");
662 g_test_trap_assert_failed ();
665 res = g_str_has_prefix ("foo", "bar");
666 g_assert_cmpint (res, ==, FALSE);
668 res = g_str_has_prefix ("foo", "foobar");
669 g_assert_cmpint (res, ==, FALSE);
671 res = g_str_has_prefix ("foobar", "bar");
672 g_assert_cmpint (res, ==, FALSE);
674 res = g_str_has_prefix ("foobar", "foo");
675 g_assert_cmpint (res, ==, TRUE);
677 res = g_str_has_prefix ("foo", "");
678 g_assert_cmpint (res, ==, TRUE);
680 res = g_str_has_prefix ("foo", "foo");
681 g_assert_cmpint (res, ==, TRUE);
683 res = g_str_has_prefix ("", "");
684 g_assert_cmpint (res, ==, TRUE);
687 static void
688 test_has_suffix (void)
690 gboolean res;
692 if (g_test_undefined ())
694 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
696 res = g_str_has_suffix ("foo", NULL);
698 g_test_trap_assert_failed ();
700 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
702 res = g_str_has_suffix (NULL, "foo");
704 g_test_trap_assert_failed ();
707 res = g_str_has_suffix ("foo", "bar");
708 g_assert_cmpint (res, ==, FALSE);
710 res = g_str_has_suffix ("bar", "foobar");
711 g_assert_cmpint (res, ==, FALSE);
713 res = g_str_has_suffix ("foobar", "foo");
714 g_assert_cmpint (res, ==, FALSE);
716 res = g_str_has_suffix ("foobar", "bar");
717 g_assert_cmpint (res, ==, TRUE);
719 res = g_str_has_suffix ("foo", "");
720 g_assert_cmpint (res, ==, TRUE);
722 res = g_str_has_suffix ("foo", "foo");
723 g_assert_cmpint (res, ==, TRUE);
725 res = g_str_has_suffix ("", "");
726 g_assert_cmpint (res, ==, TRUE);
729 static void
730 strv_check (gchar **strv, ...)
732 gboolean ok = TRUE;
733 gint i = 0;
734 va_list list;
736 va_start (list, strv);
737 while (ok)
739 const gchar *str = va_arg (list, const char *);
740 if (strv[i] == NULL)
742 g_assert (str == NULL);
743 break;
745 if (str == NULL)
747 ok = FALSE;
749 else
751 g_assert_cmpstr (strv[i], ==, str);
753 i++;
755 va_end (list);
757 g_strfreev (strv);
760 static void
761 test_strsplit (void)
763 strv_check (g_strsplit ("", ",", 0), NULL);
764 strv_check (g_strsplit ("x", ",", 0), "x", NULL);
765 strv_check (g_strsplit ("x,y", ",", 0), "x", "y", NULL);
766 strv_check (g_strsplit ("x,y,", ",", 0), "x", "y", "", NULL);
767 strv_check (g_strsplit (",x,y", ",", 0), "", "x", "y", NULL);
768 strv_check (g_strsplit (",x,y,", ",", 0), "", "x", "y", "", NULL);
769 strv_check (g_strsplit ("x,y,z", ",", 0), "x", "y", "z", NULL);
770 strv_check (g_strsplit ("x,y,z,", ",", 0), "x", "y", "z", "", NULL);
771 strv_check (g_strsplit (",x,y,z", ",", 0), "", "x", "y", "z", NULL);
772 strv_check (g_strsplit (",x,y,z,", ",", 0), "", "x", "y", "z", "", NULL);
773 strv_check (g_strsplit (",,x,,y,,z,,", ",", 0), "", "", "x", "", "y", "", "z", "", "", NULL);
774 strv_check (g_strsplit (",,x,,y,,z,,", ",,", 0), "", "x", "y", "z", "", NULL);
776 strv_check (g_strsplit ("", ",", 1), NULL);
777 strv_check (g_strsplit ("x", ",", 1), "x", NULL);
778 strv_check (g_strsplit ("x,y", ",", 1), "x,y", NULL);
779 strv_check (g_strsplit ("x,y,", ",", 1), "x,y,", NULL);
780 strv_check (g_strsplit (",x,y", ",", 1), ",x,y", NULL);
781 strv_check (g_strsplit (",x,y,", ",", 1), ",x,y,", NULL);
782 strv_check (g_strsplit ("x,y,z", ",", 1), "x,y,z", NULL);
783 strv_check (g_strsplit ("x,y,z,", ",", 1), "x,y,z,", NULL);
784 strv_check (g_strsplit (",x,y,z", ",", 1), ",x,y,z", NULL);
785 strv_check (g_strsplit (",x,y,z,", ",", 1), ",x,y,z,", NULL);
786 strv_check (g_strsplit (",,x,,y,,z,,", ",", 1), ",,x,,y,,z,,", NULL);
787 strv_check (g_strsplit (",,x,,y,,z,,", ",,", 1), ",,x,,y,,z,,", NULL);
789 strv_check (g_strsplit ("", ",", 2), NULL);
790 strv_check (g_strsplit ("x", ",", 2), "x", NULL);
791 strv_check (g_strsplit ("x,y", ",", 2), "x", "y", NULL);
792 strv_check (g_strsplit ("x,y,", ",", 2), "x", "y,", NULL);
793 strv_check (g_strsplit (",x,y", ",", 2), "", "x,y", NULL);
794 strv_check (g_strsplit (",x,y,", ",", 2), "", "x,y,", NULL);
795 strv_check (g_strsplit ("x,y,z", ",", 2), "x", "y,z", NULL);
796 strv_check (g_strsplit ("x,y,z,", ",", 2), "x", "y,z,", NULL);
797 strv_check (g_strsplit (",x,y,z", ",", 2), "", "x,y,z", NULL);
798 strv_check (g_strsplit (",x,y,z,", ",", 2), "", "x,y,z,", NULL);
799 strv_check (g_strsplit (",,x,,y,,z,,", ",", 2), "", ",x,,y,,z,,", NULL);
800 strv_check (g_strsplit (",,x,,y,,z,,", ",,", 2), "", "x,,y,,z,,", NULL);
803 static void
804 test_strsplit_set (void)
806 strv_check (g_strsplit_set ("", ",/", 0), NULL);
807 strv_check (g_strsplit_set (":def/ghi:", ":/", -1), "", "def", "ghi", "", NULL);
808 strv_check (g_strsplit_set ("abc:def/ghi", ":/", -1), "abc", "def", "ghi", NULL);
809 strv_check (g_strsplit_set (",;,;,;,;", ",;", -1), "", "", "", "", "", "", "", "", "", NULL);
810 strv_check (g_strsplit_set (",,abc.def", ".,", -1), "", "", "abc", "def", NULL);
812 strv_check (g_strsplit_set (",x.y", ",.", 0), "", "x", "y", NULL);
813 strv_check (g_strsplit_set (".x,y,", ",.", 0), "", "x", "y", "", NULL);
814 strv_check (g_strsplit_set ("x,y.z", ",.", 0), "x", "y", "z", NULL);
815 strv_check (g_strsplit_set ("x.y,z,", ",.", 0), "x", "y", "z", "", NULL);
816 strv_check (g_strsplit_set (",x.y,z", ",.", 0), "", "x", "y", "z", NULL);
817 strv_check (g_strsplit_set (",x,y,z,", ",.", 0), "", "x", "y", "z", "", NULL);
818 strv_check (g_strsplit_set (",.x,,y,;z..", ".,;", 0), "", "", "x", "", "y", "", "z", "", "", NULL);
819 strv_check (g_strsplit_set (",,x,,y,,z,,", ",,", 0), "", "", "x", "", "y", "", "z", "", "", NULL);
821 strv_check (g_strsplit_set ("x,y.z", ",.", 1), "x,y.z", NULL);
822 strv_check (g_strsplit_set ("x.y,z,", ",.", 1), "x.y,z,", NULL);
823 strv_check (g_strsplit_set (",x,y,z", ",.", 1), ",x,y,z", NULL);
824 strv_check (g_strsplit_set (",x,y.z,", ",.", 1), ",x,y.z,", NULL);
825 strv_check (g_strsplit_set (",,x,.y,,z,,", ",.", 1), ",,x,.y,,z,,", NULL);
826 strv_check (g_strsplit_set (",.x,,y,,z,,", ",,..", 1), ",.x,,y,,z,,", NULL);
828 strv_check (g_strsplit_set ("", ",", 0), NULL);
829 strv_check (g_strsplit_set ("x", ",", 0), "x", NULL);
830 strv_check (g_strsplit_set ("x,y", ",", 0), "x", "y", NULL);
831 strv_check (g_strsplit_set ("x,y,", ",", 0), "x", "y", "", NULL);
832 strv_check (g_strsplit_set (",x,y", ",", 0), "", "x", "y", NULL);
833 strv_check (g_strsplit_set (",x,y,", ",", 0), "", "x", "y", "", NULL);
834 strv_check (g_strsplit_set ("x,y,z", ",", 0), "x", "y", "z", NULL);
835 strv_check (g_strsplit_set ("x,y,z,", ",", 0), "x", "y", "z", "", NULL);
836 strv_check (g_strsplit_set (",x,y,z", ",", 0), "", "x", "y", "z", NULL);
837 strv_check (g_strsplit_set (",x,y,z,", ",", 0), "", "x", "y", "z", "", NULL);
838 strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 0), "", "", "x", "", "y", "", "z", "", "", NULL);
840 strv_check (g_strsplit_set ("", ",", 1), NULL);
841 strv_check (g_strsplit_set ("x", ",", 1), "x", NULL);
842 strv_check (g_strsplit_set ("x,y", ",", 1), "x,y", NULL);
843 strv_check (g_strsplit_set ("x,y,", ",", 1), "x,y,", NULL);
844 strv_check (g_strsplit_set (",x,y", ",", 1), ",x,y", NULL);
845 strv_check (g_strsplit_set (",x,y,", ",", 1), ",x,y,", NULL);
846 strv_check (g_strsplit_set ("x,y,z", ",", 1), "x,y,z", NULL);
847 strv_check (g_strsplit_set ("x,y,z,", ",", 1), "x,y,z,", NULL);
848 strv_check (g_strsplit_set (",x,y,z", ",", 1), ",x,y,z", NULL);
849 strv_check (g_strsplit_set (",x,y,z,", ",", 1), ",x,y,z,", NULL);
850 strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 1), ",,x,,y,,z,,", NULL);
851 strv_check (g_strsplit_set (",,x,,y,,z,,", ",,", 1), ",,x,,y,,z,,", NULL);
853 strv_check (g_strsplit_set ("", ",", 2), NULL);
854 strv_check (g_strsplit_set ("x", ",", 2), "x", NULL);
855 strv_check (g_strsplit_set ("x,y", ",", 2), "x", "y", NULL);
856 strv_check (g_strsplit_set ("x,y,", ",", 2), "x", "y,", NULL);
857 strv_check (g_strsplit_set (",x,y", ",", 2), "", "x,y", NULL);
858 strv_check (g_strsplit_set (",x,y,", ",", 2), "", "x,y,", NULL);
859 strv_check (g_strsplit_set ("x,y,z", ",", 2), "x", "y,z", NULL);
860 strv_check (g_strsplit_set ("x,y,z,", ",", 2), "x", "y,z,", NULL);
861 strv_check (g_strsplit_set (",x,y,z", ",", 2), "", "x,y,z", NULL);
862 strv_check (g_strsplit_set (",x,y,z,", ",", 2), "", "x,y,z,", NULL);
863 strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 2), "", ",x,,y,,z,,", NULL);
865 strv_check (g_strsplit_set (",,x,.y,..z,,", ",.", 3), "", "", "x,.y,..z,,", NULL);
868 static void
869 test_strv_length (void)
871 gchar **strv;
872 guint l;
874 if (g_test_undefined ())
876 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
878 l = g_strv_length (NULL);
880 g_test_trap_assert_failed ();
883 strv = g_strsplit ("1,2,3,4", ",", -1);
884 l = g_strv_length (strv);
885 g_assert_cmpuint (l, ==, 4);
886 g_strfreev (strv);
889 static char *locales[] = {"sv_SE", "en_US", "fa_IR", "C", "ru_RU"};
891 static void
892 check_strtod_string (gchar *number,
893 double res,
894 gboolean check_end,
895 gint correct_len)
897 double d;
898 gint l;
899 gchar *dummy;
901 /* we try a copy of number, with some free space for malloc before that.
902 * This is supposed to smash the some wrong pointer calculations. */
904 dummy = g_malloc (100000);
905 number = g_strdup (number);
906 g_free (dummy);
908 for (l = 0; l < G_N_ELEMENTS (locales); l++)
910 gchar *end = "(unset)";
912 setlocale (LC_NUMERIC, locales[l]);
913 d = g_ascii_strtod (number, &end);
914 g_assert (isnan (res) ? isnan (d) : (d == res));
915 g_assert ((end - number) == (check_end ? correct_len : strlen (number)));
918 g_free (number);
921 static void
922 check_strtod_number (gdouble num, gchar *fmt, gchar *str)
924 int l;
925 gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
927 for (l = 0; l < G_N_ELEMENTS (locales); l++)
929 setlocale (LC_ALL, locales[l]);
930 g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, fmt, num);
931 g_assert_cmpstr (buf, ==, str);
935 static void
936 test_strtod (void)
938 gdouble d, our_nan, our_inf;
939 char buffer[G_ASCII_DTOSTR_BUF_SIZE];
941 #ifdef NAN
942 our_nan = NAN;
943 #else
944 /* Do this before any call to setlocale. */
945 our_nan = atof ("NaN");
946 #endif
947 g_assert (isnan (our_nan));
949 #ifdef INFINITY
950 our_inf = INFINITY;
951 #else
952 our_inf = atof ("Infinity");
953 #endif
954 g_assert (our_inf > 1 && our_inf == our_inf / 2);
956 check_strtod_string ("123.123", 123.123, FALSE, 0);
957 check_strtod_string ("123.123e2", 123.123e2, FALSE, 0);
958 check_strtod_string ("123.123e-2", 123.123e-2, FALSE, 0);
959 check_strtod_string ("-123.123", -123.123, FALSE, 0);
960 check_strtod_string ("-123.123e2", -123.123e2, FALSE, 0);
961 check_strtod_string ("-123.123e-2", -123.123e-2, FALSE, 0);
962 check_strtod_string ("5.4", 5.4, TRUE, 3);
963 check_strtod_string ("5.4,5.5", 5.4, TRUE, 3);
964 check_strtod_string ("5,4", 5.0, TRUE, 1);
965 check_strtod_string ("0xa.b", 10.6875, TRUE, 5);
966 check_strtod_string ("0xa.bP3", 85.5, TRUE, 7);
967 check_strtod_string ("0xa.bp+3", 85.5, TRUE, 8);
968 check_strtod_string ("0xa.bp-2", 2.671875, TRUE, 8);
969 check_strtod_string ("0xA.BG", 10.6875, TRUE, 5);
970 /* the following are for #156421 */
971 check_strtod_string ("1e1", 1e1, FALSE, 0);
972 check_strtod_string ("NAN", our_nan, FALSE, 0);
973 check_strtod_string ("-nan", -our_nan, FALSE, 0);
974 check_strtod_string ("INF", our_inf, FALSE, 0);
975 check_strtod_string ("-infinity", -our_inf, FALSE, 0);
976 check_strtod_string ("-.75,0", -0.75, TRUE, 4);
978 d = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
979 g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
981 d = -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
982 g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
984 d = pow (2.0, -1024.1);
985 g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
987 d = -pow (2.0, -1024.1);
988 g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
990 /* for #343899 */
991 check_strtod_string (" 0.75", 0.75, FALSE, 0);
992 check_strtod_string (" +0.75", 0.75, FALSE, 0);
993 check_strtod_string (" -0.75", -0.75, FALSE, 0);
994 check_strtod_string ("\f0.75", 0.75, FALSE, 0);
995 check_strtod_string ("\n0.75", 0.75, FALSE, 0);
996 check_strtod_string ("\r0.75", 0.75, FALSE, 0);
997 check_strtod_string ("\t0.75", 0.75, FALSE, 0);
999 #if 0
1000 /* g_ascii_isspace() returns FALSE for vertical tab, see #59388 */
1001 check_strtod_string ("\v0.75", 0.75, FALSE, 0);
1002 #endif
1004 /* for #343899 */
1005 check_strtod_number (0.75, "%0.2f", "0.75");
1006 check_strtod_number (0.75, "%5.2f", " 0.75");
1007 check_strtod_number (-0.75, "%0.2f", "-0.75");
1008 check_strtod_number (-0.75, "%5.2f", "-0.75");
1009 check_strtod_number (1e99, "%.0e", "1e+99");
1012 static void
1013 check_uint64 (const gchar *str,
1014 const gchar *end,
1015 gint base,
1016 guint64 result,
1017 gint error)
1019 guint64 actual;
1020 gchar *endptr = NULL;
1021 gint err;
1023 errno = 0;
1024 actual = g_ascii_strtoull (str, &endptr, base);
1025 err = errno;
1027 g_assert (actual == result);
1028 g_assert_cmpstr (end, ==, endptr);
1029 g_assert (err == error);
1032 static void
1033 check_int64 (const gchar *str,
1034 const gchar *end,
1035 gint base,
1036 gint64 result,
1037 gint error)
1039 gint64 actual;
1040 gchar *endptr = NULL;
1041 gint err;
1043 errno = 0;
1044 actual = g_ascii_strtoll (str, &endptr, base);
1045 err = errno;
1047 g_assert (actual == result);
1048 g_assert_cmpstr (end, ==, endptr);
1049 g_assert (err == error);
1052 static void
1053 test_strtoll (void)
1055 check_uint64 ("0", "", 10, 0, 0);
1056 check_uint64 ("+0", "", 10, 0, 0);
1057 check_uint64 ("-0", "", 10, 0, 0);
1058 check_uint64 ("18446744073709551615", "", 10, G_MAXUINT64, 0);
1059 check_uint64 ("18446744073709551616", "", 10, G_MAXUINT64, ERANGE);
1060 check_uint64 ("20xyz", "xyz", 10, 20, 0);
1061 check_uint64 ("-1", "", 10, G_MAXUINT64, 0);
1063 check_int64 ("0", "", 10, 0, 0);
1064 check_int64 ("9223372036854775807", "", 10, G_MAXINT64, 0);
1065 check_int64 ("9223372036854775808", "", 10, G_MAXINT64, ERANGE);
1066 check_int64 ("-9223372036854775808", "", 10, G_MININT64, 0);
1067 check_int64 ("-9223372036854775809", "", 10, G_MININT64, ERANGE);
1068 check_int64 ("32768", "", 10, 32768, 0);
1069 check_int64 ("-32768", "", 10, -32768, 0);
1070 check_int64 ("001", "", 10, 1, 0);
1071 check_int64 ("-001", "", 10, -1, 0);
1074 static void
1075 test_bounds (void)
1077 GMappedFile *file, *before, *after;
1078 char buffer[4097];
1079 char *tmp, *tmp2;
1080 char **array;
1081 char *string;
1083 /* if we allocate the file between two others and then free those
1084 * other two, then hopefully we end up with unmapped memory on either
1085 * side.
1087 before = g_mapped_file_new ("4096-random-bytes", TRUE, NULL);
1089 /* quick workaround until #549783 can be fixed */
1090 if (before == NULL)
1091 return;
1093 file = g_mapped_file_new ("4096-random-bytes", TRUE, NULL);
1094 after = g_mapped_file_new ("4096-random-bytes", TRUE, NULL);
1095 g_mapped_file_unref (before);
1096 g_mapped_file_unref (after);
1098 g_assert (file != NULL);
1099 g_assert_cmpint (g_mapped_file_get_length (file), ==, 4096);
1100 string = g_mapped_file_get_contents (file);
1102 /* ensure they're all non-nul */
1103 g_assert (memchr (string, '\0', 4096) == NULL);
1105 /* test set 1: ensure that nothing goes past its maximum length, even in
1106 * light of a missing nul terminator.
1108 * we try to test all of the 'n' functions here.
1110 tmp = g_strndup (string, 4096);
1111 g_assert_cmpint (strlen (tmp), ==, 4096);
1112 g_free (tmp);
1114 /* found no bugs in gnome, i hope :) */
1115 g_assert (g_strstr_len (string, 4096, "BUGS") == NULL);
1116 g_strstr_len (string, 4096, "B");
1117 g_strstr_len (string, 4096, ".");
1118 g_strstr_len (string, 4096, "");
1120 g_strrstr_len (string, 4096, "BUGS");
1121 g_strrstr_len (string, 4096, "B");
1122 g_strrstr_len (string, 4096, ".");
1123 g_strrstr_len (string, 4096, "");
1125 g_ascii_strdown (string, 4096);
1126 g_ascii_strdown (string, 4096);
1127 g_ascii_strup (string, 4096);
1128 g_ascii_strup (string, 4096);
1130 g_ascii_strncasecmp (string, string, 4096);
1132 tmp = g_markup_escape_text (string, 4096);
1133 g_free (tmp);
1135 /* test set 2: ensure that nothing reads even one byte past a '\0'.
1137 g_assert_cmpint (string[4095], ==, '\n');
1138 string[4095] = '\0';
1140 tmp = g_strdup (string);
1141 g_assert_cmpint (strlen (tmp), ==, 4095);
1142 g_free (tmp);
1144 tmp = g_strndup (string, 10000);
1145 g_assert_cmpint (strlen (tmp), ==, 4095);
1146 g_free (tmp);
1148 g_stpcpy (buffer, string);
1149 g_assert_cmpint (strlen (buffer), ==, 4095);
1151 g_strstr_len (string, 10000, "BUGS");
1152 g_strstr_len (string, 10000, "B");
1153 g_strstr_len (string, 10000, ".");
1154 g_strstr_len (string, 10000, "");
1156 g_strrstr (string, "BUGS");
1157 g_strrstr (string, "B");
1158 g_strrstr (string, ".");
1159 g_strrstr (string, "");
1161 g_strrstr_len (string, 10000, "BUGS");
1162 g_strrstr_len (string, 10000, "B");
1163 g_strrstr_len (string, 10000, ".");
1164 g_strrstr_len (string, 10000, "");
1166 g_str_has_prefix (string, "this won't do very much...");
1167 g_str_has_suffix (string, "but maybe this will...");
1168 g_str_has_suffix (string, "HMMMM.");
1169 g_str_has_suffix (string, "MMMM.");
1170 g_str_has_suffix (string, "M.");
1172 g_strlcpy (buffer, string, sizeof buffer);
1173 g_assert_cmpint (strlen (buffer), ==, 4095);
1174 g_strlcpy (buffer, string, sizeof buffer);
1175 buffer[0] = '\0';
1176 g_strlcat (buffer, string, sizeof buffer);
1177 g_assert_cmpint (strlen (buffer), ==, 4095);
1179 tmp = g_strdup_printf ("<%s>", string);
1180 g_assert_cmpint (strlen (tmp), ==, 4095 + 2);
1181 g_free (tmp);
1183 g_ascii_strdown (string, -1);
1184 g_ascii_strdown (string, -1);
1185 g_ascii_strup (string, -1);
1186 g_ascii_strup (string, -1);
1188 g_ascii_strcasecmp (string, string);
1189 g_ascii_strncasecmp (string, string, 10000);
1191 g_strreverse (string);
1192 g_strreverse (string);
1193 g_strchug (string);
1194 g_strchomp (string);
1195 g_strstrip (string);
1196 g_assert_cmpint (strlen (string), ==, 4095);
1198 g_strdelimit (string, "M", 'N');
1199 g_strcanon (string, " N.", ':');
1200 g_assert_cmpint (strlen (string), ==, 4095);
1202 array = g_strsplit (string, ".", -1);
1203 tmp = g_strjoinv (".", array);
1204 g_strfreev (array);
1206 g_assert_cmpint (strlen (tmp), ==, 4095);
1207 g_assert (memcmp (tmp, string, 4095) == 0);
1208 g_free (tmp);
1210 tmp = g_strconcat (string, string, string, NULL);
1211 g_assert_cmpint (strlen (tmp), ==, 4095 * 3);
1212 g_free (tmp);
1214 tmp = g_strjoin ("!", string, string, NULL);
1215 g_assert_cmpint (strlen (tmp), ==, 4095 + 1 + 4095);
1216 g_free (tmp);
1218 tmp = g_markup_escape_text (string, -1);
1219 g_free (tmp);
1221 tmp = g_markup_printf_escaped ("%s", string);
1222 g_free (tmp);
1224 tmp = g_strescape (string, NULL);
1225 tmp2 = g_strcompress (tmp);
1226 g_assert_cmpstr (string, ==, tmp2);
1227 g_free (tmp2);
1228 g_free (tmp);
1230 g_mapped_file_unref (file);
1233 static void
1234 test_strip_context (void)
1236 const gchar *msgid;
1237 const gchar *msgval;
1238 const gchar *s;
1241 msgid = "blabla";
1242 msgval = "bla";
1243 s = g_strip_context (msgid, msgval);
1244 g_assert (s == msgval);
1246 msgid = msgval = "blabla";
1247 s = g_strip_context (msgid, msgval);
1248 g_assert (s == msgval);
1250 msgid = msgval = "blabla|foo";
1251 s = g_strip_context (msgid, msgval);
1252 g_assert (s == msgval + 7);
1254 msgid = msgval = "blabla||bar";
1255 s = g_strip_context (msgid, msgval);
1256 g_assert (s == msgval + 7);
1259 static void
1260 test_strerror (void)
1262 gint i;
1263 const gchar *str;
1265 for (i = 1; i < 100; i++)
1267 str = g_strerror (i);
1268 g_assert (str != NULL);
1269 g_assert (g_utf8_validate (str, -1, NULL));
1273 static void
1274 test_strsignal (void)
1276 gint i;
1277 const gchar *str;
1279 for (i = 1; i < 20; i++)
1281 str = g_strsignal (i);
1282 g_assert (str != NULL);
1283 g_assert (g_utf8_validate (str, -1, NULL));
1287 static void
1288 test_strup (void)
1290 gchar *s;
1292 s = g_strdup ("lower");
1293 g_assert_cmpstr (g_strup (s), ==, "LOWER");
1294 g_assert_cmpstr (g_strdown (s), ==, "lower");
1295 g_assert (g_strcasecmp ("lower", "LOWER") == 0);
1296 g_free (s);
1300 main (int argc,
1301 char *argv[])
1303 g_test_init (&argc, &argv, NULL);
1305 g_test_add_func ("/strfuncs/test-is-to-digit", test_is_to_digit);
1306 g_test_add_func ("/strfuncs/strdup", test_strdup);
1307 g_test_add_func ("/strfuncs/strndup", test_strndup);
1308 g_test_add_func ("/strfuncs/strdup-printf", test_strdup_printf);
1309 g_test_add_func ("/strfuncs/strdupv", test_strdupv);
1310 g_test_add_func ("/strfuncs/strnfill", test_strnfill);
1311 g_test_add_func ("/strfuncs/strconcat", test_strconcat);
1312 g_test_add_func ("/strfuncs/strjoin", test_strjoin);
1313 g_test_add_func ("/strfuncs/strcanon", test_strcanon);
1314 g_test_add_func ("/strfuncs/strcompress-strescape", test_strcompress_strescape);
1315 g_test_add_func ("/strfuncs/ascii-strcasecmp", test_ascii_strcasecmp);
1316 g_test_add_func ("/strfuncs/strchug", test_strchug);
1317 g_test_add_func ("/strfuncs/strchomp", test_strchomp);
1318 g_test_add_func ("/strfuncs/strreverse", test_strreverse);
1319 g_test_add_func ("/strfuncs/strstr", test_strstr);
1320 g_test_add_func ("/strfuncs/has-prefix", test_has_prefix);
1321 g_test_add_func ("/strfuncs/has-suffix", test_has_suffix);
1322 g_test_add_func ("/strfuncs/strsplit", test_strsplit);
1323 g_test_add_func ("/strfuncs/strsplit-set", test_strsplit_set);
1324 g_test_add_func ("/strfuncs/strv-length", test_strv_length);
1325 g_test_add_func ("/strfuncs/strtod", test_strtod);
1326 g_test_add_func ("/strfuncs/strtoull-strtoll", test_strtoll);
1327 g_test_add_func ("/strfuncs/bounds-check", test_bounds);
1328 g_test_add_func ("/strfuncs/strip-context", test_strip_context);
1329 g_test_add_func ("/strfuncs/strerror", test_strerror);
1330 g_test_add_func ("/strfuncs/strsignal", test_strsignal);
1331 g_test_add_func ("/strfuncs/strup", test_strup);
1333 return g_test_run();