Mark some functions 'static' in glib/tests
[platform/upstream/glib.git] / glib / tests / strfuncs.c
1 /* Unit tests for gstrfuncs
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This work is provided "as is"; redistribution and modification
5  * in whole or in part, in any medium, physical or electronic is
6  * permitted without restriction.
7  *
8  * This work is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  *
12  * In no event shall the authors or contributors be liable for any
13  * direct, indirect, incidental, special, exemplary, or consequential
14  * damages (including, but not limited to, procurement of substitute
15  * goods or services; loss of use, data, or profits; or business
16  * interruption) however caused and on any theory of liability, whether
17  * in contract, strict liability, or tort (including negligence or
18  * otherwise) arising in any way out of the use of this software, even
19  * if advised of the possibility of such damage.
20  */
21
22 #define GLIB_DISABLE_DEPRECATION_WARNINGS
23
24 #include <ctype.h>
25 #include <errno.h>
26 #include <locale.h>
27 #include <math.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include "glib.h"
33
34 #define GLIB_TEST_STRING "el dorado "
35
36 #define FOR_ALL_CTYPE(macro)    \
37         macro(isalnum)          \
38         macro(isalpha)          \
39         macro(iscntrl)          \
40         macro(isdigit)          \
41         macro(isgraph)          \
42         macro(islower)          \
43         macro(isprint)          \
44         macro(ispunct)          \
45         macro(isspace)          \
46         macro(isupper)          \
47         macro(isxdigit)
48
49 #define DEFINE_CALL_CTYPE(function)             \
50         static int                              \
51         call_##function (int c)                 \
52         {                                       \
53                 return function (c);            \
54         }
55
56 #define DEFINE_CALL_G_ASCII_CTYPE(function)     \
57         static gboolean                         \
58         call_g_ascii_##function (gchar c)       \
59         {                                       \
60                 return g_ascii_##function (c);  \
61         }
62
63 FOR_ALL_CTYPE (DEFINE_CALL_CTYPE)
64 FOR_ALL_CTYPE (DEFINE_CALL_G_ASCII_CTYPE)
65
66 static void
67 test_is_function (const char *name,
68                   gboolean (* ascii_function) (gchar),
69                   int (* c_library_function) (int),
70                   gboolean (* unicode_function) (gunichar))
71 {
72   int c;
73
74   for (c = 0; c <= 0x7F; c++)
75     {
76       gboolean ascii_result = ascii_function ((gchar)c);
77       gboolean c_library_result = c_library_function (c) != 0;
78       gboolean unicode_result = unicode_function ((gunichar) c);
79       if (ascii_result != c_library_result && c != '\v')
80         {
81           g_error ("g_ascii_%s returned %d and %s returned %d for 0x%X",
82                    name, ascii_result, name, c_library_result, c);
83         }
84       if (ascii_result != unicode_result)
85         {
86           g_error ("g_ascii_%s returned %d and g_unichar_%s returned %d for 0x%X",
87                    name, ascii_result, name, unicode_result, c);
88         }
89     }
90   for (c = 0x80; c <= 0xFF; c++)
91     {
92       gboolean ascii_result = ascii_function ((gchar)c);
93       if (ascii_result)
94         {
95           g_error ("g_ascii_%s returned TRUE for 0x%X", name, c);
96         }
97     }
98 }
99
100 static void
101 test_to_function (const char *name,
102                   gchar (* ascii_function) (gchar),
103                   int (* c_library_function) (int),
104                   gunichar (* unicode_function) (gunichar))
105 {
106   int c;
107
108   for (c = 0; c <= 0x7F; c++)
109     {
110       int ascii_result = (guchar) ascii_function ((gchar) c);
111       int c_library_result = c_library_function (c);
112       int unicode_result = unicode_function ((gunichar) c);
113       if (ascii_result != c_library_result)
114         {
115           g_error ("g_ascii_%s returned 0x%X and %s returned 0x%X for 0x%X",
116                    name, ascii_result, name, c_library_result, c);
117         }
118       if (ascii_result != unicode_result)
119         {
120           g_error ("g_ascii_%s returned 0x%X and g_unichar_%s returned 0x%X for 0x%X",
121                    name, ascii_result, name, unicode_result, c);
122         }
123     }
124   for (c = 0x80; c <= 0xFF; c++)
125     {
126       int ascii_result = (guchar) ascii_function ((gchar) c);
127       if (ascii_result != c)
128         {
129           g_error ("g_ascii_%s returned 0x%X for 0x%X",
130                    name, ascii_result, c);
131         }
132     }
133 }
134
135 static void
136 test_digit_function (const char *name,
137                      int (* ascii_function) (gchar),
138                      int (* unicode_function) (gunichar))
139 {
140   int c;
141
142   for (c = 0; c <= 0x7F; c++)
143     {
144       int ascii_result = ascii_function ((gchar) c);
145       int unicode_result = unicode_function ((gunichar) c);
146       if (ascii_result != unicode_result)
147         {
148           g_error ("g_ascii_%s_value returned %d and g_unichar_%s_value returned %d for 0x%X",
149                    name, ascii_result, name, unicode_result, c);
150         }
151     }
152   for (c = 0x80; c <= 0xFF; c++)
153     {
154       int ascii_result = ascii_function ((gchar) c);
155       if (ascii_result != -1)
156         {
157           g_error ("g_ascii_%s_value returned %d for 0x%X",
158                    name, ascii_result, c);
159         }
160     }
161 }
162
163 static void
164 test_is_to_digit (void)
165 {
166   #define TEST_IS(name) test_is_function (#name, call_g_ascii_##name, call_##name, g_unichar_##name);
167
168   FOR_ALL_CTYPE(TEST_IS)
169
170   #undef TEST_IS
171
172   #define TEST_TO(name) test_to_function (#name, g_ascii_##name, name, g_unichar_##name)
173
174   TEST_TO (tolower);
175   TEST_TO (toupper);
176
177   #undef TEST_TO
178
179   #define TEST_DIGIT(name) test_digit_function (#name, g_ascii_##name##_value, g_unichar_##name##_value)
180
181   TEST_DIGIT (digit);
182   TEST_DIGIT (xdigit);
183
184   #undef TEST_DIGIT
185 }
186
187 static void
188 test_strdup (void)
189 {
190   gchar *str;
191
192   str = g_strdup (NULL);
193   g_assert (str == NULL);
194
195   str = g_strdup (GLIB_TEST_STRING);
196   g_assert (str != NULL);
197   g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
198   g_free (str);
199 }
200
201 static void
202 test_strndup (void)
203 {
204   gchar *str;
205
206   str = g_strndup (NULL, 3);
207   g_assert (str == NULL);
208
209   str = g_strndup ("aaaa", 5);
210   g_assert (str != NULL);
211   g_assert_cmpstr (str, ==, "aaaa");
212   g_free (str);
213
214   str = g_strndup ("aaaa", 2);
215   g_assert (str != NULL);
216   g_assert_cmpstr (str, ==, "aa");
217   g_free (str);
218 }
219
220 static void
221 test_strdup_printf (void)
222 {
223   gchar *str;
224
225   str = g_strdup_printf ("%05d %-5s", 21, "test");
226   g_assert (str != NULL);
227   g_assert_cmpstr (str, ==, "00021 test ");
228   g_free (str);
229 }
230
231 static void
232 test_strdupv (void)
233 {
234   gchar *vec[] = { "Foo", "Bar", NULL };
235   gchar **copy;
236
237   copy = g_strdupv (NULL);
238   g_assert (copy == NULL);  
239
240   copy = g_strdupv (vec);
241   g_assert (copy != NULL);
242   g_assert_cmpstr (copy[0], ==, "Foo");
243   g_assert_cmpstr (copy[1], ==, "Bar");
244   g_assert (copy[2] == NULL);
245   g_strfreev (copy);
246 }
247
248 static void
249 test_strnfill (void)
250 {
251   gchar *str;
252
253   str = g_strnfill (0, 'a');
254   g_assert (str != NULL);
255   g_assert (*str == '\0');
256   g_free (str);
257
258   str = g_strnfill (5, 'a');
259   g_assert (str != NULL);
260   g_assert_cmpstr (str, ==, "aaaaa");
261   g_free (str);
262 }
263
264 static void
265 test_strconcat (void)
266 {
267   gchar *str;
268
269   str = g_strconcat (GLIB_TEST_STRING, NULL);
270   g_assert (str != NULL);
271   g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
272   g_free (str);
273
274   str = g_strconcat (GLIB_TEST_STRING,
275                      GLIB_TEST_STRING, 
276                      GLIB_TEST_STRING,
277                      NULL);
278   g_assert (str != NULL);
279   g_assert_cmpstr (str, ==, GLIB_TEST_STRING GLIB_TEST_STRING GLIB_TEST_STRING);
280   g_free (str);
281
282   g_assert (g_strconcat (NULL, "bla", NULL) == NULL);
283 }
284
285 static void
286 test_strjoin (void)
287 {
288   gchar *str;
289
290   str = g_strjoin (NULL, NULL);
291   g_assert (str != NULL);
292   g_assert (*str == '\0');
293   g_free (str);
294
295   str = g_strjoin (":", NULL);
296   g_assert (str != NULL);
297   g_assert (*str == '\0');
298   g_free (str);
299
300   str = g_strjoin (NULL, GLIB_TEST_STRING, NULL);
301   g_assert (str != NULL);
302   g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
303   g_free (str);
304
305   str = g_strjoin (NULL,
306                    GLIB_TEST_STRING,
307                    GLIB_TEST_STRING, 
308                    GLIB_TEST_STRING,
309                    NULL);
310   g_assert (str != NULL);
311   g_assert_cmpstr (str, ==, GLIB_TEST_STRING GLIB_TEST_STRING GLIB_TEST_STRING);
312   g_free (str);
313
314   str = g_strjoin (":",
315                    GLIB_TEST_STRING,
316                    GLIB_TEST_STRING, 
317                    GLIB_TEST_STRING,
318                    NULL);
319   g_assert (str != NULL);
320   g_assert_cmpstr (str, ==, GLIB_TEST_STRING ":" GLIB_TEST_STRING ":" GLIB_TEST_STRING);
321   g_free (str);
322 }
323
324 static void
325 test_strcanon (void)
326 {
327   gchar *str;
328
329   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
330     {
331       str = g_strcanon (NULL, "ab", 'y');
332     }
333   g_test_trap_assert_failed ();
334
335   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
336     {
337       str = g_strdup ("abxabxab");
338       str = g_strcanon (str, NULL, 'y');
339       g_free (str);
340     }
341   g_test_trap_assert_failed ();
342
343   str = g_strdup ("abxabxab");
344   str = g_strcanon (str, "ab", 'y');
345   g_assert (str != NULL);
346   g_assert_cmpstr (str, ==, "abyabyab");
347   g_free (str);
348 }
349
350 static void
351 test_strcompress_strescape (void)
352 {
353   gchar *str;
354   gchar *tmp;
355
356   /* test compress */
357   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
358     {
359       str = g_strcompress (NULL);
360     }
361   g_test_trap_assert_failed ();
362
363   /* trailing slashes are not allowed */
364   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
365     {
366       str = g_strcompress ("abc\\");
367     }
368   g_test_trap_assert_failed ();
369
370   str = g_strcompress ("abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313\\12345z");
371   g_assert (str != NULL);
372   g_assert_cmpstr (str, ==, "abc\\\"\b\f\n\r\t\003\177\234\313\12345z");
373   g_free (str);
374
375   /* test escape */
376   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
377     {
378       str = g_strescape (NULL, NULL);
379     }
380   g_test_trap_assert_failed ();
381
382   str = g_strescape ("abc\\\"\b\f\n\r\t\003\177\234\313", NULL);
383   g_assert (str != NULL);
384   g_assert_cmpstr (str, ==, "abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313");
385   g_free (str);
386
387   str = g_strescape ("abc\\\"\b\f\n\r\t\003\177\234\313",
388                      "\b\f\001\002\003\004");
389   g_assert (str != NULL);
390   g_assert_cmpstr (str, ==, "abc\\\\\\\"\b\f\\n\\r\\t\003\\177\\234\\313");
391   g_free (str);
392
393   /* round trip */
394   tmp = g_strescape ("abc\\\"\b\f\n\r\t\003\177\234\313", NULL);
395   str = g_strcompress (tmp);
396   g_assert (str != NULL); 
397   g_assert_cmpstr (str, ==, "abc\\\"\b\f\n\r\t\003\177\234\313");
398   g_free (str);
399   g_free (tmp);
400 }
401
402 static void
403 test_ascii_strcasecmp (void)
404 {
405   gboolean res;
406
407   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
408     {
409       res = g_ascii_strcasecmp ("foo", NULL);
410     }
411   g_test_trap_assert_failed ();
412
413   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
414     {
415       res = g_ascii_strcasecmp (NULL, "foo");
416     }
417   g_test_trap_assert_failed ();
418
419   res = g_ascii_strcasecmp ("FroboZZ", "frobozz");
420   g_assert_cmpint (res, ==, 0);
421
422   res = g_ascii_strcasecmp ("frobozz", "frobozz");
423   g_assert_cmpint (res, ==, 0);
424
425   res = g_ascii_strcasecmp ("frobozz", "FROBOZZ");
426   g_assert_cmpint (res, ==, 0);
427
428   res = g_ascii_strcasecmp ("FROBOZZ", "froboz");
429   g_assert_cmpint (res, !=, 0);
430
431   res = g_ascii_strcasecmp ("", "");
432   g_assert_cmpint (res, ==, 0);
433
434   res = g_ascii_strcasecmp ("!#%&/()", "!#%&/()");
435   g_assert_cmpint (res, ==, 0);
436
437   res = g_ascii_strcasecmp ("a", "b");
438   g_assert_cmpint (res, <, 0);
439
440   res = g_ascii_strcasecmp ("a", "B");
441   g_assert_cmpint (res, <, 0);
442
443   res = g_ascii_strcasecmp ("A", "b");
444   g_assert_cmpint (res, <, 0);
445
446   res = g_ascii_strcasecmp ("A", "B");
447   g_assert_cmpint (res, <, 0);
448
449   res = g_ascii_strcasecmp ("b", "a");
450   g_assert_cmpint (res, >, 0);
451
452   res = g_ascii_strcasecmp ("b", "A");
453   g_assert_cmpint (res, >, 0);
454
455   res = g_ascii_strcasecmp ("B", "a");
456   g_assert_cmpint (res, >, 0);
457
458   res = g_ascii_strcasecmp ("B", "A");
459   g_assert_cmpint (res, >, 0);
460 }
461
462 static void
463 do_test_strchug (const gchar *str, const gchar *expected)
464 {
465   gchar *tmp;
466   gboolean res;
467
468   tmp = g_strdup (str);
469
470   g_strchug (tmp);
471   res = (strcmp (tmp, expected) == 0);
472   g_free (tmp);
473
474   g_assert_cmpint (res, ==, TRUE);
475 }
476
477 static void
478 test_strchug (void)
479 {
480   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
481     {
482       g_strchug (NULL);
483     }
484   g_test_trap_assert_failed ();
485
486   do_test_strchug ("", "");
487   do_test_strchug (" ", "");
488   do_test_strchug ("\t\r\n ", "");
489   do_test_strchug (" a", "a");
490   do_test_strchug ("  a", "a");
491   do_test_strchug ("a a", "a a");
492   do_test_strchug (" a a", "a a");
493 }
494
495 static void
496 do_test_strchomp (const gchar *str, const gchar *expected)
497 {
498   gchar *tmp;
499   gboolean res;
500
501   tmp = g_strdup (str);
502
503   g_strchomp (tmp);
504   res = (strcmp (tmp, expected) == 0);
505   g_free (tmp);
506
507   g_assert_cmpint (res, ==, TRUE);
508 }
509
510 static void
511 test_strchomp (void)
512 {
513   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
514     {
515       g_strchomp (NULL);
516     }
517   g_test_trap_assert_failed ();
518
519   do_test_strchomp ("", "");
520   do_test_strchomp (" ", "");
521   do_test_strchomp (" \t\r\n", "");
522   do_test_strchomp ("a ", "a");
523   do_test_strchomp ("a  ", "a");
524   do_test_strchomp ("a a", "a a");
525   do_test_strchomp ("a a ", "a a");
526 }
527
528 static void
529 test_strreverse (void)
530 {
531   gchar *str;
532   gchar *p;
533
534   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
535     {
536       str = g_strreverse (NULL);
537     }
538   g_test_trap_assert_failed ();
539
540   str = p = g_strdup ("abcde");
541   str = g_strreverse (str);
542   g_assert (str != NULL);
543   g_assert (p == str);
544   g_assert_cmpstr (str, ==, "edcba");
545   g_free (str);
546 }
547
548 static void
549 test_strstr (void)
550 {
551   gchar *haystack;
552   gchar *res;
553
554   haystack = g_strdup ("FooBarFooBarFoo");
555
556   /* strstr_len */
557   res = g_strstr_len (haystack, 6, "xxx");
558   g_assert (res == NULL);
559
560   res = g_strstr_len (haystack, 6, "FooBarFooBarFooBar");
561   g_assert (res == NULL);
562
563   res = g_strstr_len (haystack, 3, "Bar");
564   g_assert (res == NULL);
565
566   res = g_strstr_len (haystack, 6, "");
567   g_assert (res == haystack);
568   g_assert_cmpstr (res, ==, "FooBarFooBarFoo");
569
570   res = g_strstr_len (haystack, 6, "Bar");
571   g_assert (res == haystack + 3);
572   g_assert_cmpstr (res, ==, "BarFooBarFoo");
573
574   res = g_strstr_len (haystack, -1, "Bar");
575   g_assert (res == haystack + 3);
576   g_assert_cmpstr (res, ==, "BarFooBarFoo");
577
578   /* strrstr */
579   res = g_strrstr (haystack, "xxx");
580   g_assert (res == NULL);
581
582   res = g_strrstr (haystack, "FooBarFooBarFooBar");
583   g_assert (res == NULL);
584
585   res = g_strrstr (haystack, "");
586   g_assert (res == haystack);
587   g_assert_cmpstr (res, ==, "FooBarFooBarFoo");
588
589   res = g_strrstr (haystack, "Bar");
590   g_assert (res == haystack + 9);
591   g_assert_cmpstr (res, ==, "BarFoo");
592
593   /* strrstr_len */
594   res = g_strrstr_len (haystack, 14, "xxx");
595   g_assert (res == NULL);
596
597   res = g_strrstr_len (haystack, 14, "FooBarFooBarFooBar");
598   g_assert (res == NULL);
599
600   res = g_strrstr_len (haystack, 3, "Bar");
601   g_assert (res == NULL);
602
603   res = g_strrstr_len (haystack, 14, "BarFoo");
604   g_assert (res == haystack + 3);
605   g_assert_cmpstr (res, ==, "BarFooBarFoo");
606
607   res = g_strrstr_len (haystack, 15, "BarFoo");
608   g_assert (res == haystack + 9);
609   g_assert_cmpstr (res, ==, "BarFoo");
610
611   res = g_strrstr_len (haystack, -1, "BarFoo");
612   g_assert (res == haystack + 9);
613   g_assert_cmpstr (res, ==, "BarFoo");
614
615   /* test case for strings with \0 in the middle */
616   *(haystack + 7) = '\0';
617   res = g_strstr_len (haystack, 15, "BarFoo");
618   g_assert (res == NULL);
619
620   g_free (haystack);
621 }
622
623 static void
624 test_has_prefix (void)
625 {
626   gboolean res;
627
628   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
629     {
630       res = g_str_has_prefix ("foo", NULL);
631     }
632   g_test_trap_assert_failed ();
633
634   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
635     {
636       res = g_str_has_prefix (NULL, "foo");
637     }
638   g_test_trap_assert_failed ();
639
640   res = g_str_has_prefix ("foo", "bar");
641   g_assert_cmpint (res, ==, FALSE);
642
643   res = g_str_has_prefix ("foo", "foobar");
644   g_assert_cmpint (res, ==, FALSE);
645
646   res = g_str_has_prefix ("foobar", "bar");
647   g_assert_cmpint (res, ==, FALSE);
648
649   res = g_str_has_prefix ("foobar", "foo");
650   g_assert_cmpint (res, ==, TRUE);
651
652   res = g_str_has_prefix ("foo", "");
653   g_assert_cmpint (res, ==, TRUE);
654
655   res = g_str_has_prefix ("foo", "foo");
656   g_assert_cmpint (res, ==, TRUE);
657
658   res = g_str_has_prefix ("", "");
659   g_assert_cmpint (res, ==, TRUE);
660 }
661
662 static void
663 test_has_suffix (void)
664 {
665   gboolean res;
666
667   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
668     {
669       res = g_str_has_suffix ("foo", NULL);
670     }
671   g_test_trap_assert_failed ();
672
673   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
674     {
675       res = g_str_has_suffix (NULL, "foo");
676     }
677   g_test_trap_assert_failed ();
678
679   res = g_str_has_suffix ("foo", "bar");
680   g_assert_cmpint (res, ==, FALSE);
681
682   res = g_str_has_suffix ("bar", "foobar");
683   g_assert_cmpint (res, ==, FALSE);
684
685   res = g_str_has_suffix ("foobar", "foo");
686   g_assert_cmpint (res, ==, FALSE);
687
688   res = g_str_has_suffix ("foobar", "bar");
689   g_assert_cmpint (res, ==, TRUE);
690
691   res = g_str_has_suffix ("foo", "");
692   g_assert_cmpint (res, ==, TRUE);
693
694   res = g_str_has_suffix ("foo", "foo");
695   g_assert_cmpint (res, ==, TRUE);
696
697   res = g_str_has_suffix ("", "");
698   g_assert_cmpint (res, ==, TRUE);
699 }
700
701 static void
702 strv_check (gchar **strv, ...)
703 {
704   gboolean ok = TRUE;
705   gint i = 0;
706   va_list list;
707
708   va_start (list, strv);
709   while (ok)
710     {
711       const gchar *str = va_arg (list, const char *);
712       if (strv[i] == NULL)
713         {
714           g_assert (str == NULL);
715           break;
716         }
717       if (str == NULL)
718         {
719           ok = FALSE;
720         }
721       else
722         {
723           g_assert_cmpstr (strv[i], ==, str);
724         }
725       i++;
726     }
727   va_end (list);
728
729   g_strfreev (strv);
730 }
731
732 static void
733 test_strsplit (void)
734 {
735   strv_check (g_strsplit ("", ",", 0), NULL);
736   strv_check (g_strsplit ("x", ",", 0), "x", NULL);
737   strv_check (g_strsplit ("x,y", ",", 0), "x", "y", NULL);
738   strv_check (g_strsplit ("x,y,", ",", 0), "x", "y", "", NULL);
739   strv_check (g_strsplit (",x,y", ",", 0), "", "x", "y", NULL);
740   strv_check (g_strsplit (",x,y,", ",", 0), "", "x", "y", "", NULL);
741   strv_check (g_strsplit ("x,y,z", ",", 0), "x", "y", "z", NULL);
742   strv_check (g_strsplit ("x,y,z,", ",", 0), "x", "y", "z", "", NULL);
743   strv_check (g_strsplit (",x,y,z", ",", 0), "", "x", "y", "z", NULL);
744   strv_check (g_strsplit (",x,y,z,", ",", 0), "", "x", "y", "z", "", NULL);
745   strv_check (g_strsplit (",,x,,y,,z,,", ",", 0), "", "", "x", "", "y", "", "z", "", "", NULL);
746   strv_check (g_strsplit (",,x,,y,,z,,", ",,", 0), "", "x", "y", "z", "", NULL);
747
748   strv_check (g_strsplit ("", ",", 1), NULL);
749   strv_check (g_strsplit ("x", ",", 1), "x", NULL);
750   strv_check (g_strsplit ("x,y", ",", 1), "x,y", NULL);
751   strv_check (g_strsplit ("x,y,", ",", 1), "x,y,", NULL);
752   strv_check (g_strsplit (",x,y", ",", 1), ",x,y", NULL);
753   strv_check (g_strsplit (",x,y,", ",", 1), ",x,y,", NULL);
754   strv_check (g_strsplit ("x,y,z", ",", 1), "x,y,z", NULL);
755   strv_check (g_strsplit ("x,y,z,", ",", 1), "x,y,z,", NULL);
756   strv_check (g_strsplit (",x,y,z", ",", 1), ",x,y,z", NULL);
757   strv_check (g_strsplit (",x,y,z,", ",", 1), ",x,y,z,", NULL);
758   strv_check (g_strsplit (",,x,,y,,z,,", ",", 1), ",,x,,y,,z,,", NULL);
759   strv_check (g_strsplit (",,x,,y,,z,,", ",,", 1), ",,x,,y,,z,,", NULL);
760
761   strv_check (g_strsplit ("", ",", 2), NULL);
762   strv_check (g_strsplit ("x", ",", 2), "x", NULL);
763   strv_check (g_strsplit ("x,y", ",", 2), "x", "y", NULL);
764   strv_check (g_strsplit ("x,y,", ",", 2), "x", "y,", NULL);
765   strv_check (g_strsplit (",x,y", ",", 2), "", "x,y", NULL);
766   strv_check (g_strsplit (",x,y,", ",", 2), "", "x,y,", NULL);
767   strv_check (g_strsplit ("x,y,z", ",", 2), "x", "y,z", NULL);
768   strv_check (g_strsplit ("x,y,z,", ",", 2), "x", "y,z,", NULL);
769   strv_check (g_strsplit (",x,y,z", ",", 2), "", "x,y,z", NULL);
770   strv_check (g_strsplit (",x,y,z,", ",", 2), "", "x,y,z,", NULL);
771   strv_check (g_strsplit (",,x,,y,,z,,", ",", 2), "", ",x,,y,,z,,", NULL);
772   strv_check (g_strsplit (",,x,,y,,z,,", ",,", 2), "", "x,,y,,z,,", NULL);
773 }
774
775 static void
776 test_strsplit_set (void)
777 {
778   strv_check (g_strsplit_set ("", ",/", 0), NULL);
779   strv_check (g_strsplit_set (":def/ghi:", ":/", -1), "", "def", "ghi", "", NULL);
780   strv_check (g_strsplit_set ("abc:def/ghi", ":/", -1), "abc", "def", "ghi", NULL);
781   strv_check (g_strsplit_set (",;,;,;,;", ",;", -1), "", "", "", "", "", "", "", "", "", NULL);
782   strv_check (g_strsplit_set (",,abc.def", ".,", -1), "", "", "abc", "def", NULL);
783
784   strv_check (g_strsplit_set (",x.y", ",.", 0), "", "x", "y", NULL);
785   strv_check (g_strsplit_set (".x,y,", ",.", 0), "", "x", "y", "", NULL);
786   strv_check (g_strsplit_set ("x,y.z", ",.", 0), "x", "y", "z", NULL);
787   strv_check (g_strsplit_set ("x.y,z,", ",.", 0), "x", "y", "z", "", NULL);
788   strv_check (g_strsplit_set (",x.y,z", ",.", 0), "", "x", "y", "z", NULL);
789   strv_check (g_strsplit_set (",x,y,z,", ",.", 0), "", "x", "y", "z", "", NULL);
790   strv_check (g_strsplit_set (",.x,,y,;z..", ".,;", 0), "", "", "x", "", "y", "", "z", "", "", NULL);
791   strv_check (g_strsplit_set (",,x,,y,,z,,", ",,", 0), "", "", "x", "", "y", "", "z", "", "", NULL);
792
793   strv_check (g_strsplit_set ("x,y.z", ",.", 1), "x,y.z", NULL);
794   strv_check (g_strsplit_set ("x.y,z,", ",.", 1), "x.y,z,", NULL);
795   strv_check (g_strsplit_set (",x,y,z", ",.", 1), ",x,y,z", NULL);
796   strv_check (g_strsplit_set (",x,y.z,", ",.", 1), ",x,y.z,", NULL);
797   strv_check (g_strsplit_set (",,x,.y,,z,,", ",.", 1), ",,x,.y,,z,,", NULL);
798   strv_check (g_strsplit_set (",.x,,y,,z,,", ",,..", 1), ",.x,,y,,z,,", NULL);
799    
800   strv_check (g_strsplit_set ("", ",", 0), NULL);
801   strv_check (g_strsplit_set ("x", ",", 0), "x", NULL);
802   strv_check (g_strsplit_set ("x,y", ",", 0), "x", "y", NULL);
803   strv_check (g_strsplit_set ("x,y,", ",", 0), "x", "y", "", NULL);
804   strv_check (g_strsplit_set (",x,y", ",", 0), "", "x", "y", NULL);
805   strv_check (g_strsplit_set (",x,y,", ",", 0), "", "x", "y", "", NULL);
806   strv_check (g_strsplit_set ("x,y,z", ",", 0), "x", "y", "z", NULL);
807   strv_check (g_strsplit_set ("x,y,z,", ",", 0), "x", "y", "z", "", NULL);
808   strv_check (g_strsplit_set (",x,y,z", ",", 0), "", "x", "y", "z", NULL);
809   strv_check (g_strsplit_set (",x,y,z,", ",", 0), "", "x", "y", "z", "", NULL);
810   strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 0), "", "", "x", "", "y", "", "z", "", "", NULL);
811
812   strv_check (g_strsplit_set ("", ",", 1), NULL);
813   strv_check (g_strsplit_set ("x", ",", 1), "x", NULL);
814   strv_check (g_strsplit_set ("x,y", ",", 1), "x,y", NULL);
815   strv_check (g_strsplit_set ("x,y,", ",", 1), "x,y,", NULL);
816   strv_check (g_strsplit_set (",x,y", ",", 1), ",x,y", NULL);
817   strv_check (g_strsplit_set (",x,y,", ",", 1), ",x,y,", NULL);
818   strv_check (g_strsplit_set ("x,y,z", ",", 1), "x,y,z", NULL);
819   strv_check (g_strsplit_set ("x,y,z,", ",", 1), "x,y,z,", NULL);
820   strv_check (g_strsplit_set (",x,y,z", ",", 1), ",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
825   strv_check (g_strsplit_set ("", ",", 2), NULL);
826   strv_check (g_strsplit_set ("x", ",", 2), "x", NULL);
827   strv_check (g_strsplit_set ("x,y", ",", 2), "x", "y", NULL);
828   strv_check (g_strsplit_set ("x,y,", ",", 2), "x", "y,", NULL);
829   strv_check (g_strsplit_set (",x,y", ",", 2), "", "x,y", NULL);
830   strv_check (g_strsplit_set (",x,y,", ",", 2), "", "x,y,", NULL);
831   strv_check (g_strsplit_set ("x,y,z", ",", 2), "x", "y,z", NULL);
832   strv_check (g_strsplit_set ("x,y,z,", ",", 2), "x", "y,z,", NULL);
833   strv_check (g_strsplit_set (",x,y,z", ",", 2), "", "x,y,z", NULL);
834   strv_check (g_strsplit_set (",x,y,z,", ",", 2), "", "x,y,z,", NULL);
835   strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 2), "", ",x,,y,,z,,", NULL);
836   
837   strv_check (g_strsplit_set (",,x,.y,..z,,", ",.", 3), "", "", "x,.y,..z,,", NULL);
838 }
839
840 static void
841 test_strv_length (void)
842 {
843   guint l;
844
845   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
846     {
847       l = g_strv_length (NULL);
848     }
849   g_test_trap_assert_failed ();
850
851   l = g_strv_length (g_strsplit ("1,2,3,4", ",", -1));
852   g_assert_cmpuint (l, ==, 4);
853 }
854
855 static char *locales[] = {"sv_SE", "en_US", "fa_IR", "C", "ru_RU"};
856
857 static void
858 check_strtod_string (gchar    *number,
859                      double    res,
860                      gboolean  check_end,
861                      gint      correct_len)
862 {
863   double d;
864   gint l;
865   gchar *dummy;
866
867   /* we try a copy of number, with some free space for malloc before that. 
868    * This is supposed to smash the some wrong pointer calculations. */
869
870   dummy = g_malloc (100000);
871   number = g_strdup (number);
872   g_free (dummy);
873
874   for (l = 0; l < G_N_ELEMENTS (locales); l++)
875     {
876       gboolean ok;
877       gchar *end = "(unset)";
878
879       setlocale (LC_NUMERIC, locales[l]);
880       d = g_ascii_strtod (number, &end);
881       ok = isnan (res) ? isnan (d) : (d == res);
882       if (!ok)
883         {
884           g_error ("g_ascii_strtod on \"%s\" for locale %s failed\n" \
885                    "expected %f (nan %d) actual %f (nan %d)\n", 
886                    number, locales[l],
887                    res, isnan (res),
888                    d, isnan (d));
889         }
890
891       ok = (end - number) == (check_end ? correct_len : strlen (number));
892       if (!ok) {
893         if (end == NULL)
894           g_error ("g_ascii_strtod on \"%s\" for locale %s endptr was NULL\n",
895                    number, locales[l]);
896         else if (end >= number && end <= number + strlen (number))
897           g_error ("g_ascii_strtod on \"%s\" for locale %s endptr was wrong, leftover: \"%s\"\n",
898                    number, locales[l], end);
899         else
900           g_error ("g_ascii_strtod on \"%s\" for locale %s endptr was REALLY wrong (number=%p, end=%p)\n",
901                    number, locales[l], number, end);
902       }
903     }
904
905   g_free (number);
906 }
907
908 static void
909 check_strtod_number (gdouble num, gchar *fmt, gchar *str)
910 {
911   int l;
912   gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
913
914   for (l = 0; l < G_N_ELEMENTS (locales); l++)
915     {
916       setlocale (LC_ALL, locales[l]);
917       g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, fmt, num);
918       g_assert_cmpstr (buf, ==, str);
919     }
920 }
921
922 static void
923 test_strtod (void)
924 {
925   gdouble d, our_nan, our_inf;
926   char buffer[G_ASCII_DTOSTR_BUF_SIZE];
927
928 #ifdef NAN
929   our_nan = NAN;
930 #else
931   /* Do this before any call to setlocale.  */
932   our_nan = atof ("NaN");
933 #endif
934   g_assert (isnan (our_nan));
935
936 #ifdef INFINITY
937   our_inf = INFINITY;
938 #else
939   our_inf = atof ("Infinity");
940 #endif
941   g_assert (our_inf > 1 && our_inf == our_inf / 2);
942
943   check_strtod_string ("123.123", 123.123, FALSE, 0);
944   check_strtod_string ("123.123e2", 123.123e2, FALSE, 0);
945   check_strtod_string ("123.123e-2", 123.123e-2, FALSE, 0);
946   check_strtod_string ("-123.123", -123.123, FALSE, 0);
947   check_strtod_string ("-123.123e2", -123.123e2, FALSE, 0);
948   check_strtod_string ("-123.123e-2", -123.123e-2, FALSE, 0);
949   check_strtod_string ("5.4", 5.4, TRUE, 3);
950   check_strtod_string ("5.4,5.5", 5.4, TRUE, 3);
951   check_strtod_string ("5,4", 5.0, TRUE, 1);
952   check_strtod_string ("0xa.b", 10.6875, TRUE, 5);
953   check_strtod_string ("0xa.bP3", 85.5, TRUE, 7);
954   check_strtod_string ("0xa.bp+3", 85.5, TRUE, 8);
955   check_strtod_string ("0xa.bp-2", 2.671875, TRUE, 8);
956   check_strtod_string ("0xA.BG", 10.6875, TRUE, 5);
957   /* the following are for #156421 */
958   check_strtod_string ("1e1", 1e1, FALSE, 0); 
959   check_strtod_string ("NAN", our_nan, FALSE, 0);
960   check_strtod_string ("-nan", -our_nan, FALSE, 0);
961   check_strtod_string ("INF", our_inf, FALSE, 0);
962   check_strtod_string ("-infinity", -our_inf, FALSE, 0);
963   check_strtod_string ("-.75,0", -0.75, TRUE, 4);
964   
965   d = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
966   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
967
968   d = -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
969   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
970   
971   d = pow (2.0, -1024.1);
972   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
973   
974   d = -pow (2.0, -1024.1);
975   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
976
977   /* for #343899 */
978   check_strtod_string (" 0.75", 0.75, FALSE, 0);
979   check_strtod_string (" +0.75", 0.75, FALSE, 0);
980   check_strtod_string (" -0.75", -0.75, FALSE, 0);
981   check_strtod_string ("\f0.75", 0.75, FALSE, 0);
982   check_strtod_string ("\n0.75", 0.75, FALSE, 0);
983   check_strtod_string ("\r0.75", 0.75, FALSE, 0);
984   check_strtod_string ("\t0.75", 0.75, FALSE, 0);
985
986 #if 0
987   /* g_ascii_isspace() returns FALSE for vertical tab, see #59388 */
988   check_strtod_string ("\v0.75", 0.75, FALSE, 0);
989 #endif
990
991   /* for #343899 */
992   check_strtod_number (0.75, "%0.2f", "0.75");
993   check_strtod_number (0.75, "%5.2f", " 0.75");
994   check_strtod_number (-0.75, "%0.2f", "-0.75");
995   check_strtod_number (-0.75, "%5.2f", "-0.75");
996   check_strtod_number (1e99, "%.0e", "1e+99");
997 }
998
999 static void
1000 check_uint64 (const gchar *str,
1001               const gchar *end,
1002               gint         base,
1003               guint64      result,
1004               gint         error)
1005 {
1006   guint64 actual;
1007   gchar *endptr = NULL;
1008   gint err;
1009
1010   errno = 0;
1011   actual = g_ascii_strtoull (str, &endptr, base);
1012   err = errno;
1013
1014   g_assert (actual == result);
1015   g_assert_cmpstr (end, ==, endptr);
1016   g_assert (err == error);
1017 }
1018
1019 static void
1020 check_int64 (const gchar *str,
1021              const gchar *end,
1022              gint         base,
1023              gint64       result,
1024              gint         error)
1025 {
1026   gint64 actual;
1027   gchar *endptr = NULL;
1028   gint err;
1029
1030   errno = 0;
1031   actual = g_ascii_strtoll (str, &endptr, base);
1032   err = errno;
1033
1034   g_assert (actual == result);
1035   g_assert_cmpstr (end, ==, endptr);
1036   g_assert (err == error);
1037 }
1038
1039 static void
1040 test_strtoll (void)
1041 {
1042   check_uint64 ("0", "", 10, 0, 0);
1043   check_uint64 ("+0", "", 10, 0, 0);
1044   check_uint64 ("-0", "", 10, 0, 0);
1045   check_uint64 ("18446744073709551615", "", 10, G_MAXUINT64, 0);
1046   check_uint64 ("18446744073709551616", "", 10, G_MAXUINT64, ERANGE);
1047   check_uint64 ("20xyz", "xyz", 10, 20, 0);
1048   check_uint64 ("-1", "", 10, G_MAXUINT64, 0);
1049
1050   check_int64 ("0", "", 10, 0, 0);
1051   check_int64 ("9223372036854775807", "", 10, G_MAXINT64, 0);
1052   check_int64 ("9223372036854775808", "", 10, G_MAXINT64, ERANGE);
1053   check_int64 ("-9223372036854775808", "", 10, G_MININT64, 0);
1054   check_int64 ("-9223372036854775809", "", 10, G_MININT64, ERANGE);
1055   check_int64 ("32768", "", 10, 32768, 0);
1056   check_int64 ("-32768", "", 10, -32768, 0);
1057   check_int64 ("001", "", 10, 1, 0);
1058   check_int64 ("-001", "", 10, -1, 0);
1059 }
1060
1061 static void
1062 test_bounds (void)
1063 {
1064   GMappedFile *file, *before, *after;
1065   char buffer[4097];
1066   char *tmp, *tmp2;
1067   char **array;
1068   char *string;
1069
1070   /* if we allocate the file between two others and then free those
1071    * other two, then hopefully we end up with unmapped memory on either
1072    * side.
1073    */
1074   before = g_mapped_file_new ("4096-random-bytes", TRUE, NULL);
1075
1076   /* quick workaround until #549783 can be fixed */
1077   if (before == NULL)
1078     return;
1079
1080   file = g_mapped_file_new ("4096-random-bytes", TRUE, NULL);
1081   after = g_mapped_file_new ("4096-random-bytes", TRUE, NULL);
1082   g_mapped_file_unref (before);
1083   g_mapped_file_unref (after);
1084
1085   g_assert (file != NULL);
1086   g_assert_cmpint (g_mapped_file_get_length (file), ==, 4096);
1087   string = g_mapped_file_get_contents (file);
1088
1089   /* ensure they're all non-nul */
1090   g_assert (memchr (string, '\0', 4096) == NULL);
1091
1092   /* test set 1: ensure that nothing goes past its maximum length, even in
1093    *             light of a missing nul terminator.
1094    *
1095    * we try to test all of the 'n' functions here.
1096    */
1097   tmp = g_strndup (string, 4096);
1098   g_assert_cmpint (strlen (tmp), ==, 4096);
1099   g_free (tmp);
1100
1101   /* found no bugs in gnome, i hope :) */
1102   g_assert (g_strstr_len (string, 4096, "BUGS") == NULL);
1103   g_strstr_len (string, 4096, "B");
1104   g_strstr_len (string, 4096, ".");
1105   g_strstr_len (string, 4096, "");
1106
1107   g_strrstr_len (string, 4096, "BUGS");
1108   g_strrstr_len (string, 4096, "B");
1109   g_strrstr_len (string, 4096, ".");
1110   g_strrstr_len (string, 4096, "");
1111
1112   g_ascii_strdown (string, 4096);
1113   g_ascii_strdown (string, 4096);
1114   g_ascii_strup (string, 4096);
1115   g_ascii_strup (string, 4096);
1116
1117   g_ascii_strncasecmp (string, string, 4096);
1118
1119   tmp = g_markup_escape_text (string, 4096);
1120   g_free (tmp);
1121
1122   /* test set 2: ensure that nothing reads even one byte past a '\0'.
1123    */
1124   g_assert_cmpint (string[4095], ==, '\n');
1125   string[4095] = '\0';
1126
1127   tmp = g_strdup (string);
1128   g_assert_cmpint (strlen (tmp), ==, 4095);
1129   g_free (tmp);
1130
1131   tmp = g_strndup (string, 10000);
1132   g_assert_cmpint (strlen (tmp), ==, 4095);
1133   g_free (tmp);
1134
1135   g_stpcpy (buffer, string);
1136   g_assert_cmpint (strlen (buffer), ==, 4095);
1137
1138   g_strstr_len (string, 10000, "BUGS");
1139   g_strstr_len (string, 10000, "B");
1140   g_strstr_len (string, 10000, ".");
1141   g_strstr_len (string, 10000, "");
1142
1143   g_strrstr (string, "BUGS");
1144   g_strrstr (string, "B");
1145   g_strrstr (string, ".");
1146   g_strrstr (string, "");
1147
1148   g_strrstr_len (string, 10000, "BUGS");
1149   g_strrstr_len (string, 10000, "B");
1150   g_strrstr_len (string, 10000, ".");
1151   g_strrstr_len (string, 10000, "");
1152
1153   g_str_has_prefix (string, "this won't do very much...");
1154   g_str_has_suffix (string, "but maybe this will...");
1155   g_str_has_suffix (string, "HMMMM.");
1156   g_str_has_suffix (string, "MMMM.");
1157   g_str_has_suffix (string, "M.");
1158
1159   g_strlcpy (buffer, string, sizeof buffer);
1160   g_assert_cmpint (strlen (buffer), ==, 4095);
1161   g_strlcpy (buffer, string, sizeof buffer);
1162   buffer[0] = '\0';
1163   g_strlcat (buffer, string, sizeof buffer);
1164   g_assert_cmpint (strlen (buffer), ==, 4095);
1165
1166   tmp = g_strdup_printf ("<%s>", string);
1167   g_assert_cmpint (strlen (tmp), ==, 4095 + 2);
1168   g_free (tmp);
1169
1170   g_ascii_strdown (string, -1);
1171   g_ascii_strdown (string, -1);
1172   g_ascii_strup (string, -1);
1173   g_ascii_strup (string, -1);
1174
1175   g_ascii_strcasecmp (string, string);
1176   g_ascii_strncasecmp (string, string, 10000);
1177
1178   g_strreverse (string);
1179   g_strreverse (string);
1180   g_strchug (string);
1181   g_strchomp (string);
1182   g_strstrip (string);
1183   g_assert_cmpint (strlen (string), ==, 4095);
1184
1185   g_strdelimit (string, "M", 'N');
1186   g_strcanon (string, " N.", ':');
1187   g_assert_cmpint (strlen (string), ==, 4095);
1188
1189   array = g_strsplit (string, ".", -1);
1190   tmp = g_strjoinv (".", array);
1191   g_strfreev (array);
1192
1193   g_assert_cmpint (strlen (tmp), ==, 4095);
1194   g_assert (memcmp (tmp, string, 4095) == 0);
1195   g_free (tmp);
1196
1197   tmp = g_strconcat (string, string, string, NULL);
1198   g_assert_cmpint (strlen (tmp), ==, 4095 * 3);
1199   g_free (tmp);
1200
1201   tmp = g_strjoin ("!", string, string, NULL);
1202   g_assert_cmpint (strlen (tmp), ==, 4095 + 1 + 4095);
1203   g_free (tmp);
1204
1205   tmp = g_markup_escape_text (string, -1);
1206   g_free (tmp);
1207
1208   tmp = g_markup_printf_escaped ("%s", string);
1209   g_free (tmp);
1210
1211   tmp = g_strescape (string, NULL);
1212   tmp2 = g_strcompress (tmp);
1213   g_assert_cmpstr (string, ==, tmp2);
1214   g_free (tmp2);
1215   g_free (tmp);
1216
1217   g_mapped_file_unref (file);
1218 }
1219
1220 static void
1221 test_strip_context (void)
1222 {
1223   const gchar *msgid;
1224   const gchar *msgval;
1225   const gchar *s;
1226
1227
1228   msgid = "blabla";
1229   msgval = "bla";
1230   s = g_strip_context (msgid, msgval);
1231   g_assert (s == msgval);
1232
1233   msgid = msgval = "blabla";
1234   s = g_strip_context (msgid, msgval);
1235   g_assert (s == msgval);
1236
1237   msgid = msgval = "blabla|foo";
1238   s = g_strip_context (msgid, msgval);
1239   g_assert (s == msgval + 7);
1240
1241   msgid = msgval = "blabla||bar";
1242   s = g_strip_context (msgid, msgval);
1243   g_assert (s == msgval + 7);
1244 }
1245
1246 static void
1247 test_strerror (void)
1248 {
1249   gint i;
1250   const gchar *str;
1251
1252   for (i = 1; i < 100; i++)
1253     {
1254       str = g_strerror (i);
1255       g_assert (str != NULL);
1256       g_assert (g_utf8_validate (str, -1, NULL));
1257     }
1258 }
1259
1260 static void
1261 test_strsignal (void)
1262 {
1263   gint i;
1264   const gchar *str;
1265
1266   for (i = 1; i < 20; i++)
1267     {
1268       str = g_strsignal (i);
1269       g_assert (str != NULL);
1270       g_assert (g_utf8_validate (str, -1, NULL));
1271     }
1272 }
1273
1274 static void
1275 test_strup (void)
1276 {
1277   gchar *s;
1278
1279   s = g_strdup ("lower");
1280   g_assert_cmpstr (g_strup (s), ==, "LOWER");
1281   g_assert_cmpstr (g_strdown (s), ==, "lower");
1282   g_assert (g_strcasecmp ("lower", "LOWER") == 0);
1283   g_free (s);
1284 }
1285
1286 int
1287 main (int   argc,
1288       char *argv[])
1289 {
1290   g_test_init (&argc, &argv, NULL);
1291
1292   g_test_add_func ("/strfuncs/test-is-to-digit", test_is_to_digit);
1293   g_test_add_func ("/strfuncs/strdup", test_strdup);
1294   g_test_add_func ("/strfuncs/strndup", test_strndup);
1295   g_test_add_func ("/strfuncs/strdup-printf", test_strdup_printf);
1296   g_test_add_func ("/strfuncs/strdupv", test_strdupv);
1297   g_test_add_func ("/strfuncs/strnfill", test_strnfill);
1298   g_test_add_func ("/strfuncs/strconcat", test_strconcat);
1299   g_test_add_func ("/strfuncs/strjoin", test_strjoin);
1300   g_test_add_func ("/strfuncs/strcanon", test_strcanon);
1301   g_test_add_func ("/strfuncs/strcompress-strescape", test_strcompress_strescape);
1302   g_test_add_func ("/strfuncs/ascii-strcasecmp", test_ascii_strcasecmp);
1303   g_test_add_func ("/strfuncs/strchug", test_strchug);
1304   g_test_add_func ("/strfuncs/strchomp", test_strchomp);
1305   g_test_add_func ("/strfuncs/strreverse", test_strreverse);
1306   g_test_add_func ("/strfuncs/strstr", test_strstr);
1307   g_test_add_func ("/strfuncs/has-prefix", test_has_prefix);
1308   g_test_add_func ("/strfuncs/has-suffix", test_has_suffix);
1309   g_test_add_func ("/strfuncs/strsplit", test_strsplit);
1310   g_test_add_func ("/strfuncs/strsplit-set", test_strsplit_set);
1311   g_test_add_func ("/strfuncs/strv-length", test_strv_length);
1312   g_test_add_func ("/strfuncs/strtod", test_strtod);
1313   g_test_add_func ("/strfuncs/strtoull-strtoll", test_strtoll);
1314   g_test_add_func ("/strfuncs/bounds-check", test_bounds);
1315   g_test_add_func ("/strfuncs/strip-context", test_strip_context);
1316   g_test_add_func ("/strfuncs/strerror", test_strerror);
1317   g_test_add_func ("/strfuncs/strsignal", test_strsignal);
1318   g_test_add_func ("/strfuncs/strup", test_strup);
1319
1320   return g_test_run();
1321 }