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
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));
42 test_unichar_character_type (void)
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 (g_unichar_type (examples[i].c) == examples[i].type);
88 test_unichar_break_type (void)
92 GUnicodeBreakType type;
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 }
136 for (i = 0; i < G_N_ELEMENTS (examples); i++)
138 g_assert (g_unichar_break_type (examples[i].c) == examples[i].type);
143 test_unichar_script (void)
147 GUnicodeScript script;
150 { G_UNICODE_SCRIPT_COMMON, 0x002A },
151 { G_UNICODE_SCRIPT_INHERITED, 0x1CED },
152 { G_UNICODE_SCRIPT_INHERITED, 0x0670 },
153 { G_UNICODE_SCRIPT_ARABIC, 0x060D },
154 { G_UNICODE_SCRIPT_ARMENIAN, 0x0559 },
155 { G_UNICODE_SCRIPT_BENGALI, 0x09CD },
156 { G_UNICODE_SCRIPT_BOPOMOFO, 0x31B6 },
157 { G_UNICODE_SCRIPT_CHEROKEE, 0x13A2 },
158 { G_UNICODE_SCRIPT_COPTIC, 0x2CFD },
159 { G_UNICODE_SCRIPT_CYRILLIC, 0x0482 },
160 { G_UNICODE_SCRIPT_DESERET, 0x10401 },
161 { G_UNICODE_SCRIPT_DEVANAGARI, 0x094D },
162 { G_UNICODE_SCRIPT_ETHIOPIC, 0x1258 },
163 { G_UNICODE_SCRIPT_GEORGIAN, 0x10FC },
164 { G_UNICODE_SCRIPT_GOTHIC, 0x10341 },
165 { G_UNICODE_SCRIPT_GREEK, 0x0375 },
166 { G_UNICODE_SCRIPT_GUJARATI, 0x0A83 },
167 { G_UNICODE_SCRIPT_GURMUKHI, 0x0A3C },
168 { G_UNICODE_SCRIPT_HAN, 0x3005 },
169 { G_UNICODE_SCRIPT_HANGUL, 0x1100 },
170 { G_UNICODE_SCRIPT_HEBREW, 0x05BF },
171 { G_UNICODE_SCRIPT_HIRAGANA, 0x309F },
172 { G_UNICODE_SCRIPT_KANNADA, 0x0CBC },
173 { G_UNICODE_SCRIPT_KATAKANA, 0x30FF },
174 { G_UNICODE_SCRIPT_KHMER, 0x17DD },
175 { G_UNICODE_SCRIPT_LAO, 0x0EDD },
176 { G_UNICODE_SCRIPT_LATIN, 0x0061 },
177 { G_UNICODE_SCRIPT_MALAYALAM, 0x0D3D },
178 { G_UNICODE_SCRIPT_MONGOLIAN, 0x1843 },
179 { G_UNICODE_SCRIPT_MYANMAR, 0x1031 },
180 { G_UNICODE_SCRIPT_OGHAM, 0x169C },
181 { G_UNICODE_SCRIPT_OLD_ITALIC, 0x10322 },
182 { G_UNICODE_SCRIPT_ORIYA, 0x0B3C },
183 { G_UNICODE_SCRIPT_RUNIC, 0x16EF },
184 { G_UNICODE_SCRIPT_SINHALA, 0x0DBD },
185 { G_UNICODE_SCRIPT_SYRIAC, 0x0711 },
186 { G_UNICODE_SCRIPT_TAMIL, 0x0B82 },
187 { G_UNICODE_SCRIPT_TELUGU, 0x0C03 },
188 { G_UNICODE_SCRIPT_THAANA, 0x07B1 },
189 { G_UNICODE_SCRIPT_THAI, 0x0E31 },
190 { G_UNICODE_SCRIPT_TIBETAN, 0x0FD4 },
191 { G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL, 0x1400 },
192 { G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL, 0x1401 },
193 { G_UNICODE_SCRIPT_YI, 0xA015 },
194 { G_UNICODE_SCRIPT_TAGALOG, 0x1700 },
195 { G_UNICODE_SCRIPT_HANUNOO, 0x1720 },
196 { G_UNICODE_SCRIPT_BUHID, 0x1740 },
197 { G_UNICODE_SCRIPT_TAGBANWA, 0x1760 },
198 { G_UNICODE_SCRIPT_BRAILLE, 0x2800 },
199 { G_UNICODE_SCRIPT_CYPRIOT, 0x10808 },
200 { G_UNICODE_SCRIPT_LIMBU, 0x1932 },
201 { G_UNICODE_SCRIPT_OSMANYA, 0x10480 },
202 { G_UNICODE_SCRIPT_SHAVIAN, 0x10450 },
203 { G_UNICODE_SCRIPT_LINEAR_B, 0x10000 },
204 { G_UNICODE_SCRIPT_TAI_LE, 0x1950 },
205 { G_UNICODE_SCRIPT_UGARITIC, 0x1039F },
206 { G_UNICODE_SCRIPT_NEW_TAI_LUE, 0x1980 },
207 { G_UNICODE_SCRIPT_BUGINESE, 0x1A1F },
208 { G_UNICODE_SCRIPT_GLAGOLITIC, 0x2C00 },
209 { G_UNICODE_SCRIPT_TIFINAGH, 0x2D6F },
210 { G_UNICODE_SCRIPT_SYLOTI_NAGRI, 0xA800 },
211 { G_UNICODE_SCRIPT_OLD_PERSIAN, 0x103D0 },
212 { G_UNICODE_SCRIPT_KHAROSHTHI, 0x10A3F },
213 { G_UNICODE_SCRIPT_UNKNOWN, 0x1111111 },
214 { G_UNICODE_SCRIPT_BALINESE, 0x1B04 },
215 { G_UNICODE_SCRIPT_CUNEIFORM, 0x12000 },
216 { G_UNICODE_SCRIPT_PHOENICIAN, 0x10900 },
217 { G_UNICODE_SCRIPT_PHAGS_PA, 0xA840 },
218 { G_UNICODE_SCRIPT_NKO, 0x07C0 },
219 { G_UNICODE_SCRIPT_KAYAH_LI, 0xA900 },
220 { G_UNICODE_SCRIPT_LEPCHA, 0x1C00 },
221 { G_UNICODE_SCRIPT_REJANG, 0xA930 },
222 { G_UNICODE_SCRIPT_SUNDANESE, 0x1B80 },
223 { G_UNICODE_SCRIPT_SAURASHTRA, 0xA880 },
224 { G_UNICODE_SCRIPT_CHAM, 0xAA00 },
225 { G_UNICODE_SCRIPT_OL_CHIKI, 0x1C50 },
226 { G_UNICODE_SCRIPT_VAI, 0xA500 },
227 { G_UNICODE_SCRIPT_CARIAN, 0x102A0 },
228 { G_UNICODE_SCRIPT_LYCIAN, 0x10280 },
229 { G_UNICODE_SCRIPT_LYDIAN, 0x1093F },
230 { G_UNICODE_SCRIPT_AVESTAN, 0x10B00 },
231 { G_UNICODE_SCRIPT_BAMUM, 0xA6A0 },
232 { G_UNICODE_SCRIPT_EGYPTIAN_HIEROGLYPHS, 0x13000 },
233 { G_UNICODE_SCRIPT_IMPERIAL_ARAMAIC, 0x10840 },
234 { G_UNICODE_SCRIPT_INSCRIPTIONAL_PAHLAVI, 0x10B60 },
235 { G_UNICODE_SCRIPT_INSCRIPTIONAL_PARTHIAN, 0x10B40 },
236 { G_UNICODE_SCRIPT_JAVANESE, 0xA980 },
237 { G_UNICODE_SCRIPT_KAITHI, 0x11082 },
238 { G_UNICODE_SCRIPT_LISU, 0xA4D0 },
239 { G_UNICODE_SCRIPT_MEETEI_MAYEK, 0xABE5 },
240 { G_UNICODE_SCRIPT_OLD_SOUTH_ARABIAN, 0x10A60 },
241 { G_UNICODE_SCRIPT_OLD_TURKIC, 0x10C00 },
242 { G_UNICODE_SCRIPT_SAMARITAN, 0x0800 },
243 { G_UNICODE_SCRIPT_TAI_THAM, 0x1A20 },
244 { G_UNICODE_SCRIPT_TAI_VIET, 0xAA80 },
245 { G_UNICODE_SCRIPT_BATAK, 0x1BC0 },
246 { G_UNICODE_SCRIPT_BRAHMI, 0x11000 },
247 { G_UNICODE_SCRIPT_MANDAIC, 0x0840 },
248 { G_UNICODE_SCRIPT_CHAKMA, 0x11100 },
249 { G_UNICODE_SCRIPT_MEROITIC_CURSIVE, 0x109A0 },
250 { G_UNICODE_SCRIPT_MEROITIC_HIEROGLYPHS, 0x10980 },
251 { G_UNICODE_SCRIPT_MIAO, 0x16F00 },
252 { G_UNICODE_SCRIPT_SHARADA, 0x11180 },
253 { G_UNICODE_SCRIPT_SORA_SOMPENG, 0x110D0 },
254 { G_UNICODE_SCRIPT_TAKRI, 0x11680 }
256 for (i = 0; i < G_N_ELEMENTS (examples); i++)
258 g_assert (g_unichar_get_script (examples[i].c) == examples[i].script);
263 test_combining_class (void)
304 for (i = 0; i < G_N_ELEMENTS (examples); i++)
306 g_assert (g_unichar_combining_class (examples[i].c) == examples[i].class);
315 g_assert (g_unichar_get_mirror_char ('(', &mirror));
316 g_assert_cmpint (mirror, ==, ')');
317 g_assert (g_unichar_get_mirror_char (')', &mirror));
318 g_assert_cmpint (mirror, ==, '(');
319 g_assert (g_unichar_get_mirror_char ('{', &mirror));
320 g_assert_cmpint (mirror, ==, '}');
321 g_assert (g_unichar_get_mirror_char ('}', &mirror));
322 g_assert_cmpint (mirror, ==, '{');
323 g_assert (g_unichar_get_mirror_char (0x208D, &mirror));
324 g_assert_cmpint (mirror, ==, 0x208E);
325 g_assert (g_unichar_get_mirror_char (0x208E, &mirror));
326 g_assert_cmpint (mirror, ==, 0x208D);
327 g_assert (!g_unichar_get_mirror_char ('a', &mirror));
333 g_assert (g_unichar_ismark (0x0903));
334 g_assert (g_unichar_ismark (0x20DD));
335 g_assert (g_unichar_ismark (0xA806));
336 g_assert (!g_unichar_ismark ('a'));
340 test_zerowidth (void)
342 g_assert (!g_unichar_iszerowidth (0x00AD));
343 g_assert (!g_unichar_iszerowidth (0x00AD));
344 g_assert (!g_unichar_iszerowidth (0x115F));
345 g_assert (g_unichar_iszerowidth (0x1160));
346 g_assert (g_unichar_iszerowidth (0x11AA));
347 g_assert (g_unichar_iszerowidth (0x11FF));
348 g_assert (!g_unichar_iszerowidth (0x1200));
349 g_assert (g_unichar_iszerowidth (0x200B));
350 g_assert (g_unichar_iszerowidth (0x591));
356 g_assert (g_unichar_istitle (0x01c5));
357 g_assert (g_unichar_istitle (0x1f88));
358 g_assert (g_unichar_istitle (0x1fcc));
359 g_assert (!g_unichar_istitle ('a'));
360 g_assert (!g_unichar_istitle ('A'));
362 g_assert (g_unichar_totitle (0x01c6) == 0x01c5);
363 g_assert (g_unichar_totitle (0x01c4) == 0x01c5);
364 g_assert (g_unichar_totitle (0x01c5) == 0x01c5);
365 g_assert (g_unichar_totitle (0x1f80) == 0x1f88);
366 g_assert (g_unichar_totitle (0x1f88) == 0x1f88);
367 g_assert (g_unichar_totitle ('a') == 'A');
368 g_assert (g_unichar_totitle ('A') == 'A');
374 g_assert (g_unichar_toupper ('a') == 'A');
375 g_assert (g_unichar_toupper ('A') == 'A');
376 g_assert (g_unichar_toupper (0x01C5) == 0x01C4);
377 g_assert (g_unichar_toupper (0x01C6) == 0x01C4);
378 g_assert (g_unichar_tolower ('A') == 'a');
379 g_assert (g_unichar_tolower ('a') == 'a');
380 g_assert (g_unichar_tolower (0x01C4) == 0x01C6);
381 g_assert (g_unichar_tolower (0x01C5) == 0x01C6);
382 g_assert (g_unichar_tolower (0x1F8A) == 0x1F82);
383 g_assert (g_unichar_totitle (0x1F8A) == 0x1F8A);
384 g_assert (g_unichar_toupper (0x1F8A) == 0x1F8A);
385 g_assert (g_unichar_tolower (0x1FB2) == 0x1FB2);
386 g_assert (g_unichar_toupper (0x1FB2) == 0x1FB2);
392 g_assert (g_unichar_isdefined (0x0903));
393 g_assert (g_unichar_isdefined (0x20DD));
394 g_assert (g_unichar_isdefined (0xA806));
395 g_assert (g_unichar_isdefined ('a'));
396 g_assert (!g_unichar_isdefined (0x10C49));
397 g_assert (!g_unichar_isdefined (0x169D));
413 { 0x0000, NOT_WIDE },
414 { 0x0483, NOT_WIDE },
415 { 0x0641, NOT_WIDE },
416 { 0xFFFC, NOT_WIDE },
417 { 0x10000, NOT_WIDE },
418 { 0xE0001, NOT_WIDE },
421 { 0x0020, NOT_WIDE },
422 { 0x0041, NOT_WIDE },
423 { 0x27E6, NOT_WIDE },
426 { 0x20A9, NOT_WIDE },
427 { 0xFF61, NOT_WIDE },
428 { 0xFF69, NOT_WIDE },
429 { 0xFFEE, NOT_WIDE },
432 { 0x00A1, WIDE_CJK },
433 { 0x00BE, WIDE_CJK },
434 { 0x02DD, WIDE_CJK },
435 { 0x2020, WIDE_CJK },
436 { 0xFFFD, WIDE_CJK },
437 { 0x00A1, WIDE_CJK },
438 { 0x1F100, WIDE_CJK },
439 { 0xE0100, WIDE_CJK },
440 { 0x100000, WIDE_CJK },
441 { 0x10FFFD, WIDE_CJK },
454 /* Default Wide blocks */
463 /* Uniode-5.2 character additions */
467 /* Uniode-6.0 character additions */
472 { 0x111111, NOT_WIDE }
475 for (i = 0; i < G_N_ELEMENTS (examples); i++)
477 g_assert (g_unichar_iswide (examples[i].c) == (examples[i].wide == WIDE));
478 g_assert (g_unichar_iswide_cjk (examples[i].c) == (examples[i].wide != NOT_WIDE));
488 g_assert (!g_unichar_compose (0x0041, 0x0042, &ch) && ch == 0);
489 g_assert (!g_unichar_compose (0x0041, 0, &ch) && ch == 0);
490 g_assert (!g_unichar_compose (0x0066, 0x0069, &ch) && ch == 0);
492 /* Tricky non-composable */
493 g_assert (!g_unichar_compose (0x0308, 0x0301, &ch) && ch == 0); /* !0x0344 */
494 g_assert (!g_unichar_compose (0x0F71, 0x0F72, &ch) && ch == 0); /* !0x0F73 */
496 /* Singletons should not compose */
497 g_assert (!g_unichar_compose (0x212B, 0, &ch) && ch == 0);
498 g_assert (!g_unichar_compose (0x00C5, 0, &ch) && ch == 0);
499 g_assert (!g_unichar_compose (0x2126, 0, &ch) && ch == 0);
500 g_assert (!g_unichar_compose (0x03A9, 0, &ch) && ch == 0);
503 g_assert (g_unichar_compose (0x0041, 0x030A, &ch) && ch == 0x00C5);
504 g_assert (g_unichar_compose (0x006F, 0x0302, &ch) && ch == 0x00F4);
505 g_assert (g_unichar_compose (0x1E63, 0x0307, &ch) && ch == 0x1E69);
506 g_assert (g_unichar_compose (0x0073, 0x0323, &ch) && ch == 0x1E63);
507 g_assert (g_unichar_compose (0x0064, 0x0307, &ch) && ch == 0x1E0B);
508 g_assert (g_unichar_compose (0x0064, 0x0323, &ch) && ch == 0x1E0D);
511 g_assert (g_unichar_compose (0xD4CC, 0x11B6, &ch) && ch == 0xD4DB);
512 g_assert (g_unichar_compose (0x1111, 0x1171, &ch) && ch == 0xD4CC);
513 g_assert (g_unichar_compose (0xCE20, 0x11B8, &ch) && ch == 0xCE31);
514 g_assert (g_unichar_compose (0x110E, 0x1173, &ch) && ch == 0xCE20);
518 test_decompose (void)
522 /* Not decomposable */
523 g_assert (!g_unichar_decompose (0x0041, &a, &b) && a == 0x0041 && b == 0);
524 g_assert (!g_unichar_decompose (0xFB01, &a, &b) && a == 0xFB01 && b == 0);
527 g_assert (g_unichar_decompose (0x212B, &a, &b) && a == 0x00C5 && b == 0);
528 g_assert (g_unichar_decompose (0x2126, &a, &b) && a == 0x03A9 && b == 0);
531 g_assert (g_unichar_decompose (0x0344, &a, &b) && a == 0x0308 && b == 0x0301);
532 g_assert (g_unichar_decompose (0x0F73, &a, &b) && a == 0x0F71 && b == 0x0F72);
535 g_assert (g_unichar_decompose (0x00C5, &a, &b) && a == 0x0041 && b == 0x030A);
536 g_assert (g_unichar_decompose (0x00F4, &a, &b) && a == 0x006F && b == 0x0302);
537 g_assert (g_unichar_decompose (0x1E69, &a, &b) && a == 0x1E63 && b == 0x0307);
538 g_assert (g_unichar_decompose (0x1E63, &a, &b) && a == 0x0073 && b == 0x0323);
539 g_assert (g_unichar_decompose (0x1E0B, &a, &b) && a == 0x0064 && b == 0x0307);
540 g_assert (g_unichar_decompose (0x1E0D, &a, &b) && a == 0x0064 && b == 0x0323);
543 g_assert (g_unichar_decompose (0xD4DB, &a, &b) && a == 0xD4CC && b == 0x11B6);
544 g_assert (g_unichar_decompose (0xD4CC, &a, &b) && a == 0x1111 && b == 0x1171);
545 g_assert (g_unichar_decompose (0xCE31, &a, &b) && a == 0xCE20 && b == 0x11B8);
546 g_assert (g_unichar_decompose (0xCE20, &a, &b) && a == 0x110E && b == 0x1173);
550 test_fully_decompose_canonical (void)
555 #define TEST_DECOMP(ch, expected_len, a, b, c, d) \
556 len = g_unichar_fully_decompose (ch, FALSE, decomp, G_N_ELEMENTS (decomp)); \
557 g_assert_cmpint (expected_len, ==, len); \
558 if (expected_len >= 1) g_assert_cmphex (decomp[0], ==, a); \
559 if (expected_len >= 2) g_assert_cmphex (decomp[1], ==, b); \
560 if (expected_len >= 3) g_assert_cmphex (decomp[2], ==, c); \
561 if (expected_len >= 4) g_assert_cmphex (decomp[3], ==, d); \
563 #define TEST0(ch) TEST_DECOMP (ch, 1, ch, 0, 0, 0)
564 #define TEST1(ch, a) TEST_DECOMP (ch, 1, a, 0, 0, 0)
565 #define TEST2(ch, a, b) TEST_DECOMP (ch, 2, a, b, 0, 0)
566 #define TEST3(ch, a, b, c) TEST_DECOMP (ch, 3, a, b, c, 0)
567 #define TEST4(ch, a, b, c, d) TEST_DECOMP (ch, 4, a, b, c, d)
569 /* Not decomposable */
574 TEST2 (0x212B, 0x0041, 0x030A);
575 TEST1 (0x2126, 0x03A9);
578 TEST2 (0x0344, 0x0308, 0x0301);
579 TEST2 (0x0F73, 0x0F71, 0x0F72);
582 TEST2 (0x00C5, 0x0041, 0x030A);
583 TEST2 (0x00F4, 0x006F, 0x0302);
584 TEST3 (0x1E69, 0x0073, 0x0323, 0x0307);
585 TEST2 (0x1E63, 0x0073, 0x0323);
586 TEST2 (0x1E0B, 0x0064, 0x0307);
587 TEST2 (0x1E0D, 0x0064, 0x0323);
590 TEST3 (0xD4DB, 0x1111, 0x1171, 0x11B6);
591 TEST2 (0xD4CC, 0x1111, 0x1171);
592 TEST3 (0xCE31, 0x110E, 0x1173, 0x11B8);
593 TEST2 (0xCE20, 0x110E, 0x1173);
599 test_canonical_decomposition (void)
604 #define TEST_DECOMP(ch, expected_len, a, b, c, d) \
605 decomp = g_unicode_canonical_decomposition (ch, &len); \
606 g_assert_cmpint (expected_len, ==, len); \
607 if (expected_len >= 1) g_assert_cmphex (decomp[0], ==, a); \
608 if (expected_len >= 2) g_assert_cmphex (decomp[1], ==, b); \
609 if (expected_len >= 3) g_assert_cmphex (decomp[2], ==, c); \
610 if (expected_len >= 4) g_assert_cmphex (decomp[3], ==, d); \
613 #define TEST0(ch) TEST_DECOMP (ch, 1, ch, 0, 0, 0)
614 #define TEST1(ch, a) TEST_DECOMP (ch, 1, a, 0, 0, 0)
615 #define TEST2(ch, a, b) TEST_DECOMP (ch, 2, a, b, 0, 0)
616 #define TEST3(ch, a, b, c) TEST_DECOMP (ch, 3, a, b, c, 0)
617 #define TEST4(ch, a, b, c, d) TEST_DECOMP (ch, 4, a, b, c, d)
619 /* Not decomposable */
624 TEST2 (0x212B, 0x0041, 0x030A);
625 TEST1 (0x2126, 0x03A9);
628 TEST2 (0x0344, 0x0308, 0x0301);
629 TEST2 (0x0F73, 0x0F71, 0x0F72);
632 TEST2 (0x00C5, 0x0041, 0x030A);
633 TEST2 (0x00F4, 0x006F, 0x0302);
634 TEST3 (0x1E69, 0x0073, 0x0323, 0x0307);
635 TEST2 (0x1E63, 0x0073, 0x0323);
636 TEST2 (0x1E0B, 0x0064, 0x0307);
637 TEST2 (0x1E0D, 0x0064, 0x0323);
640 TEST3 (0xD4DB, 0x1111, 0x1171, 0x11B6);
641 TEST2 (0xD4CC, 0x1111, 0x1171);
642 TEST3 (0xCE31, 0x110E, 0x1173, 0x11B8);
643 TEST2 (0xCE20, 0x110E, 0x1173);
649 test_decompose_tail (void)
651 gunichar ch, a, b, c, d;
653 /* Test that whenever a char ch decomposes into a and b, b itself
654 * won't decompose any further. */
656 for (ch = 0; ch < 0x110000; ch++)
657 if (g_unichar_decompose (ch, &a, &b))
658 g_assert (!g_unichar_decompose (b, &c, &d));
660 g_assert (a == ch && b == 0);
664 test_fully_decompose_len (void)
668 /* Test that all canonical decompositions are at most 4 in length,
669 * and compatibility decompositions are at most 18 in length.
672 for (ch = 0; ch < 0x110000; ch++) {
673 g_assert_cmpint (g_unichar_fully_decompose (ch, FALSE, NULL, 0), <=, 4);
674 g_assert_cmpint (g_unichar_fully_decompose (ch, TRUE, NULL, 0), <=, 18);
681 g_assert_cmphex (0, ==, g_unicode_script_to_iso15924 (G_UNICODE_SCRIPT_INVALID_CODE));
682 g_assert_cmphex (0x5A7A7A7A, ==, g_unicode_script_to_iso15924 (1000));
683 g_assert_cmphex (0x41726162, ==, g_unicode_script_to_iso15924 (G_UNICODE_SCRIPT_ARABIC));
685 g_assert_cmphex (G_UNICODE_SCRIPT_INVALID_CODE, ==, g_unicode_script_from_iso15924 (0));
686 g_assert_cmphex (G_UNICODE_SCRIPT_UNKNOWN, ==, g_unicode_script_from_iso15924 (0x12345678));
687 g_assert_cmphex (G_UNICODE_SCRIPT_ARABIC, ==, g_unicode_script_from_iso15924 (0x41726162));
694 g_test_init (&argc, &argv, NULL);
696 g_test_add_func ("/unicode/validate", test_unichar_validate);
697 g_test_add_func ("/unicode/character-type", test_unichar_character_type);
698 g_test_add_func ("/unicode/break-type", test_unichar_break_type);
699 g_test_add_func ("/unicode/script", test_unichar_script);
700 g_test_add_func ("/unicode/combining-class", test_combining_class);
701 g_test_add_func ("/unicode/mirror", test_mirror);
702 g_test_add_func ("/unicode/mark", test_mark);
703 g_test_add_func ("/unicode/title", test_title);
704 g_test_add_func ("/unicode/zero-width", test_zerowidth);
705 g_test_add_func ("/unicode/defined", test_defined);
706 g_test_add_func ("/unicode/wide", test_wide);
707 g_test_add_func ("/unicode/compose", test_compose);
708 g_test_add_func ("/unicode/decompose", test_decompose);
709 g_test_add_func ("/unicode/fully-decompose-canonical", test_fully_decompose_canonical);
710 g_test_add_func ("/unicode/canonical-decomposition", test_canonical_decomposition);
711 g_test_add_func ("/unicode/decompose-tail", test_decompose_tail);
712 g_test_add_func ("/unicode/fully-decompose-len", test_fully_decompose_len);
713 g_test_add_func ("/unicode/iso15924", test_iso15924);
714 g_test_add_func ("/unicode/cases", test_cases);