Changeset c78a03d in mainline for uspace/lib/gfxfont/test
- Timestamp:
- 2020-07-21T22:48:59Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5592c56
- Parents:
- 703c743
- Location:
- uspace/lib/gfxfont/test
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/test/font.c
r703c743 rc78a03d 27 27 */ 28 28 29 #include <gfx/context.h> 29 30 #include <gfx/font.h> 30 31 #include <pcut/pcut.h> … … 34 35 PCUT_TEST_SUITE(font); 35 36 36 PCUT_TEST(dummy) 37 { 37 static errno_t testgc_set_color(void *, gfx_color_t *); 38 static errno_t testgc_fill_rect(void *, gfx_rect_t *); 39 40 static gfx_context_ops_t test_ops = { 41 .set_color = testgc_set_color, 42 .fill_rect = testgc_fill_rect 43 }; 44 45 /** Test creating and destroying font */ 46 PCUT_TEST(create_destroy) 47 { 48 gfx_font_metrics_t metrics; 49 gfx_font_t *font; 50 gfx_context_t *gc; 51 errno_t rc; 52 53 rc = gfx_context_new(&test_ops, NULL, &gc); 54 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 55 56 gfx_font_metrics_init(&metrics); 57 rc = gfx_font_create(gc, &metrics, &font); 58 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 59 60 gfx_font_destroy(font); 61 rc = gfx_context_delete(gc); 62 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 63 } 64 65 /** Test gfx_font_get_metrics() */ 66 PCUT_TEST(get_metrics) 67 { 68 gfx_font_metrics_t metrics; 69 gfx_font_metrics_t gmetrics; 70 gfx_font_t *font; 71 gfx_context_t *gc; 72 errno_t rc; 73 74 rc = gfx_context_new(&test_ops, NULL, &gc); 75 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 76 77 gfx_font_metrics_init(&metrics); 78 metrics.ascent = 1; 79 metrics.descent = 2; 80 metrics.leading = 3; 81 82 rc = gfx_font_create(gc, &metrics, &font); 83 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 84 85 gfx_font_get_metrics(font, &gmetrics); 86 PCUT_ASSERT_INT_EQUALS(metrics.ascent, gmetrics.ascent); 87 PCUT_ASSERT_INT_EQUALS(metrics.descent, gmetrics.descent); 88 PCUT_ASSERT_INT_EQUALS(metrics.leading, gmetrics.leading); 89 90 gfx_font_destroy(font); 91 rc = gfx_context_delete(gc); 92 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 93 } 94 95 /** Test gfx_font_set_metrics() */ 96 PCUT_TEST(set_metrics) 97 { 98 gfx_font_metrics_t metrics1; 99 gfx_font_metrics_t metrics2; 100 gfx_font_metrics_t gmetrics; 101 gfx_font_t *font; 102 gfx_context_t *gc; 103 errno_t rc; 104 105 rc = gfx_context_new(&test_ops, NULL, &gc); 106 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 107 108 gfx_font_metrics_init(&metrics1); 109 metrics1.ascent = 1; 110 metrics1.descent = 2; 111 metrics1.leading = 3; 112 113 rc = gfx_font_create(gc, &metrics1, &font); 114 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 115 116 gfx_font_metrics_init(&metrics2); 117 metrics1.ascent = 4; 118 metrics1.descent = 5; 119 metrics1.leading = 6; 120 121 rc = gfx_font_set_metrics(font, &metrics2); 122 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 123 124 gfx_font_get_metrics(font, &gmetrics); 125 PCUT_ASSERT_INT_EQUALS(metrics2.ascent, gmetrics.ascent); 126 PCUT_ASSERT_INT_EQUALS(metrics2.descent, gmetrics.descent); 127 PCUT_ASSERT_INT_EQUALS(metrics2.leading, gmetrics.leading); 128 129 gfx_font_destroy(font); 130 rc = gfx_context_delete(gc); 131 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 132 } 133 134 /** Test gfx_font_first_glyph() */ 135 PCUT_TEST(first_glyph) 136 { 137 gfx_font_metrics_t metrics; 138 gfx_font_t *font; 139 gfx_context_t *gc; 140 gfx_glyph_t *glyph; 141 errno_t rc; 142 143 rc = gfx_context_new(&test_ops, NULL, &gc); 144 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 145 146 gfx_font_metrics_init(&metrics); 147 148 rc = gfx_font_create(gc, &metrics, &font); 149 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 150 151 glyph = gfx_font_first_glyph(font); 152 PCUT_ASSERT_NULL(glyph); 153 154 gfx_font_destroy(font); 155 rc = gfx_context_delete(gc); 156 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 157 } 158 159 /** Test gfx_font_next_glyph() */ 160 PCUT_TEST(next_glyph) 161 { 162 /* TODO */ 163 } 164 165 /** Test gfx_font_search_glyph() */ 166 PCUT_TEST(search_glyph) 167 { 168 gfx_font_metrics_t metrics; 169 gfx_font_t *font; 170 gfx_context_t *gc; 171 gfx_glyph_t *glyph; 172 size_t bytes; 173 errno_t rc; 174 175 rc = gfx_context_new(&test_ops, NULL, &gc); 176 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 177 178 gfx_font_metrics_init(&metrics); 179 180 rc = gfx_font_create(gc, &metrics, &font); 181 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 182 183 rc = gfx_font_search_glyph(font, "Hello", &glyph, &bytes); 184 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc); 185 186 gfx_font_destroy(font); 187 rc = gfx_context_delete(gc); 188 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 189 } 190 191 static errno_t testgc_set_color(void *arg, gfx_color_t *color) 192 { 193 return EOK; 194 } 195 196 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect) 197 { 198 return EOK; 38 199 } 39 200 -
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 -
uspace/lib/gfxfont/test/glyph_bmp.c
r703c743 rc78a03d 27 27 */ 28 28 29 #include <gfx/context.h> 30 #include <gfx/font.h> 29 31 #include <gfx/glyph.h> 32 #include <gfx/glyph_bmp.h> 30 33 #include <pcut/pcut.h> 31 34 … … 34 37 PCUT_TEST_SUITE(glyph_bmp); 35 38 36 PCUT_TEST(dummy) 37 { 39 static errno_t testgc_set_color(void *, gfx_color_t *); 40 static errno_t testgc_fill_rect(void *, gfx_rect_t *); 41 42 static gfx_context_ops_t test_ops = { 43 .set_color = testgc_set_color, 44 .fill_rect = testgc_fill_rect 45 }; 46 47 /** Test opening and closing glyph bitmap */ 48 PCUT_TEST(open_close) 49 { 50 gfx_font_metrics_t fmetrics; 51 gfx_font_t *font; 52 gfx_glyph_metrics_t gmetrics; 53 gfx_glyph_t *glyph; 54 gfx_context_t *gc; 55 gfx_glyph_bmp_t *bmp; 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 gmetrics.advance = 1; 67 68 rc = gfx_glyph_create(font, &gmetrics, &glyph); 69 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 70 71 bmp = NULL; 72 73 rc = gfx_glyph_bmp_open(glyph, &bmp); 74 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 75 PCUT_ASSERT_NOT_NULL(bmp); 76 77 gfx_glyph_bmp_close(bmp); 78 79 gfx_glyph_destroy(glyph); 80 81 gfx_font_destroy(font); 82 rc = gfx_context_delete(gc); 83 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 84 } 85 86 /** Test glyph_bmp_save() */ 87 PCUT_TEST(save) 88 { 89 gfx_font_metrics_t fmetrics; 90 gfx_font_t *font; 91 gfx_glyph_metrics_t gmetrics; 92 gfx_glyph_t *glyph; 93 gfx_context_t *gc; 94 gfx_glyph_bmp_t *bmp; 95 errno_t rc; 96 97 rc = gfx_context_new(&test_ops, NULL, &gc); 98 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 99 100 gfx_font_metrics_init(&fmetrics); 101 rc = gfx_font_create(gc, &fmetrics, &font); 102 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 103 104 gfx_glyph_metrics_init(&gmetrics); 105 gmetrics.advance = 1; 106 107 rc = gfx_glyph_create(font, &gmetrics, &glyph); 108 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 109 110 bmp = NULL; 111 112 rc = gfx_glyph_bmp_open(glyph, &bmp); 113 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 114 PCUT_ASSERT_NOT_NULL(bmp); 115 116 /* TODO: Need a test to verify that save actually worked */ 117 rc = gfx_glyph_bmp_save(bmp); 118 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 119 120 gfx_glyph_bmp_close(bmp); 121 122 gfx_glyph_destroy(glyph); 123 124 gfx_font_destroy(font); 125 rc = gfx_context_delete(gc); 126 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 127 } 128 129 /** Test glyph_bmp_getpix() */ 130 PCUT_TEST(getpix) 131 { 132 gfx_font_metrics_t fmetrics; 133 gfx_font_t *font; 134 gfx_glyph_metrics_t gmetrics; 135 gfx_glyph_t *glyph; 136 gfx_context_t *gc; 137 gfx_glyph_bmp_t *bmp; 138 int pix; 139 errno_t rc; 140 141 rc = gfx_context_new(&test_ops, NULL, &gc); 142 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 143 144 gfx_font_metrics_init(&fmetrics); 145 rc = gfx_font_create(gc, &fmetrics, &font); 146 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 147 148 gfx_glyph_metrics_init(&gmetrics); 149 gmetrics.advance = 1; 150 151 rc = gfx_glyph_create(font, &gmetrics, &glyph); 152 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 153 154 bmp = NULL; 155 156 rc = gfx_glyph_bmp_open(glyph, &bmp); 157 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 158 PCUT_ASSERT_NOT_NULL(bmp); 159 160 pix = gfx_glyph_bmp_getpix(bmp, 0, 0); 161 PCUT_ASSERT_INT_EQUALS(0, pix); 162 163 gfx_glyph_bmp_close(bmp); 164 165 gfx_glyph_destroy(glyph); 166 167 gfx_font_destroy(font); 168 rc = gfx_context_delete(gc); 169 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 170 } 171 172 /** Test glyph_bmp_setpix() can flip pixel value both ways */ 173 PCUT_TEST(setpix_flip) 174 { 175 gfx_font_metrics_t fmetrics; 176 gfx_font_t *font; 177 gfx_glyph_metrics_t gmetrics; 178 gfx_glyph_t *glyph; 179 gfx_context_t *gc; 180 gfx_glyph_bmp_t *bmp; 181 int pix; 182 errno_t rc; 183 184 rc = gfx_context_new(&test_ops, NULL, &gc); 185 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 186 187 gfx_font_metrics_init(&fmetrics); 188 rc = gfx_font_create(gc, &fmetrics, &font); 189 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 190 191 gfx_glyph_metrics_init(&gmetrics); 192 gmetrics.advance = 1; 193 194 rc = gfx_glyph_create(font, &gmetrics, &glyph); 195 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 196 197 bmp = NULL; 198 199 rc = gfx_glyph_bmp_open(glyph, &bmp); 200 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 201 PCUT_ASSERT_NOT_NULL(bmp); 202 203 pix = gfx_glyph_bmp_getpix(bmp, 0, 0); 204 PCUT_ASSERT_INT_EQUALS(0, pix); 205 206 rc = gfx_glyph_bmp_setpix(bmp, 0, 0, 1); 207 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 208 209 pix = gfx_glyph_bmp_getpix(bmp, 0, 0); 210 PCUT_ASSERT_INT_EQUALS(1, pix); 211 212 rc = gfx_glyph_bmp_setpix(bmp, 0, 0, 0); 213 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 214 215 pix = gfx_glyph_bmp_getpix(bmp, 0, 0); 216 PCUT_ASSERT_INT_EQUALS(0, pix); 217 218 gfx_glyph_bmp_close(bmp); 219 220 gfx_glyph_destroy(glyph); 221 222 gfx_font_destroy(font); 223 rc = gfx_context_delete(gc); 224 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 225 } 226 227 /** Test glyph_bmp_setpix() properly extends pixel array */ 228 PCUT_TEST(setpix_externd) 229 { 230 gfx_font_metrics_t fmetrics; 231 gfx_font_t *font; 232 gfx_glyph_metrics_t gmetrics; 233 gfx_glyph_t *glyph; 234 gfx_context_t *gc; 235 gfx_glyph_bmp_t *bmp; 236 gfx_coord_t x, y; 237 int pix; 238 errno_t rc; 239 240 rc = gfx_context_new(&test_ops, NULL, &gc); 241 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 242 243 gfx_font_metrics_init(&fmetrics); 244 rc = gfx_font_create(gc, &fmetrics, &font); 245 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 246 247 gfx_glyph_metrics_init(&gmetrics); 248 gmetrics.advance = 1; 249 250 rc = gfx_glyph_create(font, &gmetrics, &glyph); 251 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 252 253 bmp = NULL; 254 255 rc = gfx_glyph_bmp_open(glyph, &bmp); 256 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 257 PCUT_ASSERT_NOT_NULL(bmp); 258 259 /* 260 * Fill the rectangle [0, 0]..[3, 3] with alternating pixel pattern 261 * and then check it. 262 */ 263 264 rc = gfx_glyph_bmp_setpix(bmp, 0, 0, 1); 265 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 266 267 rc = gfx_glyph_bmp_setpix(bmp, 1, 1, 1); 268 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 269 270 rc = gfx_glyph_bmp_setpix(bmp, 2, 0, 1); 271 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 272 273 rc = gfx_glyph_bmp_setpix(bmp, 0, 2, 1); 274 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 275 276 rc = gfx_glyph_bmp_setpix(bmp, 2, 2, 1); 277 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 278 279 for (y = 0; y <= 2; y++) { 280 for (x = 0; x <= 2; x++) { 281 pix = gfx_glyph_bmp_getpix(bmp, x, y); 282 PCUT_ASSERT_INT_EQUALS((x & 1) ^ (y & 1) ^ 1, pix); 283 } 284 } 285 286 gfx_glyph_bmp_close(bmp); 287 288 gfx_glyph_destroy(glyph); 289 290 gfx_font_destroy(font); 291 rc = gfx_context_delete(gc); 292 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 293 } 294 295 static errno_t testgc_set_color(void *arg, gfx_color_t *color) 296 { 297 return EOK; 298 } 299 300 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect) 301 { 302 return EOK; 38 303 } 39 304
Note:
See TracChangeset
for help on using the changeset viewer.
