1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
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/.
27 #undef G_DISABLE_ASSERT
36 test_iconv_state (void)
38 gchar *in = "\xf4\xe5\xf8\xe5\xed";
39 gchar *expected = "\xd7\xa4\xd7\x95\xd7\xa8\xd7\x95\xd7\x9d";
42 gsize bytes_written = 0;
45 out = g_convert (in, -1, "UTF-8", "CP1255",
46 &bytes_read, &bytes_written, &error);
48 g_assert (error == NULL);
49 g_assert (bytes_read == 5);
50 g_assert (bytes_written == 10);
51 g_assert (strcmp (out, expected) == 0);
54 /* some tests involving "vulgar fraction one half" */
58 gchar *in = "\xc2\xbd";
61 gsize bytes_written = 0;
64 out = g_convert (in, -1,
66 &bytes_read, &bytes_written,
69 g_assert (error == NULL);
70 g_assert (bytes_read == 2);
71 g_assert (bytes_written == 1);
72 g_assert (strcmp (out, "\xbd") == 0);
75 out = g_convert (in, -1,
76 "ISO8859-15", "UTF-8",
77 &bytes_read, &bytes_written,
80 g_assert (error && error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE);
81 g_assert (bytes_read == 0);
82 g_assert (bytes_written == 0);
83 g_assert (out == NULL);
84 g_clear_error (&error);
86 out = g_convert_with_fallback (in, -1,
87 "ISO8859-15", "UTF-8",
89 &bytes_read, &bytes_written,
92 g_assert (error == NULL);
93 g_assert (bytes_read == 2);
94 g_assert (bytes_written == 1);
95 g_assert (strcmp (out, "a") == 0);
100 test_byte_order (void)
102 gchar in_be[4] = { 0xfe, 0xff, 0x03, 0x93}; /* capital gamma */
103 gchar in_le[4] = { 0xff, 0xfe, 0x93, 0x03};
104 gchar *expected = "\xce\x93";
106 gsize bytes_read = 0;
107 gsize bytes_written = 0;
108 GError *error = NULL;
110 out = g_convert (in_be, sizeof (in_be),
112 &bytes_read, &bytes_written,
115 g_assert (error == NULL);
116 g_assert (bytes_read == 4);
117 g_assert (bytes_written == 2);
118 g_assert (strcmp (out, expected) == 0);
121 out = g_convert (in_le, sizeof (in_le),
123 &bytes_read, &bytes_written,
126 g_assert (error == NULL);
127 g_assert (bytes_read == 4);
128 g_assert (bytes_written == 2);
129 g_assert (strcmp (out, expected) == 0);
134 main (int argc, char *argv[])