Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/test/paint.c

    r1eaead4 r81ec7e1  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    7575} testgc_bitmap_t;
    7676
    77 /** Test box characters */
    78 static ui_box_chars_t test_box_chars = {
    79         {
    80                 { "A", "B", "C" },
    81                 { "D", " ", "E" },
    82                 { "F", "G", "H" }
    83         }
    84 };
    85 
    8677/** Paint bevel */
    8778PCUT_TEST(bevel)
     
    234225        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    235226
    236         center.x = 0;
    237         center.y = 0;
    238 
    239227        /* Paint filled circle / upper-left half */
    240228        rc = ui_paint_filled_circle(gc, &center, 10, ui_fcircle_upleft);
     
    253241}
    254242
    255 /** Paint up pointing triangle */
    256 PCUT_TEST(up_triangle)
    257 {
    258         errno_t rc;
    259         gfx_context_t *gc = NULL;
    260         test_gc_t tgc;
    261         gfx_coord2_t center;
    262 
    263         memset(&tgc, 0, sizeof(tgc));
    264         rc = gfx_context_new(&ops, &tgc, &gc);
    265         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    266 
    267         center.x = 0;
    268         center.y = 0;
    269 
    270         rc = ui_paint_up_triangle(gc, &center, 5);
    271         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    272 
    273         rc = gfx_context_delete(gc);
    274         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    275 }
    276 
    277 /** Paint down pointing triangle */
    278 PCUT_TEST(down_triangle)
    279 {
    280         errno_t rc;
    281         gfx_context_t *gc = NULL;
    282         test_gc_t tgc;
    283         gfx_coord2_t center;
    284 
    285         memset(&tgc, 0, sizeof(tgc));
    286         rc = gfx_context_new(&ops, &tgc, &gc);
    287         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    288 
    289         center.x = 0;
    290         center.y = 0;
    291 
    292         rc = ui_paint_down_triangle(gc, &center, 5);
    293         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    294 
    295         rc = gfx_context_delete(gc);
    296         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    297 }
    298 
    299 /** Paint left pointing triangle */
    300 PCUT_TEST(left_triangle)
    301 {
    302         errno_t rc;
    303         gfx_context_t *gc = NULL;
    304         test_gc_t tgc;
    305         gfx_coord2_t center;
    306 
    307         memset(&tgc, 0, sizeof(tgc));
    308         rc = gfx_context_new(&ops, &tgc, &gc);
    309         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    310 
    311         center.x = 0;
    312         center.y = 0;
    313 
    314         rc = ui_paint_left_triangle(gc, &center, 5);
    315         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    316 
    317         rc = gfx_context_delete(gc);
    318         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    319 }
    320 
    321 /** Paint right pointing triangle */
    322 PCUT_TEST(right_triangle)
    323 {
    324         errno_t rc;
    325         gfx_context_t *gc = NULL;
    326         test_gc_t tgc;
    327         gfx_coord2_t center;
    328 
    329         memset(&tgc, 0, sizeof(tgc));
    330         rc = gfx_context_new(&ops, &tgc, &gc);
    331         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    332 
    333         center.x = 0;
    334         center.y = 0;
    335 
    336         rc = ui_paint_right_triangle(gc, &center, 5);
    337         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    338 
    339         rc = gfx_context_delete(gc);
    340         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    341 }
    342 
    343 /** Paint diagonal cross (X) */
    344 PCUT_TEST(cross)
    345 {
    346         errno_t rc;
    347         gfx_context_t *gc = NULL;
    348         test_gc_t tgc;
    349         gfx_coord2_t center;
    350 
    351         memset(&tgc, 0, sizeof(tgc));
    352         rc = gfx_context_new(&ops, &tgc, &gc);
    353         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    354 
    355         center.x = 0;
    356         center.y = 0;
    357 
    358         rc = ui_paint_cross(gc, &center, 5, 1, 2);
    359         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    360 
    361         rc = gfx_context_delete(gc);
    362         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    363 }
    364 
    365 /** Paint mimimize icon */
    366 PCUT_TEST(minicon)
    367 {
    368         errno_t rc;
    369         gfx_context_t *gc = NULL;
    370         ui_resource_t *resource = NULL;
    371         test_gc_t tgc;
    372         gfx_coord2_t center;
    373 
    374         memset(&tgc, 0, sizeof(tgc));
    375         rc = gfx_context_new(&ops, &tgc, &gc);
    376         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    377 
    378         rc = ui_resource_create(gc, false, &resource);
    379         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    380         PCUT_ASSERT_NOT_NULL(resource);
    381 
    382         center.x = 0;
    383         center.y = 0;
    384 
    385         rc = ui_paint_minicon(resource, &center, 8, 6);
    386         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    387 
    388         ui_resource_destroy(resource);
    389         rc = gfx_context_delete(gc);
    390         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    391 }
    392 
    393 /** Paint maximize icon */
    394 PCUT_TEST(maxicon)
    395 {
    396         errno_t rc;
    397         gfx_context_t *gc = NULL;
    398         ui_resource_t *resource = NULL;
    399         test_gc_t tgc;
    400         gfx_coord2_t center;
    401 
    402         memset(&tgc, 0, sizeof(tgc));
    403         rc = gfx_context_new(&ops, &tgc, &gc);
    404         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    405 
    406         rc = ui_resource_create(gc, false, &resource);
    407         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    408         PCUT_ASSERT_NOT_NULL(resource);
    409 
    410         center.x = 0;
    411         center.y = 0;
    412 
    413         rc = ui_paint_maxicon(resource, &center, 8, 6);
    414         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    415 
    416         ui_resource_destroy(resource);
    417         rc = gfx_context_delete(gc);
    418         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    419 }
    420 
    421 /** Paint unmaximize icon */
    422 PCUT_TEST(unmaxicon)
    423 {
    424         errno_t rc;
    425         gfx_context_t *gc = NULL;
    426         ui_resource_t *resource = NULL;
    427         test_gc_t tgc;
    428         gfx_coord2_t center;
    429 
    430         memset(&tgc, 0, sizeof(tgc));
    431         rc = gfx_context_new(&ops, &tgc, &gc);
    432         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    433 
    434         rc = ui_resource_create(gc, false, &resource);
    435         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    436         PCUT_ASSERT_NOT_NULL(resource);
    437 
    438         center.x = 0;
    439         center.y = 0;
    440 
    441         rc = ui_paint_unmaxicon(resource, &center, 8, 8, 3, 3);
    442         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    443 
    444         ui_resource_destroy(resource);
    445         rc = gfx_context_delete(gc);
    446         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    447 }
    448 
    449243/** Paint text box */
    450244PCUT_TEST(text_box)
     
    475269        /* Paint text box */
    476270        rc = ui_paint_text_box(resource, &rect, ui_box_single, color);
    477         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    478 
    479         gfx_color_delete(color);
    480         ui_resource_destroy(resource);
    481         rc = gfx_context_delete(gc);
    482         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    483 }
    484 
    485 /** Paint custom text box */
    486 PCUT_TEST(text_box_custom)
    487 {
    488         errno_t rc;
    489         gfx_context_t *gc = NULL;
    490         ui_resource_t *resource = NULL;
    491         gfx_color_t *color = NULL;
    492         test_gc_t tgc;
    493         gfx_rect_t rect;
    494 
    495         memset(&tgc, 0, sizeof(tgc));
    496         rc = gfx_context_new(&ops, &tgc, &gc);
    497         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    498 
    499         rc = ui_resource_create(gc, false, &resource);
    500         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    501         PCUT_ASSERT_NOT_NULL(resource);
    502 
    503         rc = gfx_color_new_rgb_i16(1, 2, 3, &color);
    504         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    505 
    506         rect.p0.x = 10;
    507         rect.p0.y = 20;
    508         rect.p1.x = 30;
    509         rect.p1.y = 40;
    510 
    511         /* Paint text box */
    512         rc = ui_paint_text_box_custom(resource, &rect, &test_box_chars, color);
    513271        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    514272
     
    548306        rc = ui_paint_text_hbrace(resource, &rect, ui_box_single,
    549307            color);
    550 
    551         gfx_color_delete(color);
    552         ui_resource_destroy(resource);
    553         rc = gfx_context_delete(gc);
    554         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    555 }
    556 
    557 /** Paint text rectangle */
    558 PCUT_TEST(text_rect)
    559 {
    560         errno_t rc;
    561         gfx_context_t *gc = NULL;
    562         ui_resource_t *resource = NULL;
    563         gfx_color_t *color = NULL;
    564         test_gc_t tgc;
    565         gfx_rect_t rect;
    566 
    567         memset(&tgc, 0, sizeof(tgc));
    568         rc = gfx_context_new(&ops, &tgc, &gc);
    569         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    570 
    571         rc = ui_resource_create(gc, false, &resource);
    572         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    573         PCUT_ASSERT_NOT_NULL(resource);
    574 
    575         rc = gfx_color_new_rgb_i16(1, 2, 3, &color);
    576         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    577 
    578         rect.p0.x = 10;
    579         rect.p0.y = 20;
    580         rect.p1.x = 30;
    581         rect.p1.y = 40;
    582 
    583         /* Paint text box */
    584         rc = ui_paint_text_rect(resource, &rect, color, "A");
    585         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    586308
    587309        gfx_color_delete(color);
Note: See TracChangeset for help on using the changeset viewer.