1 /* -*- mode: C; c-file-style: "gnu" -*- */
3 * testscript.c: Test cases for PangoScriptIter
5 * Copyright (C) 2002 Red Hat Software
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
22 * The test strings here come from ICU:
24 * icu/sources/test/cintltst/cucdtst.c
26 ********************************************************************
28 * Copyright (c) 1997-2001, International Business Machines Corporation and
29 * others. All Rights Reserved.
30 ********************************************************************
32 * Permission is hereby granted, free of charge, to any person obtaining a
33 * copy of this software and associated documentation files (the
34 * "Software"), to deal in the Software without restriction, including
35 * without limitation the rights to use, copy, modify, merge, publish,
36 * distribute, and/or sell copies of the Software, and to permit persons
37 * to whom the Software is furnished to do so, provided that the above
38 * copyright notice(s) and this permission notice appear in all copies of
39 * the Software and that both the above copyright notice(s) and this
40 * permission notice appear in supporting documentation.
42 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
43 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
45 * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46 * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
47 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
48 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
49 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
50 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
52 * Except as contained in this notice, the name of a copyright holder
53 * shall not be used in advertising or otherwise to promote the sale, use
54 * or other dealings in this Software without prior written authorization
55 * of the copyright holder.
61 #include "pango/pango-script.h"
65 #define ASSERT(stmt) G_STMT_START { \
69 g_warning ("%s:%d (%s): assertion '%s' failed", \
70 __FILE__, __LINE__, G_STRFUNC, #stmt); \
77 const char *run_text_escaped;
83 unescape (const char *text)
85 gboolean escaped = FALSE;
86 GString *result = g_string_new (NULL);
89 for (p = text; *p; p = g_utf8_next_char (p))
91 gunichar ch = g_utf8_get_char (p);
95 if (ch == 'u' || ch == 'U')
97 int n_chars = ch == 'u' ? 4 : 8;
101 for (i = 0; i < n_chars; i++)
105 if (*p <= '9' && *p >= '0')
107 else if (*p <= 'F' && *p >= 'A')
109 else if (*p <= 'f' && *p >= 'a')
112 g_assert_not_reached ();
121 g_assert_not_reached ();
135 g_string_append_unichar (result, ch);
138 return g_string_free (result, FALSE);
142 test_script_iter (void)
144 static RunTestData test_data[] = {
145 { "\\u0020\\u0946\\u0939\\u093F\\u0928\\u094D\\u0926\\u0940\\u0020", NULL, PANGO_SCRIPT_DEVANAGARI },
146 { "\\u0627\\u0644\\u0639\\u0631\\u0628\\u064A\\u0629\\u0020", NULL, PANGO_SCRIPT_ARABIC },
147 { "\\u0420\\u0443\\u0441\\u0441\\u043A\\u0438\\u0439\\u0020", NULL, PANGO_SCRIPT_CYRILLIC },
148 { "English (", NULL, PANGO_SCRIPT_LATIN },
149 { "\\u0E44\\u0E17\\u0E22", NULL, PANGO_SCRIPT_THAI },
150 { ") ", NULL, PANGO_SCRIPT_LATIN },
151 { "\\u6F22\\u5B75", NULL, PANGO_SCRIPT_HAN },
152 { "\\u3068\\u3072\\u3089\\u304C\\u306A\\u3068", NULL, PANGO_SCRIPT_HIRAGANA },
153 { "\\u30AB\\u30BF\\u30AB\\u30CA", NULL, PANGO_SCRIPT_KATAKANA },
154 { "\\U00010400\\U00010401\\U00010402\\U00010403", NULL, PANGO_SCRIPT_DESERET }
157 PangoScriptIter *iter;
158 GString *all = g_string_new (FALSE);
165 for (i = 0; i < G_N_ELEMENTS(test_data); i++)
167 test_data[i].run_text = unescape (test_data[i].run_text_escaped);
168 g_string_append (all, test_data[i].run_text);
171 iter = pango_script_iter_new (all->str, -1);
174 g_print ("Total length: %d\n", all->len);
178 for (i = 0; i < G_N_ELEMENTS(test_data); i++)
180 char *next_pos = pos + strlen (test_data[i].run_text);
183 pango_script_iter_get_range (iter, &start, &end, &script);
185 g_print ("Range: %d-%d: %d\n", start - all->str, end - all->str, script);
188 ASSERT (start == pos);
189 ASSERT (end == next_pos);
190 ASSERT (script == test_data[i].run_code);
192 result = pango_script_iter_next (iter);
193 ASSERT (result == (i != G_N_ELEMENTS (test_data) - 1));
198 pango_script_iter_free (iter);
201 * Test an empty string.
203 iter = pango_script_iter_new (all->str, 0);
205 pango_script_iter_get_range (iter, &start, &end, &script);
207 ASSERT (start == all->str);
208 ASSERT (end == all->str);
209 ASSERT (script == PANGO_SCRIPT_COMMON);
210 ASSERT (!pango_script_iter_next (iter));
212 pango_script_iter_free (iter);
216 for (i = 0; i < G_N_ELEMENTS (test_data); i++)
217 g_free (test_data[i].run_text);
219 g_string_free (all, TRUE);
223 main (int argc, char **argv)
225 g_setenv ("PANGO_RC_FILE", "./pangorc", TRUE);