Ignore:
File:
1 edited

Legend:

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

    r7470d97 r1eaead4  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    7575} testgc_bitmap_t;
    7676
     77/** Test box characters */
     78static ui_box_chars_t test_box_chars = {
     79        {
     80                { "A", "B", "C" },
     81                { "D", " ", "E" },
     82                { "F", "G", "H" }
     83        }
     84};
     85
    7786/** Paint bevel */
    7887PCUT_TEST(bevel)
     
    96105        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    97106
     107        rect.p0.x = 10;
     108        rect.p0.y = 20;
     109        rect.p1.x = 30;
     110        rect.p1.y = 40;
     111
    98112        /* Paint bevel with NULL 'inside' output parameter */
    99113        rc = ui_paint_bevel(gc, &rect, color1, color2, 2, NULL);
     
    110124}
    111125
     126/** Get bevel inside */
     127PCUT_TEST(get_bevel_inside)
     128{
     129        errno_t rc;
     130        gfx_context_t *gc = NULL;
     131        test_gc_t tgc;
     132        gfx_rect_t rect;
     133        gfx_rect_t inside;
     134
     135        memset(&tgc, 0, sizeof(tgc));
     136        rc = gfx_context_new(&ops, &tgc, &gc);
     137        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     138
     139        rect.p0.x = 10;
     140        rect.p0.y = 20;
     141        rect.p1.x = 30;
     142        rect.p1.y = 40;
     143
     144        ui_paint_get_bevel_inside(gc, &rect, 2, &inside);
     145        PCUT_ASSERT_INT_EQUALS(12, inside.p0.x);
     146        PCUT_ASSERT_INT_EQUALS(22, inside.p0.y);
     147        PCUT_ASSERT_INT_EQUALS(28, inside.p1.x);
     148        PCUT_ASSERT_INT_EQUALS(38, inside.p1.y);
     149
     150        rc = gfx_context_delete(gc);
     151        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     152}
     153
    112154/** Paint inset frame */
    113155PCUT_TEST(inset_frame)
     
    128170        PCUT_ASSERT_NOT_NULL(resource);
    129171
     172        rect.p0.x = 10;
     173        rect.p0.y = 20;
     174        rect.p1.x = 30;
     175        rect.p1.y = 40;
     176
    130177        /* Paint inset frame with NULL 'inside' output parameter */
    131178        rc = ui_paint_inset_frame(resource, &rect, NULL);
     
    141188}
    142189
     190/** Get inset frame inside */
     191PCUT_TEST(get_inset_frame_inside)
     192{
     193        errno_t rc;
     194        gfx_context_t *gc = NULL;
     195        ui_resource_t *resource = NULL;
     196        test_gc_t tgc;
     197        gfx_rect_t rect;
     198        gfx_rect_t inside;
     199
     200        memset(&tgc, 0, sizeof(tgc));
     201        rc = gfx_context_new(&ops, &tgc, &gc);
     202        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     203
     204        rc = ui_resource_create(gc, false, &resource);
     205        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     206        PCUT_ASSERT_NOT_NULL(resource);
     207
     208        rect.p0.x = 10;
     209        rect.p0.y = 20;
     210        rect.p1.x = 30;
     211        rect.p1.y = 40;
     212
     213        ui_paint_get_inset_frame_inside(resource, &rect, &inside);
     214        PCUT_ASSERT_INT_EQUALS(12, inside.p0.x);
     215        PCUT_ASSERT_INT_EQUALS(22, inside.p0.y);
     216        PCUT_ASSERT_INT_EQUALS(28, inside.p1.x);
     217        PCUT_ASSERT_INT_EQUALS(38, inside.p1.y);
     218
     219        ui_resource_destroy(resource);
     220        rc = gfx_context_delete(gc);
     221        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     222}
     223
    143224/** Paint filled circle */
    144225PCUT_TEST(filled_circle)
     
    153234        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    154235
     236        center.x = 0;
     237        center.y = 0;
     238
    155239        /* Paint filled circle / upper-left half */
    156240        rc = ui_paint_filled_circle(gc, &center, 10, ui_fcircle_upleft);
     
    165249        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    166250
     251        rc = gfx_context_delete(gc);
     252        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     253}
     254
     255/** Paint up pointing triangle */
     256PCUT_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 */
     278PCUT_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 */
     300PCUT_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 */
     322PCUT_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) */
     344PCUT_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 */
     366PCUT_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 */
     394PCUT_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 */
     422PCUT_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
     449/** Paint text box */
     450PCUT_TEST(text_box)
     451{
     452        errno_t rc;
     453        gfx_context_t *gc = NULL;
     454        ui_resource_t *resource = NULL;
     455        gfx_color_t *color = NULL;
     456        test_gc_t tgc;
     457        gfx_rect_t rect;
     458
     459        memset(&tgc, 0, sizeof(tgc));
     460        rc = gfx_context_new(&ops, &tgc, &gc);
     461        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     462
     463        rc = ui_resource_create(gc, false, &resource);
     464        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     465        PCUT_ASSERT_NOT_NULL(resource);
     466
     467        rc = gfx_color_new_rgb_i16(1, 2, 3, &color);
     468        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     469
     470        rect.p0.x = 10;
     471        rect.p0.y = 20;
     472        rect.p1.x = 30;
     473        rect.p1.y = 40;
     474
     475        /* Paint text box */
     476        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 */
     486PCUT_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);
     513        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     514
     515        gfx_color_delete(color);
     516        ui_resource_destroy(resource);
     517        rc = gfx_context_delete(gc);
     518        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     519}
     520
     521/** Paint text horizontal brace */
     522PCUT_TEST(text_hbrace)
     523{
     524        errno_t rc;
     525        gfx_context_t *gc = NULL;
     526        ui_resource_t *resource = NULL;
     527        gfx_color_t *color = NULL;
     528        test_gc_t tgc;
     529        gfx_rect_t rect;
     530
     531        memset(&tgc, 0, sizeof(tgc));
     532        rc = gfx_context_new(&ops, &tgc, &gc);
     533        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     534
     535        rc = ui_resource_create(gc, false, &resource);
     536        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     537        PCUT_ASSERT_NOT_NULL(resource);
     538
     539        rc = gfx_color_new_rgb_i16(1, 2, 3, &color);
     540        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     541
     542        rect.p0.x = 10;
     543        rect.p0.y = 20;
     544        rect.p1.x = 30;
     545        rect.p1.y = 40;
     546
     547        /* Paint text horizontal brace */
     548        rc = ui_paint_text_hbrace(resource, &rect, ui_box_single,
     549            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 */
     558PCUT_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);
     586
     587        gfx_color_delete(color);
     588        ui_resource_destroy(resource);
    167589        rc = gfx_context_delete(gc);
    168590        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
Note: See TracChangeset for help on using the changeset viewer.