Update contrib.
     1 /* Unit tests for gstrfuncs
 
     2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
 
     3  * Portions copyright (c) 2009 Nokia Corporation.  All rights reserved.
 
     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.
 
    33 #include <glib_global.h>
 
    34 #include "mrt2_glib2_test.h"
 
    35 #endif /*__SYMBIAN32__*/
 
    36 #define GLIB_TEST_STRING "el dorado "
 
    38 #define FOR_ALL_CTYPE(macro)	\
 
    51 #define DEFINE_CALL_CTYPE(function)		\
 
    53 	call_##function (int c)			\
 
    55 		return function (c);		\
 
    58 #define DEFINE_CALL_G_ASCII_CTYPE(function)	\
 
    60 	call_g_ascii_##function (gchar c)	\
 
    62 		return g_ascii_##function (c);	\
 
    65 FOR_ALL_CTYPE (DEFINE_CALL_CTYPE)
 
    66 FOR_ALL_CTYPE (DEFINE_CALL_G_ASCII_CTYPE)
 
    69 test_is_function (const char *name,
 
    70 		  gboolean (* ascii_function) (gchar),
 
    71 		  int (* c_library_function) (int),
 
    72 		  gboolean (* unicode_function) (gunichar))
 
    76   for (c = 0; c <= 0x7F; c++)
 
    78       gboolean ascii_result = ascii_function ((gchar)c);
 
    79       gboolean c_library_result = c_library_function (c) != 0;
 
    80       gboolean unicode_result = unicode_function ((gunichar) c);
 
    81       if (ascii_result != c_library_result && c != '\v')
 
    83 	  g_error ("g_ascii_%s returned %d and %s returned %d for 0x%X",
 
    84 		   name, ascii_result, name, c_library_result, c);
 
    86       if (ascii_result != unicode_result)
 
    88 	  g_error ("g_ascii_%s returned %d and g_unichar_%s returned %d for 0x%X",
 
    89 		   name, ascii_result, name, unicode_result, c);
 
    92   for (c = 0x80; c <= 0xFF; c++)
 
    94       gboolean ascii_result = ascii_function ((gchar)c);
 
    97 	  g_error ("g_ascii_%s returned TRUE for 0x%X", name, c);
 
   103 test_to_function (const char *name,
 
   104 		  gchar (* ascii_function) (gchar),
 
   105 		  int (* c_library_function) (int),
 
   106 		  gunichar (* unicode_function) (gunichar))
 
   110   for (c = 0; c <= 0x7F; c++)
 
   112       int ascii_result = (guchar) ascii_function ((gchar) c);
 
   113       int c_library_result = c_library_function (c);
 
   114       int unicode_result = unicode_function ((gunichar) c);
 
   115       if (ascii_result != c_library_result)
 
   117 	  g_error ("g_ascii_%s returned 0x%X and %s returned 0x%X for 0x%X",
 
   118 		   name, ascii_result, name, c_library_result, c);
 
   120       if (ascii_result != unicode_result)
 
   122 	  g_error ("g_ascii_%s returned 0x%X and g_unichar_%s returned 0x%X for 0x%X",
 
   123 		   name, ascii_result, name, unicode_result, c);
 
   126   for (c = 0x80; c <= 0xFF; c++)
 
   128       int ascii_result = (guchar) ascii_function ((gchar) c);
 
   129       if (ascii_result != c)
 
   131 	  g_error ("g_ascii_%s returned 0x%X for 0x%X",
 
   132 		   name, ascii_result, c);
 
   138 test_digit_function (const char *name,
 
   139 		     int (* ascii_function) (gchar),
 
   140 		     int (* unicode_function) (gunichar))
 
   144   for (c = 0; c <= 0x7F; c++)
 
   146       int ascii_result = ascii_function ((gchar) c);
 
   147       int unicode_result = unicode_function ((gunichar) c);
 
   148       if (ascii_result != unicode_result)
 
   150 	  g_error ("g_ascii_%s_value returned %d and g_unichar_%s_value returned %d for 0x%X",
 
   151 		   name, ascii_result, name, unicode_result, c);
 
   154   for (c = 0x80; c <= 0xFF; c++)
 
   156       int ascii_result = ascii_function ((gchar) c);
 
   157       if (ascii_result != -1)
 
   159 	  g_error ("g_ascii_%s_value returned %d for 0x%X",
 
   160 		   name, ascii_result, c);
 
   166 test_is_to_digit (void)
 
   168   #define TEST_IS(name) test_is_function (#name, call_g_ascii_##name, call_##name, g_unichar_##name);
 
   170   FOR_ALL_CTYPE(TEST_IS)
 
   174   #define TEST_TO(name) test_to_function (#name, g_ascii_##name, name, g_unichar_##name)
 
   181   #define TEST_DIGIT(name) test_digit_function (#name, g_ascii_##name##_value, g_unichar_##name##_value)
 
   194   str = g_strdup (NULL);
 
   195   g_assert (str == NULL);
 
   197   str = g_strdup (GLIB_TEST_STRING);
 
   198   g_assert (str != NULL);
 
   199   g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
 
   208   str = g_strndup (NULL, 3);
 
   209   g_assert (str == NULL);
 
   211   str = g_strndup ("aaaa", 5);
 
   212   g_assert (str != NULL);
 
   213   g_assert_cmpstr (str, ==, "aaaa");
 
   216   str = g_strndup ("aaaa", 2);
 
   217   g_assert (str != NULL);
 
   218   g_assert_cmpstr (str, ==, "aa");
 
   223 test_strdup_printf (void)
 
   227   str = g_strdup_printf ("%05d %-5s", 21, "test");
 
   228   g_assert (str != NULL);
 
   229   g_assert_cmpstr (str, ==, "00021 test ");
 
   236   gchar *vec[] = { "Foo", "Bar", NULL };
 
   239   copy = g_strdupv (NULL);
 
   240   g_assert (copy == NULL);  
 
   242   copy = g_strdupv (vec);
 
   243   g_assert (copy != NULL);
 
   244   g_assert_cmpstr (copy[0], ==, "Foo");
 
   245   g_assert_cmpstr (copy[1], ==, "Bar");
 
   246   g_assert (copy[2] == NULL);
 
   255   str = g_strnfill (0, 'a');
 
   256   g_assert (str != NULL);
 
   257   g_assert (*str == '\0');
 
   260   str = g_strnfill (5, 'a');
 
   261   g_assert (str != NULL);
 
   262   g_assert_cmpstr (str, ==, "aaaaa");
 
   267 test_strconcat (void)
 
   271   str = g_strconcat (GLIB_TEST_STRING, NULL);
 
   272   g_assert (str != NULL);
 
   273   g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
 
   276   str = g_strconcat (GLIB_TEST_STRING,
 
   280   g_assert (str != NULL);
 
   281   g_assert_cmpstr (str, ==, GLIB_TEST_STRING GLIB_TEST_STRING GLIB_TEST_STRING);
 
   290   str = g_strjoin (NULL, NULL);
 
   291   g_assert (str != NULL);
 
   292   g_assert (*str == '\0');
 
   295   str = g_strjoin (":", NULL);
 
   296   g_assert (str != NULL);
 
   297   g_assert (*str == '\0');
 
   300   str = g_strjoin (NULL, GLIB_TEST_STRING, NULL);
 
   301   g_assert (str != NULL);
 
   302   g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
 
   305   str = g_strjoin (NULL,
 
   310   g_assert (str != NULL);
 
   311   g_assert_cmpstr (str, ==, GLIB_TEST_STRING GLIB_TEST_STRING GLIB_TEST_STRING);
 
   314   str = g_strjoin (":",
 
   319   g_assert (str != NULL);
 
   320   g_assert_cmpstr (str, ==, GLIB_TEST_STRING ":" GLIB_TEST_STRING ":" GLIB_TEST_STRING);
 
   329   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
 
   331       str = g_strcanon (NULL, "ab", 'y');
 
   333   g_test_trap_assert_failed ();
 
   335   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
 
   337       str = g_strdup ("abxabxab");
 
   338       str = g_strcanon (str, NULL, 'y');
 
   341   g_test_trap_assert_failed ();
 
   343   str = g_strdup ("abxabxab");
 
   344   str = g_strcanon (str, "ab", 'y');
 
   345   g_assert (str != NULL);
 
   346   g_assert_cmpstr (str, ==, "abyabyab");
 
   351 test_strcompress_strescape (void)
 
   357   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
 
   359       str = g_strcompress (NULL);
 
   361   g_test_trap_assert_failed ();
 
   363   /* trailing slashes are not allowed */
 
   364   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
 
   366       str = g_strcompress ("abc\\");
 
   368   g_test_trap_assert_failed ();
 
   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");
 
   376   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
 
   378       str = g_strescape (NULL, NULL);
 
   380   g_test_trap_assert_failed ();
 
   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");
 
   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");
 
   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");
 
   403 test_ascii_strcasecmp (void)
 
   407   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
 
   409       res = g_ascii_strcasecmp ("foo", NULL);
 
   411   g_test_trap_assert_failed ();
 
   413   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
 
   415       res = g_ascii_strcasecmp (NULL, "foo");
 
   417   g_test_trap_assert_failed ();
 
   419   res = g_ascii_strcasecmp ("FroboZZ", "frobozz");
 
   420   g_assert_cmpint (res, ==, 0);
 
   422   res = g_ascii_strcasecmp ("frobozz", "frobozz");
 
   423   g_assert_cmpint (res, ==, 0);
 
   425   res = g_ascii_strcasecmp ("frobozz", "FROBOZZ");
 
   426   g_assert_cmpint (res, ==, 0);
 
   428   res = g_ascii_strcasecmp ("FROBOZZ", "froboz");
 
   429   g_assert_cmpint (res, !=, 0);
 
   431   res = g_ascii_strcasecmp ("", "");
 
   432   g_assert_cmpint (res, ==, 0);
 
   434   res = g_ascii_strcasecmp ("!#%&/()", "!#%&/()");
 
   435   g_assert_cmpint (res, ==, 0);
 
   437   res = g_ascii_strcasecmp ("a", "b");
 
   438   g_assert_cmpint (res, <, 0);
 
   440   res = g_ascii_strcasecmp ("a", "B");
 
   441   g_assert_cmpint (res, <, 0);
 
   443   res = g_ascii_strcasecmp ("A", "b");
 
   444   g_assert_cmpint (res, <, 0);
 
   446   res = g_ascii_strcasecmp ("A", "B");
 
   447   g_assert_cmpint (res, <, 0);
 
   449   res = g_ascii_strcasecmp ("b", "a");
 
   450   g_assert_cmpint (res, >, 0);
 
   452   res = g_ascii_strcasecmp ("b", "A");
 
   453   g_assert_cmpint (res, >, 0);
 
   455   res = g_ascii_strcasecmp ("B", "a");
 
   456   g_assert_cmpint (res, >, 0);
 
   458   res = g_ascii_strcasecmp ("B", "A");
 
   459   g_assert_cmpint (res, >, 0);
 
   463 do_test_strchug (const gchar *str, const gchar *expected)
 
   468   tmp = g_strdup (str);
 
   471   res = (strcmp (tmp, expected) == 0);
 
   474   g_assert_cmpint (res, ==, TRUE);
 
   480   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
 
   484   g_test_trap_assert_failed ();
 
   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");
 
   496 do_test_strchomp (const gchar *str, const gchar *expected)
 
   501   tmp = g_strdup (str);
 
   504   res = (strcmp (tmp, expected) == 0);
 
   507   g_assert_cmpint (res, ==, TRUE);
 
   513   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
 
   517   g_test_trap_assert_failed ();
 
   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");
 
   529 test_strreverse (void)
 
   534   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
 
   536       str = g_strreverse (NULL);
 
   538   g_test_trap_assert_failed ();
 
   540   str = p = g_strdup ("abcde");
 
   541   str = g_strreverse (str);
 
   542   g_assert (str != NULL);
 
   544   g_assert_cmpstr (str, ==, "edcba");
 
   554   haystack = g_strdup ("FooBarFooBarFoo");
 
   557   res = g_strstr_len (haystack, 6, "xxx");
 
   558   g_assert (res == NULL);
 
   560   res = g_strstr_len (haystack, 6, "FooBarFooBarFooBar");
 
   561   g_assert (res == NULL);
 
   563   res = g_strstr_len (haystack, 3, "Bar");
 
   564   g_assert (res == NULL);
 
   566   res = g_strstr_len (haystack, 6, "");
 
   567   g_assert (res == haystack);
 
   568   g_assert_cmpstr (res, ==, "FooBarFooBarFoo");
 
   570   res = g_strstr_len (haystack, 6, "Bar");
 
   571   g_assert (res == haystack + 3);
 
   572   g_assert_cmpstr (res, ==, "BarFooBarFoo");
 
   574   res = g_strstr_len (haystack, -1, "Bar");
 
   575   g_assert (res == haystack + 3);
 
   576   g_assert_cmpstr (res, ==, "BarFooBarFoo");
 
   579   res = g_strrstr (haystack, "xxx");
 
   580   g_assert (res == NULL);
 
   582   res = g_strrstr (haystack, "FooBarFooBarFooBar");
 
   583   g_assert (res == NULL);
 
   585   res = g_strrstr (haystack, "");
 
   586   g_assert (res == haystack);
 
   587   g_assert_cmpstr (res, ==, "FooBarFooBarFoo");
 
   589   res = g_strrstr (haystack, "Bar");
 
   590   g_assert (res == haystack + 9);
 
   591   g_assert_cmpstr (res, ==, "BarFoo");
 
   594   res = g_strrstr_len (haystack, 14, "xxx");
 
   595   g_assert (res == NULL);
 
   597   res = g_strrstr_len (haystack, 14, "FooBarFooBarFooBar");
 
   598   g_assert (res == NULL);
 
   600   res = g_strrstr_len (haystack, 3, "Bar");
 
   601   g_assert (res == NULL);
 
   603   res = g_strrstr_len (haystack, 14, "BarFoo");
 
   604   g_assert (res == haystack + 3);
 
   605   g_assert_cmpstr (res, ==, "BarFooBarFoo");
 
   607   res = g_strrstr_len (haystack, 15, "BarFoo");
 
   608   g_assert (res == haystack + 9);
 
   609   g_assert_cmpstr (res, ==, "BarFoo");
 
   611   res = g_strrstr_len (haystack, -1, "BarFoo");
 
   612   g_assert (res == haystack + 9);
 
   613   g_assert_cmpstr (res, ==, "BarFoo");
 
   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);
 
   624 test_has_prefix (void)
 
   628   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
 
   630       res = g_str_has_prefix ("foo", NULL);
 
   632   g_test_trap_assert_failed ();
 
   634   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
 
   636       res = g_str_has_prefix (NULL, "foo");
 
   638   g_test_trap_assert_failed ();
 
   640   res = g_str_has_prefix ("foo", "bar");
 
   641   g_assert_cmpint (res, ==, FALSE);
 
   643   res = g_str_has_prefix ("foo", "foobar");
 
   644   g_assert_cmpint (res, ==, FALSE);
 
   646   res = g_str_has_prefix ("foobar", "bar");
 
   647   g_assert_cmpint (res, ==, FALSE);
 
   649   res = g_str_has_prefix ("foobar", "foo");
 
   650   g_assert_cmpint (res, ==, TRUE);
 
   652   res = g_str_has_prefix ("foo", "");
 
   653   g_assert_cmpint (res, ==, TRUE);
 
   655   res = g_str_has_prefix ("foo", "foo");
 
   656   g_assert_cmpint (res, ==, TRUE);
 
   658   res = g_str_has_prefix ("", "");
 
   659   g_assert_cmpint (res, ==, TRUE);
 
   663 test_has_suffix (void)
 
   667   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
 
   669       res = g_str_has_suffix ("foo", NULL);
 
   671   g_test_trap_assert_failed ();
 
   673   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
 
   675       res = g_str_has_suffix (NULL, "foo");
 
   677   g_test_trap_assert_failed ();
 
   679   res = g_str_has_suffix ("foo", "bar");
 
   680   g_assert_cmpint (res, ==, FALSE);
 
   682   res = g_str_has_suffix ("bar", "foobar");
 
   683   g_assert_cmpint (res, ==, FALSE);
 
   685   res = g_str_has_suffix ("foobar", "foo");
 
   686   g_assert_cmpint (res, ==, FALSE);
 
   688   res = g_str_has_suffix ("foobar", "bar");
 
   689   g_assert_cmpint (res, ==, TRUE);
 
   691   res = g_str_has_suffix ("foo", "");
 
   692   g_assert_cmpint (res, ==, TRUE);
 
   694   res = g_str_has_suffix ("foo", "foo");
 
   695   g_assert_cmpint (res, ==, TRUE);
 
   697   res = g_str_has_suffix ("", "");
 
   698   g_assert_cmpint (res, ==, TRUE);
 
   702 strv_check (gchar **strv, ...)
 
   708   va_start (list, strv);
 
   711       const gchar *str = va_arg (list, const char *);
 
   714 	  g_assert (str == NULL);
 
   723           g_assert_cmpstr (strv[i], ==, str);
 
   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);
 
   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);
 
   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);
 
   776 test_strsplit_set (void)
 
   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);
 
   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);
 
   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);
 
   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);
 
   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);
 
   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);
 
   837   strv_check (g_strsplit_set (",,x,.y,..z,,", ",.", 3), "", "", "x,.y,..z,,", NULL);
 
   841 test_strv_length (void)
 
   845   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
 
   847       l = g_strv_length (NULL);
 
   849   g_test_trap_assert_failed ();
 
   851   l = g_strv_length (g_strsplit ("1,2,3,4", ",", -1));
 
   852   g_assert_cmpuint (l, ==, 4);
 
   855 static char *locales[] = {"sv_SE", "en_US", "fa_IR", "C", "ru_RU"};
 
   858 check_strtod_string (gchar    *number,
 
   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. */
 
   870   dummy = g_malloc (100000);
 
   871   number = g_strdup (number);
 
   874   for (l = 0; l < G_N_ELEMENTS (locales); l++)
 
   877       gchar *end = "(unset)";
 
   879       setlocale (LC_NUMERIC, locales[l]);
 
   880       d = g_ascii_strtod (number, &end);
 
   881       ok = isnan (res) ? isnan (d) : (d == res);
 
   884 	  g_error ("g_ascii_strtod on \"%s\" for locale %s failed\n" \
 
   885                    "expected %f (nan %d) actual %f (nan %d)\n", 
 
   891       ok = (end - number) == (check_end ? correct_len : strlen (number));
 
   894 	  g_error ("g_ascii_strtod on \"%s\" for locale %s endptr was NULL\n",
 
   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);
 
   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);
 
   909 check_strtod_number (gdouble num, gchar *fmt, gchar *str)
 
   912   gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
 
   914   for (l = 0; l < G_N_ELEMENTS (locales); l++)
 
   916       g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, fmt, num);
 
   917       g_assert_cmpstr (buf, ==, str);
 
   924   gdouble d, our_nan, our_inf;
 
   925   char buffer[G_ASCII_DTOSTR_BUF_SIZE];
 
   931   /* Do this before any call to setlocale.  */
 
   932   our_nan = atof ("NaN");
 
   934   g_assert (isnan (our_nan));
 
   939   our_inf = atof ("Infinity");
 
   941   g_assert (our_inf > 1 && our_inf == our_inf / 2);
 
   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   /* the following are for #156421 */
 
   953   check_strtod_string ("1e1", 1e1, FALSE, 0); 
 
   954   check_strtod_string ("NAN", our_nan, FALSE, 0);
 
   955   check_strtod_string ("-nan", -our_nan, FALSE, 0);
 
   956   check_strtod_string ("INF", our_inf, FALSE, 0);
 
   957   check_strtod_string ("-infinity", -our_inf, FALSE, 0);
 
   958   check_strtod_string ("-.75,0", -0.75, TRUE, 4);
 
   960   d = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
 
   961   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
 
   963   d = -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
 
   964   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
 
   966   d = pow (2.0, -1021.1);
 
   967   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
 
   969   d = -pow (2.0, -1021.1);
 
   970   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
 
   973   check_strtod_string (" 0.75", 0.75, FALSE, 0);
 
   974   check_strtod_string (" +0.75", 0.75, FALSE, 0);
 
   975   check_strtod_string (" -0.75", -0.75, FALSE, 0);
 
   976   check_strtod_string ("\f0.75", 0.75, FALSE, 0);
 
   977   check_strtod_string ("\n0.75", 0.75, FALSE, 0);
 
   978   check_strtod_string ("\r0.75", 0.75, FALSE, 0);
 
   979   check_strtod_string ("\t0.75", 0.75, FALSE, 0);
 
   982   /* g_ascii_isspace() returns FALSE for vertical tab, see #59388 */
 
   983   check_strtod_string ("\v0.75", 0.75, FALSE, 0);
 
   987   check_strtod_number (0.75, "%0.2f", "0.75");
 
   988   check_strtod_number (0.75, "%5.2f", " 0.75");
 
   989   check_strtod_number (-0.75, "%0.2f", "-0.75");
 
   990   check_strtod_number (-0.75, "%5.2f", "-0.75");
 
   991   check_strtod_number (1e99, "%.0e", "1e+99");
 
   995 check_uint64 (const gchar *str,
 
  1002   gchar *endptr = NULL;
 
  1006   actual = g_ascii_strtoull (str, &endptr, base);
 
  1009   g_assert (actual == result);
 
  1010   g_assert_cmpstr (end, ==, endptr);
 
  1011   g_assert (err == error);
 
  1015 check_int64 (const gchar *str,
 
  1022   gchar *endptr = NULL;
 
  1026   actual = g_ascii_strtoll (str, &endptr, base);
 
  1029   g_assert (actual == result);
 
  1030   g_assert_cmpstr (end, ==, endptr);
 
  1031   g_assert (err == error);
 
  1037   check_uint64 ("0", "", 10, 0, 0);
 
  1038   check_uint64 ("+0", "", 10, 0, 0);
 
  1039   check_uint64 ("-0", "", 10, 0, 0);
 
  1040   check_uint64 ("18446744073709551615", "", 10, G_MAXUINT64, 0);
 
  1041   check_uint64 ("18446744073709551616", "", 10, G_MAXUINT64, ERANGE);
 
  1042   check_uint64 ("20xyz", "xyz", 10, 20, 0);
 
  1043   check_uint64 ("-1", "", 10, G_MAXUINT64, 0);
 
  1045   check_int64 ("0", "", 10, 0, 0);
 
  1046   check_int64 ("9223372036854775807", "", 10, G_MAXINT64, 0);
 
  1047   check_int64 ("9223372036854775808", "", 10, G_MAXINT64, ERANGE);
 
  1048   check_int64 ("-9223372036854775808", "", 10, G_MININT64, 0);
 
  1049   check_int64 ("-9223372036854775809", "", 10, G_MININT64, ERANGE);
 
  1050   check_int64 ("32768", "", 10, 32768, 0);
 
  1051   check_int64 ("-32768", "", 10, -32768, 0);
 
  1052   check_int64 ("001", "", 10, 1, 0);
 
  1053   check_int64 ("-001", "", 10, -1, 0);
 
  1059   GMappedFile *file, *before, *after;
 
  1065   /* if we allocate the file between two others and then free those
 
  1066    * other two, then hopefully we end up with unmapped memory on either
 
  1069   before = g_mapped_file_new ("c:\\4096-random-bytes", TRUE, NULL);
 
  1071   /* quick workaround until #549783 can be fixed */
 
  1075   file = g_mapped_file_new ("c:\\4096-random-bytes", TRUE, NULL);
 
  1076   after = g_mapped_file_new ("c:\\4096-random-bytes", TRUE, NULL);
 
  1077   g_mapped_file_free (before);
 
  1078   g_mapped_file_free (after);
 
  1080   g_assert (file != NULL);
 
  1081   g_assert_cmpint (g_mapped_file_get_length (file), ==, 4096);
 
  1082   string = g_mapped_file_get_contents (file);
 
  1084   /* ensure they're all non-nul */
 
  1085   g_assert (memchr (string, '\0', 4096) == NULL);
 
  1087   /* test set 1: ensure that nothing goes past its maximum length, even in
 
  1088    *             light of a missing nul terminator.
 
  1090    * we try to test all of the 'n' functions here.
 
  1092   tmp = g_strndup (string, 4096);
 
  1093   g_assert_cmpint (strlen (tmp), ==, 4096);
 
  1096   /* found no bugs in gnome, i hope :) */
 
  1097   g_assert (g_strstr_len (string, 4096, "BUGS") == NULL);
 
  1098   g_strstr_len (string, 4096, "B");
 
  1099   g_strstr_len (string, 4096, ".");
 
  1100   g_strstr_len (string, 4096, "");
 
  1102   g_strrstr_len (string, 4096, "BUGS");
 
  1103   g_strrstr_len (string, 4096, "B");
 
  1104   g_strrstr_len (string, 4096, ".");
 
  1105   g_strrstr_len (string, 4096, "");
 
  1107   g_ascii_strdown (string, 4096);
 
  1108   g_ascii_strdown (string, 4096);
 
  1109   g_ascii_strup (string, 4096);
 
  1110   g_ascii_strup (string, 4096);
 
  1112   g_ascii_strncasecmp (string, string, 4096);
 
  1114   tmp = g_markup_escape_text (string, 4096);
 
  1117   /* test set 2: ensure that nothing reads even one byte past a '\0'.
 
  1119   g_assert_cmpint (string[4095], ==, '\n');
 
  1120   string[4095] = '\0';
 
  1122   tmp = g_strdup (string);
 
  1123   g_assert_cmpint (strlen (tmp), ==, 4095);
 
  1126   tmp = g_strndup (string, 10000);
 
  1127   g_assert_cmpint (strlen (tmp), ==, 4095);
 
  1130   g_stpcpy (buffer, string);
 
  1131   g_assert_cmpint (strlen (buffer), ==, 4095);
 
  1133   g_strstr_len (string, 10000, "BUGS");
 
  1134   g_strstr_len (string, 10000, "B");
 
  1135   g_strstr_len (string, 10000, ".");
 
  1136   g_strstr_len (string, 10000, "");
 
  1138   g_strrstr (string, "BUGS");
 
  1139   g_strrstr (string, "B");
 
  1140   g_strrstr (string, ".");
 
  1141   g_strrstr (string, "");
 
  1143   g_strrstr_len (string, 10000, "BUGS");
 
  1144   g_strrstr_len (string, 10000, "B");
 
  1145   g_strrstr_len (string, 10000, ".");
 
  1146   g_strrstr_len (string, 10000, "");
 
  1148   g_str_has_prefix (string, "this won't do very much...");
 
  1149   g_str_has_suffix (string, "but maybe this will...");
 
  1150   g_str_has_suffix (string, "HMMMM.");
 
  1151   g_str_has_suffix (string, "MMMM.");
 
  1152   g_str_has_suffix (string, "M.");
 
  1154   g_strlcpy (buffer, string, sizeof buffer);
 
  1155   g_assert_cmpint (strlen (buffer), ==, 4095);
 
  1156   g_strlcpy (buffer, string, sizeof buffer);
 
  1158   g_strlcat (buffer, string, sizeof buffer);
 
  1159   g_assert_cmpint (strlen (buffer), ==, 4095);
 
  1161   tmp = g_strdup_printf ("<%s>", string);
 
  1162   g_assert_cmpint (strlen (tmp), ==, 4095 + 2);
 
  1165   g_ascii_strdown (string, -1);
 
  1166   g_ascii_strdown (string, -1);
 
  1167   g_ascii_strup (string, -1);
 
  1168   g_ascii_strup (string, -1);
 
  1170   g_ascii_strcasecmp (string, string);
 
  1171   g_ascii_strncasecmp (string, string, 10000);
 
  1173   g_strreverse (string);
 
  1174   g_strreverse (string);
 
  1176   g_strchomp (string);
 
  1177   g_strstrip (string);
 
  1178   g_assert_cmpint (strlen (string), ==, 4094);
 
  1180   g_strdelimit (string, "M", 'N');
 
  1181   g_strcanon (string, " N.", ':');
 
  1182   g_assert_cmpint (strlen (string), ==, 4094);
 
  1184   array = g_strsplit (string, ".", -1);
 
  1185   tmp = g_strjoinv (".", array);
 
  1188   g_assert_cmpint (strlen (tmp), ==, 4094);
 
  1189   g_assert (memcmp (tmp, string, 4095) == 0);
 
  1192   tmp = g_strconcat (string, string, string, NULL);
 
  1193   g_assert_cmpint (strlen (tmp), ==, 4094 * 3);
 
  1196   tmp = g_strjoin ("!", string, string, NULL);
 
  1197   g_assert_cmpint (strlen (tmp), ==, 4094 + 1 + 4094);
 
  1200   tmp = g_markup_escape_text (string, -1);
 
  1203   tmp = g_markup_printf_escaped ("%s", string);
 
  1206   tmp = g_strescape (string, NULL);
 
  1207   tmp2 = g_strcompress (tmp);
 
  1208   g_assert_cmpstr (string, ==, tmp2);
 
  1212   g_mapped_file_free (file);
 
  1219   #ifdef __SYMBIAN32__
 
  1220   g_log_set_handler (NULL,  G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
 
  1221   g_set_print_handler(mrtPrintHandler);
 
  1222   #endif /*__SYMBIAN32__*/
 
  1223   g_test_init (&argc, &argv, NULL);
 
  1225   g_test_add_func ("/strfuncs/test-is-to-digit", test_is_to_digit);
 
  1226   g_test_add_func ("/strfuncs/strdup", test_strdup);
 
  1227   g_test_add_func ("/strfuncs/strndup", test_strndup);
 
  1228   g_test_add_func ("/strfuncs/strdup-printf", test_strdup_printf);
 
  1229   g_test_add_func ("/strfuncs/strdupv", test_strdupv);
 
  1230   g_test_add_func ("/strfuncs/strnfill", test_strnfill);
 
  1231   g_test_add_func ("/strfuncs/strconcat", test_strconcat);
 
  1232   g_test_add_func ("/strfuncs/strjoin", test_strjoin);
 
  1233   g_test_add_func ("/strfuncs/strcanon", test_strcanon);
 
  1234   g_test_add_func ("/strfuncs/strcompress-strescape", test_strcompress_strescape);
 
  1235   g_test_add_func ("/strfuncs/ascii-strcasecmp", test_ascii_strcasecmp);
 
  1236   g_test_add_func ("/strfuncs/strchug", test_strchug);
 
  1237   g_test_add_func ("/strfuncs/strchomp", test_strchomp);
 
  1238   g_test_add_func ("/strfuncs/strreverse", test_strreverse);
 
  1239   g_test_add_func ("/strfuncs/strstr", test_strstr);
 
  1240   g_test_add_func ("/strfuncs/has-prefix", test_has_prefix);
 
  1241   g_test_add_func ("/strfuncs/has-suffix", test_has_suffix);
 
  1242   g_test_add_func ("/strfuncs/strsplit", test_strsplit);
 
  1243   g_test_add_func ("/strfuncs/strsplit-set", test_strsplit_set);
 
  1244   g_test_add_func ("/strfuncs/strv-length", test_strv_length);
 
  1245   g_test_add_func ("/strfuncs/strtod", test_strtod);
 
  1246   g_test_add_func ("/strfuncs/strtoull-strtoll", test_strtoll);
 
  1247   g_test_add_func ("/strfuncs/bounds-check", test_bounds);
 
  1249   /*return*/ g_test_run();
 
  1250 #ifdef __SYMBIAN32__
 
  1251   testResultXml("strfunc");
 
  1252 #endif /* EMULATOR */