mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 15:36:17 +01:00
Add convert-test here.
2005-08-08 Matthias Clasen <mclasen@redhat.com> * tests/Makefile.am: Add convert-test here. * tests/convert-test.c: Add the beginning of a testsuite for g_convert() and friends.
This commit is contained in:
parent
ddad5d479e
commit
308678a613
@ -1,3 +1,10 @@
|
||||
2005-08-08 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* tests/Makefile.am: Add convert-test here.
|
||||
|
||||
* tests/convert-test.c: Add the beginning of a testsuite
|
||||
for g_convert() and friends.
|
||||
|
||||
2005-08-06 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* glib/glib.symbols: Include glib_on_error_halt.
|
||||
|
@ -1,3 +1,10 @@
|
||||
2005-08-08 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* tests/Makefile.am: Add convert-test here.
|
||||
|
||||
* tests/convert-test.c: Add the beginning of a testsuite
|
||||
for g_convert() and friends.
|
||||
|
||||
2005-08-06 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* glib/glib.symbols: Include glib_on_error_halt.
|
||||
|
@ -1,3 +1,10 @@
|
||||
2005-08-08 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* tests/Makefile.am: Add convert-test here.
|
||||
|
||||
* tests/convert-test.c: Add the beginning of a testsuite
|
||||
for g_convert() and friends.
|
||||
|
||||
2005-08-06 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* glib/glib.symbols: Include glib_on_error_halt.
|
||||
|
@ -1,3 +1,10 @@
|
||||
2005-08-08 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* tests/Makefile.am: Add convert-test here.
|
||||
|
||||
* tests/convert-test.c: Add the beginning of a testsuite
|
||||
for g_convert() and friends.
|
||||
|
||||
2005-08-06 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* glib/glib.symbols: Include glib_on_error_halt.
|
||||
|
@ -67,6 +67,7 @@ test_programs = \
|
||||
$(CXX_TEST) \
|
||||
child-test \
|
||||
completion-test \
|
||||
convert-test \
|
||||
date-test \
|
||||
dirname-test \
|
||||
file-test \
|
||||
@ -123,6 +124,7 @@ atomic_test_LDADD = $(progs_ldadd)
|
||||
array_test_LDADD = $(progs_ldadd)
|
||||
child_test_LDADD = $(thread_ldadd)
|
||||
completion_test_LDADD = $(progs_ldadd)
|
||||
convert_test_LDADD = $(progs_ldadd)
|
||||
date_test_LDADD = $(progs_ldadd)
|
||||
dirname_test_LDADD = $(progs_ldadd)
|
||||
file_test_LDADD = $(progs_ldadd)
|
||||
|
107
tests/convert-test.c
Normal file
107
tests/convert-test.c
Normal file
@ -0,0 +1,107 @@
|
||||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#undef G_DISABLE_ASSERT
|
||||
#undef G_LOG_DOMAIN
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
/* Bug 311337 */
|
||||
static void
|
||||
test_iconv_state (void)
|
||||
{
|
||||
gchar *in = "\xf4\xe5\xf8\xe5\xed";
|
||||
gchar *expected = "\xd7\xa4\xd7\x95\xd7\xa8\xd7\x95\xd7\x9d";
|
||||
gchar *out;
|
||||
gsize bytes_read = 0;
|
||||
gsize bytes_written = 0;
|
||||
GError *error = NULL;
|
||||
|
||||
out = g_convert (in, -1, "UTF-8", "CP1255",
|
||||
&bytes_read, &bytes_written, &error);
|
||||
|
||||
g_assert (error == NULL);
|
||||
g_assert (bytes_read == 5);
|
||||
g_assert (bytes_written == 10);
|
||||
g_assert (strcmp (out, expected) == 0);
|
||||
}
|
||||
|
||||
/* some tests involving "vulgar fraction one half" */
|
||||
static void
|
||||
test_one_half (void)
|
||||
{
|
||||
gchar *in = "\xc2\xbd";
|
||||
gchar *out;
|
||||
gsize bytes_read = 0;
|
||||
gsize bytes_written = 0;
|
||||
GError *error = NULL;
|
||||
|
||||
out = g_convert (in, -1,
|
||||
"ISO8859-1", "UTF-8",
|
||||
&bytes_read, &bytes_written,
|
||||
&error);
|
||||
|
||||
g_assert (error == NULL);
|
||||
g_assert (bytes_read == 2);
|
||||
g_assert (bytes_written == 1);
|
||||
g_assert (strcmp (out, "\xbd") == 0);
|
||||
g_free (out);
|
||||
|
||||
out = g_convert (in, -1,
|
||||
"ISO8859-15", "UTF-8",
|
||||
&bytes_read, &bytes_written,
|
||||
&error);
|
||||
|
||||
g_assert (error && error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE);
|
||||
g_assert (bytes_read == 0);
|
||||
g_assert (bytes_written == 0);
|
||||
g_assert (out == NULL);
|
||||
g_clear_error (&error);
|
||||
|
||||
out = g_convert_with_fallback (in, -1,
|
||||
"ISO8859-15", "UTF-8",
|
||||
"a",
|
||||
&bytes_read, &bytes_written,
|
||||
&error);
|
||||
|
||||
g_assert (error == NULL);
|
||||
g_assert (bytes_read == 2);
|
||||
g_assert (bytes_written == 1);
|
||||
g_assert (strcmp (out, "a") == 0);
|
||||
g_free (out);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
test_iconv_state ();
|
||||
test_one_half ();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user