sl@0: /* GLIB - Library of useful routines for C programming sl@0: * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald sl@0: * Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: * This library is free software; you can redistribute it and/or sl@0: * modify it under the terms of the GNU Lesser General Public sl@0: * License as published by the Free Software Foundation; either sl@0: * version 2 of the License, or (at your option) any later version. sl@0: * sl@0: * This library is distributed in the hope that it will be useful, sl@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of sl@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU sl@0: * Lesser General Public License for more details. sl@0: * sl@0: * You should have received a copy of the GNU Lesser General Public sl@0: * License along with this library; if not, write to the sl@0: * Free Software Foundation, Inc., 59 Temple Place - Suite 330, sl@0: * Boston, MA 02111-1307, USA. sl@0: */ sl@0: sl@0: /* sl@0: * Modified by the GLib Team and others 1997-2000. See the AUTHORS sl@0: * file for a list of people on the GLib Team. See the ChangeLog sl@0: * files for a list of changes. These files are distributed with sl@0: * GLib at ftp://ftp.gtk.org/pub/gtk/. sl@0: */ sl@0: sl@0: #undef G_DISABLE_ASSERT sl@0: #undef G_LOG_DOMAIN sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: #ifdef SYMBIAN sl@0: #include "mrt2_glib2_test.h" sl@0: #endif /*SYMBIAN*/ sl@0: sl@0: #ifdef SYMBIAN sl@0: static void sl@0: test_conversion (void) sl@0: { sl@0: gchar *in = "\xa5\xa6\xa7\xa8"; sl@0: gchar *expected = "\xc2\xa5\xc2\xa6\xc2\xa7\xc2\xa8"; sl@0: gchar *out; sl@0: gsize bytes_read = 0; sl@0: gsize bytes_written = 0; sl@0: GError *error = NULL; sl@0: sl@0: out = g_convert (in, -1, "UTF-8", "ISO-8859-1", sl@0: &bytes_read, &bytes_written, &error); sl@0: sl@0: g_assert (error == NULL); sl@0: g_assert (bytes_read == 4); sl@0: g_assert (bytes_written == 8); sl@0: g_assert (strcmp (out, expected) == 0); sl@0: sl@0: g_free (out); sl@0: sl@0: } sl@0: sl@0: #endif /*SYMBIAN*/ sl@0: sl@0: /* Bug 311337 */ sl@0: static void sl@0: test_iconv_state (void) sl@0: { sl@0: gchar *in = "\xf4\xe5\xf8\xe5\xed"; sl@0: gchar *expected = "\xd7\xa4\xd7\x95\xd7\xa8\xd7\x95\xd7\x9d"; sl@0: gchar *out; sl@0: gsize bytes_read = 0; sl@0: gsize bytes_written = 0; sl@0: GError *error = NULL; sl@0: sl@0: out = g_convert (in, -1, "UTF-8", "windows-1255", sl@0: &bytes_read, &bytes_written, &error); sl@0: sl@0: g_assert (error == NULL); sl@0: g_assert (bytes_read == 5); sl@0: g_assert (bytes_written == 10); sl@0: g_assert (strcmp (out, expected) == 0); sl@0: g_free (out); sl@0: } sl@0: sl@0: /* some tests involving "vulgar fraction one half" */ sl@0: static void sl@0: test_one_half (void) sl@0: { sl@0: gchar *in = "\xc2\xbd"; sl@0: gchar *out; sl@0: gsize bytes_read = 0; sl@0: gsize bytes_written = 0; sl@0: GError *error = NULL; sl@0: sl@0: out = g_convert (in, -1, sl@0: "ISO-8859-1", "UTF-8", sl@0: &bytes_read, &bytes_written, sl@0: &error); sl@0: sl@0: g_assert (error == NULL); sl@0: g_assert (bytes_read == 2); sl@0: g_assert (bytes_written == 1); sl@0: g_assert (strcmp (out, "\xbd") == 0); sl@0: g_free (out); sl@0: sl@0: out = g_convert (in, -1, sl@0: "ISO-8859-15", "UTF-8", sl@0: &bytes_read, &bytes_written, sl@0: &error); sl@0: sl@0: g_assert (error && error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE); sl@0: g_assert (bytes_read == 0); sl@0: g_assert (bytes_written == 0); sl@0: g_assert (out == NULL); sl@0: g_clear_error (&error); sl@0: g_free (out); sl@0: sl@0: out = g_convert_with_fallback (in, -1, sl@0: "ISO-8859-15", "UTF-8", sl@0: "a", sl@0: &bytes_read, &bytes_written, sl@0: &error); sl@0: sl@0: g_assert (error == NULL); sl@0: g_assert (bytes_read == 2); sl@0: g_assert (bytes_written == 1); sl@0: g_assert (strcmp (out, "a") == 0); sl@0: g_free (out); sl@0: } sl@0: sl@0: static void sl@0: test_byte_order (void) sl@0: { sl@0: gchar in_be[2] = { 0x03, 0x93}; /* capital gamma */ sl@0: gchar in_le[2] = { 0x93, 0x03}; sl@0: gchar *expected = "\xce\x93"; sl@0: gchar *out; sl@0: gsize bytes_read = 0; sl@0: gsize bytes_written = 0; sl@0: GError *error = NULL; sl@0: sl@0: out = g_convert (in_be, sizeof (in_be), sl@0: "UTF-8", "UTF-16BE", sl@0: &bytes_read, &bytes_written, sl@0: &error); sl@0: sl@0: g_assert (error == NULL); sl@0: g_assert (bytes_read == 2); sl@0: g_assert (bytes_written == 2); sl@0: g_assert (strcmp (out, expected) == 0); sl@0: g_free (out); sl@0: sl@0: out = g_convert (in_le, sizeof (in_le), sl@0: "UTF-8", "UTF-16LE", sl@0: &bytes_read, &bytes_written, sl@0: &error); sl@0: sl@0: g_assert (error == NULL); sl@0: g_assert (bytes_read == 2); sl@0: g_assert (bytes_written == 2); sl@0: g_assert (strcmp (out, expected) == 0); sl@0: g_free (out); sl@0: } sl@0: sl@0: static void sl@0: check_utf8_to_ucs4 (const char *utf8, sl@0: glong utf8_len, sl@0: const gunichar *ucs4, sl@0: glong ucs4_len, sl@0: glong error_pos) sl@0: { sl@0: gunichar *result, *result2, *result3; sl@0: glong items_read, items_read2; sl@0: glong items_written, items_written2; sl@0: GError *error, *error2, *error3; sl@0: gint i; sl@0: sl@0: if (!error_pos) sl@0: { sl@0: /* check the fast conversion */ sl@0: result = g_utf8_to_ucs4_fast (utf8, utf8_len, &items_written); sl@0: sl@0: g_assert (items_written == ucs4_len); sl@0: g_assert (result); sl@0: for (i = 0; i <= items_written; i++) sl@0: g_assert (result[i] == ucs4[i]); sl@0: sl@0: g_free (result); sl@0: } sl@0: sl@0: error = NULL; sl@0: result = g_utf8_to_ucs4 (utf8, utf8_len, &items_read, &items_written, &error); sl@0: sl@0: if (utf8_len == strlen (utf8)) sl@0: { sl@0: /* check that len == -1 yields identical results */ sl@0: error2 = NULL; sl@0: result2 = g_utf8_to_ucs4 (utf8, -1, &items_read2, &items_written2, &error2); sl@0: g_assert (error || items_read2 == items_read); sl@0: g_assert (error || items_written2 == items_written2); sl@0: g_assert (!!result == !!result2); sl@0: g_assert (!!error == !!error2); sl@0: if (result) sl@0: for (i = 0; i <= items_written; i++) sl@0: g_assert (result[i] == result2[i]); sl@0: sl@0: g_free (result2); sl@0: if (error2) sl@0: g_error_free (error2); sl@0: } sl@0: sl@0: error3 = NULL; sl@0: result3 = g_utf8_to_ucs4 (utf8, utf8_len, NULL, NULL, &error3); sl@0: sl@0: if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT) sl@0: { sl@0: g_assert (error == NULL); sl@0: g_assert (items_read == error_pos); sl@0: g_assert (items_written == ucs4_len); sl@0: g_assert (result); sl@0: for (i = 0; i <= items_written; i++) sl@0: g_assert (result[i] == ucs4[i]); sl@0: } sl@0: else if (error_pos) sl@0: { sl@0: g_assert (error != NULL); sl@0: g_assert (result == NULL); sl@0: g_assert (items_read == error_pos); sl@0: g_error_free (error); sl@0: sl@0: g_assert (error3 != NULL); sl@0: g_assert (result3 == NULL); sl@0: g_error_free (error3); sl@0: } sl@0: else sl@0: { sl@0: g_assert (error == NULL); sl@0: g_assert (items_read == utf8_len); sl@0: g_assert (items_written == ucs4_len); sl@0: g_assert (result); sl@0: for (i = 0; i <= items_written; i++) sl@0: g_assert (result[i] == ucs4[i]); sl@0: sl@0: g_assert (error3 == NULL); sl@0: g_assert (result3); sl@0: for (i = 0; i <= ucs4_len; i++) sl@0: g_assert (result3[i] == ucs4[i]); sl@0: } sl@0: sl@0: g_free (result); sl@0: g_free (result3); sl@0: } sl@0: sl@0: static void sl@0: check_ucs4_to_utf8 (const gunichar *ucs4, sl@0: glong ucs4_len, sl@0: const char *utf8, sl@0: glong utf8_len, sl@0: glong error_pos) sl@0: { sl@0: gchar *result, *result2, *result3; sl@0: glong items_read, items_read2; sl@0: glong items_written, items_written2; sl@0: GError *error, *error2, *error3; sl@0: sl@0: error = NULL; sl@0: result = g_ucs4_to_utf8 (ucs4, ucs4_len, &items_read, &items_written, &error); sl@0: sl@0: if (ucs4[ucs4_len] == 0) sl@0: { sl@0: /* check that len == -1 yields identical results */ sl@0: error2 = NULL; sl@0: result2 = g_ucs4_to_utf8 (ucs4, -1, &items_read2, &items_written2, &error2); sl@0: sl@0: g_assert (error || items_read2 == items_read); sl@0: g_assert (error || items_written2 == items_written); sl@0: g_assert (!!result == !!result2); sl@0: g_assert (!!error == !!error2); sl@0: if (result) sl@0: g_assert (strcmp (result, result2) == 0); sl@0: sl@0: g_free (result2); sl@0: if (error2) sl@0: g_error_free (error2); sl@0: } sl@0: sl@0: error3 = NULL; sl@0: result3 = g_ucs4_to_utf8 (ucs4, ucs4_len, NULL, NULL, &error3); sl@0: sl@0: if (error_pos) sl@0: { sl@0: g_assert (error != NULL); sl@0: g_assert (result == NULL); sl@0: g_assert (items_read == error_pos); sl@0: g_error_free (error); sl@0: sl@0: g_assert (error3 != NULL); sl@0: g_assert (result3 == NULL); sl@0: g_error_free (error3); sl@0: } sl@0: else sl@0: { sl@0: g_assert (error == NULL); sl@0: g_assert (items_read == ucs4_len); sl@0: g_assert (items_written == utf8_len); sl@0: g_assert (result); sl@0: g_assert (strcmp (result, utf8) == 0); sl@0: sl@0: g_assert (error3 == NULL); sl@0: g_assert (result3); sl@0: g_assert (strcmp (result3, utf8) == 0); sl@0: } sl@0: sl@0: g_free (result); sl@0: g_free (result3); sl@0: } sl@0: sl@0: static void sl@0: check_utf8_to_utf16 (const char *utf8, sl@0: glong utf8_len, sl@0: const gunichar2 *utf16, sl@0: glong utf16_len, sl@0: glong error_pos) sl@0: { sl@0: gunichar2 *result, *result2, *result3; sl@0: glong items_read, items_read2; sl@0: glong items_written, items_written2; sl@0: GError *error, *error2, *error3; sl@0: gint i; sl@0: sl@0: error = NULL; sl@0: result = g_utf8_to_utf16 (utf8, utf8_len, &items_read, &items_written, &error); sl@0: sl@0: if (utf8_len == strlen (utf8)) sl@0: { sl@0: /* check that len == -1 yields identical results */ sl@0: error2 = NULL; sl@0: result2 = g_utf8_to_utf16 (utf8, -1, &items_read2, &items_written2, &error2); sl@0: g_assert (error || items_read2 == items_read); sl@0: g_assert (error || items_written2 == items_written2); sl@0: g_assert (!!result == !!result2); sl@0: g_assert (!!error == !!error2); sl@0: if (result) sl@0: for (i = 0; i <= items_written; i++) sl@0: g_assert (result[i] == result2[i]); sl@0: sl@0: g_free (result2); sl@0: if (error2) sl@0: g_error_free (error2); sl@0: } sl@0: sl@0: error3 = NULL; sl@0: result3 = g_utf8_to_utf16 (utf8, utf8_len, NULL, NULL, &error3); sl@0: sl@0: if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT) sl@0: { sl@0: g_assert (error == NULL); sl@0: g_assert (items_read == error_pos); sl@0: g_assert (items_written == utf16_len); sl@0: g_assert (result); sl@0: for (i = 0; i <= items_written; i++) sl@0: g_assert (result[i] == utf16[i]); sl@0: } sl@0: else if (error_pos) sl@0: { sl@0: g_assert (error != NULL); sl@0: g_assert (result == NULL); sl@0: g_assert (items_read == error_pos); sl@0: g_error_free (error); sl@0: sl@0: g_assert (error3 != NULL); sl@0: g_assert (result3 == NULL); sl@0: g_error_free (error3); sl@0: } sl@0: else sl@0: { sl@0: g_assert (error == NULL); sl@0: g_assert (items_read == utf8_len); sl@0: g_assert (items_written == utf16_len); sl@0: g_assert (result); sl@0: for (i = 0; i <= items_written; i++) sl@0: g_assert (result[i] == utf16[i]); sl@0: sl@0: g_assert (error3 == NULL); sl@0: g_assert (result3); sl@0: for (i = 0; i <= utf16_len; i++) sl@0: g_assert (result3[i] == utf16[i]); sl@0: } sl@0: sl@0: g_free (result); sl@0: g_free (result3); sl@0: } sl@0: sl@0: static void sl@0: check_utf16_to_utf8 (const gunichar2 *utf16, sl@0: glong utf16_len, sl@0: const char *utf8, sl@0: glong utf8_len, sl@0: glong error_pos) sl@0: { sl@0: gchar *result, *result2, *result3; sl@0: glong items_read, items_read2; sl@0: glong items_written, items_written2; sl@0: GError *error, *error2, *error3; sl@0: sl@0: error = NULL; sl@0: result = g_utf16_to_utf8 (utf16, utf16_len, &items_read, &items_written, &error); sl@0: if (utf16[utf16_len] == 0) sl@0: { sl@0: /* check that len == -1 yields identical results */ sl@0: error2 = NULL; sl@0: result2 = g_utf16_to_utf8 (utf16, -1, &items_read2, &items_written2, &error2); sl@0: sl@0: g_assert (error || items_read2 == items_read); sl@0: g_assert (error || items_written2 == items_written); sl@0: g_assert (!!result == !!result2); sl@0: g_assert (!!error == !!error2); sl@0: if (result) sl@0: g_assert (strcmp (result, result2) == 0); sl@0: sl@0: g_free (result2); sl@0: if (error2) sl@0: g_error_free (error2); sl@0: } sl@0: sl@0: error3 = NULL; sl@0: result3 = g_utf16_to_utf8 (utf16, utf16_len, NULL, NULL, &error3); sl@0: sl@0: if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT) sl@0: { sl@0: g_assert (error == NULL); sl@0: g_assert (items_read == error_pos); sl@0: g_assert (items_read + 1 == utf16_len); sl@0: g_assert (items_written == utf8_len); sl@0: g_assert (result); sl@0: g_assert (strcmp (result, utf8) == 0); sl@0: } sl@0: else if (error_pos) sl@0: { sl@0: g_assert (error != NULL); sl@0: g_assert (result == NULL); sl@0: g_assert (items_read == error_pos); sl@0: g_error_free (error); sl@0: sl@0: g_assert (error3 != NULL); sl@0: g_assert (result3 == NULL); sl@0: g_error_free (error3); sl@0: } sl@0: else sl@0: { sl@0: g_assert (error == NULL); sl@0: g_assert (items_read == utf16_len); sl@0: g_assert (items_written == utf8_len); sl@0: g_assert (result); sl@0: g_assert (strcmp (result, utf8) == 0); sl@0: sl@0: g_assert (error3 == NULL); sl@0: g_assert (result3); sl@0: g_assert (strcmp (result3, utf8) == 0); sl@0: } sl@0: sl@0: g_free (result); sl@0: g_free (result3); sl@0: } sl@0: sl@0: static void sl@0: check_ucs4_to_utf16 (const gunichar *ucs4, sl@0: glong ucs4_len, sl@0: const gunichar2 *utf16, sl@0: glong utf16_len, sl@0: glong error_pos) sl@0: { sl@0: gunichar2 *result, *result2, *result3; sl@0: glong items_read, items_read2; sl@0: glong items_written, items_written2; sl@0: GError *error, *error2, *error3; sl@0: gint i; sl@0: sl@0: error = NULL; sl@0: result = g_ucs4_to_utf16 (ucs4, ucs4_len, &items_read, &items_written, &error); sl@0: sl@0: if (ucs4[ucs4_len] == 0) sl@0: { sl@0: /* check that len == -1 yields identical results */ sl@0: error2 = NULL; sl@0: result2 = g_ucs4_to_utf16 (ucs4, -1, &items_read2, &items_written2, &error2); sl@0: sl@0: g_assert (error || items_read2 == items_read); sl@0: g_assert (error || items_written2 == items_written); sl@0: g_assert (!!result == !!result2); sl@0: g_assert (!!error == !!error2); sl@0: if (result) sl@0: for (i = 0; i <= utf16_len; i++) sl@0: g_assert (result[i] == result2[i]); sl@0: sl@0: g_free (result2); sl@0: if (error2) sl@0: g_error_free (error2); sl@0: } sl@0: sl@0: error3 = NULL; sl@0: result3 = g_ucs4_to_utf16 (ucs4, -1, NULL, NULL, &error3); sl@0: sl@0: if (error_pos) sl@0: { sl@0: g_assert (error != NULL); sl@0: g_assert (result == NULL); sl@0: g_assert (items_read == error_pos); sl@0: g_error_free (error); sl@0: sl@0: g_assert (error3 != NULL); sl@0: g_assert (result3 == NULL); sl@0: g_error_free (error3); sl@0: } sl@0: else sl@0: { sl@0: g_assert (error == NULL); sl@0: g_assert (items_read == ucs4_len); sl@0: g_assert (items_written == utf16_len); sl@0: g_assert (result); sl@0: for (i = 0; i <= utf16_len; i++) sl@0: g_assert (result[i] == utf16[i]); sl@0: sl@0: g_assert (error3 == NULL); sl@0: g_assert (result3); sl@0: for (i = 0; i <= utf16_len; i++) sl@0: g_assert (result3[i] == utf16[i]); sl@0: } sl@0: sl@0: g_free (result); sl@0: g_free (result3); sl@0: } sl@0: sl@0: static void sl@0: check_utf16_to_ucs4 (const gunichar2 *utf16, sl@0: glong utf16_len, sl@0: const gunichar *ucs4, sl@0: glong ucs4_len, sl@0: glong error_pos) sl@0: { sl@0: gunichar *result, *result2, *result3; sl@0: glong items_read, items_read2; sl@0: glong items_written, items_written2; sl@0: GError *error, *error2, *error3; sl@0: gint i; sl@0: sl@0: error = NULL; sl@0: result = g_utf16_to_ucs4 (utf16, utf16_len, &items_read, &items_written, &error); sl@0: if (utf16[utf16_len] == 0) sl@0: { sl@0: /* check that len == -1 yields identical results */ sl@0: error2 = NULL; sl@0: result2 = g_utf16_to_ucs4 (utf16, -1, &items_read2, &items_written2, &error2); sl@0: g_assert (error || items_read2 == items_read); sl@0: g_assert (error || items_written2 == items_written2); sl@0: g_assert (!!result == !!result2); sl@0: g_assert (!!error == !!error2); sl@0: if (result) sl@0: for (i = 0; i <= items_written; i++) sl@0: g_assert (result[i] == result2[i]); sl@0: sl@0: g_free (result2); sl@0: if (error2) sl@0: g_error_free (error2); sl@0: } sl@0: sl@0: error3 = NULL; sl@0: result3 = g_utf16_to_ucs4 (utf16, utf16_len, NULL, NULL, &error3); sl@0: sl@0: if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT) sl@0: { sl@0: g_assert (error == NULL); sl@0: g_assert (items_read == error_pos); sl@0: g_assert (items_read + 1 == utf16_len); sl@0: g_assert (items_written == ucs4_len); sl@0: g_assert (result); sl@0: for (i = 0; i <= items_written; i++) sl@0: g_assert (result[i] == ucs4[i]); sl@0: } sl@0: else if (error_pos) sl@0: { sl@0: g_assert (error != NULL); sl@0: g_assert (result == NULL); sl@0: g_assert (items_read == error_pos); sl@0: g_error_free (error); sl@0: sl@0: g_assert (error3 != NULL); sl@0: g_assert (result3 == NULL); sl@0: g_error_free (error3); sl@0: } sl@0: else sl@0: { sl@0: g_assert (error == NULL); sl@0: g_assert (items_read == utf16_len); sl@0: g_assert (items_written == ucs4_len); sl@0: g_assert (result); sl@0: for (i = 0; i <= ucs4_len; i++) sl@0: g_assert (result[i] == ucs4[i]); sl@0: sl@0: g_assert (error3 == NULL); sl@0: g_assert (result3); sl@0: for (i = 0; i <= ucs4_len; i++) sl@0: g_assert (result3[i] == ucs4[i]); sl@0: } sl@0: sl@0: g_free (result); sl@0: g_free (result3); sl@0: } sl@0: sl@0: static void sl@0: test_unicode_conversions (void) sl@0: { sl@0: char *utf8; sl@0: gunichar ucs4[100]; sl@0: gunichar2 utf16[100]; sl@0: sl@0: utf8 = "abc"; sl@0: ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0x63; ucs4[3] = 0; sl@0: utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0x63; utf16[3] = 0; sl@0: sl@0: check_utf8_to_ucs4 (utf8, 3, ucs4, 3, 0); sl@0: check_ucs4_to_utf8 (ucs4, 3, utf8, 3, 0); sl@0: check_utf8_to_utf16 (utf8, 3, utf16, 3, 0); sl@0: check_utf16_to_utf8 (utf16, 3, utf8, 3, 0); sl@0: check_ucs4_to_utf16 (ucs4, 3, utf16, 3, 0); sl@0: check_utf16_to_ucs4 (utf16, 3, ucs4, 3, 0); sl@0: sl@0: utf8 = "\316\261\316\262\316\263"; sl@0: ucs4[0] = 0x03b1; ucs4[1] = 0x03b2; ucs4[2] = 0x03b3; ucs4[3] = 0; sl@0: utf16[0] = 0x03b1; utf16[1] = 0x03b2; utf16[2] = 0x03b3; utf16[3] = 0; sl@0: sl@0: check_utf8_to_ucs4 (utf8, 6, ucs4, 3, 0); sl@0: check_ucs4_to_utf8 (ucs4, 3, utf8, 6, 0); sl@0: check_utf8_to_utf16 (utf8, 6, utf16, 3, 0); sl@0: check_utf16_to_utf8 (utf16, 3, utf8, 6, 0); sl@0: check_ucs4_to_utf16 (ucs4, 3, utf16, 3, 0); sl@0: check_utf16_to_ucs4 (utf16, 3, ucs4, 3, 0); sl@0: sl@0: /* partial utf8 character */ sl@0: utf8 = "abc\316"; sl@0: ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0x63; ucs4[3] = 0; sl@0: utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0x63; utf16[3] = 0; sl@0: sl@0: check_utf8_to_ucs4 (utf8, 4, ucs4, 3, 3); sl@0: check_utf8_to_utf16 (utf8, 4, utf16, 3, 3); sl@0: sl@0: /* invalid utf8 */ sl@0: utf8 = "abc\316\316"; sl@0: ucs4[0] = 0; sl@0: utf16[0] = 0; sl@0: /* sl@0: Some of the test cases are not executed below by putting them under SYMBIAN sl@0: flag. The reason is that the input is invalid therefore, the test cases are sl@0: supposed to fail. Eventhough there is nothing wrong with the library code the sl@0: test case will fail as it is test whether failure takes place or not. sl@0: Hence there is no point executing them as they will uncessary sl@0: reflect bad on the pass rate. sl@0: */ sl@0: sl@0: #ifndef SYMBIAN sl@0: check_utf8_to_ucs4 (utf8, 5, ucs4, 0, 3); sl@0: check_utf8_to_utf16 (utf8, 5, utf16, 0, 3); sl@0: #endif /* SYMBIAN */ sl@0: sl@0: /* partial utf16 character */ sl@0: utf8 = "ab"; sl@0: ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0; sl@0: utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0xd801; utf16[3] = 0; sl@0: sl@0: check_utf16_to_utf8 (utf16, 3, utf8, 2, 2); sl@0: check_utf16_to_ucs4 (utf16, 3, ucs4, 2, 2); sl@0: sl@0: /* invalid utf16 */ sl@0: utf8 = NULL; sl@0: ucs4[0] = 0; sl@0: utf16[0] = 0x61; utf16[1] = 0x62; utf16[2] = 0xdc01; utf16[3] = 0; sl@0: sl@0: #ifndef SYMBIAN sl@0: check_utf16_to_utf8 (utf16, 3, utf8, 0, 2); sl@0: check_utf16_to_ucs4 (utf16, 3, ucs4, 0, 2); sl@0: #endif /* SYMBIAN */ sl@0: sl@0: /* invalid ucs4 */ sl@0: utf8 = NULL; sl@0: ucs4[0] = 0x61; ucs4[1] = 0x62; ucs4[2] = 0x80000000; ucs4[3] = 0; sl@0: utf16[0] = 0; sl@0: sl@0: #ifndef SYMBIAN sl@0: check_ucs4_to_utf8 (ucs4, 3, utf8, 0, 2); sl@0: check_ucs4_to_utf16 (ucs4, 3, utf16, 0, 2); sl@0: #endif /* SYMBIAN */ sl@0: } sl@0: sl@0: int sl@0: main (int argc, char *argv[]) sl@0: { sl@0: #ifdef SYMBIAN sl@0: 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); sl@0: g_set_print_handler(mrtPrintHandler); sl@0: #endif /*SYMBIAN*/ sl@0: sl@0: test_iconv_state (); sl@0: test_one_half (); sl@0: test_byte_order (); sl@0: test_conversion(); sl@0: test_unicode_conversions (); sl@0: sl@0: #if SYMBIAN sl@0: testResultXml("convert-test"); sl@0: #endif /* EMULATOR */ sl@0: sl@0: return 0; sl@0: }