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: #include sl@0: #include sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: #include sl@0: #include "mrt2_glib2_test.h" sl@0: #endif //__SYMBIAN32__ sl@0: sl@0: /* Test conversions between offsets and pointers */ sl@0: sl@0: static void test_utf8 (gchar *string) sl@0: { sl@0: gint num_chars; sl@0: gchar **p; sl@0: gint i, j; sl@0: sl@0: g_assert (g_utf8_validate (string, -1, NULL)); sl@0: sl@0: num_chars = g_utf8_strlen (string, -1); sl@0: sl@0: p = (gchar **) g_malloc (num_chars * sizeof (gchar *)); sl@0: sl@0: p[0] = string; sl@0: for (i = 1; i < num_chars; i++) sl@0: p[i] = g_utf8_next_char (p[i-1]); sl@0: sl@0: for (i = 0; i < num_chars; i++) sl@0: for (j = 0; j < num_chars; j++) sl@0: { sl@0: g_assert (g_utf8_offset_to_pointer (p[i], j - i) == p[j]); sl@0: g_assert (g_utf8_pointer_to_offset (p[i], p[j]) == j - i); sl@0: } sl@0: sl@0: g_free (p); sl@0: } sl@0: sl@0: gchar *longline = "asdasdas dsaf asfd as fdasdf asfd asdf as dfas dfasdf a" sl@0: "asd fasdf asdf asdf asd fasfd as fdasfd asdf as fdççççççççças ffsd asfd as fdASASASAs As" sl@0: "Asfdsf sdfg sdfg dsfg dfg sdfgsdfgsdfgsdfg sdfgsdfg sdfg sdfg sdf gsdfg sdfg sd" sl@0: "asd fasdf asdf asdf asd fasfd as fdaèèèèèèè òòòòòòòòòòòòsfd asdf as fdas ffsd asfd as fdASASASAs D" sl@0: "Asfdsf sdfg sdfg dsfg dfg sdfgsdfgsdfgsdfg sdfgsdfg sdfgùùùùùùùùùùùùùù sdfg sdf gsdfg sdfg sd" sl@0: "asd fasdf asdf asdf asd fasfd as fdasfd asd@@@@@@@f as fdas ffsd asfd as fdASASASAs D " sl@0: "Asfdsf sdfg sdfg dsfg dfg sdfgsdfgsdfgsdfg sdfgsdf€€€€€€€€€€€€€€€€€€g sdfg sdfg sdf gsdfg sdfg sd" sl@0: "asd fasdf asdf asdf asd fasfd as fdasfd asdf as fdas ffsd asfd as fdASASASAs D" sl@0: "Asfdsf sdfg sdfg dsfg dfg sdfgsdfgsdfgsdfg sdfgsdfg sdfg sdfg sdf gsdfg sdfg sd\n\nlalala\n"; sl@0: sl@0: static void sl@0: test_length (void) sl@0: { sl@0: g_assert (g_utf8_strlen ("1234", -1) == 4); sl@0: g_assert (g_utf8_strlen ("1234", 0) == 0); sl@0: g_assert (g_utf8_strlen ("1234", 1) == 1); sl@0: g_assert (g_utf8_strlen ("1234", 2) == 2); sl@0: g_assert (g_utf8_strlen ("1234", 3) == 3); sl@0: g_assert (g_utf8_strlen ("1234", 4) == 4); sl@0: g_assert (g_utf8_strlen ("1234", 5) == 4); sl@0: sl@0: g_assert (g_utf8_strlen (longline, -1) == 762); sl@0: g_assert (g_utf8_strlen (longline, strlen (longline)) == 762); sl@0: g_assert (g_utf8_strlen (longline, 1024) == 762); sl@0: sl@0: g_assert (g_utf8_strlen (NULL, 0) == 0); sl@0: sl@0: g_assert (g_utf8_strlen ("a\340\250\201c", -1) == 3); sl@0: g_assert (g_utf8_strlen ("a\340\250\201c", 1) == 1); sl@0: g_assert (g_utf8_strlen ("a\340\250\201c", 2) == 1); sl@0: g_assert (g_utf8_strlen ("a\340\250\201c", 3) == 1); sl@0: g_assert (g_utf8_strlen ("a\340\250\201c", 4) == 2); sl@0: g_assert (g_utf8_strlen ("a\340\250\201c", 5) == 3); sl@0: } sl@0: sl@0: static void sl@0: test_misc (void) sl@0: { sl@0: char *s; sl@0: s = g_utf8_strreverse ("1234", -1); sl@0: g_assert (strcmp (s, "4321") == 0); sl@0: g_free (s); sl@0: s = g_utf8_strreverse ("1234", 3); sl@0: g_assert (strcmp (s, "321") == 0); sl@0: g_free (s); sl@0: } sl@0: sl@0: int main (int argc, char *argv[]) sl@0: { sl@0: sl@0: #ifdef __SYMBIAN32__ 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 /*__SYMBIAN32__*/ sl@0: sl@0: test_utf8 (longline); sl@0: test_length (); sl@0: test_misc (); sl@0: #ifdef __SYMBIAN32__ sl@0: testResultXml("utf8-pointer"); sl@0: #endif //__SYMBIAN32__ sl@0: sl@0: return 0; sl@0: }