Changeset c78a03d in mainline for uspace/lib/gfxfont/test/glyph.c
- Timestamp:
- 2020-07-21T22:48:59Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5592c56
- Parents:
- 703c743
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/test/glyph.c
r703c743 rc78a03d 27 27 */ 28 28 29 #include <gfx/context.h> 30 #include <gfx/font.h> 29 31 #include <gfx/glyph.h> 30 32 #include <pcut/pcut.h> 33 #include <stdbool.h> 34 #include <str.h> 31 35 32 36 PCUT_INIT; … … 34 38 PCUT_TEST_SUITE(glyph); 35 39 36 PCUT_TEST(dummy) 37 { 40 static errno_t testgc_set_color(void *, gfx_color_t *); 41 static errno_t testgc_fill_rect(void *, gfx_rect_t *); 42 43 static gfx_context_ops_t test_ops = { 44 .set_color = testgc_set_color, 45 .fill_rect = testgc_fill_rect 46 }; 47 48 /** Test creating and destroying glyph */ 49 PCUT_TEST(create_destroy) 50 { 51 gfx_font_metrics_t fmetrics; 52 gfx_font_t *font; 53 gfx_glyph_metrics_t gmetrics; 54 gfx_glyph_t *glyph; 55 gfx_context_t *gc; 56 errno_t rc; 57 58 rc = gfx_context_new(&test_ops, NULL, &gc); 59 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 60 61 gfx_font_metrics_init(&fmetrics); 62 rc = gfx_font_create(gc, &fmetrics, &font); 63 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 64 65 gfx_glyph_metrics_init(&gmetrics); 66 rc = gfx_glyph_create(font, &gmetrics, &glyph); 67 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 68 69 gfx_glyph_destroy(glyph); 70 71 gfx_font_destroy(font); 72 rc = gfx_context_delete(gc); 73 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 74 } 75 76 /** Test gfx_glyph_get_metrics() */ 77 PCUT_TEST(get_metrics) 78 { 79 gfx_font_metrics_t fmetrics; 80 gfx_font_t *font; 81 gfx_glyph_metrics_t gmetrics; 82 gfx_glyph_t *glyph; 83 gfx_glyph_metrics_t rmetrics; 84 gfx_context_t *gc; 85 errno_t rc; 86 87 rc = gfx_context_new(&test_ops, NULL, &gc); 88 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 89 90 gfx_font_metrics_init(&fmetrics); 91 rc = gfx_font_create(gc, &fmetrics, &font); 92 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 93 94 gfx_glyph_metrics_init(&gmetrics); 95 gmetrics.advance = 42; 96 97 rc = gfx_glyph_create(font, &gmetrics, &glyph); 98 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 99 100 gfx_glyph_get_metrics(glyph, &rmetrics); 101 PCUT_ASSERT_INT_EQUALS(gmetrics.advance, rmetrics.advance); 102 103 gfx_glyph_destroy(glyph); 104 105 gfx_font_destroy(font); 106 rc = gfx_context_delete(gc); 107 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 108 } 109 110 /** Test gfx_glyph_set_metrics() */ 111 PCUT_TEST(set_metrics) 112 { 113 gfx_font_metrics_t fmetrics; 114 gfx_font_t *font; 115 gfx_glyph_metrics_t gmetrics1; 116 gfx_glyph_metrics_t gmetrics2; 117 gfx_glyph_t *glyph; 118 gfx_glyph_metrics_t rmetrics; 119 gfx_context_t *gc; 120 errno_t rc; 121 122 rc = gfx_context_new(&test_ops, NULL, &gc); 123 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 124 125 gfx_font_metrics_init(&fmetrics); 126 rc = gfx_font_create(gc, &fmetrics, &font); 127 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 128 129 gfx_glyph_metrics_init(&gmetrics1); 130 gmetrics1.advance = 1; 131 132 rc = gfx_glyph_create(font, &gmetrics1, &glyph); 133 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 134 135 gfx_glyph_metrics_init(&gmetrics2); 136 gmetrics2.advance = 2; 137 138 gfx_glyph_set_metrics(glyph, &gmetrics2); 139 140 gfx_glyph_get_metrics(glyph, &rmetrics); 141 PCUT_ASSERT_INT_EQUALS(gmetrics2.advance, rmetrics.advance); 142 143 gfx_glyph_destroy(glyph); 144 145 gfx_font_destroy(font); 146 rc = gfx_context_delete(gc); 147 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 148 } 149 150 /** Test gfx_glyph_set_pattern() */ 151 PCUT_TEST(set_pattern) 152 { 153 gfx_font_metrics_t fmetrics; 154 gfx_font_t *font; 155 gfx_glyph_metrics_t gmetrics; 156 gfx_glyph_t *glyph; 157 gfx_context_t *gc; 158 errno_t rc; 159 160 rc = gfx_context_new(&test_ops, NULL, &gc); 161 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 162 163 gfx_font_metrics_init(&fmetrics); 164 rc = gfx_font_create(gc, &fmetrics, &font); 165 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 166 167 gfx_glyph_metrics_init(&gmetrics); 168 gmetrics.advance = 1; 169 170 rc = gfx_glyph_create(font, &gmetrics, &glyph); 171 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 172 173 PCUT_ASSERT_NULL(gfx_glyph_first_pattern(glyph)); 174 175 /* Set a pattern */ 176 rc = gfx_glyph_set_pattern(glyph, "A"); 177 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 178 PCUT_ASSERT_NOT_NULL(gfx_glyph_first_pattern(glyph)); 179 180 /* Setting the same pattern again should be OK */ 181 rc = gfx_glyph_set_pattern(glyph, "A"); 182 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 183 PCUT_ASSERT_NOT_NULL(gfx_glyph_first_pattern(glyph)); 184 185 gfx_glyph_destroy(glyph); 186 187 gfx_font_destroy(font); 188 rc = gfx_context_delete(gc); 189 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 190 } 191 192 /** Test gfx_glyph_clear_pattern() */ 193 PCUT_TEST(clear_pattern) 194 { 195 gfx_font_metrics_t fmetrics; 196 gfx_font_t *font; 197 gfx_glyph_metrics_t gmetrics; 198 gfx_glyph_t *glyph; 199 gfx_context_t *gc; 200 errno_t rc; 201 202 rc = gfx_context_new(&test_ops, NULL, &gc); 203 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 204 205 gfx_font_metrics_init(&fmetrics); 206 rc = gfx_font_create(gc, &fmetrics, &font); 207 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 208 209 gfx_glyph_metrics_init(&gmetrics); 210 gmetrics.advance = 1; 211 212 rc = gfx_glyph_create(font, &gmetrics, &glyph); 213 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 214 215 PCUT_ASSERT_NULL(gfx_glyph_first_pattern(glyph)); 216 217 /* Set a pattern */ 218 rc = gfx_glyph_set_pattern(glyph, "A"); 219 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 220 PCUT_ASSERT_NOT_NULL(gfx_glyph_first_pattern(glyph)); 221 222 /* Now clear a different pattern - should be OK */ 223 gfx_glyph_clear_pattern(glyph, "AA"); 224 PCUT_ASSERT_NOT_NULL(gfx_glyph_first_pattern(glyph)); 225 226 /* Now clear the pattern which has been set */ 227 gfx_glyph_clear_pattern(glyph, "A"); 228 PCUT_ASSERT_NULL(gfx_glyph_first_pattern(glyph)); 229 230 gfx_glyph_destroy(glyph); 231 232 gfx_font_destroy(font); 233 rc = gfx_context_delete(gc); 234 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 235 } 236 237 /** Test gfx_glyph_matches() */ 238 PCUT_TEST(matches) 239 { 240 gfx_font_metrics_t fmetrics; 241 gfx_font_t *font; 242 gfx_glyph_metrics_t gmetrics; 243 gfx_glyph_t *glyph; 244 gfx_context_t *gc; 245 bool match; 246 size_t msize; 247 errno_t rc; 248 249 rc = gfx_context_new(&test_ops, NULL, &gc); 250 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 251 252 gfx_font_metrics_init(&fmetrics); 253 rc = gfx_font_create(gc, &fmetrics, &font); 254 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 255 256 gfx_glyph_metrics_init(&gmetrics); 257 gmetrics.advance = 1; 258 259 rc = gfx_glyph_create(font, &gmetrics, &glyph); 260 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 261 262 PCUT_ASSERT_NULL(gfx_glyph_first_pattern(glyph)); 263 264 /* Set a pattern */ 265 rc = gfx_glyph_set_pattern(glyph, "AB"); 266 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 267 PCUT_ASSERT_NOT_NULL(gfx_glyph_first_pattern(glyph)); 268 269 match = gfx_glyph_matches(glyph, "A", &msize); 270 PCUT_ASSERT_FALSE(match); 271 272 match = gfx_glyph_matches(glyph, "AB", &msize); 273 PCUT_ASSERT_TRUE(match); 274 PCUT_ASSERT_INT_EQUALS(2, msize); 275 276 match = gfx_glyph_matches(glyph, "ABC", &msize); 277 PCUT_ASSERT_TRUE(match); 278 PCUT_ASSERT_INT_EQUALS(2, msize); 279 280 match = gfx_glyph_matches(glyph, "BAB", &msize); 281 PCUT_ASSERT_FALSE(match); 282 283 gfx_glyph_destroy(glyph); 284 285 gfx_font_destroy(font); 286 rc = gfx_context_delete(gc); 287 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 288 } 289 290 /** Test gfx_glyph_first_pattern(), gfx_glyph_next_pattern() */ 291 PCUT_TEST(first_next_pattern) 292 { 293 gfx_font_metrics_t fmetrics; 294 gfx_font_t *font; 295 gfx_glyph_metrics_t gmetrics; 296 gfx_glyph_t *glyph; 297 gfx_context_t *gc; 298 gfx_glyph_pattern_t *pat; 299 errno_t rc; 300 301 rc = gfx_context_new(&test_ops, NULL, &gc); 302 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 303 304 gfx_font_metrics_init(&fmetrics); 305 rc = gfx_font_create(gc, &fmetrics, &font); 306 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 307 308 gfx_glyph_metrics_init(&gmetrics); 309 gmetrics.advance = 1; 310 311 rc = gfx_glyph_create(font, &gmetrics, &glyph); 312 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 313 314 PCUT_ASSERT_NULL(gfx_glyph_first_pattern(glyph)); 315 316 /* Set a pattern */ 317 rc = gfx_glyph_set_pattern(glyph, "A"); 318 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 319 PCUT_ASSERT_NOT_NULL(gfx_glyph_first_pattern(glyph)); 320 321 pat = gfx_glyph_first_pattern(glyph); 322 PCUT_ASSERT_NOT_NULL(pat); 323 324 pat = gfx_glyph_next_pattern(pat); 325 PCUT_ASSERT_NULL(pat); 326 327 gfx_glyph_destroy(glyph); 328 329 gfx_font_destroy(font); 330 rc = gfx_context_delete(gc); 331 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 332 } 333 334 /** Test gfx_glyph_pattern_str() */ 335 PCUT_TEST(pattern_str) 336 { 337 gfx_font_metrics_t fmetrics; 338 gfx_font_t *font; 339 gfx_glyph_metrics_t gmetrics; 340 gfx_glyph_t *glyph; 341 gfx_context_t *gc; 342 gfx_glyph_pattern_t *pat; 343 const char *pstr; 344 errno_t rc; 345 346 rc = gfx_context_new(&test_ops, NULL, &gc); 347 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 348 349 gfx_font_metrics_init(&fmetrics); 350 rc = gfx_font_create(gc, &fmetrics, &font); 351 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 352 353 gfx_glyph_metrics_init(&gmetrics); 354 gmetrics.advance = 1; 355 356 rc = gfx_glyph_create(font, &gmetrics, &glyph); 357 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 358 359 PCUT_ASSERT_NULL(gfx_glyph_first_pattern(glyph)); 360 361 /* Set a pattern */ 362 rc = gfx_glyph_set_pattern(glyph, "A"); 363 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 364 PCUT_ASSERT_NOT_NULL(gfx_glyph_first_pattern(glyph)); 365 366 pat = gfx_glyph_first_pattern(glyph); 367 PCUT_ASSERT_NOT_NULL(pat); 368 369 pstr = gfx_glyph_pattern_str(pat); 370 PCUT_ASSERT_INT_EQUALS(0, str_cmp("A", pstr)); 371 372 gfx_glyph_destroy(glyph); 373 374 gfx_font_destroy(font); 375 rc = gfx_context_delete(gc); 376 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 377 } 378 379 static errno_t testgc_set_color(void *arg, gfx_color_t *color) 380 { 381 return EOK; 382 } 383 384 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect) 385 { 386 return EOK; 38 387 } 39 388
Note:
See TracChangeset
for help on using the changeset viewer.