1/* -*- mode: C; c-file-style: "gnu" -*- */
2/* Pango
3 * testscript.c: Test cases for PangoScriptIter
4 *
5 * Copyright (C) 2002 Red Hat Software
6 *
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.
11 *
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.
16 *
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.
21 */
22
23#undef PANGO_DISABLE_DEPRECATED
24#include <pango/pango-ot.h>
25
26#undef VERBOSE
27
28#define ASSERT(stmt) G_STMT_START { \
29 if (stmt) { } \
30 else \
31 { \
32 g_warning ("%s:%d (%s): assertion '%s' failed", \
33 __FILE__, __LINE__, G_STRFUNC, #stmt); \
34 exit (1); \
35 } \
36} G_STMT_END
37
38G_GNUC_BEGIN_IGNORE_DEPRECATIONS
39
40static void
41test_script_tags (void)
42{
43 gunichar ch;
44 PangoScript i, max_script;
45
46 /* we need to know what the maximum script number is. but we don't
47 * provide an api for that. instead of looking into internal tables,
48 * we'll go over all chars and see what their script is, taking the max!
49 */
50
51 max_script = PANGO_SCRIPT_INVALID_CODE;
52 for (ch = 0; ch <= 0x10FFFF; ch++)
53 max_script = MAX (max_script, pango_script_for_unichar (ch));
54
55 for (i = PANGO_SCRIPT_COMMON; i <= max_script; i++)
56 {
57 PangoOTTag tag = pango_ot_tag_from_script (script: i);
58 PangoScript j = pango_ot_tag_to_script (script_tag: tag);
59
60 if (tag == FT_MAKE_TAG ('k', 'a', 'n', 'a'))
61 {
62 /* Hiragana and Katakana both map to tag 'kana' */
63 ASSERT (i == PANGO_SCRIPT_HIRAGANA || i == PANGO_SCRIPT_KATAKANA);
64 ASSERT (j == PANGO_SCRIPT_HIRAGANA || j == PANGO_SCRIPT_KATAKANA);
65 }
66 else
67 {
68 if (j != i)
69 g_error ("Got back %d for script %d (OT tag '%c%c%c%c')", j, i,
70 tag>>24, (tag>>16)&255, (tag>>8)&255, tag&255);
71 }
72 }
73
74 ASSERT (pango_ot_tag_to_script (FT_MAKE_TAG ('X', 'Y', 'Z', ' ')) == PANGO_SCRIPT_UNKNOWN);
75}
76
77static void
78test_language_tags (void)
79{
80 /* just test it for a few known languages to make sure it's working */
81 const char languages[][6] = {
82 "xy", /* hopefully nonexistent */
83 "aa",
84 "az_IR",
85 "en",
86 "en_US",
87 "fa",
88 "fa_IR",
89 "fr",
90 "zh_CN",
91 "zu"
92 };
93 unsigned int i;
94
95 for (i = 0; i < G_N_ELEMENTS (languages); i++)
96 {
97 PangoLanguage *l = pango_language_from_string (language: languages[i]);
98 PangoOTTag tag = pango_ot_tag_from_language (language: l);
99#if 0
100 PangoLanguage *m = pango_ot_tag_to_language (tag);
101#endif
102
103 if (i == 0)
104 {
105 ASSERT (tag == PANGO_OT_TAG_DEFAULT_LANGUAGE);
106 }
107 else
108 {
109 if (tag == PANGO_OT_TAG_DEFAULT_LANGUAGE)
110 g_error ("Got PANGO_OT_TAG_DEFAULT_LANGUAGE for language '%s'", pango_language_to_string (l));
111
112 /* The following test can't work without proper BCP 47 language tag
113 * support. So, disable it. */
114#if 0
115 if (!pango_language_matches (l, pango_language_to_string (m)))
116 g_error ("Got back %s for language %s (OT tag '%c%c%c%c')",
117 pango_language_to_string (m), pango_language_to_string (l),
118 tag>>24, (tag>>16)&255, (tag>>8)&255, tag&255);
119#endif
120 }
121 }
122}
123
124int
125main (int argc, char **argv)
126{
127 g_test_init (argc: &argc, argv: &argv, NULL);
128
129 g_test_add_func (testpath: "/tags/script", test_func: test_script_tags);
130 g_test_add_func (testpath: "/tags/language", test_func: test_language_tags);
131
132 return g_test_run ();
133}
134
135G_GNUC_END_IGNORE_DEPRECATIONS
136

source code of gtk/subprojects/pango/tests/test-ot-tags.c