2 * Copyright © 2011 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Google Author(s): Behdad Esfahbod
29 /* Unit tests for hb-shape.h */
32 * This test provides a framework to test aspects of hb_shape() that are
33 * font-independent. Please add tests for any feature that fits that
37 /* TODO Make this test data-driven and add some real test data */
40 static const char test_data[] = "test\0data";
43 glyph_h_advance_func (hb_font_t *font, void *font_data,
56 glyph_func (hb_font_t *font, void *font_data,
57 hb_codepoint_t unicode, hb_codepoint_t variant_selector,
58 hb_codepoint_t *glyph,
62 case 'T': *glyph = 1; return TRUE;
63 case 'e': *glyph = 2; return TRUE;
64 case 's': *glyph = 3; return TRUE;
70 glyph_h_kerning_func (hb_font_t *font, void *font_data,
71 hb_codepoint_t left, hb_codepoint_t right,
74 if (left == 1 && right == 2)
80 static const char TesT[] = "TesT";
87 hb_font_funcs_t *ffuncs;
91 hb_glyph_info_t *glyphs;
92 hb_glyph_position_t *positions;
94 blob = hb_blob_create (test_data, sizeof (test_data), HB_MEMORY_MODE_READONLY, NULL, NULL);
95 face = hb_face_create (blob, 0);
96 hb_blob_destroy (blob);
97 font = hb_font_create (face);
98 hb_face_destroy (face);
99 hb_font_set_scale (font, 10, 10);
101 ffuncs = hb_font_funcs_create ();
102 hb_font_funcs_set_glyph_h_advance_func (ffuncs, glyph_h_advance_func, NULL, NULL);
103 hb_font_funcs_set_glyph_func (ffuncs, glyph_func, NULL, NULL);
104 hb_font_funcs_set_glyph_h_kerning_func (ffuncs, glyph_h_kerning_func, NULL, NULL);
105 hb_font_set_funcs (font, ffuncs, NULL, NULL);
106 hb_font_funcs_destroy (ffuncs);
108 buffer = hb_buffer_create (0);
109 hb_buffer_set_direction (buffer, HB_DIRECTION_LTR);
110 hb_buffer_add_utf8 (buffer, TesT, 4, 0, 4);
112 hb_shape (font, buffer, NULL, 0);
114 len = hb_buffer_get_length (buffer);
115 glyphs = hb_buffer_get_glyph_infos (buffer, NULL);
116 positions = hb_buffer_get_glyph_positions (buffer, NULL);
119 const hb_codepoint_t output_glyphs[] = {1, 2, 3, 1};
120 const hb_position_t output_x_advances[] = {9, 5, 5, 10};
121 const hb_position_t output_x_offsets[] = {0, -1, 0, 0};
123 g_assert_cmpint (len, ==, 4);
124 for (i = 0; i < len; i++) {
125 g_assert_cmphex (glyphs[i].codepoint, ==, output_glyphs[i]);
126 g_assert_cmphex (glyphs[i].cluster, ==, i);
128 for (i = 0; i < len; i++) {
129 g_assert_cmpint (output_x_advances[i], ==, positions[i].x_advance);
130 g_assert_cmpint (output_x_offsets [i], ==, positions[i].x_offset);
131 g_assert_cmpint (0, ==, positions[i].y_advance);
132 g_assert_cmpint (0, ==, positions[i].y_offset);
136 hb_buffer_destroy (buffer);
137 hb_font_destroy (font);
142 main (int argc, char **argv)
144 hb_test_init (&argc, &argv);
146 hb_test_add (test_shape);
148 return hb_test_run();