2 * Copyright © 2018 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): Garret Rieger
28 #include "hb-subset-test.h"
30 /* Unit tests for hb-subset-glyf.h */
33 test_subset_32_tables (void)
35 hb_face_t *face = hb_test_open_font_file ("../fuzzing/fonts/oom-6ef8c96d3710262511bcc730dce9c00e722cb653");
37 hb_subset_input_t *input = hb_subset_input_create_or_fail ();
38 hb_set_t *codepoints = hb_subset_input_unicode_set (input);
41 hb_set_add (codepoints, 'a');
42 hb_set_add (codepoints, 'b');
43 hb_set_add (codepoints, 'c');
45 subset = hb_subset_or_fail (face, input);
47 g_assert (subset != hb_face_get_empty ());
49 hb_subset_input_destroy (input);
50 hb_face_destroy (subset);
51 hb_face_destroy (face);
55 test_subset_no_inf_loop (void)
57 hb_face_t *face = hb_test_open_font_file ("../fuzzing/fonts/clusterfuzz-testcase-minimized-hb-subset-fuzzer-5521982557782016");
59 hb_subset_input_t *input = hb_subset_input_create_or_fail ();
60 hb_set_t *codepoints = hb_subset_input_unicode_set (input);
63 hb_set_add (codepoints, 'a');
64 hb_set_add (codepoints, 'b');
65 hb_set_add (codepoints, 'c');
67 subset = hb_subset_or_fail (face, input);
70 hb_subset_input_destroy (input);
71 hb_face_destroy (subset);
72 hb_face_destroy (face);
76 test_subset_crash (void)
78 hb_face_t *face = hb_test_open_font_file ("../fuzzing/fonts/crash-4b60576767ee4d9fe1cc10959d89baf73d4e8249");
80 hb_subset_input_t *input = hb_subset_input_create_or_fail ();
81 hb_set_t *codepoints = hb_subset_input_unicode_set (input);
84 hb_set_add (codepoints, 'a');
85 hb_set_add (codepoints, 'b');
86 hb_set_add (codepoints, 'c');
88 subset = hb_subset_or_fail (face, input);
91 hb_subset_input_destroy (input);
92 hb_face_destroy (subset);
93 hb_face_destroy (face);
97 test_subset_set_flags (void)
99 hb_subset_input_t *input = hb_subset_input_create_or_fail ();
101 g_assert (hb_subset_input_get_flags (input) == HB_SUBSET_FLAGS_DEFAULT);
103 hb_subset_input_set_flags (input,
104 HB_SUBSET_FLAGS_NAME_LEGACY |
105 HB_SUBSET_FLAGS_NOTDEF_OUTLINE |
106 HB_SUBSET_FLAGS_GLYPH_NAMES);
108 g_assert (hb_subset_input_get_flags (input) ==
109 (hb_subset_flags_t) (
110 HB_SUBSET_FLAGS_NAME_LEGACY |
111 HB_SUBSET_FLAGS_NOTDEF_OUTLINE |
112 HB_SUBSET_FLAGS_GLYPH_NAMES));
114 hb_subset_input_set_flags (input,
115 HB_SUBSET_FLAGS_NAME_LEGACY |
116 HB_SUBSET_FLAGS_NOTDEF_OUTLINE |
117 HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES);
119 g_assert (hb_subset_input_get_flags (input) ==
120 (hb_subset_flags_t) (
121 HB_SUBSET_FLAGS_NAME_LEGACY |
122 HB_SUBSET_FLAGS_NOTDEF_OUTLINE |
123 HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES));
126 hb_subset_input_destroy (input);
131 test_subset_sets (void)
133 hb_subset_input_t *input = hb_subset_input_create_or_fail ();
134 hb_set_t* set = hb_set_create ();
136 hb_set_add (hb_subset_input_set (input, HB_SUBSET_SETS_GLYPH_INDEX), 83);
137 hb_set_add (hb_subset_input_set (input, HB_SUBSET_SETS_UNICODE), 85);
139 hb_set_clear (hb_subset_input_set (input, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG));
140 hb_set_add (hb_subset_input_set (input, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG), 87);
142 hb_set_add (set, 83);
143 g_assert (hb_set_is_equal (hb_subset_input_glyph_set (input), set));
146 hb_set_add (set, 85);
147 g_assert (hb_set_is_equal (hb_subset_input_unicode_set (input), set));
150 hb_set_add (set, 87);
151 g_assert (hb_set_is_equal (hb_subset_input_set (input, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG), set));
154 hb_set_destroy (set);
155 hb_subset_input_destroy (input);
159 test_subset_plan (void)
161 hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
162 hb_face_t *face_ac = hb_test_open_font_file ("fonts/Roboto-Regular.ac.ttf");
164 hb_set_t *codepoints = hb_set_create();
165 hb_set_add (codepoints, 97);
166 hb_set_add (codepoints, 99);
167 hb_subset_input_t* input = hb_subset_test_create_input (codepoints);
168 hb_set_destroy (codepoints);
170 hb_subset_plan_t* plan = hb_subset_plan_create_or_fail (face_abc, input);
173 const hb_map_t* mapping = hb_subset_plan_old_to_new_glyph_mapping (plan);
174 g_assert (hb_map_get (mapping, 1) == 1);
175 g_assert (hb_map_get (mapping, 3) == 2);
177 mapping = hb_subset_plan_new_to_old_glyph_mapping (plan);
178 g_assert (hb_map_get (mapping, 1) == 1);
179 g_assert (hb_map_get (mapping, 2) == 3);
181 mapping = hb_subset_plan_unicode_to_old_glyph_mapping (plan);
182 g_assert (hb_map_get (mapping, 0x63) == 3);
184 hb_face_t* face_abc_subset = hb_subset_plan_execute_or_fail (plan);
186 hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('l','o','c', 'a'));
187 hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('g','l','y','f'));
189 hb_subset_input_destroy (input);
190 hb_subset_plan_destroy (plan);
191 hb_face_destroy (face_abc_subset);
192 hb_face_destroy (face_abc);
193 hb_face_destroy (face_ac);
197 _ref_table (hb_face_t *face, hb_tag_t tag, void *user_data)
199 return hb_face_reference_table ((hb_face_t*) user_data, tag);
203 test_subset_create_for_tables_face (void)
205 hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
206 hb_face_t *face_ac = hb_test_open_font_file ("fonts/Roboto-Regular.ac.ttf");
207 hb_face_t *face_create_for_tables = hb_face_create_for_tables (
212 hb_set_t *codepoints = hb_set_create();
213 hb_set_add (codepoints, 97);
214 hb_set_add (codepoints, 99);
216 hb_subset_input_t* input = hb_subset_test_create_input (codepoints);
217 hb_set_destroy (codepoints);
219 hb_face_t* face_abc_subset = hb_subset_or_fail (face_create_for_tables, input);
221 hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('l','o','c', 'a'));
222 hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('g','l','y','f'));
223 hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('g','a','s','p'));
225 hb_subset_input_destroy (input);
226 hb_face_destroy (face_abc_subset);
227 hb_face_destroy (face_create_for_tables);
228 hb_face_destroy (face_abc);
229 hb_face_destroy (face_ac);
233 main (int argc, char **argv)
235 hb_test_init (&argc, &argv);
237 hb_test_add (test_subset_32_tables);
238 hb_test_add (test_subset_no_inf_loop);
239 hb_test_add (test_subset_crash);
240 hb_test_add (test_subset_set_flags);
241 hb_test_add (test_subset_sets);
242 hb_test_add (test_subset_plan);
243 hb_test_add (test_subset_create_for_tables_face);
245 return hb_test_run();