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.
23 #define PANGO_ENABLE_ENGINE
24 #include <pango/pango-ot.h>
28 #define ASSERT(stmt) G_STMT_START { \
32 g_warning ("%s:%d (%s): assertion '%s' failed", \
33 __FILE__, __LINE__, G_STRFUNC, #stmt); \
39 test_script_tags (void)
42 PangoScript i, max_script;
44 /* we need to know what the maximum script number is. but we don't
45 * provide an api for that. instead of looking into internal tables,
46 * we'll go over all chars and see what their script is, taking the max!
49 max_script = PANGO_SCRIPT_INVALID_CODE;
50 for (ch = 0; ch <= 0x10FFFF; ch++)
51 max_script = MAX (max_script, pango_script_for_unichar (ch));
53 for (i = PANGO_SCRIPT_COMMON; i <= max_script; i++)
55 PangoOTTag tag = pango_ot_tag_from_script (i);
56 PangoScript j = pango_ot_tag_to_script (tag);
58 if (i <= PANGO_SCRIPT_INHERITED || i == PANGO_SCRIPT_UNKNOWN)
60 ASSERT (tag == PANGO_OT_TAG_DEFAULT_SCRIPT);
61 ASSERT (j == PANGO_SCRIPT_COMMON);
63 else if (tag == FT_MAKE_TAG ('k', 'a', 'n', 'a'))
65 /* Hiragana and Katakana both map to tag 'kana' */
66 ASSERT (i == PANGO_SCRIPT_HIRAGANA || i == PANGO_SCRIPT_KATAKANA);
67 ASSERT (j == PANGO_SCRIPT_HIRAGANA || j == PANGO_SCRIPT_KATAKANA);
72 g_error ("Got back %d for script %d (OT tag '%c%c%c%c')", j, i,
73 tag>>24, (tag>>16)&255, (tag>>8)&255, tag&255);
77 ASSERT (pango_ot_tag_to_script (FT_MAKE_TAG ('X', 'Y', 'Z', ' ')) == PANGO_SCRIPT_UNKNOWN);
81 test_language_tags (void)
83 /* just test it for a few known languages to make sure it's working */
84 const char languages[][6] = {
85 "xy", /* hopefully nonexistent */
98 for (i = 0; i < G_N_ELEMENTS (languages); i++)
100 PangoLanguage *l = pango_language_from_string (languages[i]);
101 PangoOTTag tag = pango_ot_tag_from_language (l);
102 PangoLanguage *m = pango_ot_tag_to_language (tag);
106 ASSERT (tag == PANGO_OT_TAG_DEFAULT_LANGUAGE);
107 ASSERT (strcmp (pango_language_to_string (m), "xx") == 0);
111 if (tag == PANGO_OT_TAG_DEFAULT_LANGUAGE)
112 g_error ("Got PANGO_OT_TAG_DEFAULT_LANGUAGE for language '%s'", pango_language_to_string (l));
114 if (!pango_language_matches (l, pango_language_to_string (m)))
115 g_error ("Got back %s for language %s (OT tag '%c%c%c%c')",
116 pango_language_to_string (m), pango_language_to_string (l),
117 tag>>24, (tag>>16)&255, (tag>>8)&255, tag&255);
123 main (int argc, char **argv)
125 g_setenv ("PANGO_RC_FILE", "./pangorc", TRUE);
128 test_language_tags ();