[HarfBuzz] harfbuzz-ng: Branch 'master' - 23 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Mon May 2 16:55:36 PDT 2011
src/hb-blob.cc | 2
src/hb-blob.h | 2
src/hb-buffer.cc | 8
src/hb-common.cc | 10
src/hb-common.h | 5
src/hb-font.cc | 5
src/hb-icu.cc | 3
src/hb-object-private.hh | 7
src/hb-open-type-private.hh | 2
src/hb-ot-tag.cc | 2
src/hb-private.hh | 26 -
src/hb-unicode-private.hh | 2
src/hb-unicode.cc | 29 -
src/hb-unicode.h | 2
test/Makefile.am | 4
test/hb-test.h | 4
test/test-buffer.c | 156 ++++----
test/test-c.c | 1
test/test-common.c | 3
test/test-cplusplus.cc | 1
test/test-object.c | 316 ++++++++++++++++++
test/test-unicode.c | 765 ++++++++++++++++++++++++++++++++++++++------
22 files changed, 1144 insertions(+), 211 deletions(-)
New commits:
commit 5a5030366e40baa8d96ca67b47a52ad5af143157
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 19:54:29 2011 -0400
Fix bug in array growth implementation
With this, test/object is now passing. Yay!
diff --git a/src/hb-private.hh b/src/hb-private.hh
index dc47000..02fc099 100644
--- a/src/hb-private.hh
+++ b/src/hb-private.hh
@@ -294,30 +294,28 @@ struct hb_static_array_t {
}
if (likely (len < allocated))
return &array[len++];
+
/* Need to reallocate */
unsigned int new_allocated = allocated + (allocated >> 1) + 8;
- Type *new_array;
+ Type *new_array = NULL;
+
if (array == static_array) {
new_array = (Type *) calloc (new_allocated, sizeof (Type));
- if (new_array) {
+ if (new_array)
memcpy (new_array, array, len * sizeof (Type));
- array = new_array;
- }
} else {
bool overflows = (new_allocated < allocated) || _hb_unsigned_int_mul_overflows (new_allocated, sizeof (Type));
- if (unlikely (overflows))
- new_array = NULL;
- else
+ if (likely (!overflows)) {
new_array = (Type *) realloc (array, new_allocated * sizeof (Type));
- if (new_array) {
- free (array);
- array = new_array;
}
}
- if ((len < allocated))
- return &array[len++];
- else
+
+ if (unlikely (!new_array))
return NULL;
+
+ array = new_array;
+ allocated = new_allocated;
+ return &array[len++];
}
inline void pop (void)
commit 16123e10700436df18d14e37371bb621b31ea5d1
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 19:54:17 2011 -0400
Fix bug in map implementation
diff --git a/src/hb-private.hh b/src/hb-private.hh
index b91595d..dc47000 100644
--- a/src/hb-private.hh
+++ b/src/hb-private.hh
@@ -379,7 +379,7 @@ struct hb_map_t
if (!item) return;
item->finish ();
- items[items.len - 1] = *item;
+ *item = items[items.len - 1];
items.pop ();
}
commit 1cd5969f253528b1fc05a06c7a9f222baa29f68d
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 19:53:39 2011 -0400
[object] Fix bug in get_user_data() implementation
diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh
index d124758..47cef7e 100644
--- a/src/hb-object-private.hh
+++ b/src/hb-object-private.hh
@@ -91,7 +91,8 @@ struct hb_user_data_array_t {
}
inline void *get (hb_user_data_key_t *key) {
- return map.get (key);
+ hb_user_data_t *user_data = map.get (key);
+ return user_data ? user_data->data : NULL;
}
void finish (void) { map.finish (); }
@@ -177,7 +178,7 @@ static inline void hb_object_trace (const Type *obj, const char *function)
obj->header.trace (function);
}
template <typename Type>
-static inline Type *hb_object_create ()
+static inline Type *hb_object_create (void)
{
Type *obj = (Type *) hb_object_header_t::create (sizeof (Type));
hb_object_trace (obj, HB_FUNC);
@@ -186,7 +187,7 @@ static inline Type *hb_object_create ()
template <typename Type>
static inline bool hb_object_is_inert (const Type *obj)
{
- return unlikely (obj->header.is_inert());
+ return unlikely (obj->header.is_inert ());
}
template <typename Type>
static inline Type *hb_object_reference (Type *obj)
commit db99589529a22a2113bcef1680ab6d9b934f382e
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 19:52:47 2011 -0400
[test/object] Add test for object lifecycle stuff
Revealed many bugs in the (untested and known buggy) user_data
support.
diff --git a/test/Makefile.am b/test/Makefile.am
index e48708b..56d6118 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -12,6 +12,7 @@ noinst_PROGRAMS = $(TEST_PROGS)
TEST_PROGS += \
test-buffer \
test-common \
+ test-object \
test-unicode \
$(NULL)
@@ -31,6 +32,9 @@ endif
if HAVE_FREETYPE
test_c_CPPFLAGS += $(FREETYPE_CFLAGS)
test_cplusplus_CPPFLAGS += $(FREETYPE_CFLAGS)
+# TODO replace freetype with other stuff in the following test
+test_object_CPPFLAGS = $(AM_CPPFLAGS) $(FREETYPE_CFLAGS)
+test_object_LIBS = $(LDADD) $(FREETYPE_LIBS)
endif
diff --git a/test/test-object.c b/test/test-object.c
new file mode 100644
index 0000000..0fbabd8
--- /dev/null
+++ b/test/test-object.c
@@ -0,0 +1,316 @@
+/*
+ * Copyright © 2011 Google, Inc.
+ *
+ * This is part of HarfBuzz, a text shaping library.
+ *
+ * Permission is hereby granted, without written agreement and without
+ * license or royalty fees, to use, copy, modify, and distribute this
+ * software and its documentation for any purpose, provided that the
+ * above copyright notice and the following two paragraphs appear in
+ * all copies of this software.
+ *
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
+ * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Google Author(s): Behdad Esfahbod
+ */
+
+#include "hb-test.h"
+
+/* Unit tests for hb-object-private.h */
+
+
+#ifdef HAVE_FREETYPE
+#include <hb-ft.h>
+#endif
+
+
+static void *
+create_blob (void)
+{
+ static char data[] = "test data";
+ return hb_blob_create (data, sizeof (data), HB_MEMORY_MODE_READONLY, NULL, NULL);
+}
+static void *
+create_blob_inert (void)
+{
+ return hb_blob_get_empty ();
+}
+
+static void *
+create_buffer (void)
+{
+ return hb_buffer_create (0);
+}
+static void *
+create_buffer_inert (void)
+{
+ return hb_buffer_create (-1);
+}
+
+static void *
+create_face (void)
+{
+ hb_blob_t *blob = (hb_blob_t *) create_blob ();
+ hb_face_t *face = hb_face_create_for_data (blob, 0);
+ hb_blob_destroy (blob);
+ return face;
+}
+static void *
+create_face_inert (void)
+{
+ return hb_face_create_for_data ((hb_blob_t *) create_blob_inert (), 0);
+}
+
+static void *
+create_font (void)
+{
+ return hb_font_create ();
+}
+static void *
+create_font_inert (void)
+{
+ return NULL;
+}
+
+static void *
+create_font_funcs (void)
+{
+ return hb_font_funcs_create ();
+}
+static void *
+create_font_funcs_inert (void)
+{
+#ifdef HAVE_FREETYPE
+ return hb_ft_get_font_funcs ();
+#else
+ return NULL;
+#endif
+}
+
+static void *
+create_unicode_funcs (void)
+{
+ return hb_unicode_funcs_create (NULL);
+}
+static void *
+create_unicode_funcs_inert (void)
+{
+ return hb_unicode_funcs_get_default ();
+}
+
+
+
+typedef void *(*create_func_t) (void);
+typedef void *(*reference_func_t) (void *obj);
+typedef void (*destroy_func_t) (void *obj);
+typedef hb_bool_t (*set_user_data_func_t) (void *obj, hb_user_data_key_t *key, void *data, hb_destroy_func_t destroy);
+typedef void * (*get_user_data_func_t) (void *obj, hb_user_data_key_t *key);
+typedef void (*make_immutable_func_t) (void *obj);
+typedef hb_bool_t (*is_immutable_func_t) (void *obj);
+
+typedef struct {
+ create_func_t create;
+ create_func_t create_inert;
+ reference_func_t reference;
+ destroy_func_t destroy;
+ set_user_data_func_t set_user_data;
+ get_user_data_func_t get_user_data;
+ make_immutable_func_t make_immutable;
+ is_immutable_func_t is_immutable;
+ const char *name;
+} object_t;
+
+#define OBJECT_WITHOUT_IMMUTABILITY(name) \
+ { \
+ (create_func_t) create_##name, \
+ (create_func_t) create_##name##_inert, \
+ (reference_func_t) hb_##name##_reference, \
+ (destroy_func_t) hb_##name##_destroy, \
+ (set_user_data_func_t) hb_##name##_set_user_data, \
+ (get_user_data_func_t) hb_##name##_get_user_data, \
+ (make_immutable_func_t) NULL, \
+ (is_immutable_func_t) NULL, \
+ #name, \
+ }
+#define OBJECT_WITH_IMMUTABILITY(name) \
+ { \
+ (create_func_t) create_##name, \
+ (create_func_t) create_##name##_inert, \
+ (reference_func_t) hb_##name##_reference, \
+ (destroy_func_t) hb_##name##_destroy, \
+ (set_user_data_func_t) hb_##name##_set_user_data, \
+ (get_user_data_func_t) hb_##name##_get_user_data, \
+ (make_immutable_func_t) hb_##name##_make_immutable, \
+ (is_immutable_func_t) hb_##name##_is_immutable, \
+ #name, \
+ }
+static const object_t objects[] =
+{
+ OBJECT_WITHOUT_IMMUTABILITY (blob),
+ OBJECT_WITHOUT_IMMUTABILITY (buffer),
+ OBJECT_WITHOUT_IMMUTABILITY (face),
+ OBJECT_WITHOUT_IMMUTABILITY (font),
+ OBJECT_WITH_IMMUTABILITY (font_funcs),
+ OBJECT_WITH_IMMUTABILITY (unicode_funcs)
+};
+#undef OBJECT
+
+
+#define MAGIC0 0x12345678
+#define MAGIC1 0x76543210
+
+typedef struct {
+ int value;
+ gboolean freed;
+} data_t;
+
+static int global_data;
+
+static void global_free_up (void *p G_GNUC_UNUSED)
+{
+ global_data++;
+}
+
+static void free_up0 (void *p)
+{
+ data_t *data = (data_t *) p;
+
+ g_assert_cmphex (data->value, ==, MAGIC0);
+ g_assert (!data->freed);
+ data->freed = TRUE;
+}
+
+static void free_up1 (void *p)
+{
+ data_t *data = (data_t *) p;
+
+ g_assert_cmphex (data->value, ==, MAGIC1);
+ g_assert (!data->freed);
+ data->freed = TRUE;
+}
+
+static void
+test_object (void)
+{
+ unsigned int i;
+
+ for (i = 0; i < G_N_ELEMENTS (objects); i++) {
+ const object_t *o = &objects[i];
+ void *obj;
+ hb_user_data_key_t key[2];
+
+ {
+ unsigned int i;
+ data_t data[2] = {{MAGIC0, FALSE}, {MAGIC1, FALSE}};
+
+ g_test_message ("Testing object %s", o->name);
+
+ g_test_message ("->create()");
+ obj = o->create ();
+ g_assert (obj);
+
+ g_assert (obj == o->reference (obj));
+ o->destroy (obj);
+
+ if (o->is_immutable)
+ g_assert (!o->is_immutable (obj));
+
+ g_assert (o->set_user_data (obj, &key[0], &data[0], free_up0));
+ g_assert (o->get_user_data (obj, &key[0]) == &data[0]);
+
+ if (o->is_immutable) {
+ o->make_immutable (obj);
+ g_assert (o->is_immutable (obj));
+ }
+
+ /* Should still work even if object is made immutable */
+ g_assert (o->set_user_data (obj, &key[1], &data[1], free_up1));
+ g_assert (o->get_user_data (obj, &key[1]) == &data[1]);
+
+ g_assert (!o->set_user_data (obj, NULL, &data[0], free_up0));
+ g_assert (o->get_user_data (obj, &key[0]) == &data[0]);
+ g_assert (o->set_user_data (obj, &key[0], &data[1], NULL));
+ g_assert (data[0].freed);
+ g_assert (o->get_user_data (obj, &key[0]) == &data[1]);
+ g_assert (!data[1].freed);
+
+ data[0].freed = FALSE;
+ g_assert (o->set_user_data (obj, &key[0], &data[0], free_up0));
+ g_assert (!data[0].freed);
+ g_assert (o->set_user_data (obj, &key[0], NULL, NULL));
+ g_assert (data[0].freed);
+
+ data[0].freed = FALSE;
+ global_data = 0;
+ g_assert (o->set_user_data (obj, &key[0], &data[0], free_up0));
+ g_assert_cmpuint (global_data, ==, 0);
+ g_assert (o->set_user_data (obj, &key[0], NULL, global_free_up));
+ g_assert_cmpuint (global_data, ==, 0);
+ g_assert (o->set_user_data (obj, &key[0], NULL, NULL));
+ g_assert_cmpuint (global_data, ==, 1);
+
+ global_data = 0;
+ for (i = 2; i < 1000; i++)
+ g_assert (o->set_user_data (obj, &key[i], &data[i], global_free_up));
+ for (i = 2; i < 1000; i++)
+ g_assert (o->get_user_data (obj, &key[i]) == &data[i]);
+ for (i = 100; i < 1000; i++)
+ g_assert (o->set_user_data (obj, &key[i], NULL, NULL));
+ g_assert_cmpuint (global_data, ==, 900);
+
+
+ g_assert (!data[1].freed);
+ o->destroy (obj);
+ g_assert (data[0].freed);
+ g_assert (data[1].freed);
+ g_assert_cmpuint (global_data, ==, 1000-2);
+ }
+
+ {
+ data_t data[2] = {{MAGIC0, FALSE}, {MAGIC1, FALSE}};
+
+ g_test_message ("->create_inert()");
+ obj = o->create_inert ();
+ if (!obj)
+ continue;
+
+ g_assert (obj == o->reference (obj));
+ o->destroy (obj);
+
+ if (o->is_immutable)
+ g_assert (o->is_immutable (obj));
+
+ g_assert (!o->set_user_data (obj, &key[0], &data[0], free_up0));
+ g_assert (!o->get_user_data (obj, &key[0]));
+
+ o->destroy (obj);
+ o->destroy (obj);
+ o->destroy (obj);
+ o->destroy (obj);
+ o->destroy (obj);
+
+ g_assert (!data[0].freed);
+ }
+ }
+}
+
+
+int
+main (int argc, char **argv)
+{
+ hb_test_init (&argc, &argv);
+
+ hb_test_add (test_object);
+
+ return hb_test_run ();
+}
commit f74d6c81f14f117b3cecfb65f0d5df22849c9a07
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 19:52:32 2011 -0400
Cosmetic
diff --git a/test/test-unicode.c b/test/test-unicode.c
index 43ccda5..c730aed 100644
--- a/test/test-unicode.c
+++ b/test/test-unicode.c
@@ -56,7 +56,7 @@ static void free_up (void *p)
data_t *data = (data_t *) p;
g_assert (data->value == MAGIC0 || data->value == MAGIC1);
- g_assert (data->freed == FALSE);
+ g_assert (!data->freed);
data->freed = TRUE;
}
@@ -68,8 +68,8 @@ simple_get_script (hb_unicode_funcs_t *ufuncs,
data_t *data = (data_t *) user_data;
g_assert (hb_unicode_funcs_get_parent (ufuncs) != NULL);
- g_assert (data->value == MAGIC0);
- g_assert (data->freed == FALSE);
+ g_assert_cmphex (data->value, ==, MAGIC0);
+ g_assert (!data->freed);
if ('a' <= codepoint && codepoint <= 'z')
return HB_SCRIPT_LATIN;
@@ -85,8 +85,8 @@ a_is_for_arabic_get_script (hb_unicode_funcs_t *ufuncs,
data_t *data = (data_t *) user_data;
g_assert (hb_unicode_funcs_get_parent (ufuncs) != NULL);
- g_assert (data->value == MAGIC1);
- g_assert (data->freed == FALSE);
+ g_assert_cmphex (data->value, ==, MAGIC1);
+ g_assert (!data->freed);
if (codepoint == 'a') {
return HB_SCRIPT_ARABIC;
commit 4911062d5be0d937ee8f1a70cc93e05d162f45b3
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 19:36:39 2011 -0400
[API] Rename hb_blob_create_empty() to hb_blob_get_empty()
diff --git a/src/hb-blob.cc b/src/hb-blob.cc
index 83a75f6..db12758 100644
--- a/src/hb-blob.cc
+++ b/src/hb-blob.cc
@@ -141,7 +141,7 @@ hb_blob_create_sub_blob (hb_blob_t *parent,
}
hb_blob_t *
-hb_blob_create_empty (void)
+hb_blob_get_empty (void)
{
return &_hb_blob_nil;
}
diff --git a/src/hb-blob.h b/src/hb-blob.h
index d698ee2..8bfbd48 100644
--- a/src/hb-blob.h
+++ b/src/hb-blob.h
@@ -54,7 +54,7 @@ hb_blob_create_sub_blob (hb_blob_t *parent,
unsigned int length);
hb_blob_t *
-hb_blob_create_empty (void);
+hb_blob_get_empty (void);
hb_blob_t *
hb_blob_reference (hb_blob_t *blob);
diff --git a/src/hb-font.cc b/src/hb-font.cc
index 0a62fe3..91dde45 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -443,7 +443,7 @@ hb_face_reference_table (hb_face_t *face,
blob = face->get_table (tag, face->user_data);
if (unlikely (!blob))
- blob = hb_blob_create_empty();
+ blob = hb_blob_get_empty();
return blob;
}
diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index af8274d..20df95b 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -334,7 +334,7 @@ struct Sanitizer
return blob;
else {
hb_blob_destroy (blob);
- return hb_blob_create_empty ();
+ return hb_blob_get_empty ();
}
}
commit 1ab1d3e38cdf8e7331efdbc4ef0c02ee9d5c8c04
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 19:35:53 2011 -0400
[face] Return nil face if blob is inert
diff --git a/src/hb-font.cc b/src/hb-font.cc
index 5e4d379..0a62fe3 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -379,6 +379,9 @@ hb_face_t *
hb_face_create_for_data (hb_blob_t *blob,
unsigned int index)
{
+ if (unlikely (hb_object_is_inert (blob)))
+ return &_hb_face_nil;
+
hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (Sanitizer<OpenTypeFontFile>::sanitize (hb_blob_reference (blob)), index);
if (unlikely (!closure))
commit e87867cb88280e3f3a38d829e359cb686168b2cb
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 19:35:05 2011 -0400
[buffer] Fail in _create() if we cannot pre-allocate the requested size
diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc
index 1e49c7a..4009b12 100644
--- a/src/hb-buffer.cc
+++ b/src/hb-buffer.cc
@@ -142,11 +142,13 @@ hb_buffer_create (unsigned int pre_alloc_size)
if (!(buffer = hb_object_create<hb_buffer_t> ()))
return &_hb_buffer_nil;
- if (pre_alloc_size)
- _hb_buffer_ensure (buffer, pre_alloc_size);
-
hb_buffer_reset (buffer);
+ if (pre_alloc_size && !_hb_buffer_ensure (buffer, pre_alloc_size)) {
+ hb_buffer_destroy (buffer);
+ return &_hb_buffer_nil;
+ }
+
return buffer;
}
commit cd361ec9a1b2bfc271e5490dbfc0a870fd5c439a
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 16:54:05 2011 -0400
Cosmetic
diff --git a/test/test-unicode.c b/test/test-unicode.c
index cc95a9f..43ccda5 100644
--- a/test/test-unicode.c
+++ b/test/test-unicode.c
@@ -470,7 +470,7 @@ static const property_t properties[] =
PROPERTY (eastasian_width, 1),
PROPERTY (general_category, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER),
PROPERTY (mirroring, RETURNS_UNICODE_ITSELF),
- PROPERTY (script, (unsigned int) HB_SCRIPT_UNKNOWN),
+ PROPERTY (script, (unsigned int) HB_SCRIPT_UNKNOWN)
};
#undef PROPERTY
commit c784c67a28f5b92d396eaa9529d57ef91a5cb9ac
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 15:59:57 2011 -0400
[unicode] Make _get_parent() return _nil object instead of NULL
diff --git a/src/hb-unicode.cc b/src/hb-unicode.cc
index 0486be3..e8eb553 100644
--- a/src/hb-unicode.cc
+++ b/src/hb-unicode.cc
@@ -110,22 +110,18 @@ hb_unicode_funcs_create (hb_unicode_funcs_t *parent)
if (!(ufuncs = hb_object_create<hb_unicode_funcs_t> ()))
return &_hb_unicode_funcs_nil;
- if (parent != NULL)
- {
- hb_unicode_funcs_make_immutable (parent);
- ufuncs->parent = hb_unicode_funcs_reference (parent);
+ if (!parent)
+ parent = &_hb_unicode_funcs_nil;
- ufuncs->get = parent->get;
+ hb_unicode_funcs_make_immutable (parent);
+ ufuncs->parent = hb_unicode_funcs_reference (parent);
- /* We can safely copy user_data from parent since we hold a reference
- * onto it and it's immutable. We should not copy the destroy notifiers
- * though. */
- ufuncs->user_data = parent->user_data;
- }
- else
- {
- ufuncs->get = _hb_unicode_funcs_nil.get;
- }
+ ufuncs->get = parent->get;
+
+ /* We can safely copy user_data from parent since we hold a reference
+ * onto it and it's immutable. We should not copy the destroy notifiers
+ * though. */
+ ufuncs->user_data = parent->user_data;
return ufuncs;
}
@@ -149,8 +145,7 @@ hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs)
DESTROY (script);
#undef DESTROY
- if (ufuncs->parent != NULL)
- hb_unicode_funcs_destroy (ufuncs->parent);
+ hb_unicode_funcs_destroy (ufuncs->parent);
free (ufuncs);
}
@@ -190,7 +185,7 @@ hb_unicode_funcs_is_immutable (hb_unicode_funcs_t *ufuncs)
hb_unicode_funcs_t *
hb_unicode_funcs_get_parent (hb_unicode_funcs_t *ufuncs)
{
- return ufuncs->parent;
+ return ufuncs->parent ? ufuncs->parent : &_hb_unicode_funcs_nil;
}
diff --git a/test/test-unicode.c b/test/test-unicode.c
index 96d6806..cc95a9f 100644
--- a/test/test-unicode.c
+++ b/test/test-unicode.c
@@ -67,7 +67,7 @@ simple_get_script (hb_unicode_funcs_t *ufuncs,
{
data_t *data = (data_t *) user_data;
- g_assert (hb_unicode_funcs_get_parent (ufuncs) == NULL);
+ g_assert (hb_unicode_funcs_get_parent (ufuncs) != NULL);
g_assert (data->value == MAGIC0);
g_assert (data->freed == FALSE);
commit 07e22779abd089d5921bf2d19d4a3bf1bd0173c6
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 14:58:04 2011 -0400
[test/unicode] Add script roundtrip tests for glib and ICU
diff --git a/test/test-unicode.c b/test/test-unicode.c
index 19bd387..96d6806 100644
--- a/test/test-unicode.c
+++ b/test/test-unicode.c
@@ -29,6 +29,8 @@
#include "hb-test.h"
/* Unit tests for hb-unicode.h */
+/* Unit tests for hb-glib.h */
+/* Unit tests for hb-icu.h */
#ifdef HAVE_GLIB
@@ -504,7 +506,7 @@ test_unicode_properties (gconstpointer user_data)
}
if (failed)
- g_message ("Some property tests failed. You probably have an old version of one of the libraries used. Rerun with --verbose for details");
+ g_test_message ("Some property tests failed. You probably have an old version of one of the libraries used.");
}
static hb_codepoint_t
@@ -710,6 +712,61 @@ test_unicode_subclassing_deep (data_fixture_t *f, gconstpointer user_data)
}
+static hb_script_t
+script_roundtrip_default (hb_script_t script)
+{
+ return hb_script_from_iso15924_tag (hb_script_to_iso15924_tag (script));
+}
+
+#ifdef HAVE_GLIB
+static hb_script_t
+script_roundtrip_glib (hb_script_t script)
+{
+ return hb_glib_script_to_script (hb_glib_script_from_script (script));
+}
+#endif
+
+#ifdef HAVE_ICU
+static hb_script_t
+script_roundtrip_icu (hb_script_t script)
+{
+ return hb_icu_script_to_script (hb_icu_script_from_script (script));
+}
+#endif
+
+static void
+test_unicode_script_roundtrip (gconstpointer user_data)
+{
+ typedef hb_script_t (*roundtrip_func_t) (hb_script_t);
+ roundtrip_func_t roundtrip_func = (roundtrip_func_t) user_data;
+ unsigned int i;
+ gboolean failed = FALSE;
+
+ for (i = 0; i < G_N_ELEMENTS (script_tests); i++) {
+ const test_pair_t *test = &script_tests[i];
+ hb_script_t script = test->value;
+
+ g_test_message ("Test script roundtrip #%d: %x", i, script);
+ g_assert_cmphex (script, ==, roundtrip_func (script));
+ }
+ for (i = 0; i < G_N_ELEMENTS (script_tests_more); i++) {
+ const test_pair_t *test = &script_tests_more[i];
+ hb_script_t script = test->value;
+
+ g_test_message ("Test script roundtrip more #%d: %x", i, script);
+ if (script != roundtrip_func (script)) {
+ g_test_message ("Soft fail: Received %x, expected %x", roundtrip_func (script), script);
+ failed = TRUE;
+ }
+ }
+
+ g_assert_cmphex (HB_SCRIPT_INVALID, ==, roundtrip_func (HB_SCRIPT_INVALID));
+
+ if (failed)
+ g_test_message ("Some script roundtrip tests failed. You probably have an old version of one of the libraries used.");
+}
+
+
int
main (int argc, char **argv)
{
@@ -717,12 +774,15 @@ main (int argc, char **argv)
hb_test_add (test_unicode_properties_nil);
- hb_test_add_data_flavor (hb_unicode_funcs_get_default (), "default", test_unicode_properties);
+ hb_test_add_data_flavor (hb_unicode_funcs_get_default (), "default", test_unicode_properties);
+ hb_test_add_data_flavor ((gconstpointer) script_roundtrip_default, "default", test_unicode_script_roundtrip);
#ifdef HAVE_GLIB
- hb_test_add_data_flavor (hb_glib_get_unicode_funcs (), "glib", test_unicode_properties);
+ hb_test_add_data_flavor (hb_glib_get_unicode_funcs (), "glib", test_unicode_properties);
+ hb_test_add_data_flavor ((gconstpointer) script_roundtrip_glib, "glib", test_unicode_script_roundtrip);
#endif
#ifdef HAVE_ICU
- hb_test_add_data_flavor (hb_icu_get_unicode_funcs (), "icu", test_unicode_properties);
+ hb_test_add_data_flavor (hb_icu_get_unicode_funcs (), "icu", test_unicode_properties);
+ hb_test_add_data_flavor ((gconstpointer) script_roundtrip_icu, "icu", test_unicode_script_roundtrip);
#endif
hb_test_add (test_unicode_chainup);
@@ -733,7 +793,5 @@ main (int argc, char **argv)
hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_default);
hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_deep);
- /* XXX test glib & icu two-way script conversion */
-
return hb_test_run ();
}
commit 7cda65935c73c277550f6ac12f6730e96d4852a7
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 14:33:53 2011 -0400
[test/unicode] Better test chainup
diff --git a/test/test-unicode.c b/test/test-unicode.c
index 68cb320..19bd387 100644
--- a/test/test-unicode.c
+++ b/test/test-unicode.c
@@ -514,13 +514,10 @@ default_value (hb_codepoint_t default_value, hb_codepoint_t unicode)
}
static void
-test_unicode_properties_nil (void)
+_test_unicode_properties_nil (hb_unicode_funcs_t *uf)
{
- hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL);
unsigned int i, j;
- g_assert (!hb_unicode_funcs_is_immutable (uf));
-
for (i = 0; i < G_N_ELEMENTS (properties); i++) {
const property_t *p = &properties[i];
const test_pair_t *tests;
@@ -537,8 +534,54 @@ test_unicode_properties_nil (void)
g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, default_value (p->default_value, tests[j].unicode));
}
}
+}
+
+static void
+test_unicode_properties_nil (void)
+{
+ hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL);
+
+ g_assert (!hb_unicode_funcs_is_immutable (uf));
+ _test_unicode_properties_nil (uf);
+
+ hb_unicode_funcs_destroy (uf);
+}
+
+
+static void
+test_unicode_chainup (void)
+{
+ hb_unicode_funcs_t *uf, *uf2;
+
+ /* Chain-up to nil */
+
+ uf = hb_unicode_funcs_create (NULL);
+ g_assert (!hb_unicode_funcs_is_immutable (uf));
+
+ uf2 = hb_unicode_funcs_create (uf);
+ g_assert (hb_unicode_funcs_is_immutable (uf));
+ hb_unicode_funcs_destroy (uf);
+
+ g_assert (!hb_unicode_funcs_is_immutable (uf2));
+ _test_unicode_properties_nil (uf2);
+ hb_unicode_funcs_destroy (uf2);
+
+ /* Chain-up to default */
+
+ uf = hb_unicode_funcs_create (hb_unicode_funcs_get_default ());
+ g_assert (!hb_unicode_funcs_is_immutable (uf));
+
+ uf2 = hb_unicode_funcs_create (uf);
+ g_assert (hb_unicode_funcs_is_immutable (uf));
hb_unicode_funcs_destroy (uf);
+
+ g_assert (!hb_unicode_funcs_is_immutable (uf2));
+ hb_unicode_funcs_make_immutable (uf2);
+ test_unicode_properties (uf2);
+
+ hb_unicode_funcs_destroy (uf2);
+
}
static void
@@ -682,13 +725,14 @@ main (int argc, char **argv)
hb_test_add_data_flavor (hb_icu_get_unicode_funcs (), "icu", test_unicode_properties);
#endif
+ hb_test_add (test_unicode_chainup);
+
hb_test_add (test_unicode_setters);
hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_nil);
hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_default);
hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_deep);
- /* XXX test chainup */
/* XXX test glib & icu two-way script conversion */
return hb_test_run ();
commit 250c59225ead28449deb11522dee3819480a19b4
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 14:21:30 2011 -0400
[test/unicode] Port the _custom test to test all property setters
diff --git a/test/test-unicode.c b/test/test-unicode.c
index d8e38da..68cb320 100644
--- a/test/test-unicode.c
+++ b/test/test-unicode.c
@@ -39,6 +39,64 @@
#endif
+/* Some useful stuff */
+
+#define MAGIC0 0x12345678
+#define MAGIC1 0x76543210
+
+typedef struct {
+ int value;
+ gboolean freed;
+} data_t;
+
+static void free_up (void *p)
+{
+ data_t *data = (data_t *) p;
+
+ g_assert (data->value == MAGIC0 || data->value == MAGIC1);
+ g_assert (data->freed == FALSE);
+ data->freed = TRUE;
+}
+
+static hb_script_t
+simple_get_script (hb_unicode_funcs_t *ufuncs,
+ hb_codepoint_t codepoint,
+ void *user_data)
+{
+ data_t *data = (data_t *) user_data;
+
+ g_assert (hb_unicode_funcs_get_parent (ufuncs) == NULL);
+ g_assert (data->value == MAGIC0);
+ g_assert (data->freed == FALSE);
+
+ if ('a' <= codepoint && codepoint <= 'z')
+ return HB_SCRIPT_LATIN;
+ else
+ return HB_SCRIPT_UNKNOWN;
+}
+
+static hb_script_t
+a_is_for_arabic_get_script (hb_unicode_funcs_t *ufuncs,
+ hb_codepoint_t codepoint,
+ void *user_data)
+{
+ data_t *data = (data_t *) user_data;
+
+ g_assert (hb_unicode_funcs_get_parent (ufuncs) != NULL);
+ g_assert (data->value == MAGIC1);
+ g_assert (data->freed == FALSE);
+
+ if (codepoint == 'a') {
+ return HB_SCRIPT_ARABIC;
+ } else {
+ hb_unicode_funcs_t *parent = hb_unicode_funcs_get_parent (ufuncs);
+
+ return hb_unicode_get_script (parent, codepoint);
+ }
+}
+
+
+
/* Check all properties */
/* Some of the following tables where adapted from glib/glib/tests/utf8-misc.c.
@@ -374,7 +432,7 @@ typedef unsigned int (*get_func_t) (hb_unicode_funcs_t *ufuncs,
hb_codepoint_t unicode,
void *user_data);
typedef unsigned int (*func_setter_func_t) (hb_unicode_funcs_t *ufuncs,
- get_func_t *func,
+ get_func_t func,
void *user_data,
hb_destroy_func_t destroy);
typedef unsigned int (*getter_func_t) (hb_unicode_funcs_t *ufuncs,
@@ -483,96 +541,59 @@ test_unicode_properties_nil (void)
hb_unicode_funcs_destroy (uf);
}
-#define MAGIC0 0x12345678
-#define MAGIC1 0x76543210
-
-typedef struct {
- int value;
- gboolean freed;
-} data_t;
-
-typedef struct {
- data_t data[2];
-} data_fixture_t;
-static void
-data_fixture_init (data_fixture_t *f, gconstpointer user_data)
-{
- f->data[0].value = MAGIC0;
- f->data[1].value = MAGIC1;
-}
static void
-data_fixture_finish (data_fixture_t *f, gconstpointer user_data)
+test_unicode_setters (void)
{
-}
+ hb_unicode_funcs_t *uf;
+ unsigned int i;
-static void free_up (void *p)
-{
- data_t *data = (data_t *) p;
+ /* This is cruel: we use script-returning functions to test all properties,
+ * but it works. */
- g_assert (data->value == MAGIC0 || data->value == MAGIC1);
- g_assert (data->freed == FALSE);
- data->freed = TRUE;
-}
+ for (i = 0; i < G_N_ELEMENTS (properties); i++) {
+ const property_t *p = &properties[i];
+ data_t data[2] = {{MAGIC0, FALSE}, {MAGIC1, FALSE}};
-static hb_script_t
-simple_get_script (hb_unicode_funcs_t *ufuncs,
- hb_codepoint_t codepoint,
- void *user_data)
-{
- data_t *data = (data_t *) user_data;
+ g_test_message ("Testing property %s", p->name);
- g_assert (hb_unicode_funcs_get_parent (ufuncs) == NULL);
- g_assert (data->value == MAGIC0);
- g_assert (data->freed == FALSE);
+ uf = hb_unicode_funcs_create (NULL);
+ g_assert (!hb_unicode_funcs_is_immutable (uf));
- if ('a' <= codepoint && codepoint <= 'z')
- return HB_SCRIPT_LATIN;
- else
- return HB_SCRIPT_UNKNOWN;
-}
+ p->func_setter (uf, (get_func_t) simple_get_script, &data[0], free_up);
-static hb_script_t
-a_is_for_arabic_get_script (hb_unicode_funcs_t *ufuncs,
- hb_codepoint_t codepoint,
- void *user_data)
-{
- data_t *data = (data_t *) user_data;
+ g_assert_cmphex (p->getter (uf, 'a'), ==, HB_SCRIPT_LATIN);
+ g_assert_cmphex (p->getter (uf, '0'), ==, HB_SCRIPT_UNKNOWN);
- g_assert (hb_unicode_funcs_get_parent (ufuncs) != NULL);
- g_assert (data->value == MAGIC1);
- g_assert (data->freed == FALSE);
+ g_assert (!hb_unicode_funcs_is_immutable (uf));
+ hb_unicode_funcs_make_immutable (uf);
+ g_assert (hb_unicode_funcs_is_immutable (uf));
- if (codepoint == 'a') {
- return HB_SCRIPT_ARABIC;
- } else {
- hb_unicode_funcs_t *parent = hb_unicode_funcs_get_parent (ufuncs);
+ /* Since uf is immutable now, the following setter should do nothing. */
+ p->func_setter (uf, (get_func_t) a_is_for_arabic_get_script, &data[1], free_up);
- return hb_unicode_get_script (parent, codepoint);
+ g_assert (!data[0].freed && !data[1].freed);
+ hb_unicode_funcs_destroy (uf);
+ g_assert (data[0].freed && !data[1].freed);
+
+ hb_unicode_funcs_destroy (uf);
}
}
-static void
-test_unicode_custom (data_fixture_t *f, gconstpointer user_data)
-{
- hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL);
- hb_unicode_funcs_set_script_func (uf, simple_get_script,
- &f->data[0], free_up);
-
- g_assert_cmpint (hb_unicode_get_script (uf, 'a'), ==, HB_SCRIPT_LATIN);
- g_assert_cmpint (hb_unicode_get_script (uf, '0'), ==, HB_SCRIPT_UNKNOWN);
- g_assert (!hb_unicode_funcs_is_immutable (uf));
- hb_unicode_funcs_make_immutable (uf);
- g_assert (hb_unicode_funcs_is_immutable (uf));
-
- /* Since uf is immutable now, the following setter should do nothing. */
- hb_unicode_funcs_set_script_func (uf, a_is_for_arabic_get_script,
- &f->data[1], free_up);
+typedef struct {
+ data_t data[2];
+} data_fixture_t;
- g_assert (!f->data[0].freed && !f->data[1].freed);
- hb_unicode_funcs_destroy (uf);
- g_assert (f->data[0].freed && !f->data[1].freed);
+static void
+data_fixture_init (data_fixture_t *f, gconstpointer user_data)
+{
+ f->data[0].value = MAGIC0;
+ f->data[1].value = MAGIC1;
+}
+static void
+data_fixture_finish (data_fixture_t *f, gconstpointer user_data)
+{
}
static void
@@ -589,8 +610,8 @@ test_unicode_subclassing_nil (data_fixture_t *f, gconstpointer user_data)
hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
&f->data[1], free_up);
- g_assert_cmpint (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
- g_assert_cmpint (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_UNKNOWN);
+ g_assert_cmphex (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
+ g_assert_cmphex (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_UNKNOWN);
g_assert (!f->data[0].freed && !f->data[1].freed);
hb_unicode_funcs_destroy (aa);
@@ -608,8 +629,8 @@ test_unicode_subclassing_default (data_fixture_t *f, gconstpointer user_data)
hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
&f->data[1], free_up);
- g_assert_cmpint (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
- g_assert_cmpint (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_LATIN);
+ g_assert_cmphex (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
+ g_assert_cmphex (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_LATIN);
g_assert (!f->data[0].freed && !f->data[1].freed);
hb_unicode_funcs_destroy (aa);
@@ -636,9 +657,9 @@ test_unicode_subclassing_deep (data_fixture_t *f, gconstpointer user_data)
hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
&f->data[1], free_up);
- g_assert_cmpint (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
- g_assert_cmpint (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_LATIN);
- g_assert_cmpint (hb_unicode_get_script (aa, '0'), ==, HB_SCRIPT_UNKNOWN);
+ g_assert_cmphex (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
+ g_assert_cmphex (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_LATIN);
+ g_assert_cmphex (hb_unicode_get_script (aa, '0'), ==, HB_SCRIPT_UNKNOWN);
g_assert (!f->data[0].freed && !f->data[1].freed);
hb_unicode_funcs_destroy (aa);
@@ -661,7 +682,8 @@ main (int argc, char **argv)
hb_test_add_data_flavor (hb_icu_get_unicode_funcs (), "icu", test_unicode_properties);
#endif
- hb_test_add_fixture (data_fixture, NULL, test_unicode_custom);
+ hb_test_add (test_unicode_setters);
+
hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_nil);
hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_default);
hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_deep);
commit e74b5b339ab0af53d893ec84a0955d5aa508fed3
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 14:03:55 2011 -0400
[test/unicode] Test Unicode 5.2+ but don't fail
diff --git a/test/test-unicode.c b/test/test-unicode.c
index c8fdfca..d8e38da 100644
--- a/test/test-unicode.c
+++ b/test/test-unicode.c
@@ -419,6 +419,7 @@ test_unicode_properties (gconstpointer user_data)
{
hb_unicode_funcs_t *uf = (hb_unicode_funcs_t *) user_data;
unsigned int i, j;
+ gboolean failed = TRUE;
g_assert (hb_unicode_funcs_is_immutable (uf));
@@ -432,7 +433,20 @@ test_unicode_properties (gconstpointer user_data)
g_test_message ("Test %s #%d: U+%04X", p->name, j, tests[j].unicode);
g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, tests[j].value);
}
+ /* These tests are from Unicode 5.2 onward and older glib/ICU
+ * don't get them right. Just warn instead of assert. */
+ tests = p->tests_more;
+ for (j = 0; j < p->num_tests_more; j++) {
+ g_test_message ("Test %s more #%d: U+%04X", p->name, j, tests[j].unicode);
+ if (p->getter (uf, tests[j].unicode) != tests[j].value) {
+ g_test_message ("Soft fail: Received %x, expected %x", p->getter (uf, tests[j].unicode), tests[j].value);
+ failed = TRUE;
+ }
+ }
}
+
+ if (failed)
+ g_message ("Some property tests failed. You probably have an old version of one of the libraries used. Rerun with --verbose for details");
}
static hb_codepoint_t
@@ -459,6 +473,11 @@ test_unicode_properties_nil (void)
g_test_message ("Test %s #%d: U+%04X", p->name, j, tests[j].unicode);
g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, default_value (p->default_value, tests[j].unicode));
}
+ tests = p->tests_more;
+ for (j = 0; j < p->num_tests_more; j++) {
+ g_test_message ("Test %s more #%d: U+%04X", p->name, j, tests[j].unicode);
+ g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, default_value (p->default_value, tests[j].unicode));
+ }
}
hb_unicode_funcs_destroy (uf);
@@ -647,8 +666,6 @@ main (int argc, char **argv)
hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_default);
hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_deep);
- /* XXX test icu ufuncs */
- /* XXX test _more tests (warn?) */
/* XXX test chainup */
/* XXX test glib & icu two-way script conversion */
commit c763aa42b46eaee95359806cab56fa632ff3ad58
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 13:52:17 2011 -0400
[test/buffer] Clean up testing
Getting the hang of how to cleanly use gtest.
diff --git a/test/test-buffer.c b/test/test-buffer.c
index 1468bfb..3f0eb56 100644
--- a/test/test-buffer.c
+++ b/test/test-buffer.c
@@ -320,10 +320,10 @@ test_buffer_allocation (fixture_t *fixture, gconstpointer user_data)
typedef struct {
const char utf8[8];
const uint32_t codepoints[8];
-} utf8_test_t;
+} utf8_conversion_test_t;
/* note: we skip the first and last byte when adding to buffer */
-static const utf8_test_t utf8_tests[] = {
+static const utf8_conversion_test_t utf8_conversion_tests[] = {
{"a\303\207", {-1}},
{"a\303\207b", {0xC7}},
{"ab\303cd", {'b', -1, 'c'}},
@@ -331,24 +331,35 @@ static const utf8_test_t utf8_tests[] = {
};
static void
-test_buffer_utf8 (gconstpointer user_data)
+test_buffer_utf8_conversion (void)
{
- const utf8_test_t *test = user_data;
hb_buffer_t *b;
hb_glyph_info_t *glyphs;
- unsigned int bytes, chars, i, len;
-
- bytes = strlen (test->utf8);
- for (chars = 0; test->codepoints[chars]; chars++)
- ;
+ unsigned int bytes, chars, i, j, len;
b = hb_buffer_create (0);
- hb_buffer_add_utf8 (b, test->utf8, bytes, 1, bytes - 2);
- glyphs = hb_buffer_get_glyph_infos (b, &len);
- g_assert_cmpint (len, ==, chars);
- for (i = 0; i < chars; i++)
- g_assert_cmphex (glyphs[i].codepoint, ==, test->codepoints[i]);
+ for (i = 0; i < G_N_ELEMENTS (utf8_conversion_tests); i++)
+ {
+ const utf8_conversion_test_t *test = &utf8_conversion_tests[i];
+ char *escaped;
+
+ escaped = g_strescape (test->utf8, NULL);
+ g_test_message ("UTF-8 test #%d: %s", i, escaped);
+ g_free (escaped);
+
+ bytes = strlen (test->utf8);
+ for (chars = 0; test->codepoints[chars]; chars++)
+ ;
+
+ hb_buffer_reset (b);
+ hb_buffer_add_utf8 (b, test->utf8, bytes, 1, bytes - 2);
+
+ glyphs = hb_buffer_get_glyph_infos (b, &len);
+ g_assert_cmpint (len, ==, chars);
+ for (j = 0; j < chars; j++)
+ g_assert_cmphex (glyphs[j].codepoint, ==, test->codepoints[j]);
+ }
hb_buffer_destroy (b);
}
@@ -359,7 +370,7 @@ test_buffer_utf8 (gconstpointer user_data)
* with relicensing permission from Matthias Clasen. */
typedef struct {
- const char *text;
+ const char *utf8;
int max_len;
unsigned int offset;
gboolean valid;
@@ -604,30 +615,42 @@ static const utf8_validity_test_t utf8_validity_tests[] = {
};
static void
-test_buffer_utf8_validity (gconstpointer user_data)
+test_buffer_utf8_validity (void)
{
- const utf8_validity_test_t *test = user_data;
hb_buffer_t *b;
- hb_glyph_info_t *glyphs;
- unsigned int text_bytes, segment_bytes, i, len;
-
- text_bytes = strlen (test->text);
- if (test->max_len == -1)
- segment_bytes = text_bytes;
- else
- segment_bytes = test->max_len;
+ unsigned int i;
b = hb_buffer_create (0);
- hb_buffer_add_utf8 (b, test->text, text_bytes, 0, segment_bytes);
-
- glyphs = hb_buffer_get_glyph_infos (b, &len);
- for (i = 0; i < len; i++)
- if (glyphs[i].codepoint == (hb_codepoint_t) -1)
- break;
- g_assert (test->valid ? i == len : i < len);
- if (!test->valid)
- g_assert (glyphs[i].cluster == test->offset);
+ for (i = 0; i < G_N_ELEMENTS (utf8_validity_tests); i++)
+ {
+ const utf8_validity_test_t *test = &utf8_validity_tests[i];
+ unsigned int text_bytes, segment_bytes, j, len;
+ hb_glyph_info_t *glyphs;
+ char *escaped;
+
+ escaped = g_strescape (test->utf8, NULL);
+ g_test_message ("UTF-8 test #%d: %s", i, escaped);
+ g_free (escaped);
+
+ text_bytes = strlen (test->utf8);
+ if (test->max_len == -1)
+ segment_bytes = text_bytes;
+ else
+ segment_bytes = test->max_len;
+
+ hb_buffer_reset (b);
+ hb_buffer_add_utf8 (b, test->utf8, text_bytes, 0, segment_bytes);
+
+ glyphs = hb_buffer_get_glyph_infos (b, &len);
+ for (j = 0; j < len; j++)
+ if (glyphs[j].codepoint == (hb_codepoint_t) -1)
+ break;
+
+ g_assert (test->valid ? j == len : j < len);
+ if (!test->valid)
+ g_assert (glyphs[j].cluster == test->offset);
+ }
hb_buffer_destroy (b);
}
@@ -636,10 +659,10 @@ test_buffer_utf8_validity (gconstpointer user_data)
typedef struct {
const uint16_t utf16[8];
const uint32_t codepoints[8];
-} utf16_test_t;
+} utf16_conversion_test_t;
/* note: we skip the first and last item from utf16 when adding to buffer */
-static const utf16_test_t utf16_tests[] = {
+static const utf16_conversion_test_t utf16_conversion_tests[] = {
{{0x41, 0x004D, 0x0430, 0x4E8C, 0xD800, 0xDF02, 0x61} , {0x004D, 0x0430, 0x4E8C, 0x10302}},
{{0x41, 0xD800, 0xDF02, 0x61}, {0x10302}},
{{0x41, 0xD800, 0xDF02}, {-1}},
@@ -649,25 +672,34 @@ static const utf16_test_t utf16_tests[] = {
};
static void
-test_buffer_utf16 (gconstpointer user_data)
+test_buffer_utf16_conversion (void)
{
- const utf16_test_t *test = user_data;
hb_buffer_t *b;
- hb_glyph_info_t *glyphs;
- unsigned int u_len, chars, i, len;
-
- for (u_len = 0; test->utf16[u_len]; u_len++)
- ;
- for (chars = 0; test->codepoints[chars]; chars++)
- ;
+ unsigned int i;
b = hb_buffer_create (0);
- hb_buffer_add_utf16 (b, test->utf16, u_len, 1, u_len - 2);
- glyphs = hb_buffer_get_glyph_infos (b, &len);
- g_assert_cmpint (len, ==, chars);
- for (i = 0; i < chars; i++)
- g_assert_cmphex (glyphs[i].codepoint, ==, test->codepoints[i]);
+ for (i = 0; i < G_N_ELEMENTS (utf16_conversion_tests); i++)
+ {
+ const utf16_conversion_test_t *test = &utf16_conversion_tests[i];
+ unsigned int u_len, chars, j, len;
+ hb_glyph_info_t *glyphs;
+
+ g_test_message ("UTF-16 test #%d", i);
+
+ for (u_len = 0; test->utf16[u_len]; u_len++)
+ ;
+ for (chars = 0; test->codepoints[chars]; chars++)
+ ;
+
+ hb_buffer_reset (b);
+ hb_buffer_add_utf16 (b, test->utf16, u_len, 1, u_len - 2);
+
+ glyphs = hb_buffer_get_glyph_infos (b, &len);
+ g_assert_cmpint (len, ==, chars);
+ for (j = 0; j < chars; j++)
+ g_assert_cmphex (glyphs[j].codepoint, ==, test->codepoints[j]);
+ }
hb_buffer_destroy (b);
}
@@ -692,25 +724,9 @@ main (int argc, char **argv)
hb_test_add_fixture (fixture, GINT_TO_POINTER (BUFFER_EMPTY), test_buffer_allocation);
- for (i = 0; i < G_N_ELEMENTS (utf8_tests); i++)
- {
- char *flavor = g_strdup_printf ("%d", i);
- hb_test_add_data_flavor (&utf8_tests[i], flavor, test_buffer_utf8);
- g_free (flavor);
- }
- for (i = 0; i < G_N_ELEMENTS (utf8_validity_tests); i++)
- {
- char *flavor = g_strdup_printf ("%d", i);
- hb_test_add_data_flavor (&utf8_validity_tests[i], flavor, test_buffer_utf8_validity);
- g_free (flavor);
- }
-
- for (i = 0; i < G_N_ELEMENTS (utf16_tests); i++)
- {
- char *flavor = g_strdup_printf ("%d", i);
- hb_test_add_data_flavor (&utf16_tests[i], flavor, test_buffer_utf16);
- g_free (flavor);
- }
+ hb_test_add (test_buffer_utf8_conversion);
+ hb_test_add (test_buffer_utf8_validity);
+ hb_test_add (test_buffer_utf16_conversion);
return hb_test_run();
}
commit 819e9d9e5310e67e8dcce9fa885f8a086a9b9ee8
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 12:38:54 2011 -0400
Minor
diff --git a/test/test-unicode.c b/test/test-unicode.c
index 4b2585b..c8fdfca 100644
--- a/test/test-unicode.c
+++ b/test/test-unicode.c
@@ -453,9 +453,12 @@ test_unicode_properties_nil (void)
const property_t *p = &properties[i];
const test_pair_t *tests;
+ g_test_message ("Testing property %s", p->name);
tests = p->tests;
- for (j = 0; j < p->num_tests; j++)
+ for (j = 0; j < p->num_tests; j++) {
+ g_test_message ("Test %s #%d: U+%04X", p->name, j, tests[j].unicode);
g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, default_value (p->default_value, tests[j].unicode));
+ }
}
hb_unicode_funcs_destroy (uf);
commit 03034acb8a9fdd33135bc3775a1f932da9ebdd42
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 12:37:45 2011 -0400
[icu] Make sure we return script UNKNOWN instead of INVALID
diff --git a/src/hb-icu.cc b/src/hb-icu.cc
index 52645fd..9b94a94 100644
--- a/src/hb-icu.cc
+++ b/src/hb-icu.cc
@@ -157,6 +157,9 @@ hb_icu_get_script (hb_unicode_funcs_t *ufuncs,
UErrorCode status = U_ZERO_ERROR;
UScriptCode scriptCode = uscript_getScript(unicode, &status);
+ if (unlikely (status != U_ZERO_ERROR))
+ return HB_SCRIPT_UNKNOWN;
+
return hb_icu_script_to_script (scriptCode);
}
commit d02985ec5a24c659a0a133cc6bc103f1d76bcb29
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 12:35:14 2011 -0400
ISO 15924 fixes
Update to http://unicode.org/iso15924
Fixes some of the test failures in test-unicode with ICU. Still
one more to fix before the test passes.
diff --git a/src/hb-common.cc b/src/hb-common.cc
index 1a6f518..b75146d 100644
--- a/src/hb-common.cc
+++ b/src/hb-common.cc
@@ -191,9 +191,15 @@ hb_script_from_iso15924_tag (hb_tag_t tag)
tag = (tag & 0xDFDFDFDF) | 0x00202020;
switch (tag) {
+
+ /* These graduated from the 'Q' private-area codes, but
+ * the old code is still aliased by Unicode, and the Qaai
+ * one in use by ICU. */
+ case HB_TAG('Q','a','a','i'): return HB_SCRIPT_INHERITED;
+ case HB_TAG('Q','a','a','c'): return HB_SCRIPT_COPTIC;
+
+ /* Script variants from http://unicode.org/iso15924/ */
case HB_TAG('C','y','r','s'): return HB_SCRIPT_CYRILLIC;
- case HB_TAG('G','e','o','a'): return HB_SCRIPT_GEORGIAN;
- case HB_TAG('G','e','o','n'): return HB_SCRIPT_GEORGIAN;
case HB_TAG('L','a','t','f'): return HB_SCRIPT_LATIN;
case HB_TAG('L','a','t','g'): return HB_SCRIPT_LATIN;
case HB_TAG('S','y','r','e'): return HB_SCRIPT_SYRIAC;
diff --git a/src/hb-common.h b/src/hb-common.h
index 74030f4..64109da 100644
--- a/src/hb-common.h
+++ b/src/hb-common.h
@@ -153,16 +153,17 @@ typedef enum
/* hb_script_t */
+/* http://unicode.org/iso15924/ */
typedef enum
{
HB_SCRIPT_COMMON = HB_TAG ('Z','y','y','y'),
- HB_SCRIPT_INHERITED = HB_TAG ('Q','a','a','i'),
+ HB_SCRIPT_INHERITED = HB_TAG ('Z','i','n','h'),
HB_SCRIPT_ARABIC = HB_TAG ('A','r','a','b'),
HB_SCRIPT_ARMENIAN = HB_TAG ('A','r','m','n'),
HB_SCRIPT_BENGALI = HB_TAG ('B','e','n','g'),
HB_SCRIPT_BOPOMOFO = HB_TAG ('B','o','p','o'),
HB_SCRIPT_CHEROKEE = HB_TAG ('C','h','e','r'),
- HB_SCRIPT_COPTIC = HB_TAG ('Q','a','a','c'),
+ HB_SCRIPT_COPTIC = HB_TAG ('C','o','p','t'),
HB_SCRIPT_CYRILLIC = HB_TAG ('C','y','r','l'),
HB_SCRIPT_DESERET = HB_TAG ('D','s','r','t'),
HB_SCRIPT_DEVANAGARI = HB_TAG ('D','e','v','a'),
diff --git a/src/hb-ot-tag.cc b/src/hb-ot-tag.cc
index 144ee82..62c1b1a 100644
--- a/src/hb-ot-tag.cc
+++ b/src/hb-ot-tag.cc
@@ -40,7 +40,6 @@ static hb_tag_t
hb_ot_old_tag_from_script (hb_script_t script)
{
switch ((hb_tag_t) script) {
- case HB_SCRIPT_COPTIC: return HB_TAG('c','o','p','t');
case HB_SCRIPT_HIRAGANA: return HB_TAG('k','a','n','a');
case HB_SCRIPT_LAO: return HB_TAG('l','a','o',' ');
case HB_SCRIPT_YI: return HB_TAG('y','i',' ',' ');
@@ -61,7 +60,6 @@ static hb_script_t
hb_ot_old_tag_to_script (hb_tag_t tag)
{
switch (tag) {
- case HB_TAG('c','o','p','t'): return HB_SCRIPT_COPTIC;
case HB_TAG('k','a','n','a'): return HB_SCRIPT_HIRAGANA;
case HB_TAG('l','a','o',' '): return HB_SCRIPT_LAO;
case HB_TAG('y','i',' ',' '): return HB_SCRIPT_YI;
commit e8e29c725a72c2e991cd1c4422a020457e1684e9
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon May 2 12:06:18 2011 -0400
[test/unicode] Add log messages
Use with --verbose to see what's failing
diff --git a/test/test-unicode.c b/test/test-unicode.c
index fc506c7..4b2585b 100644
--- a/test/test-unicode.c
+++ b/test/test-unicode.c
@@ -426,9 +426,12 @@ test_unicode_properties (gconstpointer user_data)
const property_t *p = &properties[i];
const test_pair_t *tests;
+ g_test_message ("Testing property %s", p->name);
tests = p->tests;
- for (j = 0; j < p->num_tests; j++)
- g_assert_cmpint (p->getter (uf, tests[j].unicode), ==, tests[j].value);
+ for (j = 0; j < p->num_tests; j++) {
+ g_test_message ("Test %s #%d: U+%04X", p->name, j, tests[j].unicode);
+ g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, tests[j].value);
+ }
}
}
@@ -452,7 +455,7 @@ test_unicode_properties_nil (void)
tests = p->tests;
for (j = 0; j < p->num_tests; j++)
- g_assert_cmpint (p->getter (uf, tests[j].unicode), ==, default_value (p->default_value, tests[j].unicode));
+ g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, default_value (p->default_value, tests[j].unicode));
}
hb_unicode_funcs_destroy (uf);
commit 208c2c31501f6eb2b81b6bf80fcf39f4646eb38b
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun May 1 20:04:01 2011 -0400
Minor
diff --git a/test/test-unicode.c b/test/test-unicode.c
index 9b9566c..fc506c7 100644
--- a/test/test-unicode.c
+++ b/test/test-unicode.c
@@ -51,314 +51,322 @@ typedef struct {
static const test_pair_t combining_class_tests[] =
{
- { 0x111111, (unsigned int) 0 },
-
- { 0x0020, (unsigned int) 0 },
- { 0x0334, (unsigned int) 1 },
- { 0x093C, (unsigned int) 7 },
- { 0x3099, (unsigned int) 8 },
- { 0x094D, (unsigned int) 9 },
- { 0x05B0, (unsigned int) 10 },
- { 0x05B1, (unsigned int) 11 },
- { 0x05B2, (unsigned int) 12 },
- { 0x05B3, (unsigned int) 13 },
- { 0x05B4, (unsigned int) 14 },
- { 0x05B5, (unsigned int) 15 },
- { 0x05B6, (unsigned int) 16 },
- { 0x05B7, (unsigned int) 17 },
- { 0x05B8, (unsigned int) 18 },
- { 0x05B9, (unsigned int) 19 },
- { 0x05BB, (unsigned int) 20 },
- { 0x05BC, (unsigned int) 21 },
- { 0x05BD, (unsigned int) 22 },
- { 0x05BF, (unsigned int) 23 },
- { 0x05C1, (unsigned int) 24 },
- { 0x05C2, (unsigned int) 25 },
- { 0xFB1E, (unsigned int) 26 },
- { 0x064B, (unsigned int) 27 },
- { 0x064C, (unsigned int) 28 },
- { 0x064D, (unsigned int) 29 },
+ { 0x0020, 0 },
+ { 0x0334, 1 },
+ { 0x093C, 7 },
+ { 0x3099, 8 },
+ { 0x094D, 9 },
+ { 0x05B0, 10 },
+ { 0x05B1, 11 },
+ { 0x05B2, 12 },
+ { 0x05B3, 13 },
+ { 0x05B4, 14 },
+ { 0x05B5, 15 },
+ { 0x05B6, 16 },
+ { 0x05B7, 17 },
+ { 0x05B8, 18 },
+ { 0x05B9, 19 },
+ { 0x05BB, 20 },
+ { 0x05BC, 21 },
+ { 0x05BD, 22 },
+ { 0x05BF, 23 },
+ { 0x05C1, 24 },
+ { 0x05C2, 25 },
+ { 0xFB1E, 26 },
+ { 0x064B, 27 },
+ { 0x064C, 28 },
+ { 0x064D, 29 },
/* ... */
- { 0x05AE, (unsigned int) 228 },
- { 0x0300, (unsigned int) 230 },
- { 0x302C, (unsigned int) 232 },
- { 0x0362, (unsigned int) 233 },
- { 0x0360, (unsigned int) 234 },
- { 0x1DCD, (unsigned int) 234 },
- { 0x0345, (unsigned int) 240 },
+ { 0x05AE, 228 },
+ { 0x0300, 230 },
+ { 0x302C, 232 },
+ { 0x0362, 233 },
+ { 0x0360, 234 },
+ { 0x1DCD, 234 },
+ { 0x0345, 240 },
+
+ { 0x111111, 0 }
};
static const test_pair_t combining_class_tests_more[] =
{
/* Unicode-5.2 character additions */
- { 0xA8E0, (unsigned int) 230 },
+ { 0xA8E0, 230 },
/* Unicode-6.0 character additions */
- { 0x135D, (unsigned int) 230 },
+ { 0x135D, 230 },
+
+ { 0x111111, 0 }
};
static const test_pair_t eastasian_width_tests[] =
{
- { 0x111111, (unsigned int) 1 },
-
/* Neutral */
- { 0x0000, (unsigned int) 1 },
- { 0x0483, (unsigned int) 1 },
- { 0x0641, (unsigned int) 1 },
- { 0xFFFC, (unsigned int) 1 },
- { 0x10000, (unsigned int) 1 },
- { 0xE0001, (unsigned int) 1 },
+ { 0x0000, 1 },
+ { 0x0483, 1 },
+ { 0x0641, 1 },
+ { 0xFFFC, 1 },
+ { 0x10000, 1 },
+ { 0xE0001, 1 },
/* Narrow */
- { 0x0020, (unsigned int) 1 },
- { 0x0041, (unsigned int) 1 },
- { 0x27E6, (unsigned int) 1 },
+ { 0x0020, 1 },
+ { 0x0041, 1 },
+ { 0x27E6, 1 },
/* Halfwidth */
- { 0x20A9, (unsigned int) 1 },
- { 0xFF61, (unsigned int) 1 },
- { 0xFF69, (unsigned int) 1 },
- { 0xFFEE, (unsigned int) 1 },
+ { 0x20A9, 1 },
+ { 0xFF61, 1 },
+ { 0xFF69, 1 },
+ { 0xFFEE, 1 },
/* Ambiguous */
- { 0x00A1, (unsigned int) 1 },
- { 0x00D8, (unsigned int) 1 },
- { 0x02DD, (unsigned int) 1 },
- { 0xE0100, (unsigned int) 1 },
- { 0x100000, (unsigned int) 1 },
+ { 0x00A1, 1 },
+ { 0x00D8, 1 },
+ { 0x02DD, 1 },
+ { 0xE0100, 1 },
+ { 0x100000, 1 },
/* Fullwidth */
- { 0x3000, (unsigned int) 2 },
- { 0xFF60, (unsigned int) 2 },
+ { 0x3000, 2 },
+ { 0xFF60, 2 },
/* Wide */
- { 0x2329, (unsigned int) 2 },
- { 0x3001, (unsigned int) 2 },
- { 0xFE69, (unsigned int) 2 },
- { 0x30000, (unsigned int) 2 },
- { 0x3FFFD, (unsigned int) 2 },
+ { 0x2329, 2 },
+ { 0x3001, 2 },
+ { 0xFE69, 2 },
+ { 0x30000, 2 },
+ { 0x3FFFD, 2 },
+
+ { 0x111111, 1 }
};
static const test_pair_t eastasian_width_tests_more[] =
{
/* Default Wide blocks */
- { 0x4DBF, (unsigned int) 2 },
- { 0x9FFF, (unsigned int) 2 },
- { 0xFAFF, (unsigned int) 2 },
- { 0x2A6DF, (unsigned int) 2 },
- { 0x2B73F, (unsigned int) 2 },
- { 0x2B81F, (unsigned int) 2 },
- { 0x2FA1F, (unsigned int) 2 },
+ { 0x4DBF, 2 },
+ { 0x9FFF, 2 },
+ { 0xFAFF, 2 },
+ { 0x2A6DF, 2 },
+ { 0x2B73F, 2 },
+ { 0x2B81F, 2 },
+ { 0x2FA1F, 2 },
/* Uniode-5.2 character additions */
/* Wide */
- { 0x115F, (unsigned int) 2 },
+ { 0x115F, 2 },
/* Uniode-6.0 character additions */
/* Wide */
- { 0x2B740, (unsigned int) 2 },
- { 0x1B000, (unsigned int) 2 },
+ { 0x2B740, 2 },
+ { 0x1B000, 2 },
+
+ { 0x111111, 1 }
};
static const test_pair_t general_category_tests[] =
{
- { 0x111111, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED },
-
- { 0x000D, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_CONTROL },
- { 0x200E, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_FORMAT },
- { 0x0378, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED },
- { 0xE000, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_PRIVATE_USE },
- { 0xD800, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_SURROGATE },
- { 0x0061, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER },
- { 0x02B0, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_MODIFIER_LETTER },
- { 0x3400, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER },
- { 0x01C5, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_TITLECASE_LETTER },
- { 0xFF21, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_UPPERCASE_LETTER },
- { 0x0903, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_COMBINING_MARK },
- { 0x20DD, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK },
- { 0xA806, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK },
- { 0xFF10, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER },
- { 0x16EE, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_LETTER_NUMBER },
- { 0x17F0, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_NUMBER },
- { 0x005F, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_CONNECT_PUNCTUATION },
- { 0x058A, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_DASH_PUNCTUATION },
- { 0x0F3B, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION },
- { 0x2019, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION },
- { 0x2018, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_INITIAL_PUNCTUATION },
- { 0x2016, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION },
- { 0x0F3A, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION },
- { 0x20A0, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL },
- { 0x309B, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_MODIFIER_SYMBOL },
- { 0xFB29, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_MATH_SYMBOL },
- { 0x00A6, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
- { 0x2028, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_LINE_SEPARATOR },
- { 0x2029, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_PARAGRAPH_SEPARATOR },
- { 0x202F, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR }
+ { 0x000D, HB_UNICODE_GENERAL_CATEGORY_CONTROL },
+ { 0x200E, HB_UNICODE_GENERAL_CATEGORY_FORMAT },
+ { 0x0378, HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED },
+ { 0xE000, HB_UNICODE_GENERAL_CATEGORY_PRIVATE_USE },
+ { 0xD800, HB_UNICODE_GENERAL_CATEGORY_SURROGATE },
+ { 0x0061, HB_UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER },
+ { 0x02B0, HB_UNICODE_GENERAL_CATEGORY_MODIFIER_LETTER },
+ { 0x3400, HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER },
+ { 0x01C5, HB_UNICODE_GENERAL_CATEGORY_TITLECASE_LETTER },
+ { 0xFF21, HB_UNICODE_GENERAL_CATEGORY_UPPERCASE_LETTER },
+ { 0x0903, HB_UNICODE_GENERAL_CATEGORY_COMBINING_MARK },
+ { 0x20DD, HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK },
+ { 0xA806, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK },
+ { 0xFF10, HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER },
+ { 0x16EE, HB_UNICODE_GENERAL_CATEGORY_LETTER_NUMBER },
+ { 0x17F0, HB_UNICODE_GENERAL_CATEGORY_OTHER_NUMBER },
+ { 0x005F, HB_UNICODE_GENERAL_CATEGORY_CONNECT_PUNCTUATION },
+ { 0x058A, HB_UNICODE_GENERAL_CATEGORY_DASH_PUNCTUATION },
+ { 0x0F3B, HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION },
+ { 0x2019, HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION },
+ { 0x2018, HB_UNICODE_GENERAL_CATEGORY_INITIAL_PUNCTUATION },
+ { 0x2016, HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION },
+ { 0x0F3A, HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION },
+ { 0x20A0, HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL },
+ { 0x309B, HB_UNICODE_GENERAL_CATEGORY_MODIFIER_SYMBOL },
+ { 0xFB29, HB_UNICODE_GENERAL_CATEGORY_MATH_SYMBOL },
+ { 0x00A6, HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
+ { 0x2028, HB_UNICODE_GENERAL_CATEGORY_LINE_SEPARATOR },
+ { 0x2029, HB_UNICODE_GENERAL_CATEGORY_PARAGRAPH_SEPARATOR },
+ { 0x202F, HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR },
+
+ { 0x111111, HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED }
};
static const test_pair_t general_category_tests_more[] =
{
/* Unicode-5.2 character additions */
- { 0x1F131, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
+ { 0x1F131, HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
/* Unicode-6.0 character additions */
- { 0x0620, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER },
+ { 0x0620, HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER },
+
+ { 0x111111, HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED }
};
static const test_pair_t mirroring_tests[] =
{
- { 0x111111, (unsigned int) 0x111111 },
-
/* Some characters that do NOT mirror */
- { 0x0020, (unsigned int) 0x0020 },
- { 0x0041, (unsigned int) 0x0041 },
- { 0x00F0, (unsigned int) 0x00F0 },
- { 0x27CC, (unsigned int) 0x27CC },
- { 0xE01EF, (unsigned int) 0xE01EF },
- { 0x1D7C3, (unsigned int) 0x1D7C3 },
- { 0x100000, (unsigned int) 0x100000 },
+ { 0x0020, 0x0020 },
+ { 0x0041, 0x0041 },
+ { 0x00F0, 0x00F0 },
+ { 0x27CC, 0x27CC },
+ { 0xE01EF, 0xE01EF },
+ { 0x1D7C3, 0x1D7C3 },
+ { 0x100000, 0x100000 },
/* Some characters that do mirror */
- { 0x0029, (unsigned int) 0x0028 },
- { 0x0028, (unsigned int) 0x0029 },
- { 0x003E, (unsigned int) 0x003C },
- { 0x003C, (unsigned int) 0x003E },
- { 0x005D, (unsigned int) 0x005B },
- { 0x005B, (unsigned int) 0x005D },
- { 0x007D, (unsigned int) 0x007B },
- { 0x007B, (unsigned int) 0x007D },
- { 0x00BB, (unsigned int) 0x00AB },
- { 0x00AB, (unsigned int) 0x00BB },
- { 0x226B, (unsigned int) 0x226A },
- { 0x226A, (unsigned int) 0x226B },
- { 0x22F1, (unsigned int) 0x22F0 },
- { 0x22F0, (unsigned int) 0x22F1 },
- { 0xFF60, (unsigned int) 0xFF5F },
- { 0xFF5F, (unsigned int) 0xFF60 },
- { 0xFF63, (unsigned int) 0xFF62 },
- { 0xFF62, (unsigned int) 0xFF63 },
+ { 0x0029, 0x0028 },
+ { 0x0028, 0x0029 },
+ { 0x003E, 0x003C },
+ { 0x003C, 0x003E },
+ { 0x005D, 0x005B },
+ { 0x005B, 0x005D },
+ { 0x007D, 0x007B },
+ { 0x007B, 0x007D },
+ { 0x00BB, 0x00AB },
+ { 0x00AB, 0x00BB },
+ { 0x226B, 0x226A },
+ { 0x226A, 0x226B },
+ { 0x22F1, 0x22F0 },
+ { 0x22F0, 0x22F1 },
+ { 0xFF60, 0xFF5F },
+ { 0xFF5F, 0xFF60 },
+ { 0xFF63, 0xFF62 },
+ { 0xFF62, 0xFF63 },
+
+ { 0x111111, 0x111111 },
};
static const test_pair_t mirroring_tests_more[] =
{
/* No new mirroring characters have been encoded in recent Unicode versions. */
- { 0xFFFF, (unsigned int) 0xFFFF },
+ { 0x111111, 0x111111 }
};
static const test_pair_t script_tests[] =
{
- { 0x111111, (unsigned int) HB_SCRIPT_UNKNOWN },
-
- { 0x002A, (unsigned int) HB_SCRIPT_COMMON },
- { 0x0670, (unsigned int) HB_SCRIPT_INHERITED },
- { 0x060D, (unsigned int) HB_SCRIPT_ARABIC },
- { 0x0559, (unsigned int) HB_SCRIPT_ARMENIAN },
- { 0x09CD, (unsigned int) HB_SCRIPT_BENGALI },
- { 0x31B6, (unsigned int) HB_SCRIPT_BOPOMOFO },
- { 0x13A2, (unsigned int) HB_SCRIPT_CHEROKEE },
- { 0x2CFD, (unsigned int) HB_SCRIPT_COPTIC },
- { 0x0482, (unsigned int) HB_SCRIPT_CYRILLIC },
- { 0x10401, (unsigned int) HB_SCRIPT_DESERET },
- { 0x094D, (unsigned int) HB_SCRIPT_DEVANAGARI },
- { 0x1258, (unsigned int) HB_SCRIPT_ETHIOPIC },
- { 0x10FC, (unsigned int) HB_SCRIPT_GEORGIAN },
- { 0x10341, (unsigned int) HB_SCRIPT_GOTHIC },
- { 0x0375, (unsigned int) HB_SCRIPT_GREEK },
- { 0x0A83, (unsigned int) HB_SCRIPT_GUJARATI },
- { 0x0A3C, (unsigned int) HB_SCRIPT_GURMUKHI },
- { 0x3005, (unsigned int) HB_SCRIPT_HAN },
- { 0x1100, (unsigned int) HB_SCRIPT_HANGUL },
- { 0x05BF, (unsigned int) HB_SCRIPT_HEBREW },
- { 0x309F, (unsigned int) HB_SCRIPT_HIRAGANA },
- { 0x0CBC, (unsigned int) HB_SCRIPT_KANNADA },
- { 0x30FF, (unsigned int) HB_SCRIPT_KATAKANA },
- { 0x17DD, (unsigned int) HB_SCRIPT_KHMER },
- { 0x0EDD, (unsigned int) HB_SCRIPT_LAO },
- { 0x0061, (unsigned int) HB_SCRIPT_LATIN },
- { 0x0D3D, (unsigned int) HB_SCRIPT_MALAYALAM },
- { 0x1843, (unsigned int) HB_SCRIPT_MONGOLIAN },
- { 0x1031, (unsigned int) HB_SCRIPT_MYANMAR },
- { 0x169C, (unsigned int) HB_SCRIPT_OGHAM },
- { 0x10322, (unsigned int) HB_SCRIPT_OLD_ITALIC },
- { 0x0B3C, (unsigned int) HB_SCRIPT_ORIYA },
- { 0x16EF, (unsigned int) HB_SCRIPT_RUNIC },
- { 0x0DBD, (unsigned int) HB_SCRIPT_SINHALA },
- { 0x0711, (unsigned int) HB_SCRIPT_SYRIAC },
- { 0x0B82, (unsigned int) HB_SCRIPT_TAMIL },
- { 0x0C03, (unsigned int) HB_SCRIPT_TELUGU },
- { 0x07B1, (unsigned int) HB_SCRIPT_THAANA },
- { 0x0E31, (unsigned int) HB_SCRIPT_THAI },
- { 0x0FD4, (unsigned int) HB_SCRIPT_TIBETAN },
- { 0x1401, (unsigned int) HB_SCRIPT_CANADIAN_ABORIGINAL },
- { 0xA015, (unsigned int) HB_SCRIPT_YI },
- { 0x1700, (unsigned int) HB_SCRIPT_TAGALOG },
- { 0x1720, (unsigned int) HB_SCRIPT_HANUNOO },
- { 0x1740, (unsigned int) HB_SCRIPT_BUHID },
- { 0x1760, (unsigned int) HB_SCRIPT_TAGBANWA },
+ { 0x002A, HB_SCRIPT_COMMON },
+ { 0x0670, HB_SCRIPT_INHERITED },
+ { 0x060D, HB_SCRIPT_ARABIC },
+ { 0x0559, HB_SCRIPT_ARMENIAN },
+ { 0x09CD, HB_SCRIPT_BENGALI },
+ { 0x31B6, HB_SCRIPT_BOPOMOFO },
+ { 0x13A2, HB_SCRIPT_CHEROKEE },
+ { 0x2CFD, HB_SCRIPT_COPTIC },
+ { 0x0482, HB_SCRIPT_CYRILLIC },
+ { 0x10401, HB_SCRIPT_DESERET },
+ { 0x094D, HB_SCRIPT_DEVANAGARI },
+ { 0x1258, HB_SCRIPT_ETHIOPIC },
+ { 0x10FC, HB_SCRIPT_GEORGIAN },
+ { 0x10341, HB_SCRIPT_GOTHIC },
+ { 0x0375, HB_SCRIPT_GREEK },
+ { 0x0A83, HB_SCRIPT_GUJARATI },
+ { 0x0A3C, HB_SCRIPT_GURMUKHI },
+ { 0x3005, HB_SCRIPT_HAN },
+ { 0x1100, HB_SCRIPT_HANGUL },
+ { 0x05BF, HB_SCRIPT_HEBREW },
+ { 0x309F, HB_SCRIPT_HIRAGANA },
+ { 0x0CBC, HB_SCRIPT_KANNADA },
+ { 0x30FF, HB_SCRIPT_KATAKANA },
+ { 0x17DD, HB_SCRIPT_KHMER },
+ { 0x0EDD, HB_SCRIPT_LAO },
+ { 0x0061, HB_SCRIPT_LATIN },
+ { 0x0D3D, HB_SCRIPT_MALAYALAM },
+ { 0x1843, HB_SCRIPT_MONGOLIAN },
+ { 0x1031, HB_SCRIPT_MYANMAR },
+ { 0x169C, HB_SCRIPT_OGHAM },
+ { 0x10322, HB_SCRIPT_OLD_ITALIC },
+ { 0x0B3C, HB_SCRIPT_ORIYA },
+ { 0x16EF, HB_SCRIPT_RUNIC },
+ { 0x0DBD, HB_SCRIPT_SINHALA },
+ { 0x0711, HB_SCRIPT_SYRIAC },
+ { 0x0B82, HB_SCRIPT_TAMIL },
+ { 0x0C03, HB_SCRIPT_TELUGU },
+ { 0x07B1, HB_SCRIPT_THAANA },
+ { 0x0E31, HB_SCRIPT_THAI },
+ { 0x0FD4, HB_SCRIPT_TIBETAN },
+ { 0x1401, HB_SCRIPT_CANADIAN_ABORIGINAL },
+ { 0xA015, HB_SCRIPT_YI },
+ { 0x1700, HB_SCRIPT_TAGALOG },
+ { 0x1720, HB_SCRIPT_HANUNOO },
+ { 0x1740, HB_SCRIPT_BUHID },
+ { 0x1760, HB_SCRIPT_TAGBANWA },
/* Unicode-4.0 additions */
- { 0x2800, (unsigned int) HB_SCRIPT_BRAILLE },
- { 0x10808, (unsigned int) HB_SCRIPT_CYPRIOT },
- { 0x1932, (unsigned int) HB_SCRIPT_LIMBU },
- { 0x10480, (unsigned int) HB_SCRIPT_OSMANYA },
- { 0x10450, (unsigned int) HB_SCRIPT_SHAVIAN },
- { 0x10000, (unsigned int) HB_SCRIPT_LINEAR_B },
- { 0x1950, (unsigned int) HB_SCRIPT_TAI_LE },
- { 0x1039F, (unsigned int) HB_SCRIPT_UGARITIC },
+ { 0x2800, HB_SCRIPT_BRAILLE },
+ { 0x10808, HB_SCRIPT_CYPRIOT },
+ { 0x1932, HB_SCRIPT_LIMBU },
+ { 0x10480, HB_SCRIPT_OSMANYA },
+ { 0x10450, HB_SCRIPT_SHAVIAN },
+ { 0x10000, HB_SCRIPT_LINEAR_B },
+ { 0x1950, HB_SCRIPT_TAI_LE },
+ { 0x1039F, HB_SCRIPT_UGARITIC },
/* Unicode-4.1 additions */
- { 0x1980, (unsigned int) HB_SCRIPT_NEW_TAI_LUE },
- { 0x1A1F, (unsigned int) HB_SCRIPT_BUGINESE },
- { 0x2C00, (unsigned int) HB_SCRIPT_GLAGOLITIC },
- { 0x2D6F, (unsigned int) HB_SCRIPT_TIFINAGH },
- { 0xA800, (unsigned int) HB_SCRIPT_SYLOTI_NAGRI },
- { 0x103D0, (unsigned int) HB_SCRIPT_OLD_PERSIAN },
- { 0x10A3F, (unsigned int) HB_SCRIPT_KHAROSHTHI },
+ { 0x1980, HB_SCRIPT_NEW_TAI_LUE },
+ { 0x1A1F, HB_SCRIPT_BUGINESE },
+ { 0x2C00, HB_SCRIPT_GLAGOLITIC },
+ { 0x2D6F, HB_SCRIPT_TIFINAGH },
+ { 0xA800, HB_SCRIPT_SYLOTI_NAGRI },
+ { 0x103D0, HB_SCRIPT_OLD_PERSIAN },
+ { 0x10A3F, HB_SCRIPT_KHAROSHTHI },
/* Unicode-5.0 additions */
- { 0x0378, (unsigned int) HB_SCRIPT_UNKNOWN },
- { 0x1B04, (unsigned int) HB_SCRIPT_BALINESE },
- { 0x12000, (unsigned int) HB_SCRIPT_CUNEIFORM },
- { 0x10900, (unsigned int) HB_SCRIPT_PHOENICIAN },
- { 0xA840, (unsigned int) HB_SCRIPT_PHAGS_PA },
- { 0x07C0, (unsigned int) HB_SCRIPT_NKO },
+ { 0x0378, HB_SCRIPT_UNKNOWN },
+ { 0x1B04, HB_SCRIPT_BALINESE },
+ { 0x12000, HB_SCRIPT_CUNEIFORM },
+ { 0x10900, HB_SCRIPT_PHOENICIAN },
+ { 0xA840, HB_SCRIPT_PHAGS_PA },
+ { 0x07C0, HB_SCRIPT_NKO },
/* Unicode-5.1 additions */
- { 0xA900, (unsigned int) HB_SCRIPT_KAYAH_LI },
- { 0x1C00, (unsigned int) HB_SCRIPT_LEPCHA },
- { 0xA930, (unsigned int) HB_SCRIPT_REJANG },
- { 0x1B80, (unsigned int) HB_SCRIPT_SUNDANESE },
- { 0xA880, (unsigned int) HB_SCRIPT_SAURASHTRA },
- { 0xAA00, (unsigned int) HB_SCRIPT_CHAM },
- { 0x1C50, (unsigned int) HB_SCRIPT_OL_CHIKI },
- { 0xA500, (unsigned int) HB_SCRIPT_VAI },
- { 0x102A0, (unsigned int) HB_SCRIPT_CARIAN },
- { 0x10280, (unsigned int) HB_SCRIPT_LYCIAN },
- { 0x1093F, (unsigned int) HB_SCRIPT_LYDIAN },
+ { 0xA900, HB_SCRIPT_KAYAH_LI },
+ { 0x1C00, HB_SCRIPT_LEPCHA },
+ { 0xA930, HB_SCRIPT_REJANG },
+ { 0x1B80, HB_SCRIPT_SUNDANESE },
+ { 0xA880, HB_SCRIPT_SAURASHTRA },
+ { 0xAA00, HB_SCRIPT_CHAM },
+ { 0x1C50, HB_SCRIPT_OL_CHIKI },
+ { 0xA500, HB_SCRIPT_VAI },
+ { 0x102A0, HB_SCRIPT_CARIAN },
+ { 0x10280, HB_SCRIPT_LYCIAN },
+ { 0x1093F, HB_SCRIPT_LYDIAN },
+
+ { 0x111111, HB_SCRIPT_UNKNOWN }
};
static const test_pair_t script_tests_more[] =
{
/* Unicode-5.2 additions */
- { 0x10B00, (unsigned int) HB_SCRIPT_AVESTAN },
- { 0xA6A0, (unsigned int) HB_SCRIPT_BAMUM },
- { 0x13000, (unsigned int) HB_SCRIPT_EGYPTIAN_HIEROGLYPHS },
- { 0x10840, (unsigned int) HB_SCRIPT_IMPERIAL_ARAMAIC },
- { 0x10B60, (unsigned int) HB_SCRIPT_INSCRIPTIONAL_PAHLAVI },
- { 0x10B40, (unsigned int) HB_SCRIPT_INSCRIPTIONAL_PARTHIAN },
- { 0xA980, (unsigned int) HB_SCRIPT_JAVANESE },
- { 0x11082, (unsigned int) HB_SCRIPT_KAITHI },
- { 0xA4D0, (unsigned int) HB_SCRIPT_LISU },
- { 0xABE5, (unsigned int) HB_SCRIPT_MEETEI_MAYEK },
- { 0x10A60, (unsigned int) HB_SCRIPT_OLD_SOUTH_ARABIAN },
- { 0x10C00, (unsigned int) HB_SCRIPT_OLD_TURKIC },
- { 0x0800, (unsigned int) HB_SCRIPT_SAMARITAN },
- { 0x1A20, (unsigned int) HB_SCRIPT_TAI_THAM },
- { 0xAA80, (unsigned int) HB_SCRIPT_TAI_VIET },
+ { 0x10B00, HB_SCRIPT_AVESTAN },
+ { 0xA6A0, HB_SCRIPT_BAMUM },
+ { 0x13000, HB_SCRIPT_EGYPTIAN_HIEROGLYPHS },
+ { 0x10840, HB_SCRIPT_IMPERIAL_ARAMAIC },
+ { 0x10B60, HB_SCRIPT_INSCRIPTIONAL_PAHLAVI },
+ { 0x10B40, HB_SCRIPT_INSCRIPTIONAL_PARTHIAN },
+ { 0xA980, HB_SCRIPT_JAVANESE },
+ { 0x11082, HB_SCRIPT_KAITHI },
+ { 0xA4D0, HB_SCRIPT_LISU },
+ { 0xABE5, HB_SCRIPT_MEETEI_MAYEK },
+ { 0x10A60, HB_SCRIPT_OLD_SOUTH_ARABIAN },
+ { 0x10C00, HB_SCRIPT_OLD_TURKIC },
+ { 0x0800, HB_SCRIPT_SAMARITAN },
+ { 0x1A20, HB_SCRIPT_TAI_THAM },
+ { 0xAA80, HB_SCRIPT_TAI_VIET },
/* Unicode-6.0 additions */
- { 0x1BC0, (unsigned int) HB_SCRIPT_BATAK },
- { 0x11000, (unsigned int) HB_SCRIPT_BRAHMI },
- { 0x0840, (unsigned int) HB_SCRIPT_MANDAIC },
+ { 0x1BC0, HB_SCRIPT_BATAK },
+ { 0x11000, HB_SCRIPT_BRAHMI },
+ { 0x0840, HB_SCRIPT_MANDAIC },
/* Unicode-5.2 character additions */
- { 0x1CED, (unsigned int) HB_SCRIPT_INHERITED },
- { 0x1400, (unsigned int) HB_SCRIPT_CANADIAN_ABORIGINAL },
+ { 0x1CED, HB_SCRIPT_INHERITED },
+ { 0x1400, HB_SCRIPT_CANADIAN_ABORIGINAL },
+
+ { 0x111111, HB_SCRIPT_UNKNOWN }
};
commit 60833efaf1310c3f18e150b61daaeb0074ae3d91
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Fri Apr 29 16:49:57 2011 -0400
[test/unicode] Add testing of all unicode properties
ICU fails for now.
diff --git a/test/hb-test.h b/test/hb-test.h
index 81aba66..73f8735 100644
--- a/test/hb-test.h
+++ b/test/hb-test.h
@@ -27,6 +27,8 @@
#ifndef HB_TEST_H
#define HB_TEST_H
+#include <config.h>
+
#include <hb-glib.h>
#include <stdlib.h>
@@ -151,7 +153,7 @@ hb_test_add_data_func (const char *test_path,
g_test_add_data_func (normal_path, test_data, test_func);
g_free (normal_path);
}
-#define hb_test_add_data(Func, UserData) hb_test_add_data_func (#Func, UserData, Func)
+#define hb_test_add_data(UserData, Func) hb_test_add_data_func (#Func, UserData, Func)
static inline void
hb_test_add_data_func_flavor (const char *test_path,
diff --git a/test/test-unicode.c b/test/test-unicode.c
index 19d921b..9b9566c 100644
--- a/test/test-unicode.c
+++ b/test/test-unicode.c
@@ -31,38 +31,424 @@
/* Unit tests for hb-unicode.h */
-static void
-test_unicode_nil (void)
+#ifdef HAVE_GLIB
+#include <hb-glib.h>
+#endif
+#ifdef HAVE_ICU
+#include <hb-icu.h>
+#endif
+
+
+/* Check all properties */
+
+/* Some of the following tables where adapted from glib/glib/tests/utf8-misc.c.
+ * The license is compatible. */
+
+typedef struct {
+ hb_codepoint_t unicode;
+ unsigned int value;
+} test_pair_t;
+
+static const test_pair_t combining_class_tests[] =
{
- hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL);
+ { 0x111111, (unsigned int) 0 },
+
+ { 0x0020, (unsigned int) 0 },
+ { 0x0334, (unsigned int) 1 },
+ { 0x093C, (unsigned int) 7 },
+ { 0x3099, (unsigned int) 8 },
+ { 0x094D, (unsigned int) 9 },
+ { 0x05B0, (unsigned int) 10 },
+ { 0x05B1, (unsigned int) 11 },
+ { 0x05B2, (unsigned int) 12 },
+ { 0x05B3, (unsigned int) 13 },
+ { 0x05B4, (unsigned int) 14 },
+ { 0x05B5, (unsigned int) 15 },
+ { 0x05B6, (unsigned int) 16 },
+ { 0x05B7, (unsigned int) 17 },
+ { 0x05B8, (unsigned int) 18 },
+ { 0x05B9, (unsigned int) 19 },
+ { 0x05BB, (unsigned int) 20 },
+ { 0x05BC, (unsigned int) 21 },
+ { 0x05BD, (unsigned int) 22 },
+ { 0x05BF, (unsigned int) 23 },
+ { 0x05C1, (unsigned int) 24 },
+ { 0x05C2, (unsigned int) 25 },
+ { 0xFB1E, (unsigned int) 26 },
+ { 0x064B, (unsigned int) 27 },
+ { 0x064C, (unsigned int) 28 },
+ { 0x064D, (unsigned int) 29 },
+ /* ... */
+ { 0x05AE, (unsigned int) 228 },
+ { 0x0300, (unsigned int) 230 },
+ { 0x302C, (unsigned int) 232 },
+ { 0x0362, (unsigned int) 233 },
+ { 0x0360, (unsigned int) 234 },
+ { 0x1DCD, (unsigned int) 234 },
+ { 0x0345, (unsigned int) 240 },
+};
+static const test_pair_t combining_class_tests_more[] =
+{
+ /* Unicode-5.2 character additions */
+ { 0xA8E0, (unsigned int) 230 },
- g_assert (!hb_unicode_funcs_is_immutable (uf));
+ /* Unicode-6.0 character additions */
+ { 0x135D, (unsigned int) 230 },
+};
- g_assert_cmpint (hb_unicode_get_script (uf, 'd'), ==, HB_SCRIPT_UNKNOWN);
+static const test_pair_t eastasian_width_tests[] =
+{
+ { 0x111111, (unsigned int) 1 },
+
+ /* Neutral */
+ { 0x0000, (unsigned int) 1 },
+ { 0x0483, (unsigned int) 1 },
+ { 0x0641, (unsigned int) 1 },
+ { 0xFFFC, (unsigned int) 1 },
+ { 0x10000, (unsigned int) 1 },
+ { 0xE0001, (unsigned int) 1 },
+
+ /* Narrow */
+ { 0x0020, (unsigned int) 1 },
+ { 0x0041, (unsigned int) 1 },
+ { 0x27E6, (unsigned int) 1 },
+
+ /* Halfwidth */
+ { 0x20A9, (unsigned int) 1 },
+ { 0xFF61, (unsigned int) 1 },
+ { 0xFF69, (unsigned int) 1 },
+ { 0xFFEE, (unsigned int) 1 },
+
+ /* Ambiguous */
+ { 0x00A1, (unsigned int) 1 },
+ { 0x00D8, (unsigned int) 1 },
+ { 0x02DD, (unsigned int) 1 },
+ { 0xE0100, (unsigned int) 1 },
+ { 0x100000, (unsigned int) 1 },
+
+ /* Fullwidth */
+ { 0x3000, (unsigned int) 2 },
+ { 0xFF60, (unsigned int) 2 },
+
+ /* Wide */
+ { 0x2329, (unsigned int) 2 },
+ { 0x3001, (unsigned int) 2 },
+ { 0xFE69, (unsigned int) 2 },
+ { 0x30000, (unsigned int) 2 },
+ { 0x3FFFD, (unsigned int) 2 },
+};
+static const test_pair_t eastasian_width_tests_more[] =
+{
+ /* Default Wide blocks */
+ { 0x4DBF, (unsigned int) 2 },
+ { 0x9FFF, (unsigned int) 2 },
+ { 0xFAFF, (unsigned int) 2 },
+ { 0x2A6DF, (unsigned int) 2 },
+ { 0x2B73F, (unsigned int) 2 },
+ { 0x2B81F, (unsigned int) 2 },
+ { 0x2FA1F, (unsigned int) 2 },
+
+ /* Uniode-5.2 character additions */
+ /* Wide */
+ { 0x115F, (unsigned int) 2 },
+
+ /* Uniode-6.0 character additions */
+ /* Wide */
+ { 0x2B740, (unsigned int) 2 },
+ { 0x1B000, (unsigned int) 2 },
+};
+
+static const test_pair_t general_category_tests[] =
+{
+ { 0x111111, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED },
+
+ { 0x000D, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_CONTROL },
+ { 0x200E, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_FORMAT },
+ { 0x0378, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED },
+ { 0xE000, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_PRIVATE_USE },
+ { 0xD800, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_SURROGATE },
+ { 0x0061, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER },
+ { 0x02B0, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_MODIFIER_LETTER },
+ { 0x3400, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER },
+ { 0x01C5, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_TITLECASE_LETTER },
+ { 0xFF21, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_UPPERCASE_LETTER },
+ { 0x0903, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_COMBINING_MARK },
+ { 0x20DD, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK },
+ { 0xA806, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK },
+ { 0xFF10, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER },
+ { 0x16EE, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_LETTER_NUMBER },
+ { 0x17F0, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_NUMBER },
+ { 0x005F, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_CONNECT_PUNCTUATION },
+ { 0x058A, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_DASH_PUNCTUATION },
+ { 0x0F3B, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION },
+ { 0x2019, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION },
+ { 0x2018, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_INITIAL_PUNCTUATION },
+ { 0x2016, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION },
+ { 0x0F3A, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION },
+ { 0x20A0, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL },
+ { 0x309B, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_MODIFIER_SYMBOL },
+ { 0xFB29, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_MATH_SYMBOL },
+ { 0x00A6, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
+ { 0x2028, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_LINE_SEPARATOR },
+ { 0x2029, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_PARAGRAPH_SEPARATOR },
+ { 0x202F, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR }
+};
+static const test_pair_t general_category_tests_more[] =
+{
+ /* Unicode-5.2 character additions */
+ { 0x1F131, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
- hb_unicode_funcs_destroy (uf);
-}
+ /* Unicode-6.0 character additions */
+ { 0x0620, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER },
+};
+
+static const test_pair_t mirroring_tests[] =
+{
+ { 0x111111, (unsigned int) 0x111111 },
+
+ /* Some characters that do NOT mirror */
+ { 0x0020, (unsigned int) 0x0020 },
+ { 0x0041, (unsigned int) 0x0041 },
+ { 0x00F0, (unsigned int) 0x00F0 },
+ { 0x27CC, (unsigned int) 0x27CC },
+ { 0xE01EF, (unsigned int) 0xE01EF },
+ { 0x1D7C3, (unsigned int) 0x1D7C3 },
+ { 0x100000, (unsigned int) 0x100000 },
+
+ /* Some characters that do mirror */
+ { 0x0029, (unsigned int) 0x0028 },
+ { 0x0028, (unsigned int) 0x0029 },
+ { 0x003E, (unsigned int) 0x003C },
+ { 0x003C, (unsigned int) 0x003E },
+ { 0x005D, (unsigned int) 0x005B },
+ { 0x005B, (unsigned int) 0x005D },
+ { 0x007D, (unsigned int) 0x007B },
+ { 0x007B, (unsigned int) 0x007D },
+ { 0x00BB, (unsigned int) 0x00AB },
+ { 0x00AB, (unsigned int) 0x00BB },
+ { 0x226B, (unsigned int) 0x226A },
+ { 0x226A, (unsigned int) 0x226B },
+ { 0x22F1, (unsigned int) 0x22F0 },
+ { 0x22F0, (unsigned int) 0x22F1 },
+ { 0xFF60, (unsigned int) 0xFF5F },
+ { 0xFF5F, (unsigned int) 0xFF60 },
+ { 0xFF63, (unsigned int) 0xFF62 },
+ { 0xFF62, (unsigned int) 0xFF63 },
+};
+static const test_pair_t mirroring_tests_more[] =
+{
+ /* No new mirroring characters have been encoded in recent Unicode versions. */
+ { 0xFFFF, (unsigned int) 0xFFFF },
+};
+
+static const test_pair_t script_tests[] =
+{
+ { 0x111111, (unsigned int) HB_SCRIPT_UNKNOWN },
+
+ { 0x002A, (unsigned int) HB_SCRIPT_COMMON },
+ { 0x0670, (unsigned int) HB_SCRIPT_INHERITED },
+ { 0x060D, (unsigned int) HB_SCRIPT_ARABIC },
+ { 0x0559, (unsigned int) HB_SCRIPT_ARMENIAN },
+ { 0x09CD, (unsigned int) HB_SCRIPT_BENGALI },
+ { 0x31B6, (unsigned int) HB_SCRIPT_BOPOMOFO },
+ { 0x13A2, (unsigned int) HB_SCRIPT_CHEROKEE },
+ { 0x2CFD, (unsigned int) HB_SCRIPT_COPTIC },
+ { 0x0482, (unsigned int) HB_SCRIPT_CYRILLIC },
+ { 0x10401, (unsigned int) HB_SCRIPT_DESERET },
+ { 0x094D, (unsigned int) HB_SCRIPT_DEVANAGARI },
+ { 0x1258, (unsigned int) HB_SCRIPT_ETHIOPIC },
+ { 0x10FC, (unsigned int) HB_SCRIPT_GEORGIAN },
+ { 0x10341, (unsigned int) HB_SCRIPT_GOTHIC },
+ { 0x0375, (unsigned int) HB_SCRIPT_GREEK },
+ { 0x0A83, (unsigned int) HB_SCRIPT_GUJARATI },
+ { 0x0A3C, (unsigned int) HB_SCRIPT_GURMUKHI },
+ { 0x3005, (unsigned int) HB_SCRIPT_HAN },
+ { 0x1100, (unsigned int) HB_SCRIPT_HANGUL },
+ { 0x05BF, (unsigned int) HB_SCRIPT_HEBREW },
+ { 0x309F, (unsigned int) HB_SCRIPT_HIRAGANA },
+ { 0x0CBC, (unsigned int) HB_SCRIPT_KANNADA },
+ { 0x30FF, (unsigned int) HB_SCRIPT_KATAKANA },
+ { 0x17DD, (unsigned int) HB_SCRIPT_KHMER },
+ { 0x0EDD, (unsigned int) HB_SCRIPT_LAO },
+ { 0x0061, (unsigned int) HB_SCRIPT_LATIN },
+ { 0x0D3D, (unsigned int) HB_SCRIPT_MALAYALAM },
+ { 0x1843, (unsigned int) HB_SCRIPT_MONGOLIAN },
+ { 0x1031, (unsigned int) HB_SCRIPT_MYANMAR },
+ { 0x169C, (unsigned int) HB_SCRIPT_OGHAM },
+ { 0x10322, (unsigned int) HB_SCRIPT_OLD_ITALIC },
+ { 0x0B3C, (unsigned int) HB_SCRIPT_ORIYA },
+ { 0x16EF, (unsigned int) HB_SCRIPT_RUNIC },
+ { 0x0DBD, (unsigned int) HB_SCRIPT_SINHALA },
+ { 0x0711, (unsigned int) HB_SCRIPT_SYRIAC },
+ { 0x0B82, (unsigned int) HB_SCRIPT_TAMIL },
+ { 0x0C03, (unsigned int) HB_SCRIPT_TELUGU },
+ { 0x07B1, (unsigned int) HB_SCRIPT_THAANA },
+ { 0x0E31, (unsigned int) HB_SCRIPT_THAI },
+ { 0x0FD4, (unsigned int) HB_SCRIPT_TIBETAN },
+ { 0x1401, (unsigned int) HB_SCRIPT_CANADIAN_ABORIGINAL },
+ { 0xA015, (unsigned int) HB_SCRIPT_YI },
+ { 0x1700, (unsigned int) HB_SCRIPT_TAGALOG },
+ { 0x1720, (unsigned int) HB_SCRIPT_HANUNOO },
+ { 0x1740, (unsigned int) HB_SCRIPT_BUHID },
+ { 0x1760, (unsigned int) HB_SCRIPT_TAGBANWA },
+
+ /* Unicode-4.0 additions */
+ { 0x2800, (unsigned int) HB_SCRIPT_BRAILLE },
+ { 0x10808, (unsigned int) HB_SCRIPT_CYPRIOT },
+ { 0x1932, (unsigned int) HB_SCRIPT_LIMBU },
+ { 0x10480, (unsigned int) HB_SCRIPT_OSMANYA },
+ { 0x10450, (unsigned int) HB_SCRIPT_SHAVIAN },
+ { 0x10000, (unsigned int) HB_SCRIPT_LINEAR_B },
+ { 0x1950, (unsigned int) HB_SCRIPT_TAI_LE },
+ { 0x1039F, (unsigned int) HB_SCRIPT_UGARITIC },
+
+ /* Unicode-4.1 additions */
+ { 0x1980, (unsigned int) HB_SCRIPT_NEW_TAI_LUE },
+ { 0x1A1F, (unsigned int) HB_SCRIPT_BUGINESE },
+ { 0x2C00, (unsigned int) HB_SCRIPT_GLAGOLITIC },
+ { 0x2D6F, (unsigned int) HB_SCRIPT_TIFINAGH },
+ { 0xA800, (unsigned int) HB_SCRIPT_SYLOTI_NAGRI },
+ { 0x103D0, (unsigned int) HB_SCRIPT_OLD_PERSIAN },
+ { 0x10A3F, (unsigned int) HB_SCRIPT_KHAROSHTHI },
+
+ /* Unicode-5.0 additions */
+ { 0x0378, (unsigned int) HB_SCRIPT_UNKNOWN },
+ { 0x1B04, (unsigned int) HB_SCRIPT_BALINESE },
+ { 0x12000, (unsigned int) HB_SCRIPT_CUNEIFORM },
+ { 0x10900, (unsigned int) HB_SCRIPT_PHOENICIAN },
+ { 0xA840, (unsigned int) HB_SCRIPT_PHAGS_PA },
+ { 0x07C0, (unsigned int) HB_SCRIPT_NKO },
+
+ /* Unicode-5.1 additions */
+ { 0xA900, (unsigned int) HB_SCRIPT_KAYAH_LI },
+ { 0x1C00, (unsigned int) HB_SCRIPT_LEPCHA },
+ { 0xA930, (unsigned int) HB_SCRIPT_REJANG },
+ { 0x1B80, (unsigned int) HB_SCRIPT_SUNDANESE },
+ { 0xA880, (unsigned int) HB_SCRIPT_SAURASHTRA },
+ { 0xAA00, (unsigned int) HB_SCRIPT_CHAM },
+ { 0x1C50, (unsigned int) HB_SCRIPT_OL_CHIKI },
+ { 0xA500, (unsigned int) HB_SCRIPT_VAI },
+ { 0x102A0, (unsigned int) HB_SCRIPT_CARIAN },
+ { 0x10280, (unsigned int) HB_SCRIPT_LYCIAN },
+ { 0x1093F, (unsigned int) HB_SCRIPT_LYDIAN },
+};
+static const test_pair_t script_tests_more[] =
+{
+ /* Unicode-5.2 additions */
+ { 0x10B00, (unsigned int) HB_SCRIPT_AVESTAN },
+ { 0xA6A0, (unsigned int) HB_SCRIPT_BAMUM },
+ { 0x13000, (unsigned int) HB_SCRIPT_EGYPTIAN_HIEROGLYPHS },
+ { 0x10840, (unsigned int) HB_SCRIPT_IMPERIAL_ARAMAIC },
+ { 0x10B60, (unsigned int) HB_SCRIPT_INSCRIPTIONAL_PAHLAVI },
+ { 0x10B40, (unsigned int) HB_SCRIPT_INSCRIPTIONAL_PARTHIAN },
+ { 0xA980, (unsigned int) HB_SCRIPT_JAVANESE },
+ { 0x11082, (unsigned int) HB_SCRIPT_KAITHI },
+ { 0xA4D0, (unsigned int) HB_SCRIPT_LISU },
+ { 0xABE5, (unsigned int) HB_SCRIPT_MEETEI_MAYEK },
+ { 0x10A60, (unsigned int) HB_SCRIPT_OLD_SOUTH_ARABIAN },
+ { 0x10C00, (unsigned int) HB_SCRIPT_OLD_TURKIC },
+ { 0x0800, (unsigned int) HB_SCRIPT_SAMARITAN },
+ { 0x1A20, (unsigned int) HB_SCRIPT_TAI_THAM },
+ { 0xAA80, (unsigned int) HB_SCRIPT_TAI_VIET },
+
+ /* Unicode-6.0 additions */
+ { 0x1BC0, (unsigned int) HB_SCRIPT_BATAK },
+ { 0x11000, (unsigned int) HB_SCRIPT_BRAHMI },
+ { 0x0840, (unsigned int) HB_SCRIPT_MANDAIC },
+
+ /* Unicode-5.2 character additions */
+ { 0x1CED, (unsigned int) HB_SCRIPT_INHERITED },
+ { 0x1400, (unsigned int) HB_SCRIPT_CANADIAN_ABORIGINAL },
+};
+
+
+typedef unsigned int (*get_func_t) (hb_unicode_funcs_t *ufuncs,
+ hb_codepoint_t unicode,
+ void *user_data);
+typedef unsigned int (*func_setter_func_t) (hb_unicode_funcs_t *ufuncs,
+ get_func_t *func,
+ void *user_data,
+ hb_destroy_func_t destroy);
+typedef unsigned int (*getter_func_t) (hb_unicode_funcs_t *ufuncs,
+ hb_codepoint_t unicode);
+
+typedef struct {
+ const char *name;
+ func_setter_func_t func_setter;
+ getter_func_t getter;
+ const test_pair_t *tests;
+ unsigned int num_tests;
+ const test_pair_t *tests_more;
+ unsigned int num_tests_more;
+ unsigned int default_value;
+} property_t;
+
+#define RETURNS_UNICODE_ITSELF ((unsigned int) -1)
+
+#define PROPERTY(name, DEFAULT) \
+ { \
+ #name, \
+ (func_setter_func_t) hb_unicode_funcs_set_##name##_func, \
+ (getter_func_t) hb_unicode_get_##name, \
+ name##_tests, \
+ G_N_ELEMENTS (name##_tests), \
+ name##_tests_more, \
+ G_N_ELEMENTS (name##_tests_more), \
+ DEFAULT \
+ }
+static const property_t properties[] =
+{
+ PROPERTY (combining_class, 0),
+ PROPERTY (eastasian_width, 1),
+ PROPERTY (general_category, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER),
+ PROPERTY (mirroring, RETURNS_UNICODE_ITSELF),
+ PROPERTY (script, (unsigned int) HB_SCRIPT_UNKNOWN),
+};
+#undef PROPERTY
static void
-test_unicode_glib (void)
+test_unicode_properties (gconstpointer user_data)
{
- hb_unicode_funcs_t *uf = hb_glib_get_unicode_funcs ();
+ hb_unicode_funcs_t *uf = (hb_unicode_funcs_t *) user_data;
+ unsigned int i, j;
g_assert (hb_unicode_funcs_is_immutable (uf));
- g_assert_cmpint (hb_unicode_get_script (uf, 'd'), ==, HB_SCRIPT_LATIN);
+ for (i = 0; i < G_N_ELEMENTS (properties); i++) {
+ const property_t *p = &properties[i];
+ const test_pair_t *tests;
+
+ tests = p->tests;
+ for (j = 0; j < p->num_tests; j++)
+ g_assert_cmpint (p->getter (uf, tests[j].unicode), ==, tests[j].value);
+ }
+}
+
+static hb_codepoint_t
+default_value (hb_codepoint_t default_value, hb_codepoint_t unicode)
+{
+ return default_value == RETURNS_UNICODE_ITSELF ? unicode : default_value;
}
static void
-test_unicode_default (void)
+test_unicode_properties_nil (void)
{
- hb_unicode_funcs_t *uf = hb_unicode_funcs_get_default ();
+ hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL);
+ unsigned int i, j;
- g_assert (hb_unicode_funcs_is_immutable (uf));
+ g_assert (!hb_unicode_funcs_is_immutable (uf));
- g_assert_cmpint (hb_unicode_get_script (uf, 'd'), ==, HB_SCRIPT_LATIN);
-}
+ for (i = 0; i < G_N_ELEMENTS (properties); i++) {
+ const property_t *p = &properties[i];
+ const test_pair_t *tests;
+ tests = p->tests;
+ for (j = 0; j < p->num_tests; j++)
+ g_assert_cmpint (p->getter (uf, tests[j].unicode), ==, default_value (p->default_value, tests[j].unicode));
+ }
+
+ hb_unicode_funcs_destroy (uf);
+}
#define MAGIC0 0x12345678
#define MAGIC1 0x76543210
@@ -232,16 +618,24 @@ main (int argc, char **argv)
{
hb_test_init (&argc, &argv);
- hb_test_add (test_unicode_nil);
- hb_test_add (test_unicode_glib);
- hb_test_add (test_unicode_default);
+ hb_test_add (test_unicode_properties_nil);
+
+ hb_test_add_data_flavor (hb_unicode_funcs_get_default (), "default", test_unicode_properties);
+#ifdef HAVE_GLIB
+ hb_test_add_data_flavor (hb_glib_get_unicode_funcs (), "glib", test_unicode_properties);
+#endif
+#ifdef HAVE_ICU
+ hb_test_add_data_flavor (hb_icu_get_unicode_funcs (), "icu", test_unicode_properties);
+#endif
hb_test_add_fixture (data_fixture, NULL, test_unicode_custom);
hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_nil);
hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_default);
hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_deep);
- /* XXX test all methods for their defaults and various (glib, icu, default) implementations. */
+ /* XXX test icu ufuncs */
+ /* XXX test _more tests (warn?) */
+ /* XXX test chainup */
/* XXX test glib & icu two-way script conversion */
return hb_test_run ();
commit da96ee072fa3544c3d36cf0b82ada11806789d70
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Fri Apr 29 12:17:09 2011 -0400
[test/unicode] Test is/make_immutable()
diff --git a/test/test-unicode.c b/test/test-unicode.c
index 40bb03d..19d921b 100644
--- a/test/test-unicode.c
+++ b/test/test-unicode.c
@@ -36,6 +36,8 @@ test_unicode_nil (void)
{
hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL);
+ g_assert (!hb_unicode_funcs_is_immutable (uf));
+
g_assert_cmpint (hb_unicode_get_script (uf, 'd'), ==, HB_SCRIPT_UNKNOWN);
hb_unicode_funcs_destroy (uf);
@@ -46,6 +48,8 @@ test_unicode_glib (void)
{
hb_unicode_funcs_t *uf = hb_glib_get_unicode_funcs ();
+ g_assert (hb_unicode_funcs_is_immutable (uf));
+
g_assert_cmpint (hb_unicode_get_script (uf, 'd'), ==, HB_SCRIPT_LATIN);
}
@@ -54,6 +58,8 @@ test_unicode_default (void)
{
hb_unicode_funcs_t *uf = hb_unicode_funcs_get_default ();
+ g_assert (hb_unicode_funcs_is_immutable (uf));
+
g_assert_cmpint (hb_unicode_get_script (uf, 'd'), ==, HB_SCRIPT_LATIN);
}
@@ -106,22 +112,6 @@ simple_get_script (hb_unicode_funcs_t *ufuncs,
return HB_SCRIPT_UNKNOWN;
}
-static void
-test_unicode_custom (data_fixture_t *f, gconstpointer user_data)
-{
- hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL);
-
- hb_unicode_funcs_set_script_func (uf, simple_get_script,
- &f->data[0], free_up);
-
- g_assert_cmpint (hb_unicode_get_script (uf, 'a'), ==, HB_SCRIPT_LATIN);
- g_assert_cmpint (hb_unicode_get_script (uf, '0'), ==, HB_SCRIPT_UNKNOWN);
-
- g_assert (!f->data[0].freed && !f->data[1].freed);
- hb_unicode_funcs_destroy (uf);
- g_assert (f->data[0].freed && !f->data[1].freed);
-}
-
static hb_script_t
a_is_for_arabic_get_script (hb_unicode_funcs_t *ufuncs,
hb_codepoint_t codepoint,
@@ -143,6 +133,30 @@ a_is_for_arabic_get_script (hb_unicode_funcs_t *ufuncs,
}
static void
+test_unicode_custom (data_fixture_t *f, gconstpointer user_data)
+{
+ hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL);
+
+ hb_unicode_funcs_set_script_func (uf, simple_get_script,
+ &f->data[0], free_up);
+
+ g_assert_cmpint (hb_unicode_get_script (uf, 'a'), ==, HB_SCRIPT_LATIN);
+ g_assert_cmpint (hb_unicode_get_script (uf, '0'), ==, HB_SCRIPT_UNKNOWN);
+
+ g_assert (!hb_unicode_funcs_is_immutable (uf));
+ hb_unicode_funcs_make_immutable (uf);
+ g_assert (hb_unicode_funcs_is_immutable (uf));
+
+ /* Since uf is immutable now, the following setter should do nothing. */
+ hb_unicode_funcs_set_script_func (uf, a_is_for_arabic_get_script,
+ &f->data[1], free_up);
+
+ g_assert (!f->data[0].freed && !f->data[1].freed);
+ hb_unicode_funcs_destroy (uf);
+ g_assert (f->data[0].freed && !f->data[1].freed);
+}
+
+static void
test_unicode_subclassing_nil (data_fixture_t *f, gconstpointer user_data)
{
hb_unicode_funcs_t *uf, *aa;
commit 6af9cff5e17e82100b435c8d21aed0765296d58d
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Fri Apr 29 12:00:38 2011 -0400
[test/unicode] Use text fixture instead of static variables
diff --git a/src/hb-unicode-private.hh b/src/hb-unicode-private.hh
index 8337e42..34da030 100644
--- a/src/hb-unicode-private.hh
+++ b/src/hb-unicode-private.hh
@@ -1,6 +1,6 @@
/*
* Copyright © 2009 Red Hat, Inc.
- * Copyright © 2011 Codethink Limited
+ * Copyright © 2011 Codethink Limited
* Copyright © 2010,2011 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
diff --git a/src/hb-unicode.h b/src/hb-unicode.h
index a46431b..c7e35ba 100644
--- a/src/hb-unicode.h
+++ b/src/hb-unicode.h
@@ -1,6 +1,6 @@
/*
* Copyright © 2009 Red Hat, Inc.
- * Copyright © 2011 Codethink Limited
+ * Copyright © 2011 Codethink Limited
* Copyright © 2011 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
diff --git a/test/test-buffer.c b/test/test-buffer.c
index f9dabe6..1468bfb 100644
--- a/test/test-buffer.c
+++ b/test/test-buffer.c
@@ -26,7 +26,7 @@
#include "hb-test.h"
-/* This file tests types defined in hb-buffer.h */
+/* Unit tests for hb-buffer.h */
static const char utf8[10] = "ab\360\240\200\200defg";
diff --git a/test/test-c.c b/test/test-c.c
index a48f030..543fa7b 100644
--- a/test/test-c.c
+++ b/test/test-c.c
@@ -26,6 +26,7 @@
/* This file tests that all headers can be included from .c files */
+
#include <config.h>
#include <hb.h>
diff --git a/test/test-common.c b/test/test-common.c
index 31661f0..c2b4e1c 100644
--- a/test/test-common.c
+++ b/test/test-common.c
@@ -26,7 +26,8 @@
#include "hb-test.h"
-/* This file tests types defined in hb-common.h */
+/* Unit tests for hb-common.h */
+
static void
test_types_int (void)
diff --git a/test/test-cplusplus.cc b/test/test-cplusplus.cc
index 55a4d18..3313d74 100644
--- a/test/test-cplusplus.cc
+++ b/test/test-cplusplus.cc
@@ -26,4 +26,5 @@
/* This file tests that all headers can be included from .cc files */
+
#include "test-c.c"
diff --git a/test/test-unicode.c b/test/test-unicode.c
index 30a89be..40bb03d 100644
--- a/test/test-unicode.c
+++ b/test/test-unicode.c
@@ -1,5 +1,6 @@
/*
- * Copyright © 2011 Codethink Limited
+ * Copyright © 2011 Codethink Limited
+ * Copyright © 2011 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
@@ -22,11 +23,13 @@
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Codethink Author(s): Ryan Lortie
+ * Google Author(s): Behdad Esfahbod
*/
#include "hb-test.h"
-/* This file tests the unicode virtual functions interface */
+/* Unit tests for hb-unicode.h */
+
static void
test_unicode_nil (void)
@@ -54,20 +57,36 @@ test_unicode_default (void)
g_assert_cmpint (hb_unicode_get_script (uf, 'd'), ==, HB_SCRIPT_LATIN);
}
-static gboolean freed0, freed1;
-static int unique_pointer0[1];
-static int unique_pointer1[1];
-static void free_up (void *up)
+
+#define MAGIC0 0x12345678
+#define MAGIC1 0x76543210
+
+typedef struct {
+ int value;
+ gboolean freed;
+} data_t;
+
+typedef struct {
+ data_t data[2];
+} data_fixture_t;
+static void
+data_fixture_init (data_fixture_t *f, gconstpointer user_data)
+{
+ f->data[0].value = MAGIC0;
+ f->data[1].value = MAGIC1;
+}
+static void
+data_fixture_finish (data_fixture_t *f, gconstpointer user_data)
{
- if (up == unique_pointer0) {
- g_assert (!freed0);
- freed0 = TRUE;
- } else if (up == unique_pointer1) {
- g_assert (!freed1);
- freed1 = TRUE;
- } else {
- g_assert_not_reached ();
- }
+}
+
+static void free_up (void *p)
+{
+ data_t *data = (data_t *) p;
+
+ g_assert (data->value == MAGIC0 || data->value == MAGIC1);
+ g_assert (data->freed == FALSE);
+ data->freed = TRUE;
}
static hb_script_t
@@ -75,8 +94,11 @@ simple_get_script (hb_unicode_funcs_t *ufuncs,
hb_codepoint_t codepoint,
void *user_data)
{
+ data_t *data = (data_t *) user_data;
+
g_assert (hb_unicode_funcs_get_parent (ufuncs) == NULL);
- g_assert (unique_pointer0 == user_data);
+ g_assert (data->value == MAGIC0);
+ g_assert (data->freed == FALSE);
if ('a' <= codepoint && codepoint <= 'z')
return HB_SCRIPT_LATIN;
@@ -85,30 +107,31 @@ simple_get_script (hb_unicode_funcs_t *ufuncs,
}
static void
-test_unicode_custom (void)
+test_unicode_custom (data_fixture_t *f, gconstpointer user_data)
{
hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL);
hb_unicode_funcs_set_script_func (uf, simple_get_script,
- unique_pointer0, free_up);
+ &f->data[0], free_up);
g_assert_cmpint (hb_unicode_get_script (uf, 'a'), ==, HB_SCRIPT_LATIN);
g_assert_cmpint (hb_unicode_get_script (uf, '0'), ==, HB_SCRIPT_UNKNOWN);
- g_assert (!freed0 && !freed1);
+ g_assert (!f->data[0].freed && !f->data[1].freed);
hb_unicode_funcs_destroy (uf);
- g_assert (freed0 && !freed1);
- freed0 = FALSE;
+ g_assert (f->data[0].freed && !f->data[1].freed);
}
-
static hb_script_t
a_is_for_arabic_get_script (hb_unicode_funcs_t *ufuncs,
hb_codepoint_t codepoint,
void *user_data)
{
+ data_t *data = (data_t *) user_data;
+
g_assert (hb_unicode_funcs_get_parent (ufuncs) != NULL);
- g_assert (user_data == unique_pointer1);
+ g_assert (data->value == MAGIC1);
+ g_assert (data->freed == FALSE);
if (codepoint == 'a') {
return HB_SCRIPT_ARABIC;
@@ -120,7 +143,7 @@ a_is_for_arabic_get_script (hb_unicode_funcs_t *ufuncs,
}
static void
-test_unicode_subclassing_nil (void)
+test_unicode_subclassing_nil (data_fixture_t *f, gconstpointer user_data)
{
hb_unicode_funcs_t *uf, *aa;
@@ -131,67 +154,65 @@ test_unicode_subclassing_nil (void)
hb_unicode_funcs_destroy (uf);
hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
- unique_pointer1, free_up);
+ &f->data[1], free_up);
g_assert_cmpint (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
g_assert_cmpint (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_UNKNOWN);
- g_assert (!freed0 && !freed1);
+ g_assert (!f->data[0].freed && !f->data[1].freed);
hb_unicode_funcs_destroy (aa);
- g_assert (!freed0 && freed1);
- freed1 = FALSE;
+ g_assert (!f->data[0].freed && f->data[1].freed);
}
static void
-test_unicode_subclassing_glib (void)
+test_unicode_subclassing_default (data_fixture_t *f, gconstpointer user_data)
{
hb_unicode_funcs_t *uf, *aa;
- uf = hb_glib_get_unicode_funcs ();
+ uf = hb_unicode_funcs_get_default ();
aa = hb_unicode_funcs_create (uf);
hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
- unique_pointer1, free_up);
+ &f->data[1], free_up);
g_assert_cmpint (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
g_assert_cmpint (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_LATIN);
- g_assert (!freed0 && !freed1);
+ g_assert (!f->data[0].freed && !f->data[1].freed);
hb_unicode_funcs_destroy (aa);
- g_assert (!freed0 && freed1);
- freed1 = FALSE;
+ g_assert (!f->data[0].freed && f->data[1].freed);
}
static void
-test_unicode_subclassing_deep (void)
+test_unicode_subclassing_deep (data_fixture_t *f, gconstpointer user_data)
{
hb_unicode_funcs_t *uf, *aa;
uf = hb_unicode_funcs_create (NULL);
hb_unicode_funcs_set_script_func (uf, simple_get_script,
- unique_pointer0, free_up);
+ &f->data[0], free_up);
aa = hb_unicode_funcs_create (uf);
hb_unicode_funcs_destroy (uf);
/* make sure the 'uf' didn't get freed, since 'aa' holds a ref */
- g_assert (!freed0);
+ g_assert (!f->data[0].freed);
hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
- unique_pointer1, free_up);
+ &f->data[1], free_up);
g_assert_cmpint (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
g_assert_cmpint (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_LATIN);
g_assert_cmpint (hb_unicode_get_script (aa, '0'), ==, HB_SCRIPT_UNKNOWN);
- g_assert (!freed0 && !freed1);
+ g_assert (!f->data[0].freed && !f->data[1].freed);
hb_unicode_funcs_destroy (aa);
- g_assert (freed0 && freed1);
- freed0 = freed1 = FALSE;
+ g_assert (f->data[0].freed && f->data[1].freed);
}
+
int
main (int argc, char **argv)
{
@@ -200,10 +221,11 @@ main (int argc, char **argv)
hb_test_add (test_unicode_nil);
hb_test_add (test_unicode_glib);
hb_test_add (test_unicode_default);
- hb_test_add (test_unicode_custom);
- hb_test_add (test_unicode_subclassing_nil);
- hb_test_add (test_unicode_subclassing_glib);
- hb_test_add (test_unicode_subclassing_deep);
+
+ hb_test_add_fixture (data_fixture, NULL, test_unicode_custom);
+ hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_nil);
+ hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_default);
+ hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_deep);
/* XXX test all methods for their defaults and various (glib, icu, default) implementations. */
/* XXX test glib & icu two-way script conversion */
More information about the HarfBuzz
mailing list