Add some more cases to the app-id unit tests
[glib.git] / glib / tests / unicode.c
blob36b732acc7c635ddb5543bf2216c15c7660eb902
1 /* Unit tests for utilities
2 * Copyright (C) 2010 Red Hat, Inc.
3 * Copyright (C) 2011 Google, Inc.
5 * This work is provided "as is"; redistribution and modification
6 * in whole or in part, in any medium, physical or electronic is
7 * permitted without restriction.
9 * This work is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * In no event shall the authors or contributors be liable for any
14 * direct, indirect, incidental, special, exemplary, or consequential
15 * damages (including, but not limited to, procurement of substitute
16 * goods or services; loss of use, data, or profits; or business
17 * interruption) however caused and on any theory of liability, whether
18 * in contract, strict liability, or tort (including negligence or
19 * otherwise) arising in any way out of the use of this software, even
20 * if advised of the possibility of such damage.
22 * Author: Matthias Clasen, Behdad Esfahbod
25 /* We are testing some deprecated APIs here */
26 #define GLIB_DISABLE_DEPRECATION_WARNINGS
28 #include "glib.h"
30 static void
31 test_unichar_validate (void)
33 g_assert (g_unichar_validate ('j'));
34 g_assert (g_unichar_validate (8356));
35 g_assert (g_unichar_validate (8356));
36 g_assert (g_unichar_validate (0xfdd1));
37 g_assert (g_unichar_validate (917760));
38 g_assert (!g_unichar_validate (0x110000));
41 static void
42 test_unichar_character_type (void)
44 guint i;
45 struct {
46 GUnicodeType type;
47 gunichar c;
48 } examples[] = {
49 { G_UNICODE_CONTROL, 0x000D },
50 { G_UNICODE_FORMAT, 0x200E },
51 /* G_UNICODE_UNASSIGNED */
52 { G_UNICODE_PRIVATE_USE, 0xE000 },
53 { G_UNICODE_SURROGATE, 0xD800 },
54 { G_UNICODE_LOWERCASE_LETTER, 0x0061 },
55 { G_UNICODE_MODIFIER_LETTER, 0x02B0 },
56 { G_UNICODE_OTHER_LETTER, 0x3400 },
57 { G_UNICODE_TITLECASE_LETTER, 0x01C5 },
58 { G_UNICODE_UPPERCASE_LETTER, 0xFF21 },
59 { G_UNICODE_COMBINING_MARK, 0x0903 },
60 { G_UNICODE_ENCLOSING_MARK, 0x20DD },
61 { G_UNICODE_NON_SPACING_MARK, 0xA806 },
62 { G_UNICODE_DECIMAL_NUMBER, 0xFF10 },
63 { G_UNICODE_LETTER_NUMBER, 0x16EE },
64 { G_UNICODE_OTHER_NUMBER, 0x17F0 },
65 { G_UNICODE_CONNECT_PUNCTUATION, 0x005F },
66 { G_UNICODE_DASH_PUNCTUATION, 0x058A },
67 { G_UNICODE_CLOSE_PUNCTUATION, 0x0F3B },
68 { G_UNICODE_FINAL_PUNCTUATION, 0x2019 },
69 { G_UNICODE_INITIAL_PUNCTUATION, 0x2018 },
70 { G_UNICODE_OTHER_PUNCTUATION, 0x2016 },
71 { G_UNICODE_OPEN_PUNCTUATION, 0x0F3A },
72 { G_UNICODE_CURRENCY_SYMBOL, 0x20A0 },
73 { G_UNICODE_MODIFIER_SYMBOL, 0x309B },
74 { G_UNICODE_MATH_SYMBOL, 0xFB29 },
75 { G_UNICODE_OTHER_SYMBOL, 0x00A6 },
76 { G_UNICODE_LINE_SEPARATOR, 0x2028 },
77 { G_UNICODE_PARAGRAPH_SEPARATOR, 0x2029 },
78 { G_UNICODE_SPACE_SEPARATOR, 0x202F },
81 for (i = 0; i < G_N_ELEMENTS (examples); i++)
83 g_assert_cmpint (g_unichar_type (examples[i].c), ==, examples[i].type);
87 static void
88 test_unichar_break_type (void)
90 guint i;
91 struct {
92 GUnicodeBreakType type;
93 gunichar c;
94 } examples[] = {
95 { G_UNICODE_BREAK_MANDATORY, 0x2028 },
96 { G_UNICODE_BREAK_CARRIAGE_RETURN, 0x000D },
97 { G_UNICODE_BREAK_LINE_FEED, 0x000A },
98 { G_UNICODE_BREAK_COMBINING_MARK, 0x0300 },
99 { G_UNICODE_BREAK_SURROGATE, 0xD800 },
100 { G_UNICODE_BREAK_ZERO_WIDTH_SPACE, 0x200B },
101 { G_UNICODE_BREAK_INSEPARABLE, 0x2024 },
102 { G_UNICODE_BREAK_NON_BREAKING_GLUE, 0x00A0 },
103 { G_UNICODE_BREAK_CONTINGENT, 0xFFFC },
104 { G_UNICODE_BREAK_SPACE, 0x0020 },
105 { G_UNICODE_BREAK_AFTER, 0x05BE },
106 { G_UNICODE_BREAK_BEFORE, 0x02C8 },
107 { G_UNICODE_BREAK_BEFORE_AND_AFTER, 0x2014 },
108 { G_UNICODE_BREAK_HYPHEN, 0x002D },
109 { G_UNICODE_BREAK_NON_STARTER, 0x17D6 },
110 { G_UNICODE_BREAK_OPEN_PUNCTUATION, 0x0028 },
111 { G_UNICODE_BREAK_CLOSE_PARANTHESIS, 0x0029 },
112 { G_UNICODE_BREAK_CLOSE_PUNCTUATION, 0x007D },
113 { G_UNICODE_BREAK_QUOTATION, 0x0022 },
114 { G_UNICODE_BREAK_EXCLAMATION, 0x0021 },
115 { G_UNICODE_BREAK_IDEOGRAPHIC, 0x2E80 },
116 { G_UNICODE_BREAK_NUMERIC, 0x0030 },
117 { G_UNICODE_BREAK_INFIX_SEPARATOR, 0x002C },
118 { G_UNICODE_BREAK_SYMBOL, 0x002F },
119 { G_UNICODE_BREAK_ALPHABETIC, 0x0023 },
120 { G_UNICODE_BREAK_PREFIX, 0x0024 },
121 { G_UNICODE_BREAK_POSTFIX, 0x0025 },
122 { G_UNICODE_BREAK_COMPLEX_CONTEXT, 0x0E01 },
123 { G_UNICODE_BREAK_AMBIGUOUS, 0x00F7 },
124 { G_UNICODE_BREAK_UNKNOWN, 0xE000 },
125 { G_UNICODE_BREAK_NEXT_LINE, 0x0085 },
126 { G_UNICODE_BREAK_WORD_JOINER, 0x2060 },
127 { G_UNICODE_BREAK_HANGUL_L_JAMO, 0x1100 },
128 { G_UNICODE_BREAK_HANGUL_V_JAMO, 0x1160 },
129 { G_UNICODE_BREAK_HANGUL_T_JAMO, 0x11A8 },
130 { G_UNICODE_BREAK_HANGUL_LV_SYLLABLE, 0xAC00 },
131 { G_UNICODE_BREAK_HANGUL_LVT_SYLLABLE, 0xAC01 },
132 { G_UNICODE_BREAK_CONDITIONAL_JAPANESE_STARTER, 0x3041 },
133 { G_UNICODE_BREAK_HEBREW_LETTER, 0x05D0 },
134 { G_UNICODE_BREAK_REGIONAL_INDICATOR, 0x1F1F6 },
135 { G_UNICODE_BREAK_EMOJI_BASE, 0x1F466 },
136 { G_UNICODE_BREAK_EMOJI_MODIFIER, 0x1F3FB },
137 { G_UNICODE_BREAK_ZERO_WIDTH_JOINER, 0x200D },
140 for (i = 0; i < G_N_ELEMENTS (examples); i++)
142 g_assert_cmpint (g_unichar_break_type (examples[i].c), ==, examples[i].type);
146 static void
147 test_unichar_script (void)
149 guint i;
150 struct {
151 GUnicodeScript script;
152 gunichar c;
153 } examples[] = {
154 { G_UNICODE_SCRIPT_COMMON, 0x002A },
155 { G_UNICODE_SCRIPT_INHERITED, 0x1CED },
156 { G_UNICODE_SCRIPT_INHERITED, 0x0670 },
157 { G_UNICODE_SCRIPT_ARABIC, 0x060D },
158 { G_UNICODE_SCRIPT_ARMENIAN, 0x0559 },
159 { G_UNICODE_SCRIPT_BENGALI, 0x09CD },
160 { G_UNICODE_SCRIPT_BOPOMOFO, 0x31B6 },
161 { G_UNICODE_SCRIPT_CHEROKEE, 0x13A2 },
162 { G_UNICODE_SCRIPT_COPTIC, 0x2CFD },
163 { G_UNICODE_SCRIPT_CYRILLIC, 0x0482 },
164 { G_UNICODE_SCRIPT_DESERET, 0x10401 },
165 { G_UNICODE_SCRIPT_DEVANAGARI, 0x094D },
166 { G_UNICODE_SCRIPT_ETHIOPIC, 0x1258 },
167 { G_UNICODE_SCRIPT_GEORGIAN, 0x10FC },
168 { G_UNICODE_SCRIPT_GOTHIC, 0x10341 },
169 { G_UNICODE_SCRIPT_GREEK, 0x0375 },
170 { G_UNICODE_SCRIPT_GUJARATI, 0x0A83 },
171 { G_UNICODE_SCRIPT_GURMUKHI, 0x0A3C },
172 { G_UNICODE_SCRIPT_HAN, 0x3005 },
173 { G_UNICODE_SCRIPT_HANGUL, 0x1100 },
174 { G_UNICODE_SCRIPT_HEBREW, 0x05BF },
175 { G_UNICODE_SCRIPT_HIRAGANA, 0x309F },
176 { G_UNICODE_SCRIPT_KANNADA, 0x0CBC },
177 { G_UNICODE_SCRIPT_KATAKANA, 0x30FF },
178 { G_UNICODE_SCRIPT_KHMER, 0x17DD },
179 { G_UNICODE_SCRIPT_LAO, 0x0EDD },
180 { G_UNICODE_SCRIPT_LATIN, 0x0061 },
181 { G_UNICODE_SCRIPT_MALAYALAM, 0x0D3D },
182 { G_UNICODE_SCRIPT_MONGOLIAN, 0x1843 },
183 { G_UNICODE_SCRIPT_MYANMAR, 0x1031 },
184 { G_UNICODE_SCRIPT_OGHAM, 0x169C },
185 { G_UNICODE_SCRIPT_OLD_ITALIC, 0x10322 },
186 { G_UNICODE_SCRIPT_ORIYA, 0x0B3C },
187 { G_UNICODE_SCRIPT_RUNIC, 0x16EF },
188 { G_UNICODE_SCRIPT_SINHALA, 0x0DBD },
189 { G_UNICODE_SCRIPT_SYRIAC, 0x0711 },
190 { G_UNICODE_SCRIPT_TAMIL, 0x0B82 },
191 { G_UNICODE_SCRIPT_TELUGU, 0x0C03 },
192 { G_UNICODE_SCRIPT_THAANA, 0x07B1 },
193 { G_UNICODE_SCRIPT_THAI, 0x0E31 },
194 { G_UNICODE_SCRIPT_TIBETAN, 0x0FD4 },
195 { G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL, 0x1400 },
196 { G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL, 0x1401 },
197 { G_UNICODE_SCRIPT_YI, 0xA015 },
198 { G_UNICODE_SCRIPT_TAGALOG, 0x1700 },
199 { G_UNICODE_SCRIPT_HANUNOO, 0x1720 },
200 { G_UNICODE_SCRIPT_BUHID, 0x1740 },
201 { G_UNICODE_SCRIPT_TAGBANWA, 0x1760 },
202 { G_UNICODE_SCRIPT_BRAILLE, 0x2800 },
203 { G_UNICODE_SCRIPT_CYPRIOT, 0x10808 },
204 { G_UNICODE_SCRIPT_LIMBU, 0x1932 },
205 { G_UNICODE_SCRIPT_OSMANYA, 0x10480 },
206 { G_UNICODE_SCRIPT_SHAVIAN, 0x10450 },
207 { G_UNICODE_SCRIPT_LINEAR_B, 0x10000 },
208 { G_UNICODE_SCRIPT_TAI_LE, 0x1950 },
209 { G_UNICODE_SCRIPT_UGARITIC, 0x1039F },
210 { G_UNICODE_SCRIPT_NEW_TAI_LUE, 0x1980 },
211 { G_UNICODE_SCRIPT_BUGINESE, 0x1A1F },
212 { G_UNICODE_SCRIPT_GLAGOLITIC, 0x2C00 },
213 { G_UNICODE_SCRIPT_TIFINAGH, 0x2D6F },
214 { G_UNICODE_SCRIPT_SYLOTI_NAGRI, 0xA800 },
215 { G_UNICODE_SCRIPT_OLD_PERSIAN, 0x103D0 },
216 { G_UNICODE_SCRIPT_KHAROSHTHI, 0x10A3F },
217 { G_UNICODE_SCRIPT_UNKNOWN, 0x1111111 },
218 { G_UNICODE_SCRIPT_BALINESE, 0x1B04 },
219 { G_UNICODE_SCRIPT_CUNEIFORM, 0x12000 },
220 { G_UNICODE_SCRIPT_PHOENICIAN, 0x10900 },
221 { G_UNICODE_SCRIPT_PHAGS_PA, 0xA840 },
222 { G_UNICODE_SCRIPT_NKO, 0x07C0 },
223 { G_UNICODE_SCRIPT_KAYAH_LI, 0xA900 },
224 { G_UNICODE_SCRIPT_LEPCHA, 0x1C00 },
225 { G_UNICODE_SCRIPT_REJANG, 0xA930 },
226 { G_UNICODE_SCRIPT_SUNDANESE, 0x1B80 },
227 { G_UNICODE_SCRIPT_SAURASHTRA, 0xA880 },
228 { G_UNICODE_SCRIPT_CHAM, 0xAA00 },
229 { G_UNICODE_SCRIPT_OL_CHIKI, 0x1C50 },
230 { G_UNICODE_SCRIPT_VAI, 0xA500 },
231 { G_UNICODE_SCRIPT_CARIAN, 0x102A0 },
232 { G_UNICODE_SCRIPT_LYCIAN, 0x10280 },
233 { G_UNICODE_SCRIPT_LYDIAN, 0x1093F },
234 { G_UNICODE_SCRIPT_AVESTAN, 0x10B00 },
235 { G_UNICODE_SCRIPT_BAMUM, 0xA6A0 },
236 { G_UNICODE_SCRIPT_EGYPTIAN_HIEROGLYPHS, 0x13000 },
237 { G_UNICODE_SCRIPT_IMPERIAL_ARAMAIC, 0x10840 },
238 { G_UNICODE_SCRIPT_INSCRIPTIONAL_PAHLAVI, 0x10B60 },
239 { G_UNICODE_SCRIPT_INSCRIPTIONAL_PARTHIAN, 0x10B40 },
240 { G_UNICODE_SCRIPT_JAVANESE, 0xA980 },
241 { G_UNICODE_SCRIPT_KAITHI, 0x11082 },
242 { G_UNICODE_SCRIPT_LISU, 0xA4D0 },
243 { G_UNICODE_SCRIPT_MEETEI_MAYEK, 0xABE5 },
244 { G_UNICODE_SCRIPT_OLD_SOUTH_ARABIAN, 0x10A60 },
245 { G_UNICODE_SCRIPT_OLD_TURKIC, 0x10C00 },
246 { G_UNICODE_SCRIPT_SAMARITAN, 0x0800 },
247 { G_UNICODE_SCRIPT_TAI_THAM, 0x1A20 },
248 { G_UNICODE_SCRIPT_TAI_VIET, 0xAA80 },
249 { G_UNICODE_SCRIPT_BATAK, 0x1BC0 },
250 { G_UNICODE_SCRIPT_BRAHMI, 0x11000 },
251 { G_UNICODE_SCRIPT_MANDAIC, 0x0840 },
252 { G_UNICODE_SCRIPT_CHAKMA, 0x11100 },
253 { G_UNICODE_SCRIPT_MEROITIC_CURSIVE, 0x109A0 },
254 { G_UNICODE_SCRIPT_MEROITIC_HIEROGLYPHS, 0x10980 },
255 { G_UNICODE_SCRIPT_MIAO, 0x16F00 },
256 { G_UNICODE_SCRIPT_SHARADA, 0x11180 },
257 { G_UNICODE_SCRIPT_SORA_SOMPENG, 0x110D0 },
258 { G_UNICODE_SCRIPT_TAKRI, 0x11680 },
259 { G_UNICODE_SCRIPT_BASSA_VAH, 0x16AD0 },
260 { G_UNICODE_SCRIPT_CAUCASIAN_ALBANIAN, 0x10530 },
261 { G_UNICODE_SCRIPT_DUPLOYAN, 0x1BC00 },
262 { G_UNICODE_SCRIPT_ELBASAN, 0x10500 },
263 { G_UNICODE_SCRIPT_GRANTHA, 0x11301 },
264 { G_UNICODE_SCRIPT_KHOJKI, 0x11200 },
265 { G_UNICODE_SCRIPT_KHUDAWADI, 0x112B0 },
266 { G_UNICODE_SCRIPT_LINEAR_A, 0x10600 },
267 { G_UNICODE_SCRIPT_MAHAJANI, 0x11150 },
268 { G_UNICODE_SCRIPT_MANICHAEAN, 0x10AC0 },
269 { G_UNICODE_SCRIPT_MENDE_KIKAKUI, 0x1E800 },
270 { G_UNICODE_SCRIPT_MODI, 0x11600 },
271 { G_UNICODE_SCRIPT_MRO, 0x16A40 },
272 { G_UNICODE_SCRIPT_NABATAEAN, 0x10880 },
273 { G_UNICODE_SCRIPT_OLD_NORTH_ARABIAN, 0x10A80 },
274 { G_UNICODE_SCRIPT_OLD_PERMIC, 0x10350 },
275 { G_UNICODE_SCRIPT_PAHAWH_HMONG, 0x16B00 },
276 { G_UNICODE_SCRIPT_PALMYRENE, 0x10860 },
277 { G_UNICODE_SCRIPT_PAU_CIN_HAU, 0x11AC0 },
278 { G_UNICODE_SCRIPT_PSALTER_PAHLAVI, 0x10B80 },
279 { G_UNICODE_SCRIPT_SIDDHAM, 0x11580 },
280 { G_UNICODE_SCRIPT_TIRHUTA, 0x11480 },
281 { G_UNICODE_SCRIPT_WARANG_CITI, 0x118A0 },
282 { G_UNICODE_SCRIPT_CHEROKEE, 0x0AB71 },
283 { G_UNICODE_SCRIPT_HATRAN, 0x108E0 },
284 { G_UNICODE_SCRIPT_OLD_HUNGARIAN, 0x10C80 },
285 { G_UNICODE_SCRIPT_MULTANI, 0x11280 },
286 { G_UNICODE_SCRIPT_AHOM, 0x11700 },
287 { G_UNICODE_SCRIPT_CUNEIFORM, 0x12480 },
288 { G_UNICODE_SCRIPT_ANATOLIAN_HIEROGLYPHS, 0x14400 },
289 { G_UNICODE_SCRIPT_SIGNWRITING, 0x1D800 },
290 { G_UNICODE_SCRIPT_ADLAM, 0x1E900 },
291 { G_UNICODE_SCRIPT_BHAIKSUKI, 0x11C00 },
292 { G_UNICODE_SCRIPT_MARCHEN, 0x11C70 },
293 { G_UNICODE_SCRIPT_NEWA, 0x11400 },
294 { G_UNICODE_SCRIPT_OSAGE, 0x104B0 },
295 { G_UNICODE_SCRIPT_TANGUT, 0x16FE0 },
297 for (i = 0; i < G_N_ELEMENTS (examples); i++)
298 g_assert_cmpint (g_unichar_get_script (examples[i].c), ==, examples[i].script);
301 static void
302 test_combining_class (void)
304 guint i;
305 struct {
306 gint class;
307 gunichar c;
308 } examples[] = {
309 { 0, 0x0020 },
310 { 1, 0x0334 },
311 { 7, 0x093C },
312 { 8, 0x3099 },
313 { 9, 0x094D },
314 { 10, 0x05B0 },
315 { 11, 0x05B1 },
316 { 12, 0x05B2 },
317 { 13, 0x05B3 },
318 { 14, 0x05B4 },
319 { 15, 0x05B5 },
320 { 16, 0x05B6 },
321 { 17, 0x05B7 },
322 { 18, 0x05B8 },
323 { 19, 0x05B9 },
324 { 20, 0x05BB },
325 { 21, 0x05BC },
326 { 22, 0x05BD },
327 { 23, 0x05BF },
328 { 24, 0x05C1 },
329 { 25, 0x05C2 },
330 { 26, 0xFB1E },
331 { 27, 0x064B },
332 { 28, 0x064C },
333 { 29, 0x064D },
334 /* ... */
335 { 228, 0x05AE },
336 { 230, 0x0300 },
337 { 232, 0x302C },
338 { 233, 0x0362 },
339 { 234, 0x0360 },
340 { 234, 0x1DCD },
341 { 240, 0x0345 }
343 for (i = 0; i < G_N_ELEMENTS (examples); i++)
345 g_assert_cmpint (g_unichar_combining_class (examples[i].c), ==, examples[i].class);
349 static void
350 test_mirror (void)
352 gunichar mirror;
354 g_assert (g_unichar_get_mirror_char ('(', &mirror));
355 g_assert_cmpint (mirror, ==, ')');
356 g_assert (g_unichar_get_mirror_char (')', &mirror));
357 g_assert_cmpint (mirror, ==, '(');
358 g_assert (g_unichar_get_mirror_char ('{', &mirror));
359 g_assert_cmpint (mirror, ==, '}');
360 g_assert (g_unichar_get_mirror_char ('}', &mirror));
361 g_assert_cmpint (mirror, ==, '{');
362 g_assert (g_unichar_get_mirror_char (0x208D, &mirror));
363 g_assert_cmpint (mirror, ==, 0x208E);
364 g_assert (g_unichar_get_mirror_char (0x208E, &mirror));
365 g_assert_cmpint (mirror, ==, 0x208D);
366 g_assert (!g_unichar_get_mirror_char ('a', &mirror));
369 static void
370 test_mark (void)
372 g_assert (g_unichar_ismark (0x0903));
373 g_assert (g_unichar_ismark (0x20DD));
374 g_assert (g_unichar_ismark (0xA806));
375 g_assert (!g_unichar_ismark ('a'));
378 static void
379 test_zerowidth (void)
381 g_assert (!g_unichar_iszerowidth (0x00AD));
382 g_assert (!g_unichar_iszerowidth (0x00AD));
383 g_assert (!g_unichar_iszerowidth (0x115F));
384 g_assert (g_unichar_iszerowidth (0x1160));
385 g_assert (g_unichar_iszerowidth (0x11AA));
386 g_assert (g_unichar_iszerowidth (0x11FF));
387 g_assert (!g_unichar_iszerowidth (0x1200));
388 g_assert (g_unichar_iszerowidth (0x200B));
389 g_assert (g_unichar_iszerowidth (0x591));
392 static void
393 test_title (void)
395 g_assert (g_unichar_istitle (0x01c5));
396 g_assert (g_unichar_istitle (0x1f88));
397 g_assert (g_unichar_istitle (0x1fcc));
398 g_assert (!g_unichar_istitle ('a'));
399 g_assert (!g_unichar_istitle ('A'));
401 g_assert_cmphex (g_unichar_totitle (0x01c6), ==, 0x01c5);
402 g_assert_cmphex (g_unichar_totitle (0x01c4), ==, 0x01c5);
403 g_assert_cmphex (g_unichar_totitle (0x01c5), ==, 0x01c5);
404 g_assert_cmphex (g_unichar_totitle (0x1f80), ==, 0x1f88);
405 g_assert_cmphex (g_unichar_totitle (0x1f88), ==, 0x1f88);
406 g_assert_cmphex (g_unichar_totitle ('a'), ==, 'A');
407 g_assert_cmphex (g_unichar_totitle ('A'), ==, 'A');
410 static void
411 test_cases (void)
413 g_assert_cmphex (g_unichar_toupper ('a'), ==, 'A');
414 g_assert_cmphex (g_unichar_toupper ('A'), ==, 'A');
415 g_assert_cmphex (g_unichar_toupper (0x01C5), ==, 0x01C4);
416 g_assert_cmphex (g_unichar_toupper (0x01C6), ==, 0x01C4);
417 g_assert_cmphex (g_unichar_tolower ('A'), ==, 'a');
418 g_assert_cmphex (g_unichar_tolower ('a'), ==, 'a');
419 g_assert_cmphex (g_unichar_tolower (0x01C4), ==, 0x01C6);
420 g_assert_cmphex (g_unichar_tolower (0x01C5), ==, 0x01C6);
421 g_assert_cmphex (g_unichar_tolower (0x1F8A), ==, 0x1F82);
422 g_assert_cmphex (g_unichar_totitle (0x1F8A), ==, 0x1F8A);
423 g_assert_cmphex (g_unichar_toupper (0x1F8A), ==, 0x1F8A);
424 g_assert_cmphex (g_unichar_tolower (0x1FB2), ==, 0x1FB2);
425 g_assert_cmphex (g_unichar_toupper (0x1FB2), ==, 0x1FB2);
428 static void
429 test_defined (void)
431 g_assert (g_unichar_isdefined (0x0903));
432 g_assert (g_unichar_isdefined (0x20DD));
433 g_assert (g_unichar_isdefined (0x20BA));
434 g_assert (g_unichar_isdefined (0xA806));
435 g_assert (g_unichar_isdefined ('a'));
436 g_assert (!g_unichar_isdefined (0x10C49));
437 g_assert (!g_unichar_isdefined (0x169D));
440 static void
441 test_wide (void)
443 guint i;
444 struct {
445 gunichar c;
446 enum {
447 NOT_WIDE,
448 WIDE_CJK,
449 WIDE
450 } wide;
451 } examples[] = {
452 /* Neutral */
453 { 0x0000, NOT_WIDE },
454 { 0x0483, NOT_WIDE },
455 { 0x0641, NOT_WIDE },
456 { 0xFFFC, NOT_WIDE },
457 { 0x10000, NOT_WIDE },
458 { 0xE0001, NOT_WIDE },
459 { 0x2FFFE, NOT_WIDE },
460 { 0x3FFFE, NOT_WIDE },
462 /* Narrow */
463 { 0x0020, NOT_WIDE },
464 { 0x0041, NOT_WIDE },
465 { 0x27E6, NOT_WIDE },
467 /* Halfwidth */
468 { 0x20A9, NOT_WIDE },
469 { 0xFF61, NOT_WIDE },
470 { 0xFF69, NOT_WIDE },
471 { 0xFFEE, NOT_WIDE },
473 /* Ambiguous */
474 { 0x00A1, WIDE_CJK },
475 { 0x00BE, WIDE_CJK },
476 { 0x02DD, WIDE_CJK },
477 { 0x2020, WIDE_CJK },
478 { 0xFFFD, WIDE_CJK },
479 { 0x00A1, WIDE_CJK },
480 { 0x1F100, WIDE_CJK },
481 { 0xE0100, WIDE_CJK },
482 { 0x100000, WIDE_CJK },
483 { 0x10FFFD, WIDE_CJK },
485 /* Fullwidth */
486 { 0x3000, WIDE },
487 { 0xFF60, WIDE },
489 /* Wide */
490 { 0x2329, WIDE },
491 { 0x3001, WIDE },
492 { 0xFE69, WIDE },
493 { 0x30000, WIDE },
494 { 0x3FFFD, WIDE },
496 /* Default Wide blocks */
497 { 0x4DBF, WIDE },
498 { 0x9FFF, WIDE },
499 { 0xFAFF, WIDE },
500 { 0x2A6DF, WIDE },
501 { 0x2B73F, WIDE },
502 { 0x2B81F, WIDE },
503 { 0x2FA1F, WIDE },
505 /* Uniode-5.2 character additions */
506 /* Wide */
507 { 0x115F, WIDE },
509 /* Uniode-6.0 character additions */
510 /* Wide */
511 { 0x2B740, WIDE },
512 { 0x1B000, WIDE },
514 { 0x111111, NOT_WIDE }
517 for (i = 0; i < G_N_ELEMENTS (examples); i++)
519 g_assert_cmpint (g_unichar_iswide (examples[i].c), ==, (examples[i].wide == WIDE));
520 g_assert_cmpint (g_unichar_iswide_cjk (examples[i].c), ==, (examples[i].wide != NOT_WIDE));
524 static void
525 test_compose (void)
527 gunichar ch;
529 /* Not composable */
530 g_assert (!g_unichar_compose (0x0041, 0x0042, &ch) && ch == 0);
531 g_assert (!g_unichar_compose (0x0041, 0, &ch) && ch == 0);
532 g_assert (!g_unichar_compose (0x0066, 0x0069, &ch) && ch == 0);
534 /* Tricky non-composable */
535 g_assert (!g_unichar_compose (0x0308, 0x0301, &ch) && ch == 0); /* !0x0344 */
536 g_assert (!g_unichar_compose (0x0F71, 0x0F72, &ch) && ch == 0); /* !0x0F73 */
538 /* Singletons should not compose */
539 g_assert (!g_unichar_compose (0x212B, 0, &ch) && ch == 0);
540 g_assert (!g_unichar_compose (0x00C5, 0, &ch) && ch == 0);
541 g_assert (!g_unichar_compose (0x2126, 0, &ch) && ch == 0);
542 g_assert (!g_unichar_compose (0x03A9, 0, &ch) && ch == 0);
544 /* Pairs */
545 g_assert (g_unichar_compose (0x0041, 0x030A, &ch) && ch == 0x00C5);
546 g_assert (g_unichar_compose (0x006F, 0x0302, &ch) && ch == 0x00F4);
547 g_assert (g_unichar_compose (0x1E63, 0x0307, &ch) && ch == 0x1E69);
548 g_assert (g_unichar_compose (0x0073, 0x0323, &ch) && ch == 0x1E63);
549 g_assert (g_unichar_compose (0x0064, 0x0307, &ch) && ch == 0x1E0B);
550 g_assert (g_unichar_compose (0x0064, 0x0323, &ch) && ch == 0x1E0D);
552 /* Hangul */
553 g_assert (g_unichar_compose (0xD4CC, 0x11B6, &ch) && ch == 0xD4DB);
554 g_assert (g_unichar_compose (0x1111, 0x1171, &ch) && ch == 0xD4CC);
555 g_assert (g_unichar_compose (0xCE20, 0x11B8, &ch) && ch == 0xCE31);
556 g_assert (g_unichar_compose (0x110E, 0x1173, &ch) && ch == 0xCE20);
559 static void
560 test_decompose (void)
562 gunichar a, b;
564 /* Not decomposable */
565 g_assert (!g_unichar_decompose (0x0041, &a, &b) && a == 0x0041 && b == 0);
566 g_assert (!g_unichar_decompose (0xFB01, &a, &b) && a == 0xFB01 && b == 0);
568 /* Singletons */
569 g_assert (g_unichar_decompose (0x212B, &a, &b) && a == 0x00C5 && b == 0);
570 g_assert (g_unichar_decompose (0x2126, &a, &b) && a == 0x03A9 && b == 0);
572 /* Tricky pairs */
573 g_assert (g_unichar_decompose (0x0344, &a, &b) && a == 0x0308 && b == 0x0301);
574 g_assert (g_unichar_decompose (0x0F73, &a, &b) && a == 0x0F71 && b == 0x0F72);
576 /* Pairs */
577 g_assert (g_unichar_decompose (0x00C5, &a, &b) && a == 0x0041 && b == 0x030A);
578 g_assert (g_unichar_decompose (0x00F4, &a, &b) && a == 0x006F && b == 0x0302);
579 g_assert (g_unichar_decompose (0x1E69, &a, &b) && a == 0x1E63 && b == 0x0307);
580 g_assert (g_unichar_decompose (0x1E63, &a, &b) && a == 0x0073 && b == 0x0323);
581 g_assert (g_unichar_decompose (0x1E0B, &a, &b) && a == 0x0064 && b == 0x0307);
582 g_assert (g_unichar_decompose (0x1E0D, &a, &b) && a == 0x0064 && b == 0x0323);
584 /* Hangul */
585 g_assert (g_unichar_decompose (0xD4DB, &a, &b) && a == 0xD4CC && b == 0x11B6);
586 g_assert (g_unichar_decompose (0xD4CC, &a, &b) && a == 0x1111 && b == 0x1171);
587 g_assert (g_unichar_decompose (0xCE31, &a, &b) && a == 0xCE20 && b == 0x11B8);
588 g_assert (g_unichar_decompose (0xCE20, &a, &b) && a == 0x110E && b == 0x1173);
591 static void
592 test_fully_decompose_canonical (void)
594 gunichar decomp[5];
595 gsize len;
597 #define TEST_DECOMP(ch, expected_len, a, b, c, d) \
598 len = g_unichar_fully_decompose (ch, FALSE, decomp, G_N_ELEMENTS (decomp)); \
599 g_assert_cmpint (expected_len, ==, len); \
600 if (expected_len >= 1) g_assert_cmphex (decomp[0], ==, a); \
601 if (expected_len >= 2) g_assert_cmphex (decomp[1], ==, b); \
602 if (expected_len >= 3) g_assert_cmphex (decomp[2], ==, c); \
603 if (expected_len >= 4) g_assert_cmphex (decomp[3], ==, d); \
605 #define TEST0(ch) TEST_DECOMP (ch, 1, ch, 0, 0, 0)
606 #define TEST1(ch, a) TEST_DECOMP (ch, 1, a, 0, 0, 0)
607 #define TEST2(ch, a, b) TEST_DECOMP (ch, 2, a, b, 0, 0)
608 #define TEST3(ch, a, b, c) TEST_DECOMP (ch, 3, a, b, c, 0)
609 #define TEST4(ch, a, b, c, d) TEST_DECOMP (ch, 4, a, b, c, d)
611 /* Not decomposable */
612 TEST0 (0x0041);
613 TEST0 (0xFB01);
615 /* Singletons */
616 TEST2 (0x212B, 0x0041, 0x030A);
617 TEST1 (0x2126, 0x03A9);
619 /* Tricky pairs */
620 TEST2 (0x0344, 0x0308, 0x0301);
621 TEST2 (0x0F73, 0x0F71, 0x0F72);
623 /* General */
624 TEST2 (0x00C5, 0x0041, 0x030A);
625 TEST2 (0x00F4, 0x006F, 0x0302);
626 TEST3 (0x1E69, 0x0073, 0x0323, 0x0307);
627 TEST2 (0x1E63, 0x0073, 0x0323);
628 TEST2 (0x1E0B, 0x0064, 0x0307);
629 TEST2 (0x1E0D, 0x0064, 0x0323);
631 /* Hangul */
632 TEST3 (0xD4DB, 0x1111, 0x1171, 0x11B6);
633 TEST2 (0xD4CC, 0x1111, 0x1171);
634 TEST3 (0xCE31, 0x110E, 0x1173, 0x11B8);
635 TEST2 (0xCE20, 0x110E, 0x1173);
637 #undef TEST_DECOMP
640 static void
641 test_canonical_decomposition (void)
643 gunichar *decomp;
644 gsize len;
646 #define TEST_DECOMP(ch, expected_len, a, b, c, d) \
647 decomp = g_unicode_canonical_decomposition (ch, &len); \
648 g_assert_cmpint (expected_len, ==, len); \
649 if (expected_len >= 1) g_assert_cmphex (decomp[0], ==, a); \
650 if (expected_len >= 2) g_assert_cmphex (decomp[1], ==, b); \
651 if (expected_len >= 3) g_assert_cmphex (decomp[2], ==, c); \
652 if (expected_len >= 4) g_assert_cmphex (decomp[3], ==, d); \
653 g_free (decomp);
655 #define TEST0(ch) TEST_DECOMP (ch, 1, ch, 0, 0, 0)
656 #define TEST1(ch, a) TEST_DECOMP (ch, 1, a, 0, 0, 0)
657 #define TEST2(ch, a, b) TEST_DECOMP (ch, 2, a, b, 0, 0)
658 #define TEST3(ch, a, b, c) TEST_DECOMP (ch, 3, a, b, c, 0)
659 #define TEST4(ch, a, b, c, d) TEST_DECOMP (ch, 4, a, b, c, d)
661 /* Not decomposable */
662 TEST0 (0x0041);
663 TEST0 (0xFB01);
665 /* Singletons */
666 TEST2 (0x212B, 0x0041, 0x030A);
667 TEST1 (0x2126, 0x03A9);
669 /* Tricky pairs */
670 TEST2 (0x0344, 0x0308, 0x0301);
671 TEST2 (0x0F73, 0x0F71, 0x0F72);
673 /* General */
674 TEST2 (0x00C5, 0x0041, 0x030A);
675 TEST2 (0x00F4, 0x006F, 0x0302);
676 TEST3 (0x1E69, 0x0073, 0x0323, 0x0307);
677 TEST2 (0x1E63, 0x0073, 0x0323);
678 TEST2 (0x1E0B, 0x0064, 0x0307);
679 TEST2 (0x1E0D, 0x0064, 0x0323);
681 /* Hangul */
682 TEST3 (0xD4DB, 0x1111, 0x1171, 0x11B6);
683 TEST2 (0xD4CC, 0x1111, 0x1171);
684 TEST3 (0xCE31, 0x110E, 0x1173, 0x11B8);
685 TEST2 (0xCE20, 0x110E, 0x1173);
687 #undef TEST_DECOMP
690 static void
691 test_decompose_tail (void)
693 gunichar ch, a, b, c, d;
695 /* Test that whenever a char ch decomposes into a and b, b itself
696 * won't decompose any further. */
698 for (ch = 0; ch < 0x110000; ch++)
699 if (g_unichar_decompose (ch, &a, &b))
700 g_assert (!g_unichar_decompose (b, &c, &d));
701 else
703 g_assert_cmpuint (a, ==, ch);
704 g_assert_cmpuint (b, ==, 0);
708 static void
709 test_fully_decompose_len (void)
711 gunichar ch;
713 /* Test that all canonical decompositions are at most 4 in length,
714 * and compatibility decompositions are at most 18 in length.
717 for (ch = 0; ch < 0x110000; ch++) {
718 g_assert_cmpint (g_unichar_fully_decompose (ch, FALSE, NULL, 0), <=, 4);
719 g_assert_cmpint (g_unichar_fully_decompose (ch, TRUE, NULL, 0), <=, 18);
723 static void
724 test_iso15924 (void)
726 const struct {
727 GUnicodeScript script;
728 char four_letter_code[5];
729 } data[] = {
730 { G_UNICODE_SCRIPT_COMMON, "Zyyy" },
731 { G_UNICODE_SCRIPT_INHERITED, "Zinh" },
732 { G_UNICODE_SCRIPT_ARABIC, "Arab" },
733 { G_UNICODE_SCRIPT_ARMENIAN, "Armn" },
734 { G_UNICODE_SCRIPT_BENGALI, "Beng" },
735 { G_UNICODE_SCRIPT_BOPOMOFO, "Bopo" },
736 { G_UNICODE_SCRIPT_CHEROKEE, "Cher" },
737 { G_UNICODE_SCRIPT_COPTIC, "Copt" },
738 { G_UNICODE_SCRIPT_CYRILLIC, "Cyrl" },
739 { G_UNICODE_SCRIPT_DESERET, "Dsrt" },
740 { G_UNICODE_SCRIPT_DEVANAGARI, "Deva" },
741 { G_UNICODE_SCRIPT_ETHIOPIC, "Ethi" },
742 { G_UNICODE_SCRIPT_GEORGIAN, "Geor" },
743 { G_UNICODE_SCRIPT_GOTHIC, "Goth" },
744 { G_UNICODE_SCRIPT_GREEK, "Grek" },
745 { G_UNICODE_SCRIPT_GUJARATI, "Gujr" },
746 { G_UNICODE_SCRIPT_GURMUKHI, "Guru" },
747 { G_UNICODE_SCRIPT_HAN, "Hani" },
748 { G_UNICODE_SCRIPT_HANGUL, "Hang" },
749 { G_UNICODE_SCRIPT_HEBREW, "Hebr" },
750 { G_UNICODE_SCRIPT_HIRAGANA, "Hira" },
751 { G_UNICODE_SCRIPT_KANNADA, "Knda" },
752 { G_UNICODE_SCRIPT_KATAKANA, "Kana" },
753 { G_UNICODE_SCRIPT_KHMER, "Khmr" },
754 { G_UNICODE_SCRIPT_LAO, "Laoo" },
755 { G_UNICODE_SCRIPT_LATIN, "Latn" },
756 { G_UNICODE_SCRIPT_MALAYALAM, "Mlym" },
757 { G_UNICODE_SCRIPT_MONGOLIAN, "Mong" },
758 { G_UNICODE_SCRIPT_MYANMAR, "Mymr" },
759 { G_UNICODE_SCRIPT_OGHAM, "Ogam" },
760 { G_UNICODE_SCRIPT_OLD_ITALIC, "Ital" },
761 { G_UNICODE_SCRIPT_ORIYA, "Orya" },
762 { G_UNICODE_SCRIPT_RUNIC, "Runr" },
763 { G_UNICODE_SCRIPT_SINHALA, "Sinh" },
764 { G_UNICODE_SCRIPT_SYRIAC, "Syrc" },
765 { G_UNICODE_SCRIPT_TAMIL, "Taml" },
766 { G_UNICODE_SCRIPT_TELUGU, "Telu" },
767 { G_UNICODE_SCRIPT_THAANA, "Thaa" },
768 { G_UNICODE_SCRIPT_THAI, "Thai" },
769 { G_UNICODE_SCRIPT_TIBETAN, "Tibt" },
770 { G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL, "Cans" },
771 { G_UNICODE_SCRIPT_YI, "Yiii" },
772 { G_UNICODE_SCRIPT_TAGALOG, "Tglg" },
773 { G_UNICODE_SCRIPT_HANUNOO, "Hano" },
774 { G_UNICODE_SCRIPT_BUHID, "Buhd" },
775 { G_UNICODE_SCRIPT_TAGBANWA, "Tagb" },
777 /* Unicode-4.0 additions */
778 { G_UNICODE_SCRIPT_BRAILLE, "Brai" },
779 { G_UNICODE_SCRIPT_CYPRIOT, "Cprt" },
780 { G_UNICODE_SCRIPT_LIMBU, "Limb" },
781 { G_UNICODE_SCRIPT_OSMANYA, "Osma" },
782 { G_UNICODE_SCRIPT_SHAVIAN, "Shaw" },
783 { G_UNICODE_SCRIPT_LINEAR_B, "Linb" },
784 { G_UNICODE_SCRIPT_TAI_LE, "Tale" },
785 { G_UNICODE_SCRIPT_UGARITIC, "Ugar" },
787 /* Unicode-4.1 additions */
788 { G_UNICODE_SCRIPT_NEW_TAI_LUE, "Talu" },
789 { G_UNICODE_SCRIPT_BUGINESE, "Bugi" },
790 { G_UNICODE_SCRIPT_GLAGOLITIC, "Glag" },
791 { G_UNICODE_SCRIPT_TIFINAGH, "Tfng" },
792 { G_UNICODE_SCRIPT_SYLOTI_NAGRI, "Sylo" },
793 { G_UNICODE_SCRIPT_OLD_PERSIAN, "Xpeo" },
794 { G_UNICODE_SCRIPT_KHAROSHTHI, "Khar" },
796 /* Unicode-5.0 additions */
797 { G_UNICODE_SCRIPT_UNKNOWN, "Zzzz" },
798 { G_UNICODE_SCRIPT_BALINESE, "Bali" },
799 { G_UNICODE_SCRIPT_CUNEIFORM, "Xsux" },
800 { G_UNICODE_SCRIPT_PHOENICIAN, "Phnx" },
801 { G_UNICODE_SCRIPT_PHAGS_PA, "Phag" },
802 { G_UNICODE_SCRIPT_NKO, "Nkoo" },
804 /* Unicode-5.1 additions */
805 { G_UNICODE_SCRIPT_KAYAH_LI, "Kali" },
806 { G_UNICODE_SCRIPT_LEPCHA, "Lepc" },
807 { G_UNICODE_SCRIPT_REJANG, "Rjng" },
808 { G_UNICODE_SCRIPT_SUNDANESE, "Sund" },
809 { G_UNICODE_SCRIPT_SAURASHTRA, "Saur" },
810 { G_UNICODE_SCRIPT_CHAM, "Cham" },
811 { G_UNICODE_SCRIPT_OL_CHIKI, "Olck" },
812 { G_UNICODE_SCRIPT_VAI, "Vaii" },
813 { G_UNICODE_SCRIPT_CARIAN, "Cari" },
814 { G_UNICODE_SCRIPT_LYCIAN, "Lyci" },
815 { G_UNICODE_SCRIPT_LYDIAN, "Lydi" },
817 /* Unicode-5.2 additions */
818 { G_UNICODE_SCRIPT_AVESTAN, "Avst" },
819 { G_UNICODE_SCRIPT_BAMUM, "Bamu" },
820 { G_UNICODE_SCRIPT_EGYPTIAN_HIEROGLYPHS, "Egyp" },
821 { G_UNICODE_SCRIPT_IMPERIAL_ARAMAIC, "Armi" },
822 { G_UNICODE_SCRIPT_INSCRIPTIONAL_PAHLAVI, "Phli" },
823 { G_UNICODE_SCRIPT_INSCRIPTIONAL_PARTHIAN, "Prti" },
824 { G_UNICODE_SCRIPT_JAVANESE, "Java" },
825 { G_UNICODE_SCRIPT_KAITHI, "Kthi" },
826 { G_UNICODE_SCRIPT_LISU, "Lisu" },
827 { G_UNICODE_SCRIPT_MEETEI_MAYEK, "Mtei" },
828 { G_UNICODE_SCRIPT_OLD_SOUTH_ARABIAN, "Sarb" },
829 { G_UNICODE_SCRIPT_OLD_TURKIC, "Orkh" },
830 { G_UNICODE_SCRIPT_SAMARITAN, "Samr" },
831 { G_UNICODE_SCRIPT_TAI_THAM, "Lana" },
832 { G_UNICODE_SCRIPT_TAI_VIET, "Tavt" },
834 /* Unicode-6.0 additions */
835 { G_UNICODE_SCRIPT_BATAK, "Batk" },
836 { G_UNICODE_SCRIPT_BRAHMI, "Brah" },
837 { G_UNICODE_SCRIPT_MANDAIC, "Mand" },
839 /* Unicode-6.1 additions */
840 { G_UNICODE_SCRIPT_CHAKMA, "Cakm" },
841 { G_UNICODE_SCRIPT_MEROITIC_CURSIVE, "Merc" },
842 { G_UNICODE_SCRIPT_MEROITIC_HIEROGLYPHS, "Mero" },
843 { G_UNICODE_SCRIPT_MIAO, "Plrd" },
844 { G_UNICODE_SCRIPT_SHARADA, "Shrd" },
845 { G_UNICODE_SCRIPT_SORA_SOMPENG, "Sora" },
846 { G_UNICODE_SCRIPT_TAKRI, "Takr" },
848 /* Unicode 7.0 additions */
849 { G_UNICODE_SCRIPT_BASSA_VAH, "Bass" },
850 { G_UNICODE_SCRIPT_CAUCASIAN_ALBANIAN, "Aghb" },
851 { G_UNICODE_SCRIPT_DUPLOYAN, "Dupl" },
852 { G_UNICODE_SCRIPT_ELBASAN, "Elba" },
853 { G_UNICODE_SCRIPT_GRANTHA, "Gran" },
854 { G_UNICODE_SCRIPT_KHOJKI, "Khoj" },
855 { G_UNICODE_SCRIPT_KHUDAWADI, "Sind" },
856 { G_UNICODE_SCRIPT_LINEAR_A, "Lina" },
857 { G_UNICODE_SCRIPT_MAHAJANI, "Mahj" },
858 { G_UNICODE_SCRIPT_MANICHAEAN, "Manu" },
859 { G_UNICODE_SCRIPT_MENDE_KIKAKUI, "Mend" },
860 { G_UNICODE_SCRIPT_MODI, "Modi" },
861 { G_UNICODE_SCRIPT_MRO, "Mroo" },
862 { G_UNICODE_SCRIPT_NABATAEAN, "Nbat" },
863 { G_UNICODE_SCRIPT_OLD_NORTH_ARABIAN, "Narb" },
864 { G_UNICODE_SCRIPT_OLD_PERMIC, "Perm" },
865 { G_UNICODE_SCRIPT_PAHAWH_HMONG, "Hmng" },
866 { G_UNICODE_SCRIPT_PALMYRENE, "Palm" },
867 { G_UNICODE_SCRIPT_PAU_CIN_HAU, "Pauc" },
868 { G_UNICODE_SCRIPT_PSALTER_PAHLAVI, "Phlp" },
869 { G_UNICODE_SCRIPT_SIDDHAM, "Sidd" },
870 { G_UNICODE_SCRIPT_TIRHUTA, "Tirh" },
871 { G_UNICODE_SCRIPT_WARANG_CITI, "Wara" },
873 /* Unicode 8.0 additions */
874 { G_UNICODE_SCRIPT_AHOM, "Ahom" },
875 { G_UNICODE_SCRIPT_ANATOLIAN_HIEROGLYPHS, "Hluw" },
876 { G_UNICODE_SCRIPT_HATRAN, "Hatr" },
877 { G_UNICODE_SCRIPT_MULTANI, "Mult" },
878 { G_UNICODE_SCRIPT_OLD_HUNGARIAN, "Hung" },
879 { G_UNICODE_SCRIPT_SIGNWRITING, "Sgnw" },
881 /* Unicode 9.0 additions */
882 { G_UNICODE_SCRIPT_ADLAM, "Adlm" },
883 { G_UNICODE_SCRIPT_BHAIKSUKI, "Bhks" },
884 { G_UNICODE_SCRIPT_MARCHEN, "Marc" },
885 { G_UNICODE_SCRIPT_NEWA, "Newa" },
886 { G_UNICODE_SCRIPT_OSAGE, "Osge" },
887 { G_UNICODE_SCRIPT_TANGUT, "Tang" },
889 guint i;
891 g_assert_cmphex (0, ==, g_unicode_script_to_iso15924 (G_UNICODE_SCRIPT_INVALID_CODE));
892 g_assert_cmphex (0x5A7A7A7A, ==, g_unicode_script_to_iso15924 (1000));
893 g_assert_cmphex (0x41726162, ==, g_unicode_script_to_iso15924 (G_UNICODE_SCRIPT_ARABIC));
895 g_assert_cmphex (G_UNICODE_SCRIPT_INVALID_CODE, ==, g_unicode_script_from_iso15924 (0));
896 g_assert_cmphex (G_UNICODE_SCRIPT_UNKNOWN, ==, g_unicode_script_from_iso15924 (0x12345678));
898 #define PACK(a,b,c,d) ((guint32)((((guint8)(a))<<24)|(((guint8)(b))<<16)|(((guint8)(c))<<8)|((guint8)(d))))
900 for (i = 0; i < G_N_ELEMENTS (data); i++)
902 guint32 code = PACK (data[i].four_letter_code[0],
903 data[i].four_letter_code[1],
904 data[i].four_letter_code[2],
905 data[i].four_letter_code[3]);
907 g_assert_cmphex (g_unicode_script_to_iso15924 (data[i].script), ==, code);
908 g_assert_cmpint (g_unicode_script_from_iso15924 (code), ==, data[i].script);
911 #undef PACK
915 main (int argc,
916 char *argv[])
918 g_test_init (&argc, &argv, NULL);
920 g_test_add_func ("/unicode/validate", test_unichar_validate);
921 g_test_add_func ("/unicode/character-type", test_unichar_character_type);
922 g_test_add_func ("/unicode/break-type", test_unichar_break_type);
923 g_test_add_func ("/unicode/script", test_unichar_script);
924 g_test_add_func ("/unicode/combining-class", test_combining_class);
925 g_test_add_func ("/unicode/mirror", test_mirror);
926 g_test_add_func ("/unicode/mark", test_mark);
927 g_test_add_func ("/unicode/title", test_title);
928 g_test_add_func ("/unicode/zero-width", test_zerowidth);
929 g_test_add_func ("/unicode/defined", test_defined);
930 g_test_add_func ("/unicode/wide", test_wide);
931 g_test_add_func ("/unicode/compose", test_compose);
932 g_test_add_func ("/unicode/decompose", test_decompose);
933 g_test_add_func ("/unicode/fully-decompose-canonical", test_fully_decompose_canonical);
934 g_test_add_func ("/unicode/canonical-decomposition", test_canonical_decomposition);
935 g_test_add_func ("/unicode/decompose-tail", test_decompose_tail);
936 g_test_add_func ("/unicode/fully-decompose-len", test_fully_decompose_len);
937 g_test_add_func ("/unicode/iso15924", test_iso15924);
938 g_test_add_func ("/unicode/cases", test_cases);
940 return g_test_run();