4b2585bdb8cb216fa6cd96f3be454268b8bf0401
[profile/ivi/org.tizen.video-player.git] / test / test-unicode.c
1 /*
2  * Copyright © 2011  Codethink Limited
3  * Copyright © 2011  Google, Inc.
4  *
5  *  This is part of HarfBuzz, a text shaping library.
6  *
7  * Permission is hereby granted, without written agreement and without
8  * license or royalty fees, to use, copy, modify, and distribute this
9  * software and its documentation for any purpose, provided that the
10  * above copyright notice and the following two paragraphs appear in
11  * all copies of this software.
12  *
13  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17  * DAMAGE.
18  *
19  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24  *
25  * Codethink Author(s): Ryan Lortie
26  * Google Author(s): Behdad Esfahbod
27  */
28
29 #include "hb-test.h"
30
31 /* Unit tests for hb-unicode.h */
32
33
34 #ifdef HAVE_GLIB
35 #include <hb-glib.h>
36 #endif
37 #ifdef HAVE_ICU
38 #include <hb-icu.h>
39 #endif
40
41
42 /* Check all properties */
43
44 /* Some of the following tables where adapted from glib/glib/tests/utf8-misc.c.
45  * The license is compatible. */
46
47 typedef struct {
48   hb_codepoint_t unicode;
49   unsigned int   value;
50 } test_pair_t;
51
52 static const test_pair_t combining_class_tests[] =
53 {
54   {   0x0020, 0 },
55   {   0x0334, 1 },
56   {   0x093C, 7 },
57   {   0x3099, 8 },
58   {   0x094D, 9 },
59   {   0x05B0, 10 },
60   {   0x05B1, 11 },
61   {   0x05B2, 12 },
62   {   0x05B3, 13 },
63   {   0x05B4, 14 },
64   {   0x05B5, 15 },
65   {   0x05B6, 16 },
66   {   0x05B7, 17 },
67   {   0x05B8, 18 },
68   {   0x05B9, 19 },
69   {   0x05BB, 20 },
70   {   0x05BC, 21 },
71   {   0x05BD, 22 },
72   {   0x05BF, 23 },
73   {   0x05C1, 24 },
74   {   0x05C2, 25 },
75   {   0xFB1E, 26 },
76   {   0x064B, 27 },
77   {   0x064C, 28 },
78   {   0x064D, 29 },
79   /* ... */
80   {   0x05AE, 228 },
81   {   0x0300, 230 },
82   {   0x302C, 232 },
83   {   0x0362, 233 },
84   {   0x0360, 234 },
85   {   0x1DCD, 234 },
86   {   0x0345, 240 },
87
88   { 0x111111, 0 }
89 };
90 static const test_pair_t combining_class_tests_more[] =
91 {
92   /* Unicode-5.2 character additions */
93   {   0xA8E0, 230 },
94
95   /* Unicode-6.0 character additions */
96   {   0x135D, 230 },
97
98   { 0x111111, 0 }
99 };
100
101 static const test_pair_t eastasian_width_tests[] =
102 {
103   /* Neutral */
104   {   0x0000, 1 },
105   {   0x0483, 1 },
106   {   0x0641, 1 },
107   {   0xFFFC, 1 },
108   {  0x10000, 1 },
109   {  0xE0001, 1 },
110
111   /* Narrow */
112   {   0x0020, 1 },
113   {   0x0041, 1 },
114   {   0x27E6, 1 },
115
116   /* Halfwidth */
117   {   0x20A9, 1 },
118   {   0xFF61, 1 },
119   {   0xFF69, 1 },
120   {   0xFFEE, 1 },
121
122   /* Ambiguous */
123   {   0x00A1, 1 },
124   {   0x00D8, 1 },
125   {   0x02DD, 1 },
126   {  0xE0100, 1 },
127   { 0x100000, 1 },
128
129   /* Fullwidth */
130   {   0x3000, 2 },
131   {   0xFF60, 2 },
132
133   /* Wide */
134   {   0x2329, 2 },
135   {   0x3001, 2 },
136   {   0xFE69, 2 },
137   {  0x30000, 2 },
138   {  0x3FFFD, 2 },
139
140   { 0x111111, 1 }
141 };
142 static const test_pair_t eastasian_width_tests_more[] =
143 {
144   /* Default Wide blocks */
145   {   0x4DBF, 2 },
146   {   0x9FFF, 2 },
147   {   0xFAFF, 2 },
148   {  0x2A6DF, 2 },
149   {  0x2B73F, 2 },
150   {  0x2B81F, 2 },
151   {  0x2FA1F, 2 },
152
153   /* Uniode-5.2 character additions */
154   /* Wide */
155   {   0x115F, 2 },
156
157   /* Uniode-6.0 character additions */
158   /* Wide */
159   {  0x2B740, 2 },
160   {  0x1B000, 2 },
161
162   { 0x111111, 1 }
163 };
164
165 static const test_pair_t general_category_tests[] =
166 {
167   {   0x000D, HB_UNICODE_GENERAL_CATEGORY_CONTROL },
168   {   0x200E, HB_UNICODE_GENERAL_CATEGORY_FORMAT },
169   {   0x0378, HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED },
170   {   0xE000, HB_UNICODE_GENERAL_CATEGORY_PRIVATE_USE },
171   {   0xD800, HB_UNICODE_GENERAL_CATEGORY_SURROGATE },
172   {   0x0061, HB_UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER },
173   {   0x02B0, HB_UNICODE_GENERAL_CATEGORY_MODIFIER_LETTER },
174   {   0x3400, HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER },
175   {   0x01C5, HB_UNICODE_GENERAL_CATEGORY_TITLECASE_LETTER },
176   {   0xFF21, HB_UNICODE_GENERAL_CATEGORY_UPPERCASE_LETTER },
177   {   0x0903, HB_UNICODE_GENERAL_CATEGORY_COMBINING_MARK },
178   {   0x20DD, HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK },
179   {   0xA806, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK },
180   {   0xFF10, HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER },
181   {   0x16EE, HB_UNICODE_GENERAL_CATEGORY_LETTER_NUMBER },
182   {   0x17F0, HB_UNICODE_GENERAL_CATEGORY_OTHER_NUMBER },
183   {   0x005F, HB_UNICODE_GENERAL_CATEGORY_CONNECT_PUNCTUATION },
184   {   0x058A, HB_UNICODE_GENERAL_CATEGORY_DASH_PUNCTUATION },
185   {   0x0F3B, HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION },
186   {   0x2019, HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION },
187   {   0x2018, HB_UNICODE_GENERAL_CATEGORY_INITIAL_PUNCTUATION },
188   {   0x2016, HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION },
189   {   0x0F3A, HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION },
190   {   0x20A0, HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL },
191   {   0x309B, HB_UNICODE_GENERAL_CATEGORY_MODIFIER_SYMBOL },
192   {   0xFB29, HB_UNICODE_GENERAL_CATEGORY_MATH_SYMBOL },
193   {   0x00A6, HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
194   {   0x2028, HB_UNICODE_GENERAL_CATEGORY_LINE_SEPARATOR },
195   {   0x2029, HB_UNICODE_GENERAL_CATEGORY_PARAGRAPH_SEPARATOR },
196   {   0x202F, HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR },
197
198   { 0x111111, HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED }
199 };
200 static const test_pair_t general_category_tests_more[] =
201 {
202   /* Unicode-5.2 character additions */
203   {  0x1F131, HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
204
205   /* Unicode-6.0 character additions */
206   {   0x0620, HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER },
207
208   { 0x111111, HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED }
209 };
210
211 static const test_pair_t mirroring_tests[] =
212 {
213   /* Some characters that do NOT mirror */
214   {   0x0020, 0x0020 },
215   {   0x0041, 0x0041 },
216   {   0x00F0, 0x00F0 },
217   {   0x27CC, 0x27CC },
218   {  0xE01EF, 0xE01EF },
219   {  0x1D7C3, 0x1D7C3 },
220   { 0x100000, 0x100000 },
221
222   /* Some characters that do mirror */
223   {   0x0029, 0x0028 },
224   {   0x0028, 0x0029 },
225   {   0x003E, 0x003C },
226   {   0x003C, 0x003E },
227   {   0x005D, 0x005B },
228   {   0x005B, 0x005D },
229   {   0x007D, 0x007B },
230   {   0x007B, 0x007D },
231   {   0x00BB, 0x00AB },
232   {   0x00AB, 0x00BB },
233   {   0x226B, 0x226A },
234   {   0x226A, 0x226B },
235   {   0x22F1, 0x22F0 },
236   {   0x22F0, 0x22F1 },
237   {   0xFF60, 0xFF5F },
238   {   0xFF5F, 0xFF60 },
239   {   0xFF63, 0xFF62 },
240   {   0xFF62, 0xFF63 },
241
242   { 0x111111, 0x111111 },
243 };
244 static const test_pair_t mirroring_tests_more[] =
245 {
246   /* No new mirroring characters have been encoded in recent Unicode versions. */
247   { 0x111111, 0x111111 }
248 };
249
250 static const test_pair_t script_tests[] =
251 {
252   {   0x002A, HB_SCRIPT_COMMON },
253   {   0x0670, HB_SCRIPT_INHERITED },
254   {   0x060D, HB_SCRIPT_ARABIC },
255   {   0x0559, HB_SCRIPT_ARMENIAN },
256   {   0x09CD, HB_SCRIPT_BENGALI },
257   {   0x31B6, HB_SCRIPT_BOPOMOFO },
258   {   0x13A2, HB_SCRIPT_CHEROKEE },
259   {   0x2CFD, HB_SCRIPT_COPTIC },
260   {   0x0482, HB_SCRIPT_CYRILLIC },
261   {  0x10401, HB_SCRIPT_DESERET },
262   {   0x094D, HB_SCRIPT_DEVANAGARI },
263   {   0x1258, HB_SCRIPT_ETHIOPIC },
264   {   0x10FC, HB_SCRIPT_GEORGIAN },
265   {  0x10341, HB_SCRIPT_GOTHIC },
266   {   0x0375, HB_SCRIPT_GREEK },
267   {   0x0A83, HB_SCRIPT_GUJARATI },
268   {   0x0A3C, HB_SCRIPT_GURMUKHI },
269   {   0x3005, HB_SCRIPT_HAN },
270   {   0x1100, HB_SCRIPT_HANGUL },
271   {   0x05BF, HB_SCRIPT_HEBREW },
272   {   0x309F, HB_SCRIPT_HIRAGANA },
273   {   0x0CBC, HB_SCRIPT_KANNADA },
274   {   0x30FF, HB_SCRIPT_KATAKANA },
275   {   0x17DD, HB_SCRIPT_KHMER },
276   {   0x0EDD, HB_SCRIPT_LAO },
277   {   0x0061, HB_SCRIPT_LATIN },
278   {   0x0D3D, HB_SCRIPT_MALAYALAM },
279   {   0x1843, HB_SCRIPT_MONGOLIAN },
280   {   0x1031, HB_SCRIPT_MYANMAR },
281   {   0x169C, HB_SCRIPT_OGHAM },
282   {  0x10322, HB_SCRIPT_OLD_ITALIC },
283   {   0x0B3C, HB_SCRIPT_ORIYA },
284   {   0x16EF, HB_SCRIPT_RUNIC },
285   {   0x0DBD, HB_SCRIPT_SINHALA },
286   {   0x0711, HB_SCRIPT_SYRIAC },
287   {   0x0B82, HB_SCRIPT_TAMIL },
288   {   0x0C03, HB_SCRIPT_TELUGU },
289   {   0x07B1, HB_SCRIPT_THAANA },
290   {   0x0E31, HB_SCRIPT_THAI },
291   {   0x0FD4, HB_SCRIPT_TIBETAN },
292   {   0x1401, HB_SCRIPT_CANADIAN_ABORIGINAL },
293   {   0xA015, HB_SCRIPT_YI },
294   {   0x1700, HB_SCRIPT_TAGALOG },
295   {   0x1720, HB_SCRIPT_HANUNOO },
296   {   0x1740, HB_SCRIPT_BUHID },
297   {   0x1760, HB_SCRIPT_TAGBANWA },
298
299   /* Unicode-4.0 additions */
300   {   0x2800, HB_SCRIPT_BRAILLE },
301   {  0x10808, HB_SCRIPT_CYPRIOT },
302   {   0x1932, HB_SCRIPT_LIMBU },
303   {  0x10480, HB_SCRIPT_OSMANYA },
304   {  0x10450, HB_SCRIPT_SHAVIAN },
305   {  0x10000, HB_SCRIPT_LINEAR_B },
306   {   0x1950, HB_SCRIPT_TAI_LE },
307   {  0x1039F, HB_SCRIPT_UGARITIC },
308
309   /* Unicode-4.1 additions */
310   {   0x1980, HB_SCRIPT_NEW_TAI_LUE },
311   {   0x1A1F, HB_SCRIPT_BUGINESE },
312   {   0x2C00, HB_SCRIPT_GLAGOLITIC },
313   {   0x2D6F, HB_SCRIPT_TIFINAGH },
314   {   0xA800, HB_SCRIPT_SYLOTI_NAGRI },
315   {  0x103D0, HB_SCRIPT_OLD_PERSIAN },
316   {  0x10A3F, HB_SCRIPT_KHAROSHTHI },
317
318   /* Unicode-5.0 additions */
319   {   0x0378, HB_SCRIPT_UNKNOWN },
320   {   0x1B04, HB_SCRIPT_BALINESE },
321   {  0x12000, HB_SCRIPT_CUNEIFORM },
322   {  0x10900, HB_SCRIPT_PHOENICIAN },
323   {   0xA840, HB_SCRIPT_PHAGS_PA },
324   {   0x07C0, HB_SCRIPT_NKO },
325
326   /* Unicode-5.1 additions */
327   {   0xA900, HB_SCRIPT_KAYAH_LI },
328   {   0x1C00, HB_SCRIPT_LEPCHA },
329   {   0xA930, HB_SCRIPT_REJANG },
330   {   0x1B80, HB_SCRIPT_SUNDANESE },
331   {   0xA880, HB_SCRIPT_SAURASHTRA },
332   {   0xAA00, HB_SCRIPT_CHAM },
333   {   0x1C50, HB_SCRIPT_OL_CHIKI },
334   {   0xA500, HB_SCRIPT_VAI },
335   {  0x102A0, HB_SCRIPT_CARIAN },
336   {  0x10280, HB_SCRIPT_LYCIAN },
337   {  0x1093F, HB_SCRIPT_LYDIAN },
338
339   { 0x111111, HB_SCRIPT_UNKNOWN }
340 };
341 static const test_pair_t script_tests_more[] =
342 {
343   /* Unicode-5.2 additions */
344   {  0x10B00, HB_SCRIPT_AVESTAN },
345   {   0xA6A0, HB_SCRIPT_BAMUM },
346   {  0x13000, HB_SCRIPT_EGYPTIAN_HIEROGLYPHS },
347   {  0x10840, HB_SCRIPT_IMPERIAL_ARAMAIC },
348   {  0x10B60, HB_SCRIPT_INSCRIPTIONAL_PAHLAVI },
349   {  0x10B40, HB_SCRIPT_INSCRIPTIONAL_PARTHIAN },
350   {   0xA980, HB_SCRIPT_JAVANESE },
351   {  0x11082, HB_SCRIPT_KAITHI },
352   {   0xA4D0, HB_SCRIPT_LISU },
353   {   0xABE5, HB_SCRIPT_MEETEI_MAYEK },
354   {  0x10A60, HB_SCRIPT_OLD_SOUTH_ARABIAN },
355   {  0x10C00, HB_SCRIPT_OLD_TURKIC },
356   {   0x0800, HB_SCRIPT_SAMARITAN },
357   {   0x1A20, HB_SCRIPT_TAI_THAM },
358   {   0xAA80, HB_SCRIPT_TAI_VIET },
359
360   /* Unicode-6.0 additions */
361   {   0x1BC0, HB_SCRIPT_BATAK },
362   {  0x11000, HB_SCRIPT_BRAHMI },
363   {   0x0840, HB_SCRIPT_MANDAIC },
364
365   /* Unicode-5.2 character additions */
366   {   0x1CED, HB_SCRIPT_INHERITED },
367   {   0x1400, HB_SCRIPT_CANADIAN_ABORIGINAL },
368
369   { 0x111111, HB_SCRIPT_UNKNOWN }
370 };
371
372
373 typedef unsigned int (*get_func_t)         (hb_unicode_funcs_t *ufuncs,
374                                             hb_codepoint_t      unicode,
375                                             void               *user_data);
376 typedef unsigned int (*func_setter_func_t) (hb_unicode_funcs_t *ufuncs,
377                                             get_func_t         *func,
378                                             void               *user_data,
379                                             hb_destroy_func_t   destroy);
380 typedef unsigned int (*getter_func_t)      (hb_unicode_funcs_t *ufuncs,
381                                             hb_codepoint_t      unicode);
382
383 typedef struct {
384   const char         *name;
385   func_setter_func_t  func_setter;
386   getter_func_t       getter;
387   const test_pair_t  *tests;
388   unsigned int        num_tests;
389   const test_pair_t  *tests_more;
390   unsigned int        num_tests_more;
391   unsigned int        default_value;
392 } property_t;
393
394 #define RETURNS_UNICODE_ITSELF ((unsigned int) -1)
395
396 #define PROPERTY(name, DEFAULT) \
397   { \
398     #name, \
399     (func_setter_func_t) hb_unicode_funcs_set_##name##_func, \
400     (getter_func_t) hb_unicode_get_##name, \
401     name##_tests, \
402     G_N_ELEMENTS (name##_tests), \
403     name##_tests_more, \
404     G_N_ELEMENTS (name##_tests_more), \
405     DEFAULT \
406   }
407 static const property_t properties[] =
408 {
409   PROPERTY (combining_class, 0),
410   PROPERTY (eastasian_width, 1),
411   PROPERTY (general_category, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER),
412   PROPERTY (mirroring, RETURNS_UNICODE_ITSELF),
413   PROPERTY (script, (unsigned int) HB_SCRIPT_UNKNOWN),
414 };
415 #undef PROPERTY
416
417 static void
418 test_unicode_properties (gconstpointer user_data)
419 {
420   hb_unicode_funcs_t *uf = (hb_unicode_funcs_t *) user_data;
421   unsigned int i, j;
422
423   g_assert (hb_unicode_funcs_is_immutable (uf));
424
425   for (i = 0; i < G_N_ELEMENTS (properties); i++) {
426     const property_t *p = &properties[i];
427     const test_pair_t *tests;
428
429     g_test_message ("Testing property %s", p->name);
430     tests = p->tests;
431     for (j = 0; j < p->num_tests; j++) {
432       g_test_message ("Test %s #%d: U+%04X", p->name, j, tests[j].unicode);
433       g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, tests[j].value);
434     }
435   }
436 }
437
438 static hb_codepoint_t
439 default_value (hb_codepoint_t default_value, hb_codepoint_t unicode)
440 {
441   return default_value == RETURNS_UNICODE_ITSELF ?  unicode : default_value;
442 }
443
444 static void
445 test_unicode_properties_nil (void)
446 {
447   hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL);
448   unsigned int i, j;
449
450   g_assert (!hb_unicode_funcs_is_immutable (uf));
451
452   for (i = 0; i < G_N_ELEMENTS (properties); i++) {
453     const property_t *p = &properties[i];
454     const test_pair_t *tests;
455
456     tests = p->tests;
457     for (j = 0; j < p->num_tests; j++)
458       g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, default_value (p->default_value, tests[j].unicode));
459   }
460
461   hb_unicode_funcs_destroy (uf);
462 }
463
464 #define MAGIC0 0x12345678
465 #define MAGIC1 0x76543210
466
467 typedef struct {
468   int value;
469   gboolean freed;
470 } data_t;
471
472 typedef struct {
473   data_t data[2];
474 } data_fixture_t;
475 static void
476 data_fixture_init (data_fixture_t *f, gconstpointer user_data)
477 {
478   f->data[0].value = MAGIC0;
479   f->data[1].value = MAGIC1;
480 }
481 static void
482 data_fixture_finish (data_fixture_t *f, gconstpointer user_data)
483 {
484 }
485
486 static void free_up (void *p)
487 {
488   data_t *data = (data_t *) p;
489
490   g_assert (data->value == MAGIC0 || data->value == MAGIC1);
491   g_assert (data->freed == FALSE);
492   data->freed = TRUE;
493 }
494
495 static hb_script_t
496 simple_get_script (hb_unicode_funcs_t *ufuncs,
497                    hb_codepoint_t      codepoint,
498                    void               *user_data)
499 {
500   data_t *data = (data_t *) user_data;
501
502   g_assert (hb_unicode_funcs_get_parent (ufuncs) == NULL);
503   g_assert (data->value == MAGIC0);
504   g_assert (data->freed == FALSE);
505
506   if ('a' <= codepoint && codepoint <= 'z')
507     return HB_SCRIPT_LATIN;
508   else
509     return HB_SCRIPT_UNKNOWN;
510 }
511
512 static hb_script_t
513 a_is_for_arabic_get_script (hb_unicode_funcs_t *ufuncs,
514                             hb_codepoint_t      codepoint,
515                             void               *user_data)
516 {
517   data_t *data = (data_t *) user_data;
518
519   g_assert (hb_unicode_funcs_get_parent (ufuncs) != NULL);
520   g_assert (data->value == MAGIC1);
521   g_assert (data->freed == FALSE);
522
523   if (codepoint == 'a') {
524     return HB_SCRIPT_ARABIC;
525   } else {
526     hb_unicode_funcs_t *parent = hb_unicode_funcs_get_parent (ufuncs);
527
528     return hb_unicode_get_script (parent, codepoint);
529   }
530 }
531
532 static void
533 test_unicode_custom (data_fixture_t *f, gconstpointer user_data)
534 {
535   hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL);
536
537   hb_unicode_funcs_set_script_func (uf, simple_get_script,
538                                     &f->data[0], free_up);
539
540   g_assert_cmpint (hb_unicode_get_script (uf, 'a'), ==, HB_SCRIPT_LATIN);
541   g_assert_cmpint (hb_unicode_get_script (uf, '0'), ==, HB_SCRIPT_UNKNOWN);
542
543   g_assert (!hb_unicode_funcs_is_immutable (uf));
544   hb_unicode_funcs_make_immutable (uf);
545   g_assert (hb_unicode_funcs_is_immutable (uf));
546
547   /* Since uf is immutable now, the following setter should do nothing. */
548   hb_unicode_funcs_set_script_func (uf, a_is_for_arabic_get_script,
549                                     &f->data[1], free_up);
550
551   g_assert (!f->data[0].freed && !f->data[1].freed);
552   hb_unicode_funcs_destroy (uf);
553   g_assert (f->data[0].freed && !f->data[1].freed);
554 }
555
556 static void
557 test_unicode_subclassing_nil (data_fixture_t *f, gconstpointer user_data)
558 {
559   hb_unicode_funcs_t *uf, *aa;
560
561   uf = hb_unicode_funcs_create (NULL);
562
563   aa = hb_unicode_funcs_create (uf);
564
565   hb_unicode_funcs_destroy (uf);
566
567   hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
568                                     &f->data[1], free_up);
569
570   g_assert_cmpint (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
571   g_assert_cmpint (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_UNKNOWN);
572
573   g_assert (!f->data[0].freed && !f->data[1].freed);
574   hb_unicode_funcs_destroy (aa);
575   g_assert (!f->data[0].freed && f->data[1].freed);
576 }
577
578 static void
579 test_unicode_subclassing_default (data_fixture_t *f, gconstpointer user_data)
580 {
581   hb_unicode_funcs_t *uf, *aa;
582
583   uf = hb_unicode_funcs_get_default ();
584   aa = hb_unicode_funcs_create (uf);
585
586   hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
587                                     &f->data[1], free_up);
588
589   g_assert_cmpint (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
590   g_assert_cmpint (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_LATIN);
591
592   g_assert (!f->data[0].freed && !f->data[1].freed);
593   hb_unicode_funcs_destroy (aa);
594   g_assert (!f->data[0].freed && f->data[1].freed);
595 }
596
597 static void
598 test_unicode_subclassing_deep (data_fixture_t *f, gconstpointer user_data)
599 {
600   hb_unicode_funcs_t *uf, *aa;
601
602   uf = hb_unicode_funcs_create (NULL);
603
604   hb_unicode_funcs_set_script_func (uf, simple_get_script,
605                                     &f->data[0], free_up);
606
607   aa = hb_unicode_funcs_create (uf);
608
609   hb_unicode_funcs_destroy (uf);
610
611   /* make sure the 'uf' didn't get freed, since 'aa' holds a ref */
612   g_assert (!f->data[0].freed);
613
614   hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
615                                     &f->data[1], free_up);
616
617   g_assert_cmpint (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
618   g_assert_cmpint (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_LATIN);
619   g_assert_cmpint (hb_unicode_get_script (aa, '0'), ==, HB_SCRIPT_UNKNOWN);
620
621   g_assert (!f->data[0].freed && !f->data[1].freed);
622   hb_unicode_funcs_destroy (aa);
623   g_assert (f->data[0].freed && f->data[1].freed);
624 }
625
626
627 int
628 main (int argc, char **argv)
629 {
630   hb_test_init (&argc, &argv);
631
632   hb_test_add (test_unicode_properties_nil);
633
634   hb_test_add_data_flavor (hb_unicode_funcs_get_default (), "default", test_unicode_properties);
635 #ifdef HAVE_GLIB
636   hb_test_add_data_flavor (hb_glib_get_unicode_funcs (),    "glib",    test_unicode_properties);
637 #endif
638 #ifdef HAVE_ICU
639   hb_test_add_data_flavor (hb_icu_get_unicode_funcs (),     "icu",    test_unicode_properties);
640 #endif
641
642   hb_test_add_fixture (data_fixture, NULL, test_unicode_custom);
643   hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_nil);
644   hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_default);
645   hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_deep);
646
647   /* XXX test icu ufuncs */
648   /* XXX test _more tests (warn?) */
649   /* XXX test chainup */
650   /* XXX test glib & icu two-way script conversion */
651
652   return hb_test_run ();
653 }