1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/glib/tsrc/BC/tests/utf8-pointer.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,113 @@
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 +#include <glib.h>
1.31 +
1.32 +#ifdef SYMBIAN
1.33 +#include "mrt2_glib2_test.h"
1.34 +#endif //SYMBIAN
1.35 +
1.36 +#include "glib_global.h"
1.37 +/* Test conversions between offsets and pointers */
1.38 +
1.39 +static void test_utf8 (gchar *string)
1.40 +{
1.41 + gint num_chars;
1.42 + gchar **p;
1.43 + gint i, j;
1.44 +
1.45 + g_assert (g_utf8_validate (string, -1, NULL));
1.46 +
1.47 + num_chars = g_utf8_strlen (string, -1);
1.48 +
1.49 + p = (gchar **) g_malloc (num_chars * sizeof (gchar *));
1.50 +
1.51 + p[0] = string;
1.52 + for (i = 1; i < num_chars; i++)
1.53 + p[i] = g_utf8_next_char (p[i-1]);
1.54 +
1.55 + for (i = 0; i < num_chars; i++)
1.56 + for (j = 0; j < num_chars; j++)
1.57 + {
1.58 + g_assert (g_utf8_offset_to_pointer (p[i], j - i) == p[j]);
1.59 + g_assert (g_utf8_pointer_to_offset (p[i], p[j]) == j - i);
1.60 + }
1.61 +
1.62 + g_free (p);
1.63 +}
1.64 +
1.65 +gchar *longline = "asdasdas dsaf asfd as fdasdf asfd asdf as dfas dfasdf a"
1.66 +"asd fasdf asdf asdf asd fasfd as fdasfd asdf as fdççççççççças ffsd asfd as fdASASASAs As"
1.67 +"Asfdsf sdfg sdfg dsfg dfg sdfgsdfgsdfgsdfg sdfgsdfg sdfg sdfg sdf gsdfg sdfg sd"
1.68 +"asd fasdf asdf asdf asd fasfd as fdaèèèèèèè òòòòòòòòòòòòsfd asdf as fdas ffsd asfd as fdASASASAs D"
1.69 +"Asfdsf sdfg sdfg dsfg dfg sdfgsdfgsdfgsdfg sdfgsdfg sdfgùùùùùùùùùùùùùù sdfg sdf gsdfg sdfg sd"
1.70 +"asd fasdf asdf asdf asd fasfd as fdasfd asd@@@@@@@f as fdas ffsd asfd as fdASASASAs D "
1.71 +"Asfdsf sdfg sdfg dsfg dfg sdfgsdfgsdfgsdfg sdfgsdf€€€€€€€€€€€€€€€€€€g sdfg sdfg sdf gsdfg sdfg sd"
1.72 +"asd fasdf asdf asdf asd fasfd as fdasfd asdf as fdas ffsd asfd as fdASASASAs D"
1.73 +"Asfdsf sdfg sdfg dsfg dfg sdfgsdfgsdfgsdfg sdfgsdfg sdfg sdfg sdf gsdfg sdfg sd\n\nlalala\n";
1.74 +
1.75 +static void
1.76 +test_length (void)
1.77 +{
1.78 + g_assert (g_utf8_strlen ("1234", -1) == 4);
1.79 + g_assert (g_utf8_strlen ("1234", 0) == 0);
1.80 + g_assert (g_utf8_strlen ("1234", 1) == 1);
1.81 + g_assert (g_utf8_strlen ("1234", 2) == 2);
1.82 + g_assert (g_utf8_strlen ("1234", 3) == 3);
1.83 + g_assert (g_utf8_strlen ("1234", 4) == 4);
1.84 + g_assert (g_utf8_strlen ("1234", 5) == 4);
1.85 +
1.86 + g_assert (g_utf8_strlen (longline, -1) == 762);
1.87 + g_assert (g_utf8_strlen (longline, strlen (longline)) == 762);
1.88 + g_assert (g_utf8_strlen (longline, 1024) == 762);
1.89 +
1.90 + g_assert (g_utf8_strlen (NULL, 0) == 0);
1.91 +
1.92 + g_assert (g_utf8_strlen ("a\340\250\201c", -1) == 3);
1.93 + g_assert (g_utf8_strlen ("a\340\250\201c", 1) == 1);
1.94 + g_assert (g_utf8_strlen ("a\340\250\201c", 2) == 1);
1.95 + g_assert (g_utf8_strlen ("a\340\250\201c", 3) == 1);
1.96 + g_assert (g_utf8_strlen ("a\340\250\201c", 4) == 2);
1.97 + g_assert (g_utf8_strlen ("a\340\250\201c", 5) == 3);
1.98 +}
1.99 +
1.100 +int main (int argc, char *argv[])
1.101 +{
1.102 +
1.103 + #ifdef SYMBIAN
1.104 + 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.105 + g_set_print_handler(mrtPrintHandler);
1.106 + #endif /*SYMBIAN*/
1.107 +
1.108 + test_utf8 (longline);
1.109 + test_length ();
1.110 +
1.111 + #ifdef SYMBIAN
1.112 + testResultXml("utf8-pointer");
1.113 + #endif //SYMBIAN
1.114 +
1.115 + return 0;
1.116 +}