os/ossrv/glib/tsrc/BC/tests/convert-test.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/glib/tsrc/BC/tests/convert-test.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,712 @@
     1.4 +/* GLIB - Library of useful routines for C programming
     1.5 + * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
     1.6 + * Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     1.7 + * This library is free software; you can redistribute it and/or
     1.8 + * modify it under the terms of the GNU Lesser General Public
     1.9 + * License as published by the Free Software Foundation; either
    1.10 + * version 2 of the License, or (at your option) any later version.
    1.11 + *
    1.12 + * This library is distributed in the hope that it will be useful,
    1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.15 + * Lesser General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU Lesser General Public
    1.18 + * License along with this library; if not, write to the
    1.19 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    1.20 + * Boston, MA 02111-1307, USA.
    1.21 + */
    1.22 +
    1.23 +/*
    1.24 + * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
    1.25 + * file for a list of people on the GLib Team.  See the ChangeLog
    1.26 + * files for a list of changes.  These files are distributed with
    1.27 + * GLib at ftp://ftp.gtk.org/pub/gtk/. 
    1.28 + */
    1.29 +
    1.30 +#undef G_DISABLE_ASSERT
    1.31 +#undef G_LOG_DOMAIN
    1.32 +
    1.33 +#include <string.h>
    1.34 +#include <stdio.h>
    1.35 +
    1.36 +#include <glib.h>
    1.37 +#ifdef SYMBIAN
    1.38 +#include "mrt2_glib2_test.h"
    1.39 +#endif /*SYMBIAN*/
    1.40 +
    1.41 +#ifdef SYMBIAN
    1.42 +static void
    1.43 +test_conversion (void)
    1.44 +{
    1.45 +  gchar *in =  "\xa5\xa6\xa7\xa8";
    1.46 +  gchar *expected = "\xc2\xa5\xc2\xa6\xc2\xa7\xc2\xa8";
    1.47 +  gchar *out;
    1.48 +  gsize bytes_read = 0;
    1.49 +  gsize bytes_written = 0;
    1.50 +  GError *error = NULL;
    1.51 +
    1.52 +  out = g_convert (in, -1, "UTF-8", "ISO-8859-1", 
    1.53 +		   &bytes_read, &bytes_written, &error);
    1.54 +  
    1.55 +  g_assert (error == NULL);
    1.56 +  g_assert (bytes_read == 4);
    1.57 +  g_assert (bytes_written == 8);
    1.58 +  g_assert (strcmp (out, expected) == 0);
    1.59 +
    1.60 +  g_free (out);
    1.61 +
    1.62 +}
    1.63 +
    1.64 +#endif /*SYMBIAN*/
    1.65 +
    1.66 +/* Bug 311337 */
    1.67 +static void
    1.68 +test_iconv_state (void)
    1.69 +{
    1.70 +  gchar *in = "\xf4\xe5\xf8\xe5\xed";
    1.71 +  gchar *expected = "\xd7\xa4\xd7\x95\xd7\xa8\xd7\x95\xd7\x9d";
    1.72 +  gchar *out;
    1.73 +  gsize bytes_read = 0;
    1.74 +  gsize bytes_written = 0;
    1.75 +  GError *error = NULL;
    1.76 +
    1.77 +  out = g_convert (in, -1, "UTF-8", "windows-1255", 
    1.78 +		   &bytes_read, &bytes_written, &error);
    1.79 +  
    1.80 +  g_assert (error == NULL);
    1.81 +  g_assert (bytes_read == 5);
    1.82 +  g_assert (bytes_written == 10);
    1.83 +  g_assert (strcmp (out, expected) == 0);
    1.84 +  g_free (out);
    1.85 +}
    1.86 +
    1.87 +/* some tests involving "vulgar fraction one half" */
    1.88 +static void 
    1.89 +test_one_half (void)
    1.90 +{
    1.91 +  gchar *in = "\xc2\xbd";
    1.92 +  gchar *out;
    1.93 +  gsize bytes_read = 0;
    1.94 +  gsize bytes_written = 0;
    1.95 +  GError *error = NULL;  
    1.96 +
    1.97 +  out = g_convert (in, -1, 
    1.98 +		   "ISO-8859-1", "UTF-8",
    1.99 +		   &bytes_read, &bytes_written,
   1.100 +		   &error);
   1.101 +
   1.102 +  g_assert (error == NULL);
   1.103 +  g_assert (bytes_read == 2);
   1.104 +  g_assert (bytes_written == 1);
   1.105 +  g_assert (strcmp (out, "\xbd") == 0);
   1.106 +  g_free (out);
   1.107 +
   1.108 +  out = g_convert (in, -1, 
   1.109 +		   "ISO-8859-15", "UTF-8",
   1.110 +		   &bytes_read, &bytes_written,
   1.111 +		   &error);
   1.112 +
   1.113 +  g_assert (error && error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE);
   1.114 +  g_assert (bytes_read == 0);
   1.115 +  g_assert (bytes_written == 0);
   1.116 +  g_assert (out == NULL);
   1.117 +  g_clear_error (&error);
   1.118 +  g_free (out);
   1.119 +
   1.120 +  out = g_convert_with_fallback (in, -1, 
   1.121 +				 "ISO-8859-15", "UTF-8",
   1.122 +				 "a",
   1.123 +				 &bytes_read, &bytes_written,
   1.124 +				 &error);
   1.125 +
   1.126 +  g_assert (error == NULL);
   1.127 +  g_assert (bytes_read == 2);
   1.128 +  g_assert (bytes_written == 1);
   1.129 +  g_assert (strcmp (out, "a") == 0);
   1.130 +  g_free (out);
   1.131 +}
   1.132 +
   1.133 +static void
   1.134 +test_byte_order (void)
   1.135 +{
   1.136 +  gchar in_be[2] = { 0x03, 0x93}; /* capital gamma */
   1.137 +  gchar in_le[2] = { 0x93, 0x03};
   1.138 +  gchar *expected = "\xce\x93";
   1.139 +  gchar *out;
   1.140 +  gsize bytes_read = 0;
   1.141 +  gsize bytes_written = 0;
   1.142 +  GError *error = NULL;  
   1.143 +
   1.144 +  out = g_convert (in_be, sizeof (in_be), 
   1.145 +		   "UTF-8", "UTF-16BE",
   1.146 +		   &bytes_read, &bytes_written,
   1.147 +		   &error);
   1.148 +
   1.149 +  g_assert (error == NULL);
   1.150 +  g_assert (bytes_read == 2);
   1.151 +  g_assert (bytes_written == 2);
   1.152 +  g_assert (strcmp (out, expected) == 0);
   1.153 +  g_free (out);
   1.154 +
   1.155 +  out = g_convert (in_le, sizeof (in_le), 
   1.156 +		   "UTF-8", "UTF-16LE",
   1.157 +		   &bytes_read, &bytes_written,
   1.158 +		   &error);
   1.159 +
   1.160 +  g_assert (error == NULL);
   1.161 +  g_assert (bytes_read == 2);
   1.162 +  g_assert (bytes_written == 2);
   1.163 +  g_assert (strcmp (out, expected) == 0);
   1.164 +  g_free (out);
   1.165 +}
   1.166 +
   1.167 +static void
   1.168 +check_utf8_to_ucs4 (const char     *utf8,
   1.169 +		    glong           utf8_len,
   1.170 +		    const gunichar *ucs4,
   1.171 +		    glong           ucs4_len,
   1.172 +		    glong           error_pos)
   1.173 +{
   1.174 +  gunichar *result, *result2, *result3;
   1.175 +  glong items_read, items_read2;
   1.176 +  glong items_written, items_written2;
   1.177 +  GError *error, *error2, *error3;
   1.178 +  gint i;
   1.179 +
   1.180 +  if (!error_pos)
   1.181 +    {
   1.182 +      /* check the fast conversion */
   1.183 +      result = g_utf8_to_ucs4_fast (utf8, utf8_len, &items_written);
   1.184 +
   1.185 +      g_assert (items_written == ucs4_len);
   1.186 +      g_assert (result);
   1.187 +      for (i = 0; i <= items_written; i++)
   1.188 +	g_assert (result[i] == ucs4[i]);      
   1.189 +
   1.190 +      g_free (result);
   1.191 +    }
   1.192 +
   1.193 +  error = NULL;
   1.194 +  result = g_utf8_to_ucs4 (utf8, utf8_len, &items_read, &items_written, &error);
   1.195 +  
   1.196 +  if (utf8_len == strlen (utf8))
   1.197 +    {
   1.198 +      /* check that len == -1 yields identical results */
   1.199 +      error2 = NULL;
   1.200 +      result2 = g_utf8_to_ucs4 (utf8, -1, &items_read2, &items_written2, &error2);
   1.201 +      g_assert (error || items_read2 == items_read);
   1.202 +      g_assert (error || items_written2 == items_written2);
   1.203 +      g_assert (!!result == !!result2);
   1.204 +      g_assert (!!error == !!error2);
   1.205 +      if (result)
   1.206 +	for (i = 0; i <= items_written; i++)
   1.207 +	  g_assert (result[i] == result2[i]);
   1.208 +
   1.209 +      g_free (result2);
   1.210 +      if (error2)
   1.211 +	g_error_free (error2);
   1.212 +    }
   1.213 +
   1.214 +  error3 = NULL;
   1.215 +  result3 = g_utf8_to_ucs4 (utf8, utf8_len, NULL, NULL, &error3);
   1.216 +      
   1.217 +  if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
   1.218 +    {
   1.219 +      g_assert (error == NULL);
   1.220 +      g_assert (items_read == error_pos);
   1.221 +      g_assert (items_written == ucs4_len);
   1.222 +      g_assert (result);
   1.223 +      for (i = 0; i <= items_written; i++)
   1.224 +	g_assert (result[i] == ucs4[i]);
   1.225 +    }
   1.226 +  else if (error_pos)
   1.227 +    {
   1.228 +      g_assert (error != NULL);
   1.229 +      g_assert (result == NULL);
   1.230 +      g_assert (items_read == error_pos);
   1.231 +      g_error_free (error);
   1.232 +
   1.233 +      g_assert (error3 != NULL);
   1.234 +      g_assert (result3 == NULL);
   1.235 +      g_error_free (error3);
   1.236 +    }
   1.237 +  else
   1.238 +    {
   1.239 +      g_assert (error == NULL);
   1.240 +      g_assert (items_read == utf8_len);
   1.241 +      g_assert (items_written == ucs4_len);
   1.242 +      g_assert (result);
   1.243 +      for (i = 0; i <= items_written; i++)
   1.244 +	g_assert (result[i] == ucs4[i]);
   1.245 +
   1.246 +      g_assert (error3 == NULL);
   1.247 +      g_assert (result3);
   1.248 +      for (i = 0; i <= ucs4_len; i++)
   1.249 +	g_assert (result3[i] == ucs4[i]);
   1.250 +    }
   1.251 +
   1.252 +  g_free (result);
   1.253 +  g_free (result3);
   1.254 +}
   1.255 +
   1.256 +static void
   1.257 +check_ucs4_to_utf8 (const gunichar *ucs4,
   1.258 +		    glong           ucs4_len,
   1.259 +		    const char     *utf8,
   1.260 +		    glong           utf8_len,
   1.261 +		    glong           error_pos)
   1.262 +{
   1.263 +  gchar *result, *result2, *result3;
   1.264 +  glong items_read, items_read2;
   1.265 +  glong items_written, items_written2;
   1.266 +  GError *error, *error2, *error3;
   1.267 +
   1.268 +  error = NULL;
   1.269 +  result = g_ucs4_to_utf8 (ucs4, ucs4_len, &items_read, &items_written, &error);
   1.270 +
   1.271 +  if (ucs4[ucs4_len] == 0)
   1.272 +    {
   1.273 +      /* check that len == -1 yields identical results */
   1.274 +      error2 = NULL;
   1.275 +      result2 = g_ucs4_to_utf8 (ucs4, -1, &items_read2, &items_written2, &error2);
   1.276 +      
   1.277 +      g_assert (error || items_read2 == items_read);
   1.278 +      g_assert (error || items_written2 == items_written);
   1.279 +      g_assert (!!result == !!result2);
   1.280 +      g_assert (!!error == !!error2);
   1.281 +      if (result)
   1.282 +	g_assert (strcmp (result, result2) == 0);
   1.283 +
   1.284 +      g_free (result2);
   1.285 +      if (error2)
   1.286 +	g_error_free (error2);
   1.287 +    }
   1.288 +
   1.289 +  error3 = NULL;
   1.290 +  result3 = g_ucs4_to_utf8 (ucs4, ucs4_len, NULL, NULL, &error3);
   1.291 +      
   1.292 +  if (error_pos)
   1.293 +    {
   1.294 +      g_assert (error != NULL);
   1.295 +      g_assert (result == NULL);
   1.296 +      g_assert (items_read == error_pos);
   1.297 +      g_error_free (error);
   1.298 +
   1.299 +      g_assert (error3 != NULL);
   1.300 +      g_assert (result3 == NULL);
   1.301 +      g_error_free (error3);
   1.302 +    }
   1.303 +  else
   1.304 +    {
   1.305 +      g_assert (error == NULL);
   1.306 +      g_assert (items_read == ucs4_len);
   1.307 +      g_assert (items_written == utf8_len);
   1.308 +      g_assert (result);
   1.309 +      g_assert (strcmp (result, utf8) == 0);
   1.310 +
   1.311 +      g_assert (error3 == NULL);
   1.312 +      g_assert (result3);
   1.313 +      g_assert (strcmp (result3, utf8) == 0);
   1.314 +    }
   1.315 +
   1.316 +  g_free (result);
   1.317 +  g_free (result3);
   1.318 +}
   1.319 +
   1.320 +static void
   1.321 +check_utf8_to_utf16 (const char      *utf8,
   1.322 +		     glong            utf8_len,
   1.323 +		     const gunichar2 *utf16,
   1.324 +		     glong            utf16_len,
   1.325 +		     glong            error_pos)
   1.326 +{
   1.327 +  gunichar2 *result, *result2, *result3;
   1.328 +  glong items_read, items_read2;
   1.329 +  glong items_written, items_written2;
   1.330 +  GError *error, *error2, *error3;
   1.331 +  gint i;
   1.332 +
   1.333 +  error = NULL;
   1.334 +  result = g_utf8_to_utf16 (utf8, utf8_len, &items_read, &items_written, &error);
   1.335 +
   1.336 +  if (utf8_len == strlen (utf8))
   1.337 +    {
   1.338 +      /* check that len == -1 yields identical results */
   1.339 +      error2 = NULL;
   1.340 +      result2 = g_utf8_to_utf16 (utf8, -1, &items_read2, &items_written2, &error2);
   1.341 +      g_assert (error || items_read2 == items_read);
   1.342 +      g_assert (error || items_written2 == items_written2);
   1.343 +      g_assert (!!result == !!result2);
   1.344 +      g_assert (!!error == !!error2);
   1.345 +      if (result)
   1.346 +	for (i = 0; i <= items_written; i++)
   1.347 +	  g_assert (result[i] == result2[i]);
   1.348 +      
   1.349 +      g_free (result2);
   1.350 +      if (error2)
   1.351 +	g_error_free (error2);
   1.352 +    }
   1.353 +
   1.354 +  error3 = NULL;
   1.355 +  result3 = g_utf8_to_utf16 (utf8, utf8_len, NULL, NULL, &error3);
   1.356 +      
   1.357 +  if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
   1.358 +    {
   1.359 +      g_assert (error == NULL);
   1.360 +      g_assert (items_read == error_pos);
   1.361 +      g_assert (items_written == utf16_len);
   1.362 +      g_assert (result);
   1.363 +      for (i = 0; i <= items_written; i++)
   1.364 +	g_assert (result[i] == utf16[i]);
   1.365 +    }
   1.366 +  else if (error_pos)
   1.367 +    {
   1.368 +      g_assert (error != NULL);
   1.369 +      g_assert (result == NULL);
   1.370 +      g_assert (items_read == error_pos);
   1.371 +      g_error_free (error);
   1.372 +
   1.373 +      g_assert (error3 != NULL);
   1.374 +      g_assert (result3 == NULL);
   1.375 +      g_error_free (error3);
   1.376 +    }
   1.377 +  else
   1.378 +    {
   1.379 +      g_assert (error == NULL);
   1.380 +      g_assert (items_read == utf8_len);
   1.381 +      g_assert (items_written == utf16_len);
   1.382 +      g_assert (result);
   1.383 +      for (i = 0; i <= items_written; i++)
   1.384 +	g_assert (result[i] == utf16[i]);
   1.385 +
   1.386 +      g_assert (error3 == NULL);
   1.387 +      g_assert (result3);
   1.388 +      for (i = 0; i <= utf16_len; i++)
   1.389 +	g_assert (result3[i] == utf16[i]);
   1.390 +    }
   1.391 +
   1.392 +  g_free (result);
   1.393 +  g_free (result3);
   1.394 +}
   1.395 +
   1.396 +static void
   1.397 +check_utf16_to_utf8 (const gunichar2 *utf16,
   1.398 +		     glong            utf16_len,
   1.399 +		     const char      *utf8,
   1.400 +		     glong            utf8_len,
   1.401 +		     glong            error_pos)
   1.402 +{
   1.403 +  gchar *result, *result2, *result3;
   1.404 +  glong items_read, items_read2;
   1.405 +  glong items_written, items_written2;
   1.406 +  GError *error, *error2, *error3;
   1.407 +
   1.408 +  error = NULL;
   1.409 +  result = g_utf16_to_utf8 (utf16, utf16_len, &items_read, &items_written, &error);
   1.410 +  if (utf16[utf16_len] == 0)
   1.411 +    {
   1.412 +      /* check that len == -1 yields identical results */
   1.413 +      error2 = NULL;
   1.414 +      result2 = g_utf16_to_utf8 (utf16, -1, &items_read2, &items_written2, &error2);
   1.415 +      
   1.416 +      g_assert (error || items_read2 == items_read);
   1.417 +      g_assert (error || items_written2 == items_written);
   1.418 +      g_assert (!!result == !!result2);
   1.419 +      g_assert (!!error == !!error2);
   1.420 +      if (result)
   1.421 +	g_assert (strcmp (result, result2) == 0);
   1.422 +
   1.423 +      g_free (result2);
   1.424 +      if (error2)
   1.425 +	g_error_free (error2);
   1.426 +    }
   1.427 +
   1.428 +  error3 = NULL;
   1.429 +  result3 = g_utf16_to_utf8 (utf16, utf16_len, NULL, NULL, &error3);
   1.430 +  
   1.431 +  if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
   1.432 +    {
   1.433 +      g_assert (error == NULL);
   1.434 +      g_assert (items_read == error_pos);
   1.435 +      g_assert (items_read + 1 == utf16_len);
   1.436 +      g_assert (items_written == utf8_len);
   1.437 +      g_assert (result);
   1.438 +      g_assert (strcmp (result, utf8) == 0);
   1.439 +    }
   1.440 +  else if (error_pos)
   1.441 +    {
   1.442 +      g_assert (error != NULL);
   1.443 +      g_assert (result == NULL);
   1.444 +      g_assert (items_read == error_pos);
   1.445 +      g_error_free (error);
   1.446 +
   1.447 +      g_assert (error3 != NULL);
   1.448 +      g_assert (result3 == NULL);
   1.449 +      g_error_free (error3);
   1.450 +    }
   1.451 +  else
   1.452 +    {
   1.453 +      g_assert (error == NULL);
   1.454 +      g_assert (items_read == utf16_len);
   1.455 +      g_assert (items_written == utf8_len);
   1.456 +      g_assert (result);
   1.457 +      g_assert (strcmp (result, utf8) == 0);
   1.458 +
   1.459 +      g_assert (error3 == NULL);
   1.460 +      g_assert (result3);
   1.461 +      g_assert (strcmp (result3, utf8) == 0);
   1.462 +    }
   1.463 +
   1.464 +  g_free (result);
   1.465 +  g_free (result3);
   1.466 +}
   1.467 +
   1.468 +static void
   1.469 +check_ucs4_to_utf16 (const gunichar  *ucs4,
   1.470 +		     glong            ucs4_len,
   1.471 +		     const gunichar2 *utf16,
   1.472 +		     glong            utf16_len,
   1.473 +		     glong            error_pos)
   1.474 +{
   1.475 +  gunichar2 *result, *result2, *result3;
   1.476 +  glong items_read, items_read2;
   1.477 +  glong items_written, items_written2;
   1.478 +  GError *error, *error2, *error3;
   1.479 +  gint i;
   1.480 +
   1.481 +  error = NULL;
   1.482 +  result = g_ucs4_to_utf16 (ucs4, ucs4_len, &items_read, &items_written, &error);
   1.483 +
   1.484 +  if (ucs4[ucs4_len] == 0)
   1.485 +    {
   1.486 +      /* check that len == -1 yields identical results */
   1.487 +      error2 = NULL;
   1.488 +      result2 = g_ucs4_to_utf16 (ucs4, -1, &items_read2, &items_written2, &error2);
   1.489 +      
   1.490 +      g_assert (error || items_read2 == items_read);
   1.491 +      g_assert (error || items_written2 == items_written);
   1.492 +      g_assert (!!result == !!result2);
   1.493 +      g_assert (!!error == !!error2);
   1.494 +      if (result)
   1.495 +      for (i = 0; i <= utf16_len; i++)
   1.496 +	g_assert (result[i] == result2[i]);
   1.497 +
   1.498 +      g_free (result2);
   1.499 +      if (error2)
   1.500 +	g_error_free (error2);
   1.501 +    }
   1.502 +
   1.503 +  error3 = NULL;
   1.504 +  result3 = g_ucs4_to_utf16 (ucs4, -1, NULL, NULL, &error3);
   1.505 +      
   1.506 +  if (error_pos)
   1.507 +    {
   1.508 +      g_assert (error != NULL);
   1.509 +      g_assert (result == NULL);
   1.510 +      g_assert (items_read == error_pos);
   1.511 +      g_error_free (error);
   1.512 +
   1.513 +      g_assert (error3 != NULL);
   1.514 +      g_assert (result3 == NULL);
   1.515 +      g_error_free (error3);
   1.516 +    }
   1.517 +  else
   1.518 +    {
   1.519 +      g_assert (error == NULL);
   1.520 +      g_assert (items_read == ucs4_len);
   1.521 +      g_assert (items_written == utf16_len);
   1.522 +      g_assert (result);
   1.523 +      for (i = 0; i <= utf16_len; i++)
   1.524 +	g_assert (result[i] == utf16[i]);
   1.525 +
   1.526 +      g_assert (error3 == NULL);
   1.527 +      g_assert (result3);
   1.528 +      for (i = 0; i <= utf16_len; i++)
   1.529 +	g_assert (result3[i] == utf16[i]);
   1.530 +    }
   1.531 +
   1.532 +  g_free (result);
   1.533 +  g_free (result3);
   1.534 +}
   1.535 +
   1.536 +static void
   1.537 +check_utf16_to_ucs4 (const gunichar2 *utf16,
   1.538 +		     glong            utf16_len,
   1.539 +		     const gunichar  *ucs4,
   1.540 +		     glong            ucs4_len,
   1.541 +		     glong            error_pos)
   1.542 +{
   1.543 +  gunichar *result, *result2, *result3;
   1.544 +  glong items_read, items_read2;
   1.545 +  glong items_written, items_written2;
   1.546 +  GError *error, *error2, *error3;
   1.547 +  gint i;
   1.548 +
   1.549 +  error = NULL;
   1.550 +  result = g_utf16_to_ucs4 (utf16, utf16_len, &items_read, &items_written, &error);
   1.551 +  if (utf16[utf16_len] == 0)
   1.552 +    {
   1.553 +      /* check that len == -1 yields identical results */
   1.554 +      error2 = NULL;
   1.555 +      result2 = g_utf16_to_ucs4 (utf16, -1, &items_read2, &items_written2, &error2);
   1.556 +      g_assert (error || items_read2 == items_read);
   1.557 +      g_assert (error || items_written2 == items_written2);
   1.558 +      g_assert (!!result == !!result2);
   1.559 +      g_assert (!!error == !!error2);
   1.560 +      if (result)
   1.561 +	for (i = 0; i <= items_written; i++)
   1.562 +	  g_assert (result[i] == result2[i]);
   1.563 +
   1.564 +      g_free (result2);
   1.565 +      if (error2)
   1.566 +	g_error_free (error2);
   1.567 +    }
   1.568 +
   1.569 +  error3 = NULL;
   1.570 +  result3 = g_utf16_to_ucs4 (utf16, utf16_len, NULL, NULL, &error3);
   1.571 +      
   1.572 +  if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
   1.573 +    {
   1.574 +      g_assert (error == NULL);
   1.575 +      g_assert (items_read == error_pos);
   1.576 +      g_assert (items_read + 1 == utf16_len);
   1.577 +      g_assert (items_written == ucs4_len);
   1.578 +      g_assert (result);
   1.579 +      for (i = 0; i <= items_written; i++)
   1.580 +	g_assert (result[i] == ucs4[i]);
   1.581 +    }
   1.582 +  else if (error_pos)
   1.583 +    {
   1.584 +      g_assert (error != NULL);
   1.585 +      g_assert (result == NULL);
   1.586 +      g_assert (items_read == error_pos);
   1.587 +      g_error_free (error);
   1.588 +
   1.589 +      g_assert (error3 != NULL);
   1.590 +      g_assert (result3 == NULL);
   1.591 +      g_error_free (error3);
   1.592 +    }
   1.593 +  else
   1.594 +    {
   1.595 +      g_assert (error == NULL);
   1.596 +      g_assert (items_read == utf16_len);
   1.597 +      g_assert (items_written == ucs4_len);
   1.598 +      g_assert (result);
   1.599 +      for (i = 0; i <= ucs4_len; i++)
   1.600 +	g_assert (result[i] == ucs4[i]);
   1.601 +
   1.602 +      g_assert (error3 == NULL);
   1.603 +      g_assert (result3);
   1.604 +      for (i = 0; i <= ucs4_len; i++)
   1.605 +	g_assert (result3[i] == ucs4[i]);
   1.606 +    }
   1.607 +
   1.608 +  g_free (result);
   1.609 +  g_free (result3);
   1.610 +}
   1.611 +
   1.612 +static void
   1.613 +test_unicode_conversions (void)
   1.614 +{
   1.615 +  char *utf8;
   1.616 +  gunichar ucs4[100];
   1.617 +  gunichar2 utf16[100];
   1.618 +
   1.619 +  utf8 = "abc";
   1.620 +  ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0x63; ucs4[3] = 0;
   1.621 +  utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0x63; utf16[3] = 0;
   1.622 +
   1.623 +  check_utf8_to_ucs4 (utf8, 3, ucs4, 3, 0);
   1.624 +  check_ucs4_to_utf8 (ucs4, 3, utf8, 3, 0);
   1.625 +  check_utf8_to_utf16 (utf8, 3, utf16, 3, 0);
   1.626 +  check_utf16_to_utf8 (utf16, 3, utf8, 3, 0);
   1.627 +  check_ucs4_to_utf16 (ucs4, 3, utf16, 3, 0);
   1.628 +  check_utf16_to_ucs4 (utf16, 3, ucs4, 3, 0);
   1.629 +
   1.630 +  utf8 = "\316\261\316\262\316\263";
   1.631 +  ucs4[0] = 0x03b1; ucs4[1] = 0x03b2; ucs4[2] = 0x03b3; ucs4[3] = 0;
   1.632 +  utf16[0] = 0x03b1; utf16[1] = 0x03b2; utf16[2] = 0x03b3; utf16[3] = 0;
   1.633 +
   1.634 +  check_utf8_to_ucs4 (utf8, 6, ucs4, 3, 0);
   1.635 +  check_ucs4_to_utf8 (ucs4, 3, utf8, 6, 0);
   1.636 +  check_utf8_to_utf16 (utf8, 6, utf16, 3, 0);
   1.637 +  check_utf16_to_utf8 (utf16, 3, utf8, 6, 0);
   1.638 +  check_ucs4_to_utf16 (ucs4, 3, utf16, 3, 0);
   1.639 +  check_utf16_to_ucs4 (utf16, 3, ucs4, 3, 0);
   1.640 +
   1.641 +  /* partial utf8 character */
   1.642 +  utf8 = "abc\316";
   1.643 +  ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0x63; ucs4[3] = 0;
   1.644 +  utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0x63; utf16[3] = 0;
   1.645 +
   1.646 +  check_utf8_to_ucs4 (utf8, 4, ucs4, 3, 3);
   1.647 +  check_utf8_to_utf16 (utf8, 4, utf16, 3, 3);
   1.648 +
   1.649 +  /* invalid utf8 */
   1.650 +  utf8 = "abc\316\316";
   1.651 +  ucs4[0] = 0; 
   1.652 +  utf16[0] = 0; 
   1.653 +  /*
   1.654 +  Some of the test cases are not executed below by putting them under SYMBIAN
   1.655 +  flag. The reason is that the input is invalid therefore, the test cases are
   1.656 +  supposed to fail. Eventhough there is nothing wrong with the library code the
   1.657 +  test case will fail as it is test whether failure takes place or not.
   1.658 +  Hence there is no point executing them as they will uncessary
   1.659 +  reflect bad on the pass rate.
   1.660 +  */
   1.661 +
   1.662 +  #ifndef SYMBIAN
   1.663 +  check_utf8_to_ucs4 (utf8, 5, ucs4, 0, 3);
   1.664 +  check_utf8_to_utf16 (utf8, 5, utf16, 0, 3);
   1.665 +  #endif /* SYMBIAN */
   1.666 +
   1.667 +  /* partial utf16 character */
   1.668 +  utf8 = "ab";
   1.669 +  ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0;
   1.670 +  utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0xd801; utf16[3] = 0;
   1.671 +  
   1.672 +  check_utf16_to_utf8 (utf16, 3, utf8, 2, 2);
   1.673 +  check_utf16_to_ucs4 (utf16, 3, ucs4, 2, 2);
   1.674 +
   1.675 +  /* invalid utf16 */
   1.676 +  utf8 = NULL;
   1.677 +  ucs4[0] = 0;
   1.678 +  utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0xdc01; utf16[3] = 0;
   1.679 +
   1.680 +  #ifndef SYMBIAN
   1.681 +  check_utf16_to_utf8 (utf16, 3, utf8, 0, 2);
   1.682 +  check_utf16_to_ucs4 (utf16, 3, ucs4, 0, 2);
   1.683 +  #endif /* SYMBIAN */
   1.684 +
   1.685 +  /* invalid ucs4 */
   1.686 +  utf8 = NULL;
   1.687 +  ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0x80000000; ucs4[3] = 0;
   1.688 +  utf16[0] = 0;
   1.689 +
   1.690 +  #ifndef SYMBIAN
   1.691 +  check_ucs4_to_utf8 (ucs4, 3, utf8, 0, 2);
   1.692 +  check_ucs4_to_utf16 (ucs4, 3, utf16, 0, 2);
   1.693 +  #endif /* SYMBIAN */
   1.694 +}
   1.695 +
   1.696 +int
   1.697 +main (int argc, char *argv[])
   1.698 +{
   1.699 +  #ifdef SYMBIAN
   1.700 +  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);
   1.701 +  g_set_print_handler(mrtPrintHandler);
   1.702 +  #endif /*SYMBIAN*/
   1.703 +	  
   1.704 +  test_iconv_state ();
   1.705 +  test_one_half ();
   1.706 +  test_byte_order ();
   1.707 +  test_conversion();
   1.708 +  test_unicode_conversions ();
   1.709 +  
   1.710 +  #if SYMBIAN
   1.711 +  testResultXml("convert-test");
   1.712 +  #endif /* EMULATOR */
   1.713 +
   1.714 +  return 0;
   1.715 +}