glib/tests/convert-test.c
changeset 18 47c74d1534e1
equal deleted inserted replaced
0:e4d67989cc36 18:47c74d1534e1
       
     1 /* GLIB - Library of useful routines for C programming
       
     2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
       
     3  * Portions copyright (c) 2006-2009 Nokia Corporation.  All rights reserved.
       
     4  * This library is free software; you can redistribute it and/or
       
     5  * modify it under the terms of the GNU Lesser General Public
       
     6  * License as published by the Free Software Foundation; either
       
     7  * version 2 of the License, or (at your option) any later version.
       
     8  *
       
     9  * This library is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    12  * Lesser General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU Lesser General Public
       
    15  * License along with this library; if not, write to the
       
    16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    17  * Boston, MA 02111-1307, USA.
       
    18  */
       
    19 
       
    20 /*
       
    21  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
       
    22  * file for a list of people on the GLib Team.  See the ChangeLog
       
    23  * files for a list of changes.  These files are distributed with
       
    24  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
       
    25  */
       
    26 
       
    27 #undef G_DISABLE_ASSERT
       
    28 #undef G_LOG_DOMAIN
       
    29 
       
    30 #include <string.h>
       
    31 
       
    32 #include <glib.h>
       
    33 #ifdef __SYMBIAN32__
       
    34 #include "mrt2_glib2_test.h"
       
    35 #endif /*__SYMBIAN32__*/
       
    36 
       
    37 
       
    38 /* Bug 311337 */
       
    39 static void
       
    40 test_iconv_state (void)
       
    41 {
       
    42   gchar *in = "\xf4\xe5\xf8\xe5\xed";
       
    43   gchar *expected = "\xd7\xa4\xd7\x95\xd7\xa8\xd7\x95\xd7\x9d";
       
    44   gchar *out;
       
    45   gsize bytes_read = 0;
       
    46   gsize bytes_written = 0;
       
    47   GError *error = NULL;
       
    48 
       
    49   out = g_convert (in, -1, "UTF-8", "windows-1255", 
       
    50 		   &bytes_read, &bytes_written, &error);
       
    51 
       
    52   if (error && error->code == G_CONVERT_ERROR_NO_CONVERSION)
       
    53     return; /* silently skip if CP1255 is not supported, see bug 467707 */ 
       
    54 
       
    55   g_assert_no_error (error);
       
    56   g_assert (bytes_read == 5);
       
    57   g_assert (bytes_written == 10);
       
    58   g_assert (strcmp (out, expected) == 0);
       
    59   g_free (out);
       
    60 }
       
    61 
       
    62 /* some tests involving "vulgar fraction one half" */
       
    63 static void 
       
    64 test_one_half (void)
       
    65 {
       
    66   gchar *in = "\xc2\xbd";
       
    67   gchar *out;
       
    68   gsize bytes_read = 0;
       
    69   gsize bytes_written = 0;
       
    70   GError *error = NULL;  
       
    71 
       
    72   out = g_convert (in, -1, 
       
    73 		   "ISO-8859-1", "UTF-8",
       
    74 		   &bytes_read, &bytes_written,
       
    75 		   &error);
       
    76 
       
    77   g_assert_no_error (error);
       
    78   g_assert (bytes_read == 2);
       
    79   g_assert (bytes_written == 1);
       
    80   g_assert (strcmp (out, "\xbd") == 0);
       
    81   g_free (out);
       
    82 
       
    83   out = g_convert (in, -1, 
       
    84 		   "ISO-8859-15", "UTF-8",
       
    85 		   &bytes_read, &bytes_written,
       
    86 		   &error);
       
    87 
       
    88   g_assert_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE);
       
    89   g_assert (bytes_read == 0);
       
    90   g_assert (bytes_written == 0);
       
    91   g_assert (out == NULL);
       
    92   g_clear_error (&error);
       
    93   g_free (out);
       
    94 
       
    95   out = g_convert_with_fallback (in, -1, 
       
    96 				 "ISO-8859-15", "UTF-8",
       
    97 				 "a",
       
    98 				 &bytes_read, &bytes_written,
       
    99 				 &error);
       
   100 
       
   101   g_assert_no_error (error);
       
   102   g_assert (bytes_read == 2);
       
   103   g_assert (bytes_written == 1);
       
   104   g_assert (strcmp (out, "a") == 0);
       
   105   g_free (out);
       
   106 }
       
   107 
       
   108 static void
       
   109 test_byte_order (void)
       
   110 {
       
   111   gchar in_be[2] = { 0x03, 0x93}; /* capital gamma */
       
   112   gchar in_le[2] = { 0x93, 0x03};
       
   113   gchar *expected = "\xce\x93";
       
   114   gchar *out;
       
   115   gsize bytes_read = 0;
       
   116   gsize bytes_written = 0;
       
   117   GError *error = NULL;  
       
   118 
       
   119   out = g_convert (in_be, sizeof (in_be), 
       
   120 		   "UTF-8", "UTF-16BE",
       
   121 		   &bytes_read, &bytes_written,
       
   122 		   &error);
       
   123 
       
   124   g_assert_no_error (error);
       
   125   g_assert (bytes_read == 2);
       
   126   g_assert (bytes_written == 2);
       
   127   g_assert (strcmp (out, expected) == 0);
       
   128   g_free (out);
       
   129 
       
   130   out = g_convert (in_le, sizeof (in_le), 
       
   131 		   "UTF-8", "UTF-16LE",
       
   132 		   &bytes_read, &bytes_written,
       
   133 		   &error);
       
   134 
       
   135   g_assert_no_error (error);
       
   136   g_assert (bytes_read == 2);
       
   137   g_assert (bytes_written == 2);
       
   138   g_assert (strcmp (out, expected) == 0);
       
   139   g_free (out);
       
   140 }
       
   141 
       
   142 static void
       
   143 check_utf8_to_ucs4 (const char     *utf8,
       
   144 		    glong           utf8_len,
       
   145 		    const gunichar *ucs4,
       
   146 		    glong           ucs4_len,
       
   147 		    glong           error_pos)
       
   148 {
       
   149   gunichar *result, *result2, *result3;
       
   150   glong items_read, items_read2;
       
   151   glong items_written, items_written2;
       
   152   GError *error, *error2, *error3;
       
   153   gint i;
       
   154 
       
   155   if (!error_pos)
       
   156     {
       
   157       /* check the fast conversion */
       
   158       result = g_utf8_to_ucs4_fast (utf8, utf8_len, &items_written);
       
   159 
       
   160       g_assert (items_written == ucs4_len);
       
   161       g_assert (result);
       
   162       for (i = 0; i <= items_written; i++)
       
   163 	g_assert (result[i] == ucs4[i]);      
       
   164 
       
   165       g_free (result);
       
   166     }
       
   167 
       
   168   error = NULL;
       
   169   result = g_utf8_to_ucs4 (utf8, utf8_len, &items_read, &items_written, &error);
       
   170   
       
   171   if (utf8_len == strlen (utf8))
       
   172     {
       
   173       /* check that len == -1 yields identical results */
       
   174       error2 = NULL;
       
   175       result2 = g_utf8_to_ucs4 (utf8, -1, &items_read2, &items_written2, &error2);
       
   176       g_assert (error || items_read2 == items_read);
       
   177       g_assert (error || items_written2 == items_written2);
       
   178       g_assert (!!result == !!result2);
       
   179       g_assert (!!error == !!error2);
       
   180       if (result)
       
   181 	for (i = 0; i <= items_written; i++)
       
   182 	  g_assert (result[i] == result2[i]);
       
   183 
       
   184       g_free (result2);
       
   185       if (error2)
       
   186 	g_error_free (error2);
       
   187     }
       
   188 
       
   189   error3 = NULL;
       
   190   result3 = g_utf8_to_ucs4 (utf8, utf8_len, NULL, NULL, &error3);
       
   191       
       
   192   if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
       
   193     {
       
   194       g_assert_no_error (error);
       
   195       g_assert (items_read == error_pos);
       
   196       g_assert (items_written == ucs4_len);
       
   197       g_assert (result);
       
   198       for (i = 0; i <= items_written; i++)
       
   199 	g_assert (result[i] == ucs4[i]);
       
   200     }
       
   201   else if (error_pos)
       
   202     {
       
   203       g_assert (error != NULL);
       
   204       g_assert (result == NULL);
       
   205       g_assert (items_read == error_pos);
       
   206       g_error_free (error);
       
   207 
       
   208       g_assert (error3 != NULL);
       
   209       g_assert (result3 == NULL);
       
   210       g_error_free (error3);
       
   211     }
       
   212   else
       
   213     {
       
   214       g_assert_no_error (error);
       
   215       g_assert (items_read == utf8_len);
       
   216       g_assert (items_written == ucs4_len);
       
   217       g_assert (result);
       
   218       for (i = 0; i <= items_written; i++)
       
   219 	g_assert (result[i] == ucs4[i]);
       
   220 
       
   221       g_assert_no_error (error3);
       
   222       g_assert (result3);
       
   223       for (i = 0; i <= ucs4_len; i++)
       
   224 	g_assert (result3[i] == ucs4[i]);
       
   225     }
       
   226 
       
   227   g_free (result);
       
   228   g_free (result3);
       
   229 }
       
   230 
       
   231 static void
       
   232 check_ucs4_to_utf8 (const gunichar *ucs4,
       
   233 		    glong           ucs4_len,
       
   234 		    const char     *utf8,
       
   235 		    glong           utf8_len,
       
   236 		    glong           error_pos)
       
   237 {
       
   238   gchar *result, *result2, *result3;
       
   239   glong items_read, items_read2;
       
   240   glong items_written, items_written2;
       
   241   GError *error, *error2, *error3;
       
   242 
       
   243   error = NULL;
       
   244   result = g_ucs4_to_utf8 (ucs4, ucs4_len, &items_read, &items_written, &error);
       
   245 
       
   246   if (ucs4[ucs4_len] == 0)
       
   247     {
       
   248       /* check that len == -1 yields identical results */
       
   249       error2 = NULL;
       
   250       result2 = g_ucs4_to_utf8 (ucs4, -1, &items_read2, &items_written2, &error2);
       
   251       
       
   252       g_assert (error || items_read2 == items_read);
       
   253       g_assert (error || items_written2 == items_written);
       
   254       g_assert (!!result == !!result2);
       
   255       g_assert (!!error == !!error2);
       
   256       if (result)
       
   257 	g_assert (strcmp (result, result2) == 0);
       
   258 
       
   259       g_free (result2);
       
   260       if (error2)
       
   261 	g_error_free (error2);
       
   262     }
       
   263 
       
   264   error3 = NULL;
       
   265   result3 = g_ucs4_to_utf8 (ucs4, ucs4_len, NULL, NULL, &error3);
       
   266       
       
   267   if (error_pos)
       
   268     {
       
   269       g_assert (error != NULL);
       
   270       g_assert (result == NULL);
       
   271       g_assert (items_read == error_pos);
       
   272       g_error_free (error);
       
   273 
       
   274       g_assert (error3 != NULL);
       
   275       g_assert (result3 == NULL);
       
   276       g_error_free (error3);
       
   277     }
       
   278   else
       
   279     {
       
   280       g_assert_no_error (error);
       
   281       g_assert (items_read == ucs4_len);
       
   282       g_assert (items_written == utf8_len);
       
   283       g_assert (result);
       
   284       g_assert (strcmp (result, utf8) == 0);
       
   285 
       
   286       g_assert_no_error (error3);
       
   287       g_assert (result3);
       
   288       g_assert (strcmp (result3, utf8) == 0);
       
   289     }
       
   290 
       
   291   g_free (result);
       
   292   g_free (result3);
       
   293 }
       
   294 
       
   295 static void
       
   296 check_utf8_to_utf16 (const char      *utf8,
       
   297 		     glong            utf8_len,
       
   298 		     const gunichar2 *utf16,
       
   299 		     glong            utf16_len,
       
   300 		     glong            error_pos)
       
   301 {
       
   302   gunichar2 *result, *result2, *result3;
       
   303   glong items_read, items_read2;
       
   304   glong items_written, items_written2;
       
   305   GError *error, *error2, *error3;
       
   306   gint i;
       
   307 
       
   308   error = NULL;
       
   309   result = g_utf8_to_utf16 (utf8, utf8_len, &items_read, &items_written, &error);
       
   310 
       
   311   if (utf8_len == strlen (utf8))
       
   312     {
       
   313       /* check that len == -1 yields identical results */
       
   314       error2 = NULL;
       
   315       result2 = g_utf8_to_utf16 (utf8, -1, &items_read2, &items_written2, &error2);
       
   316       g_assert (error || items_read2 == items_read);
       
   317       g_assert (error || items_written2 == items_written2);
       
   318       g_assert (!!result == !!result2);
       
   319       g_assert (!!error == !!error2);
       
   320       if (result)
       
   321 	for (i = 0; i <= items_written; i++)
       
   322 	  g_assert (result[i] == result2[i]);
       
   323       
       
   324       g_free (result2);
       
   325       if (error2)
       
   326 	g_error_free (error2);
       
   327     }
       
   328 
       
   329   error3 = NULL;
       
   330   result3 = g_utf8_to_utf16 (utf8, utf8_len, NULL, NULL, &error3);
       
   331       
       
   332   if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
       
   333     {
       
   334       g_assert_no_error (error);
       
   335       g_assert (items_read == error_pos);
       
   336       g_assert (items_written == utf16_len);
       
   337       g_assert (result);
       
   338       for (i = 0; i <= items_written; i++)
       
   339 	g_assert (result[i] == utf16[i]);
       
   340     }
       
   341   else if (error_pos)
       
   342     {
       
   343       g_assert (error != NULL);
       
   344       g_assert (result == NULL);
       
   345       g_assert (items_read == error_pos);
       
   346       g_error_free (error);
       
   347 
       
   348       g_assert (error3 != NULL);
       
   349       g_assert (result3 == NULL);
       
   350       g_error_free (error3);
       
   351     }
       
   352   else
       
   353     {
       
   354       g_assert_no_error (error);
       
   355       g_assert (items_read == utf8_len);
       
   356       g_assert (items_written == utf16_len);
       
   357       g_assert (result);
       
   358       for (i = 0; i <= items_written; i++)
       
   359 	g_assert (result[i] == utf16[i]);
       
   360 
       
   361       g_assert_no_error (error3);
       
   362       g_assert (result3);
       
   363       for (i = 0; i <= utf16_len; i++)
       
   364 	g_assert (result3[i] == utf16[i]);
       
   365     }
       
   366 
       
   367   g_free (result);
       
   368   g_free (result3);
       
   369 }
       
   370 
       
   371 static void
       
   372 check_utf16_to_utf8 (const gunichar2 *utf16,
       
   373 		     glong            utf16_len,
       
   374 		     const char      *utf8,
       
   375 		     glong            utf8_len,
       
   376 		     glong            error_pos)
       
   377 {
       
   378   gchar *result, *result2, *result3;
       
   379   glong items_read, items_read2;
       
   380   glong items_written, items_written2;
       
   381   GError *error, *error2, *error3;
       
   382 
       
   383   error = NULL;
       
   384   result = g_utf16_to_utf8 (utf16, utf16_len, &items_read, &items_written, &error);
       
   385   if (utf16[utf16_len] == 0)
       
   386     {
       
   387       /* check that len == -1 yields identical results */
       
   388       error2 = NULL;
       
   389       result2 = g_utf16_to_utf8 (utf16, -1, &items_read2, &items_written2, &error2);
       
   390       
       
   391       g_assert (error || items_read2 == items_read);
       
   392       g_assert (error || items_written2 == items_written);
       
   393       g_assert (!!result == !!result2);
       
   394       g_assert (!!error == !!error2);
       
   395       if (result)
       
   396 	g_assert (strcmp (result, result2) == 0);
       
   397 
       
   398       g_free (result2);
       
   399       if (error2)
       
   400 	g_error_free (error2);
       
   401     }
       
   402 
       
   403   error3 = NULL;
       
   404   result3 = g_utf16_to_utf8 (utf16, utf16_len, NULL, NULL, &error3);
       
   405   
       
   406   if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
       
   407     {
       
   408       g_assert_no_error (error);
       
   409       g_assert (items_read == error_pos);
       
   410       g_assert (items_read + 1 == utf16_len);
       
   411       g_assert (items_written == utf8_len);
       
   412       g_assert (result);
       
   413       g_assert (strcmp (result, utf8) == 0);
       
   414     }
       
   415   else if (error_pos)
       
   416     {
       
   417       g_assert (error != NULL);
       
   418       g_assert (result == NULL);
       
   419       g_assert (items_read == error_pos);
       
   420       g_error_free (error);
       
   421 
       
   422       g_assert (error3 != NULL);
       
   423       g_assert (result3 == NULL);
       
   424       g_error_free (error3);
       
   425     }
       
   426   else
       
   427     {
       
   428       g_assert_no_error (error);
       
   429       g_assert (items_read == utf16_len);
       
   430       g_assert (items_written == utf8_len);
       
   431       g_assert (result);
       
   432       g_assert (strcmp (result, utf8) == 0);
       
   433 
       
   434       g_assert_no_error (error3);
       
   435       g_assert (result3);
       
   436       g_assert (strcmp (result3, utf8) == 0);
       
   437     }
       
   438 
       
   439   g_free (result);
       
   440   g_free (result3);
       
   441 }
       
   442 
       
   443 static void
       
   444 check_ucs4_to_utf16 (const gunichar  *ucs4,
       
   445 		     glong            ucs4_len,
       
   446 		     const gunichar2 *utf16,
       
   447 		     glong            utf16_len,
       
   448 		     glong            error_pos)
       
   449 {
       
   450   gunichar2 *result, *result2, *result3;
       
   451   glong items_read, items_read2;
       
   452   glong items_written, items_written2;
       
   453   GError *error, *error2, *error3;
       
   454   gint i;
       
   455 
       
   456   error = NULL;
       
   457   result = g_ucs4_to_utf16 (ucs4, ucs4_len, &items_read, &items_written, &error);
       
   458 
       
   459   if (ucs4[ucs4_len] == 0)
       
   460     {
       
   461       /* check that len == -1 yields identical results */
       
   462       error2 = NULL;
       
   463       result2 = g_ucs4_to_utf16 (ucs4, -1, &items_read2, &items_written2, &error2);
       
   464       
       
   465       g_assert (error || items_read2 == items_read);
       
   466       g_assert (error || items_written2 == items_written);
       
   467       g_assert (!!result == !!result2);
       
   468       g_assert (!!error == !!error2);
       
   469       if (result)
       
   470       for (i = 0; i <= utf16_len; i++)
       
   471 	g_assert (result[i] == result2[i]);
       
   472 
       
   473       g_free (result2);
       
   474       if (error2)
       
   475 	g_error_free (error2);
       
   476     }
       
   477 
       
   478   error3 = NULL;
       
   479   result3 = g_ucs4_to_utf16 (ucs4, -1, NULL, NULL, &error3);
       
   480       
       
   481   if (error_pos)
       
   482     {
       
   483       g_assert (error != NULL);
       
   484       g_assert (result == NULL);
       
   485       g_assert (items_read == error_pos);
       
   486       g_error_free (error);
       
   487 
       
   488       g_assert (error3 != NULL);
       
   489       g_assert (result3 == NULL);
       
   490       g_error_free (error3);
       
   491     }
       
   492   else
       
   493     {
       
   494       g_assert_no_error (error);
       
   495       g_assert (items_read == ucs4_len);
       
   496       g_assert (items_written == utf16_len);
       
   497       g_assert (result);
       
   498       for (i = 0; i <= utf16_len; i++)
       
   499 	g_assert (result[i] == utf16[i]);
       
   500 
       
   501       g_assert_no_error (error3);
       
   502       g_assert (result3);
       
   503       for (i = 0; i <= utf16_len; i++)
       
   504 	g_assert (result3[i] == utf16[i]);
       
   505     }
       
   506 
       
   507   g_free (result);
       
   508   g_free (result3);
       
   509 }
       
   510 
       
   511 static void
       
   512 check_utf16_to_ucs4 (const gunichar2 *utf16,
       
   513 		     glong            utf16_len,
       
   514 		     const gunichar  *ucs4,
       
   515 		     glong            ucs4_len,
       
   516 		     glong            error_pos)
       
   517 {
       
   518   gunichar *result, *result2, *result3;
       
   519   glong items_read, items_read2;
       
   520   glong items_written, items_written2;
       
   521   GError *error, *error2, *error3;
       
   522   gint i;
       
   523 
       
   524   error = NULL;
       
   525   result = g_utf16_to_ucs4 (utf16, utf16_len, &items_read, &items_written, &error);
       
   526   if (utf16[utf16_len] == 0)
       
   527     {
       
   528       /* check that len == -1 yields identical results */
       
   529       error2 = NULL;
       
   530       result2 = g_utf16_to_ucs4 (utf16, -1, &items_read2, &items_written2, &error2);
       
   531       g_assert (error || items_read2 == items_read);
       
   532       g_assert (error || items_written2 == items_written2);
       
   533       g_assert (!!result == !!result2);
       
   534       g_assert (!!error == !!error2);
       
   535       if (result)
       
   536 	for (i = 0; i <= items_written; i++)
       
   537 	  g_assert (result[i] == result2[i]);
       
   538 
       
   539       g_free (result2);
       
   540       if (error2)
       
   541 	g_error_free (error2);
       
   542     }
       
   543 
       
   544   error3 = NULL;
       
   545   result3 = g_utf16_to_ucs4 (utf16, utf16_len, NULL, NULL, &error3);
       
   546       
       
   547   if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
       
   548     {
       
   549       g_assert_no_error (error);
       
   550       g_assert (items_read == error_pos);
       
   551       g_assert (items_read + 1 == utf16_len);
       
   552       g_assert (items_written == ucs4_len);
       
   553       g_assert (result);
       
   554       for (i = 0; i <= items_written; i++)
       
   555 	g_assert (result[i] == ucs4[i]);
       
   556     }
       
   557   else if (error_pos)
       
   558     {
       
   559       g_assert (error != NULL);
       
   560       g_assert (result == NULL);
       
   561       g_assert (items_read == error_pos);
       
   562       g_error_free (error);
       
   563 
       
   564       g_assert (error3 != NULL);
       
   565       g_assert (result3 == NULL);
       
   566       g_error_free (error3);
       
   567     }
       
   568   else
       
   569     {
       
   570       g_assert_no_error (error);
       
   571       g_assert (items_read == utf16_len);
       
   572       g_assert (items_written == ucs4_len);
       
   573       g_assert (result);
       
   574       for (i = 0; i <= ucs4_len; i++)
       
   575 	g_assert (result[i] == ucs4[i]);
       
   576 
       
   577       g_assert_no_error (error3);
       
   578       g_assert (result3);
       
   579       for (i = 0; i <= ucs4_len; i++)
       
   580 	g_assert (result3[i] == ucs4[i]);
       
   581     }
       
   582 
       
   583   g_free (result);
       
   584   g_free (result3);
       
   585 }
       
   586 
       
   587 static void
       
   588 test_unicode_conversions (void)
       
   589 {
       
   590   char *utf8;
       
   591   gunichar ucs4[100];
       
   592   gunichar2 utf16[100];
       
   593 
       
   594   utf8 = "abc";
       
   595   ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0x63; ucs4[3] = 0;
       
   596   utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0x63; utf16[3] = 0;
       
   597 
       
   598   check_utf8_to_ucs4 (utf8, 3, ucs4, 3, 0);
       
   599   check_ucs4_to_utf8 (ucs4, 3, utf8, 3, 0);
       
   600   check_utf8_to_utf16 (utf8, 3, utf16, 3, 0);
       
   601   check_utf16_to_utf8 (utf16, 3, utf8, 3, 0);
       
   602   check_ucs4_to_utf16 (ucs4, 3, utf16, 3, 0);
       
   603   check_utf16_to_ucs4 (utf16, 3, ucs4, 3, 0);
       
   604 
       
   605   utf8 = "\316\261\316\262\316\263";
       
   606   ucs4[0] = 0x03b1; ucs4[1] = 0x03b2; ucs4[2] = 0x03b3; ucs4[3] = 0;
       
   607   utf16[0] = 0x03b1; utf16[1] = 0x03b2; utf16[2] = 0x03b3; utf16[3] = 0;
       
   608 
       
   609   check_utf8_to_ucs4 (utf8, 6, ucs4, 3, 0);
       
   610   check_ucs4_to_utf8 (ucs4, 3, utf8, 6, 0);
       
   611   check_utf8_to_utf16 (utf8, 6, utf16, 3, 0);
       
   612   check_utf16_to_utf8 (utf16, 3, utf8, 6, 0);
       
   613   check_ucs4_to_utf16 (ucs4, 3, utf16, 3, 0);
       
   614   check_utf16_to_ucs4 (utf16, 3, ucs4, 3, 0);
       
   615 
       
   616   /* partial utf8 character */
       
   617   utf8 = "abc\316";
       
   618   ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0x63; ucs4[3] = 0;
       
   619   utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0x63; utf16[3] = 0;
       
   620 
       
   621   check_utf8_to_ucs4 (utf8, 4, ucs4, 3, 3);
       
   622   check_utf8_to_utf16 (utf8, 4, utf16, 3, 3);
       
   623 
       
   624   /* invalid utf8 */
       
   625   utf8 = "abc\316\316";
       
   626   ucs4[0] = 0; 
       
   627   utf16[0] = 0; 
       
   628 
       
   629   check_utf8_to_ucs4 (utf8, 5, ucs4, 0, 3);
       
   630   check_utf8_to_utf16 (utf8, 5, utf16, 0, 3);
       
   631 
       
   632   /* partial utf16 character */
       
   633   utf8 = "ab";
       
   634   ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0;
       
   635   utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0xd801; utf16[3] = 0;
       
   636   
       
   637   check_utf16_to_utf8 (utf16, 3, utf8, 2, 2);
       
   638   check_utf16_to_ucs4 (utf16, 3, ucs4, 2, 2);
       
   639 
       
   640   /* invalid utf16 */
       
   641   utf8 = NULL;
       
   642   ucs4[0] = 0;
       
   643   utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0xdc01; utf16[3] = 0;
       
   644 
       
   645   check_utf16_to_utf8 (utf16, 3, utf8, 0, 2);
       
   646   check_utf16_to_ucs4 (utf16, 3, ucs4, 0, 2);
       
   647 
       
   648   /* invalid ucs4 */
       
   649   utf8 = NULL;
       
   650   ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0x80000000; ucs4[3] = 0;
       
   651   utf16[0] = 0;
       
   652 
       
   653   check_ucs4_to_utf8 (ucs4, 3, utf8, 0, 2);
       
   654   check_ucs4_to_utf16 (ucs4, 3, utf16, 0, 2);
       
   655 }
       
   656 
       
   657 int
       
   658 main (int argc, char *argv[])
       
   659 {
       
   660   #ifdef __SYMBIAN32__
       
   661   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);
       
   662   g_set_print_handler(mrtPrintHandler);
       
   663   #endif /*__SYMBIAN32__*/
       
   664 	  
       
   665   test_iconv_state ();
       
   666   test_one_half ();
       
   667   test_byte_order ();
       
   668   test_unicode_conversions ();
       
   669   
       
   670   #if __SYMBIAN32__
       
   671   testResultXml("convert-test");
       
   672   #endif /* EMULATOR */
       
   673 
       
   674   return 0;
       
   675 }