/* Unit tests for hb-shape.h */
+/*
+ * This test provides a framework to test aspects of hb_shape() that are
+ * font-independent. Please add tests for any feature that fits that
+ * description.
+ */
+
+/* TODO Make this test data-driven and add some real test data */
+/* TODO Test positions too. And test non-native direction. Test commit 2e18c6dbdfb */
+
static const char test_data[] = "test\0data";
-static void
-glyph_advance_func (hb_font_t *font, void *font_data,
- hb_codepoint_t glyph,
- hb_position_t *x_advance, hb_position_t *y_advance,
- void *user_data)
+static hb_position_t
+glyph_h_advance_func (hb_font_t *font, void *font_data,
+ hb_codepoint_t glyph,
+ void *user_data)
{
switch (glyph) {
- case 1: *x_advance = 10; return;
- case 2: *x_advance = 6; return;
- case 3: *x_advance = 5; return;
+ case 1: return 10;
+ case 2: return 6;
+ case 3: return 5;
}
+ return 0;
}
-static hb_codepoint_t
+static hb_bool_t
glyph_func (hb_font_t *font, void *font_data,
hb_codepoint_t unicode, hb_codepoint_t variant_selector,
+ hb_codepoint_t *glyph,
void *user_data)
{
switch (unicode) {
- case 'T': return 1;
- case 'e': return 2;
- case 's': return 3;
- default: return 0;
+ case 'T': *glyph = 1; return TRUE;
+ case 'e': *glyph = 2; return TRUE;
+ case 's': *glyph = 3; return TRUE;
}
+ return FALSE;
}
-static void
-kerning_func (hb_font_t *font, void *font_data,
- hb_codepoint_t left, hb_codepoint_t right,
- hb_position_t *x_kern, hb_position_t *y_kern,
- void *user_data)
+static hb_position_t
+glyph_h_kerning_func (hb_font_t *font, void *font_data,
+ hb_codepoint_t left, hb_codepoint_t right,
+ void *user_data)
{
- if (left == 1 && right == 2) {
- *x_kern = -2;
- }
+ if (left == 1 && right == 2)
+ return -2;
+
+ return 0;
}
static const char TesT[] = "TesT";
static void
-test_shape_ltr (void)
+test_shape (void)
{
hb_blob_t *blob;
hb_face_t *face;
hb_font_set_scale (font, 10, 10);
ffuncs = hb_font_funcs_create ();
- hb_font_funcs_set_glyph_advance_func (ffuncs, glyph_advance_func, NULL, NULL);
+ hb_font_funcs_set_glyph_h_advance_func (ffuncs, glyph_h_advance_func, NULL, NULL);
hb_font_funcs_set_glyph_func (ffuncs, glyph_func, NULL, NULL);
- hb_font_funcs_set_kerning_func (ffuncs, kerning_func, NULL, NULL);
+ hb_font_funcs_set_glyph_h_kerning_func (ffuncs, glyph_h_kerning_func, NULL, NULL);
hb_font_set_funcs (font, ffuncs, NULL, NULL);
hb_font_funcs_destroy (ffuncs);
glyphs = hb_buffer_get_glyph_infos (buffer, NULL);
positions = hb_buffer_get_glyph_positions (buffer, NULL);
- /* XXX check glyph output and positions */
+ {
+ const hb_codepoint_t output_glyphs[] = {1, 2, 3, 1};
+ const hb_position_t output_x_advances[] = {9, 5, 5, 10};
+ const hb_position_t output_x_offsets[] = {0, -1, 0, 0};
+ unsigned int i;
+ g_assert_cmpint (len, ==, 4);
+ for (i = 0; i < len; i++) {
+ g_assert_cmphex (glyphs[i].codepoint, ==, output_glyphs[i]);
+ g_assert_cmphex (glyphs[i].cluster, ==, i);
+ }
+ for (i = 0; i < len; i++) {
+ g_assert_cmpint (output_x_advances[i], ==, positions[i].x_advance);
+ g_assert_cmpint (output_x_offsets [i], ==, positions[i].x_offset);
+ g_assert_cmpint (0, ==, positions[i].y_advance);
+ g_assert_cmpint (0, ==, positions[i].y_offset);
+ }
+ }
hb_buffer_destroy (buffer);
hb_font_destroy (font);
{
hb_test_init (&argc, &argv);
- //hb_test_add (test_shape_empty);
- hb_test_add (test_shape_ltr);
+ hb_test_add (test_shape);
return hb_test_run();
}