os/ossrv/glib/glib/tests/strfuncs.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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.
     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 #include <ctype.h>
    23 #include <errno.h>
    24 #include <locale.h>
    25 #include <math.h>
    26 #include <stdarg.h>
    27 #include <stdio.h>
    28 #include <stdlib.h>
    29 #include <string.h>
    30 #include "glib.h"
    31 
    32 #ifdef __SYMBIAN32__
    33 #include <glib_global.h>
    34 #include "mrt2_glib2_test.h"
    35 #endif /*__SYMBIAN32__*/
    36 #define GLIB_TEST_STRING "el dorado "
    37 
    38 #define FOR_ALL_CTYPE(macro)	\
    39 	macro(isalnum)		\
    40 	macro(isalpha)		\
    41 	macro(iscntrl)		\
    42 	macro(isdigit)		\
    43 	macro(isgraph)		\
    44 	macro(islower)		\
    45 	macro(isprint)		\
    46 	macro(ispunct)		\
    47 	macro(isspace)		\
    48 	macro(isupper)		\
    49 	macro(isxdigit)
    50 
    51 #define DEFINE_CALL_CTYPE(function)		\
    52 	static int				\
    53 	call_##function (int c)			\
    54 	{					\
    55 		return function (c);		\
    56 	}
    57 
    58 #define DEFINE_CALL_G_ASCII_CTYPE(function)	\
    59 	static gboolean				\
    60 	call_g_ascii_##function (gchar c)	\
    61 	{					\
    62 		return g_ascii_##function (c);	\
    63 	}
    64 
    65 FOR_ALL_CTYPE (DEFINE_CALL_CTYPE)
    66 FOR_ALL_CTYPE (DEFINE_CALL_G_ASCII_CTYPE)
    67 
    68 static void
    69 test_is_function (const char *name,
    70 		  gboolean (* ascii_function) (gchar),
    71 		  int (* c_library_function) (int),
    72 		  gboolean (* unicode_function) (gunichar))
    73 {
    74   int c;
    75 
    76   for (c = 0; c <= 0x7F; c++)
    77     {
    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')
    82         {
    83 	  g_error ("g_ascii_%s returned %d and %s returned %d for 0x%X",
    84 		   name, ascii_result, name, c_library_result, c);
    85 	}
    86       if (ascii_result != unicode_result)
    87 	{
    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);
    90 	}
    91     }
    92   for (c = 0x80; c <= 0xFF; c++)
    93     {
    94       gboolean ascii_result = ascii_function ((gchar)c);
    95       if (ascii_result)
    96 	{
    97 	  g_error ("g_ascii_%s returned TRUE for 0x%X", name, c);
    98 	}
    99     }
   100 }
   101 
   102 static void
   103 test_to_function (const char *name,
   104 		  gchar (* ascii_function) (gchar),
   105 		  int (* c_library_function) (int),
   106 		  gunichar (* unicode_function) (gunichar))
   107 {
   108   int c;
   109 
   110   for (c = 0; c <= 0x7F; c++)
   111     {
   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)
   116 	{
   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);
   119 	}
   120       if (ascii_result != unicode_result)
   121 	{
   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);
   124 	}
   125     }
   126   for (c = 0x80; c <= 0xFF; c++)
   127     {
   128       int ascii_result = (guchar) ascii_function ((gchar) c);
   129       if (ascii_result != c)
   130 	{
   131 	  g_error ("g_ascii_%s returned 0x%X for 0x%X",
   132 		   name, ascii_result, c);
   133 	}
   134     }
   135 }
   136 
   137 static void
   138 test_digit_function (const char *name,
   139 		     int (* ascii_function) (gchar),
   140 		     int (* unicode_function) (gunichar))
   141 {
   142   int c;
   143 
   144   for (c = 0; c <= 0x7F; c++)
   145     {
   146       int ascii_result = ascii_function ((gchar) c);
   147       int unicode_result = unicode_function ((gunichar) c);
   148       if (ascii_result != unicode_result)
   149 	{
   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);
   152 	}
   153     }
   154   for (c = 0x80; c <= 0xFF; c++)
   155     {
   156       int ascii_result = ascii_function ((gchar) c);
   157       if (ascii_result != -1)
   158 	{
   159 	  g_error ("g_ascii_%s_value returned %d for 0x%X",
   160 		   name, ascii_result, c);
   161 	}
   162     }
   163 }
   164 
   165 static void
   166 test_is_to_digit (void)
   167 {
   168   #define TEST_IS(name) test_is_function (#name, call_g_ascii_##name, call_##name, g_unichar_##name);
   169 
   170   FOR_ALL_CTYPE(TEST_IS)
   171 
   172   #undef TEST_IS
   173 
   174   #define TEST_TO(name) test_to_function (#name, g_ascii_##name, name, g_unichar_##name)
   175 
   176   TEST_TO (tolower);
   177   TEST_TO (toupper);
   178 
   179   #undef TEST_TO
   180 
   181   #define TEST_DIGIT(name) test_digit_function (#name, g_ascii_##name##_value, g_unichar_##name##_value)
   182 
   183   TEST_DIGIT (digit);
   184   TEST_DIGIT (xdigit);
   185 
   186   #undef TEST_DIGIT
   187 }
   188 
   189 static void
   190 test_strdup (void)
   191 {
   192   gchar *str;
   193 
   194   str = g_strdup (NULL);
   195   g_assert (str == NULL);
   196 
   197   str = g_strdup (GLIB_TEST_STRING);
   198   g_assert (str != NULL);
   199   g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
   200   g_free (str);
   201 }
   202 
   203 static void
   204 test_strndup (void)
   205 {
   206   gchar *str;
   207 
   208   str = g_strndup (NULL, 3);
   209   g_assert (str == NULL);
   210 
   211   str = g_strndup ("aaaa", 5);
   212   g_assert (str != NULL);
   213   g_assert_cmpstr (str, ==, "aaaa");
   214   g_free (str);
   215 
   216   str = g_strndup ("aaaa", 2);
   217   g_assert (str != NULL);
   218   g_assert_cmpstr (str, ==, "aa");
   219   g_free (str);
   220 }
   221 
   222 static void
   223 test_strdup_printf (void)
   224 {
   225   gchar *str;
   226 
   227   str = g_strdup_printf ("%05d %-5s", 21, "test");
   228   g_assert (str != NULL);
   229   g_assert_cmpstr (str, ==, "00021 test ");
   230   g_free (str);
   231 }
   232 
   233 static void
   234 test_strdupv (void)
   235 {
   236   gchar *vec[] = { "Foo", "Bar", NULL };
   237   gchar **copy;
   238 
   239   copy = g_strdupv (NULL);
   240   g_assert (copy == NULL);  
   241 
   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);
   247   g_strfreev (copy);
   248 }
   249 
   250 static void
   251 test_strnfill (void)
   252 {
   253   gchar *str;
   254 
   255   str = g_strnfill (0, 'a');
   256   g_assert (str != NULL);
   257   g_assert (*str == '\0');
   258   g_free (str);
   259 
   260   str = g_strnfill (5, 'a');
   261   g_assert (str != NULL);
   262   g_assert_cmpstr (str, ==, "aaaaa");
   263   g_free (str);
   264 }
   265 
   266 static void
   267 test_strconcat (void)
   268 {
   269   gchar *str;
   270 
   271   str = g_strconcat (GLIB_TEST_STRING, NULL);
   272   g_assert (str != NULL);
   273   g_assert_cmpstr (str, ==, GLIB_TEST_STRING);
   274   g_free (str);
   275 
   276   str = g_strconcat (GLIB_TEST_STRING,
   277 		     GLIB_TEST_STRING, 
   278 		     GLIB_TEST_STRING,
   279 		     NULL);
   280   g_assert (str != NULL);
   281   g_assert_cmpstr (str, ==, GLIB_TEST_STRING GLIB_TEST_STRING GLIB_TEST_STRING);
   282   g_free (str);
   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 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       g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, fmt, num);
   917       g_assert_cmpstr (buf, ==, str);
   918     }
   919 }
   920 
   921 static void
   922 test_strtod (void)
   923 {
   924   gdouble d, our_nan, our_inf;
   925   char buffer[G_ASCII_DTOSTR_BUF_SIZE];
   926   gchar* gstr1;
   927   gdouble gd;
   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   /* 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);
   959   
   960   d = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
   961   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
   962 
   963   d = -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
   964   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
   965   
   966   d = pow (2.0, -1021.1);
   967   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
   968   
   969   d = -pow (2.0, -1021.1);
   970   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
   971 
   972   /* for #343899 */ 
   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);
   980 
   981 #if 0
   982   /* g_ascii_isspace() returns FALSE for vertical tab, see #59388 */
   983   check_strtod_string ("\v0.75", 0.75, FALSE, 0);
   984 #endif
   985 
   986   /* for #343899 */
   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");
   992 }
   993 
   994 static void
   995 check_uint64 (const gchar *str,
   996 	      const gchar *end,
   997 	      gint         base,
   998 	      guint64      result,
   999 	      gint         error)
  1000 {
  1001   guint64 actual;
  1002   gchar *endptr = NULL;
  1003   gint err;
  1004 
  1005   errno = 0;
  1006   actual = g_ascii_strtoull (str, &endptr, base);
  1007   err = errno;
  1008 
  1009   g_assert (actual == result);
  1010   g_assert_cmpstr (end, ==, endptr);
  1011   g_assert (err == error);
  1012 }
  1013 
  1014 static void
  1015 check_int64 (const gchar *str,
  1016 	     const gchar *end,
  1017 	     gint         base,
  1018 	     gint64       result,
  1019 	     gint         error)
  1020 {
  1021   gint64 actual;
  1022   gchar *endptr = NULL;
  1023   gint err;
  1024 
  1025   errno = 0;
  1026   actual = g_ascii_strtoll (str, &endptr, base);
  1027   err = errno;
  1028 
  1029   g_assert (actual == result);
  1030   g_assert_cmpstr (end, ==, endptr);
  1031   g_assert (err == error);
  1032 }
  1033 
  1034 static void
  1035 test_strtoll (void)
  1036 {
  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);
  1044 
  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);
  1054 }
  1055 
  1056 static void
  1057 test_bounds (void)
  1058 {
  1059   GMappedFile *file, *before, *after;
  1060   char buffer[4097];
  1061   char *tmp, *tmp2;
  1062   char **array;
  1063   char *string;
  1064 
  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
  1067    * side.
  1068    */
  1069   before = g_mapped_file_new ("c:\\4096-random-bytes", TRUE, NULL);
  1070 
  1071   /* quick workaround until #549783 can be fixed */
  1072   if (before == NULL)
  1073     return;
  1074 
  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);
  1079 
  1080   g_assert (file != NULL);
  1081   g_assert_cmpint (g_mapped_file_get_length (file), ==, 4096);
  1082   string = g_mapped_file_get_contents (file);
  1083 
  1084   /* ensure they're all non-nul */
  1085   g_assert (memchr (string, '\0', 4096) == NULL);
  1086 
  1087   /* test set 1: ensure that nothing goes past its maximum length, even in
  1088    *             light of a missing nul terminator.
  1089    *
  1090    * we try to test all of the 'n' functions here.
  1091    */
  1092   tmp = g_strndup (string, 4096);
  1093   g_assert_cmpint (strlen (tmp), ==, 4096);
  1094   g_free (tmp);
  1095 
  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, "");
  1101 
  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, "");
  1106 
  1107   g_ascii_strdown (string, 4096);
  1108   g_ascii_strdown (string, 4096);
  1109   g_ascii_strup (string, 4096);
  1110   g_ascii_strup (string, 4096);
  1111 
  1112   g_ascii_strncasecmp (string, string, 4096);
  1113 
  1114   tmp = g_markup_escape_text (string, 4096);
  1115   g_free (tmp);
  1116 
  1117   /* test set 2: ensure that nothing reads even one byte past a '\0'.
  1118    */
  1119   g_assert_cmpint (string[4095], ==, '\n');
  1120   string[4095] = '\0';
  1121 
  1122   tmp = g_strdup (string);
  1123   g_assert_cmpint (strlen (tmp), ==, 4095);
  1124   g_free (tmp);
  1125 
  1126   tmp = g_strndup (string, 10000);
  1127   g_assert_cmpint (strlen (tmp), ==, 4095);
  1128   g_free (tmp);
  1129 
  1130   g_stpcpy (buffer, string);
  1131   g_assert_cmpint (strlen (buffer), ==, 4095);
  1132 
  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, "");
  1137 
  1138   g_strrstr (string, "BUGS");
  1139   g_strrstr (string, "B");
  1140   g_strrstr (string, ".");
  1141   g_strrstr (string, "");
  1142 
  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, "");
  1147 
  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.");
  1153 
  1154   g_strlcpy (buffer, string, sizeof buffer);
  1155   g_assert_cmpint (strlen (buffer), ==, 4095);
  1156   g_strlcpy (buffer, string, sizeof buffer);
  1157   buffer[0] = '\0';
  1158   g_strlcat (buffer, string, sizeof buffer);
  1159   g_assert_cmpint (strlen (buffer), ==, 4095);
  1160 
  1161   tmp = g_strdup_printf ("<%s>", string);
  1162   g_assert_cmpint (strlen (tmp), ==, 4095 + 2);
  1163   g_free (tmp);
  1164 
  1165   g_ascii_strdown (string, -1);
  1166   g_ascii_strdown (string, -1);
  1167   g_ascii_strup (string, -1);
  1168   g_ascii_strup (string, -1);
  1169 
  1170   g_ascii_strcasecmp (string, string);
  1171   g_ascii_strncasecmp (string, string, 10000);
  1172 
  1173   g_strreverse (string);
  1174   g_strreverse (string);
  1175   g_strchug (string);
  1176   g_strchomp (string);
  1177   g_strstrip (string);
  1178   g_assert_cmpint (strlen (string), ==, 4094);
  1179 
  1180   g_strdelimit (string, "M", 'N');
  1181   g_strcanon (string, " N.", ':');
  1182   g_assert_cmpint (strlen (string), ==, 4094);
  1183 
  1184   array = g_strsplit (string, ".", -1);
  1185   tmp = g_strjoinv (".", array);
  1186   g_strfreev (array);
  1187 
  1188   g_assert_cmpint (strlen (tmp), ==, 4094);
  1189   g_assert (memcmp (tmp, string, 4095) == 0);
  1190   g_free (tmp);
  1191 
  1192   tmp = g_strconcat (string, string, string, NULL);
  1193   g_assert_cmpint (strlen (tmp), ==, 4094 * 3);
  1194   g_free (tmp);
  1195 
  1196   tmp = g_strjoin ("!", string, string, NULL);
  1197   g_assert_cmpint (strlen (tmp), ==, 4094 + 1 + 4094);
  1198   g_free (tmp);
  1199 
  1200   tmp = g_markup_escape_text (string, -1);
  1201   g_free (tmp);
  1202 
  1203   tmp = g_markup_printf_escaped ("%s", string);
  1204   g_free (tmp);
  1205 
  1206   tmp = g_strescape (string, NULL);
  1207   tmp2 = g_strcompress (tmp);
  1208   g_assert_cmpstr (string, ==, tmp2);
  1209   g_free (tmp2);
  1210   g_free (tmp);
  1211 
  1212   g_mapped_file_free (file);
  1213 }
  1214 
  1215 int
  1216 main (int   argc,
  1217       char *argv[])
  1218 {
  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);
  1224 
  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);
  1248 
  1249   /*return*/ g_test_run();
  1250 #ifdef __SYMBIAN32__
  1251   testResultXml("strfunc");
  1252 #endif /* EMULATOR */
  1253 return 0;
  1254 }