Hash :
7e353d37
Author :
Date :
2025-05-23T14:31:35
[test] Remove u8 prefix from strings No idea how/why this got in there to begin with.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
/*
* Copyright © 2025 Khaled Hosny
*
* 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.
*
*/
#include "hb-ot.h"
#include "hb-test.h"
/* Unit tests for hb-shape-plan.h */
static void
test_ot_shape_plan_get_feature_tags_rtl (void)
{
/* Test getting features enabled for horizontal RTL text */
hb_face_t *face = hb_test_open_font_file ("fonts/NotoSans-Bold.ttf");
hb_font_t *font = hb_font_create (face);
hb_segment_properties_t props = HB_SEGMENT_PROPERTIES_DEFAULT;
props.script = HB_SCRIPT_ARABIC;
props.direction = HB_DIRECTION_RTL;
hb_buffer_t *buffer = hb_buffer_create ();
hb_buffer_set_segment_properties (buffer, &props);
hb_buffer_add_utf8 (buffer, "()", -1, 0, -1);
hb_shape_plan_t *shape_plan = hb_shape_plan_create (face, &props, NULL, 0, NULL);
hb_bool_t ret = hb_shape_plan_execute (shape_plan, font, buffer, NULL, 0);
g_assert_true (ret);
hb_tag_t features[16];
unsigned int feature_count = sizeof (features) / sizeof (features[0]);
unsigned int count = hb_ot_shape_plan_get_feature_tags (shape_plan, 0, &feature_count, features);
g_assert_cmpuint (count, ==, 16);
g_assert_cmpuint (feature_count, ==, count);
g_assert_cmpint (features[0], ==, HB_TAG ('a', 'b', 'v', 'm'));
g_assert_cmpint (features[1], ==, HB_TAG ('c', 'c', 'm', 'p'));
g_assert_cmpint (features[2], ==, HB_TAG ('d', 'i', 's', 't'));
g_assert_cmpint (features[3], ==, HB_TAG ('d', 'n', 'o', 'm'));
g_assert_cmpint (features[4], ==, HB_TAG ('f', 'i', 'n', 'a'));
g_assert_cmpint (features[5], ==, HB_TAG ('f', 'r', 'a', 'c'));
g_assert_cmpint (features[6], ==, HB_TAG ('i', 'n', 'i', 't'));
g_assert_cmpint (features[7], ==, HB_TAG ('i', 's', 'o', 'l'));
g_assert_cmpint (features[8], ==, HB_TAG ('k', 'e', 'r', 'n'));
g_assert_cmpint (features[9], ==, HB_TAG ('l', 'i', 'g', 'a'));
g_assert_cmpint (features[10], ==, HB_TAG ('m', 'a', 'r', 'k'));
g_assert_cmpint (features[11], ==, HB_TAG ('m', 'e', 'd', 'i'));
g_assert_cmpint (features[12], ==, HB_TAG ('m', 'k', 'm', 'k'));
g_assert_cmpint (features[13], ==, HB_TAG ('n', 'u', 'm', 'r'));
g_assert_cmpint (features[14], ==, HB_TAG ('r', 'l', 'i', 'g'));
g_assert_cmpint (features[15], ==, HB_TAG ('r', 't', 'l', 'm'));
hb_shape_plan_destroy (shape_plan);
hb_buffer_destroy (buffer);
hb_font_destroy (font);
hb_face_destroy (face);
}
static void
test_ot_shape_plan_get_feature_tags_ltr (void)
{
/* Test getting features enabled for horizontal LTR text */
hb_face_t *face = hb_test_open_font_file ("fonts/NotoSans-Bold.ttf");
hb_font_t *font = hb_font_create (face);
hb_segment_properties_t props = HB_SEGMENT_PROPERTIES_DEFAULT;
props.script = HB_SCRIPT_LATIN;
props.direction = HB_DIRECTION_LTR;
hb_buffer_t *buffer = hb_buffer_create ();
hb_buffer_set_segment_properties (buffer, &props);
hb_buffer_add_utf8 (buffer, " ", -1, 0, -1);
hb_shape_plan_t *shape_plan = hb_shape_plan_create (face, &props, NULL, 0, NULL);
hb_bool_t ret = hb_shape_plan_execute (shape_plan, font, buffer, NULL, 0);
g_assert_true (ret);
hb_tag_t features[10];
unsigned int feature_count = sizeof (features) / sizeof (features[0]);
unsigned int count = hb_ot_shape_plan_get_feature_tags (shape_plan, 0, &feature_count, features);
g_assert_cmpuint (count, ==, 10);
g_assert_cmpuint (feature_count, ==, count);
g_assert_cmpint (features[0], ==, HB_TAG ('a', 'b', 'v', 'm'));
g_assert_cmpint (features[1], ==, HB_TAG ('c', 'c', 'm', 'p'));
g_assert_cmpint (features[2], ==, HB_TAG ('d', 'i', 's', 't'));
g_assert_cmpint (features[3], ==, HB_TAG ('d', 'n', 'o', 'm'));
g_assert_cmpint (features[4], ==, HB_TAG ('f', 'r', 'a', 'c'));
g_assert_cmpint (features[5], ==, HB_TAG ('k', 'e', 'r', 'n'));
g_assert_cmpint (features[6], ==, HB_TAG ('l', 'i', 'g', 'a'));
g_assert_cmpint (features[7], ==, HB_TAG ('m', 'a', 'r', 'k'));
g_assert_cmpint (features[8], ==, HB_TAG ('m', 'k', 'm', 'k'));
g_assert_cmpint (features[9], ==, HB_TAG ('n', 'u', 'm', 'r'));
hb_buffer_destroy (buffer);
hb_shape_plan_destroy (shape_plan);
hb_font_destroy (font);
hb_face_destroy (face);
}
static void
test_ot_shape_plan_get_feature_tags_ttb (void)
{
/* Test getting features enabled for vertical text */
hb_face_t *face = hb_test_open_font_file ("fonts/Mplus1p-Regular.ttf");
hb_font_t *font = hb_font_create (face);
hb_segment_properties_t props = HB_SEGMENT_PROPERTIES_DEFAULT;
props.script = HB_SCRIPT_HAN;
props.direction = HB_DIRECTION_TTB;
hb_buffer_t *buffer = hb_buffer_create ();
hb_buffer_set_segment_properties (buffer, &props);
hb_buffer_add_utf8 (buffer, " ", -1, 0, -1);
hb_shape_plan_t *shape_plan = hb_shape_plan_create (face, &props, NULL, 0, NULL);
hb_bool_t ret = hb_shape_plan_execute (shape_plan, font, buffer, NULL, 0);
g_assert_true (ret);
hb_tag_t features[4];
unsigned int feature_count = sizeof (features) / sizeof (features[0]);
unsigned int count = hb_ot_shape_plan_get_feature_tags (shape_plan, 0, &feature_count, features);
g_assert_cmpuint (count, ==, 4);
g_assert_cmpuint (feature_count, ==, count);
g_assert_cmpint (features[0], ==, HB_TAG ('c', 'c', 'm', 'p'));
g_assert_cmpint (features[1], ==, HB_TAG ('m', 'a', 'r', 'k'));
g_assert_cmpint (features[2], ==, HB_TAG ('m', 'k', 'm', 'k'));
g_assert_cmpint (features[3], ==, HB_TAG ('v', 'e', 'r', 't'));
hb_buffer_destroy (buffer);
hb_shape_plan_destroy (shape_plan);
hb_font_destroy (font);
hb_face_destroy (face);
}
static void
test_ot_shape_plan_get_feature_tags_userfeatures_enable (void)
{
/* test getting features enabled with user features enabling a non-default feature */
hb_face_t *face = hb_test_open_font_file ("fonts/Mada-VF.ttf");
hb_font_t *font = hb_font_create (face);
hb_segment_properties_t props = HB_SEGMENT_PROPERTIES_DEFAULT;
props.script = HB_SCRIPT_LATIN;
props.direction = HB_DIRECTION_LTR;
hb_buffer_t *buffer = hb_buffer_create ();
hb_buffer_set_segment_properties (buffer, &props);
hb_buffer_add_utf8 (buffer, " ", -1, 0, -1);
hb_feature_t user_features[1] = {{HB_TAG ('s', 's', '0', '1'), 1, 0, 1}};
hb_shape_plan_t *shape_plan = hb_shape_plan_create (face, &props, user_features, 1, NULL);
hb_bool_t ret = hb_shape_plan_execute (shape_plan, font, buffer, user_features, 1);
g_assert_true (ret);
hb_tag_t features[7];
unsigned int feature_count = sizeof (features) / sizeof (features[0]);
unsigned int count = hb_ot_shape_plan_get_feature_tags (shape_plan, 0, &feature_count, features);
g_assert_cmpuint (count, ==, 7);
g_assert_cmpuint (feature_count, ==, count);
g_assert_cmpint (features[0], ==, HB_TAG ('c', 'c', 'm', 'p'));
g_assert_cmpint (features[1], ==, HB_TAG ('k', 'e', 'r', 'n'));
g_assert_cmpint (features[2], ==, HB_TAG ('m', 'a', 'r', 'k'));
g_assert_cmpint (features[3], ==, HB_TAG ('m', 'k', 'm', 'k'));
g_assert_cmpint (features[4], ==, HB_TAG ('r', 'c', 'l', 't'));
g_assert_cmpint (features[5], ==, HB_TAG ('r', 'l', 'i', 'g'));
g_assert_cmpint (features[6], ==, HB_TAG ('s', 's', '0', '1'));
hb_buffer_destroy (buffer);
hb_shape_plan_destroy (shape_plan);
hb_font_destroy (font);
hb_face_destroy (face);
}
static void
test_ot_shape_plan_get_feature_tags_userfeatures_disable (void)
{
/* test getting features enabled with user features disabling a default feature */
hb_face_t *face = hb_test_open_font_file ("fonts/Mada-VF.ttf");
hb_font_t *font = hb_font_create (face);
hb_segment_properties_t props = HB_SEGMENT_PROPERTIES_DEFAULT;
props.script = HB_SCRIPT_LATIN;
props.direction = HB_DIRECTION_LTR;
hb_buffer_t *buffer = hb_buffer_create ();
hb_buffer_set_segment_properties (buffer, &props);
hb_buffer_add_utf8 (buffer, " ", -1, 0, -1);
hb_feature_t user_features[1] = {{HB_TAG ('k', 'e', 'r', 'n'), 0, 0, HB_FEATURE_GLOBAL_END}};
hb_shape_plan_t *shape_plan = hb_shape_plan_create (face, &props, user_features, 1, NULL);
hb_bool_t ret = hb_shape_plan_execute (shape_plan, font, buffer, user_features, 1);
g_assert_true (ret);
hb_tag_t features[5];
unsigned int feature_count = sizeof (features) / sizeof (features[0]);
unsigned int count = hb_ot_shape_plan_get_feature_tags (shape_plan, 0, &feature_count, features);
g_assert_cmpuint (count, ==, 5);
g_assert_cmpuint (feature_count, ==, count);
g_assert_cmpint (features[0], ==, HB_TAG ('c', 'c', 'm', 'p'));
g_assert_cmpint (features[1], ==, HB_TAG ('m', 'a', 'r', 'k'));
g_assert_cmpint (features[2], ==, HB_TAG ('m', 'k', 'm', 'k'));
g_assert_cmpint (features[3], ==, HB_TAG ('r', 'c', 'l', 't'));
g_assert_cmpint (features[4], ==, HB_TAG ('r', 'l', 'i', 'g'));
hb_buffer_destroy (buffer);
hb_shape_plan_destroy (shape_plan);
hb_font_destroy (font);
hb_face_destroy (face);
}
static void
test_ot_shape_plan_get_feature_tags_userfeatures_disablepartial (void)
{
/* test getting features enabled with user features disabling a non-default
feature partially; the tag of the disabled feature will be returned since
it is still enabled partially.*/
hb_face_t *face = hb_test_open_font_file ("fonts/Mada-VF.ttf");
hb_font_t *font = hb_font_create (face);
hb_segment_properties_t props = HB_SEGMENT_PROPERTIES_DEFAULT;
props.script = HB_SCRIPT_LATIN;
props.direction = HB_DIRECTION_LTR;
hb_buffer_t *buffer = hb_buffer_create ();
hb_buffer_set_segment_properties (buffer, &props);
hb_buffer_add_utf8 (buffer, " ", -1, 0, -1);
hb_feature_t user_features[1] = {{HB_TAG ('k', 'e', 'r', 'n'), 0, 0, 1}};
hb_shape_plan_t *shape_plan = hb_shape_plan_create (face, &props, user_features, 1, NULL);
hb_bool_t ret = hb_shape_plan_execute (shape_plan, font, buffer, user_features, 1);
g_assert_true (ret);
hb_tag_t features[6];
unsigned int feature_count = sizeof (features) / sizeof (features[0]);
unsigned int count = hb_ot_shape_plan_get_feature_tags (shape_plan, 0, &feature_count, features);
g_assert_cmpuint (count, ==, 6);
g_assert_cmpuint (feature_count, ==, count);
g_assert_cmpint (features[0], ==, HB_TAG ('c', 'c', 'm', 'p'));
g_assert_cmpint (features[1], ==, HB_TAG ('k', 'e', 'r', 'n'));
g_assert_cmpint (features[2], ==, HB_TAG ('m', 'a', 'r', 'k'));
g_assert_cmpint (features[3], ==, HB_TAG ('m', 'k', 'm', 'k'));
g_assert_cmpint (features[4], ==, HB_TAG ('r', 'c', 'l', 't'));
g_assert_cmpint (features[5], ==, HB_TAG ('r', 'l', 'i', 'g'));
hb_buffer_destroy (buffer);
hb_shape_plan_destroy (shape_plan);
hb_font_destroy (font);
hb_face_destroy (face);
}
static void
test_ot_shape_plan_get_feature_tags_userfeatures_disablenondeafult (void)
{
/* test getting features enabled with user features disabling a non-default
feature; the tag of the disabled feature will be returned returned.*/
hb_face_t *face = hb_test_open_font_file ("fonts/Mada-VF.ttf");
hb_font_t *font = hb_font_create (face);
hb_segment_properties_t props = HB_SEGMENT_PROPERTIES_DEFAULT;
props.script = HB_SCRIPT_LATIN;
props.direction = HB_DIRECTION_LTR;
hb_buffer_t *buffer = hb_buffer_create ();
hb_buffer_set_segment_properties (buffer, &props);
hb_buffer_add_utf8 (buffer, " ", -1, 0, -1);
hb_feature_t user_features[1] = {{HB_TAG ('s', 's', '0', '1'), 0, 0, HB_FEATURE_GLOBAL_END}};
hb_shape_plan_t *shape_plan = hb_shape_plan_create (face, &props, user_features, 1, NULL);
hb_bool_t ret = hb_shape_plan_execute (shape_plan, font, buffer, user_features, 1);
g_assert_true (ret);
hb_tag_t features[6];
unsigned int feature_count = sizeof (features) / sizeof (features[0]);
unsigned int count = hb_ot_shape_plan_get_feature_tags (shape_plan, 0, &feature_count, features);
g_assert_cmpuint (count, ==, 6);
g_assert_cmpuint (feature_count, ==, count);
g_assert_cmpint (features[0], ==, HB_TAG ('c', 'c', 'm', 'p'));
g_assert_cmpint (features[1], ==, HB_TAG ('k', 'e', 'r', 'n'));
g_assert_cmpint (features[2], ==, HB_TAG ('m', 'a', 'r', 'k'));
g_assert_cmpint (features[3], ==, HB_TAG ('m', 'k', 'm', 'k'));
g_assert_cmpint (features[4], ==, HB_TAG ('r', 'c', 'l', 't'));
g_assert_cmpint (features[5], ==, HB_TAG ('r', 'l', 'i', 'g'));
hb_buffer_destroy (buffer);
hb_shape_plan_destroy (shape_plan);
hb_font_destroy (font);
hb_face_destroy (face);
}
int
main (int argc, char **argv)
{
hb_test_init (&argc, &argv);
hb_test_add (test_ot_shape_plan_get_feature_tags_rtl);
hb_test_add (test_ot_shape_plan_get_feature_tags_ltr);
hb_test_add (test_ot_shape_plan_get_feature_tags_ttb);
hb_test_add (test_ot_shape_plan_get_feature_tags_userfeatures_enable);
hb_test_add (test_ot_shape_plan_get_feature_tags_userfeatures_disable);
hb_test_add (test_ot_shape_plan_get_feature_tags_userfeatures_disablepartial);
hb_test_add (test_ot_shape_plan_get_feature_tags_userfeatures_disablenondeafult);
return hb_test_run();
}