Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/test/display.c

    rb3eeae5 r195b7b3  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2019 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3232#include <str.h>
    3333
    34 #include "../cfgclient.h"
    3534#include "../client.h"
    3635#include "../display.h"
    37 #include "../idevcfg.h"
    3836#include "../seat.h"
    3937#include "../window.h"
    40 #include "../wmclient.h"
    4138
    4239PCUT_INIT;
     
    5047};
    5148
    52 static void test_ds_wmev_pending(void *);
    53 
    54 static ds_wmclient_cb_t test_ds_wmclient_cb = {
    55         .ev_pending = test_ds_wmev_pending
    56 };
    57 
    58 static void test_ds_cfgev_pending(void *);
    59 
    60 static ds_cfgclient_cb_t test_ds_cfgclient_cb = {
    61         .ev_pending = test_ds_cfgev_pending
    62 };
    63 
    6449static void test_ds_ev_pending(void *arg)
    6550{
     
    6853}
    6954
    70 static void test_ds_wmev_pending(void *arg)
    71 {
    72         bool *called_cb = (bool *) arg;
    73         *called_cb = true;
    74 }
    75 
    76 static void test_ds_cfgev_pending(void *arg)
    77 {
    78         bool *called_cb = (bool *) arg;
    79         *called_cb = true;
    80 }
    81 
    8255/** Display creation and destruction. */
    8356PCUT_TEST(display_create_destroy)
     
    11689}
    11790
    118 /** Basic WM client operation. */
    119 PCUT_TEST(display_wmclient)
    120 {
    121         ds_display_t *disp;
    122         ds_wmclient_t *wmclient;
    123         ds_wmclient_t *c0, *c1;
    124         errno_t rc;
    125 
    126         rc = ds_display_create(NULL, df_none, &disp);
    127         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    128 
    129         rc = ds_wmclient_create(disp, &test_ds_wmclient_cb, NULL, &wmclient);
    130         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    131 
    132         c0 = ds_display_first_wmclient(disp);
    133         PCUT_ASSERT_EQUALS(c0, wmclient);
    134 
    135         c1 = ds_display_next_wmclient(c0);
    136         PCUT_ASSERT_NULL(c1);
    137 
    138         ds_wmclient_destroy(wmclient);
    139         ds_display_destroy(disp);
    140 }
    141 
    142 /** Basic CFG client operation. */
    143 PCUT_TEST(display_cfgclient)
    144 {
    145         ds_display_t *disp;
    146         ds_cfgclient_t *cfgclient;
    147         errno_t rc;
    148 
    149         rc = ds_display_create(NULL, df_none, &disp);
    150         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    151 
    152         rc = ds_cfgclient_create(disp, &test_ds_cfgclient_cb, NULL, &cfgclient);
    153         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    154 
    155         ds_cfgclient_destroy(cfgclient);
    156         ds_display_destroy(disp);
    157 }
    158 
    15991/** Test ds_display_find_window(). */
    16092PCUT_TEST(display_find_window)
     
    16294        ds_display_t *disp;
    16395        ds_client_t *client;
    164         ds_seat_t *seat;
    16596        ds_window_t *w0;
    16697        ds_window_t *w1;
    16798        ds_window_t *wnd;
    16899        display_wnd_params_t params;
    169         bool called_cb = false;
    170         errno_t rc;
    171 
    172         rc = ds_display_create(NULL, df_none, &disp);
    173         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    174 
    175         rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
    176         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    177 
    178         rc = ds_seat_create(disp, "Alice", &seat);
     100        errno_t rc;
     101
     102        rc = ds_display_create(NULL, df_none, &disp);
     103        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     104
     105        rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
    179106        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    180107
     
    221148        ds_window_destroy(w0);
    222149        ds_window_destroy(w1);
    223         ds_seat_destroy(seat);
    224         ds_client_destroy(client);
    225         ds_display_destroy(disp);
    226 }
    227 
    228 /** Test ds_display_enlist_window() */
    229 PCUT_TEST(display_enlist_window)
    230 {
    231         ds_display_t *disp;
    232         ds_client_t *client;
    233         ds_seat_t *seat;
    234         ds_window_t *w0;
    235         ds_window_t *w1;
    236         ds_window_t *w2;
    237         ds_window_t *w3;
    238         ds_window_t *w;
    239         display_wnd_params_t params;
    240         bool called_cb = false;
    241         errno_t rc;
    242 
    243         rc = ds_display_create(NULL, df_none, &disp);
    244         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    245 
    246         rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
    247         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    248 
    249         rc = ds_seat_create(disp, "Alice", &seat);
    250         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    251 
    252         display_wnd_params_init(&params);
    253         params.rect.p0.x = params.rect.p0.y = 0;
    254         params.rect.p1.x = params.rect.p1.y = 100;
    255 
    256         /* Regular windows */
    257 
    258         rc = ds_window_create(client, &params, &w0);
    259         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    260 
    261         rc = ds_window_create(client, &params, &w1);
    262         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    263 
    264         /* Topmost windows */
    265 
    266         params.flags |= wndf_topmost;
    267 
    268         rc = ds_window_create(client, &params, &w2);
    269         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    270 
    271         rc = ds_window_create(client, &params, &w3);
    272         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    273 
    274         /* Delist w1 and w2 */
    275         list_remove(&w1->ldwindows);
    276         list_remove(&w2->ldwindows);
    277 
    278         /* Enlist the windows back and check their order */
    279         ds_display_enlist_window(disp, w1);
    280         ds_display_enlist_window(disp, w2);
    281 
    282         w = ds_display_first_window(disp);
    283         PCUT_ASSERT_EQUALS(w2, w);
    284         w = ds_display_next_window(w);
    285         PCUT_ASSERT_EQUALS(w3, w);
    286         w = ds_display_next_window(w);
    287         PCUT_ASSERT_EQUALS(w1, w);
    288         w = ds_display_next_window(w);
    289         PCUT_ASSERT_EQUALS(w0, w);
    290         w = ds_display_next_window(w);
    291         PCUT_ASSERT_EQUALS(NULL, w);
    292 
    293         ds_window_destroy(w0);
    294         ds_window_destroy(w1);
    295         ds_window_destroy(w2);
    296         ds_window_destroy(w3);
    297         ds_seat_destroy(seat);
    298         ds_client_destroy(client);
    299         ds_display_destroy(disp);
    300 }
    301 
    302 /** Test ds_display_window_to_top() */
    303 PCUT_TEST(display_window_to_top)
    304 {
    305         ds_display_t *disp;
    306         ds_client_t *client;
    307         ds_seat_t *seat;
    308         ds_window_t *w0;
    309         ds_window_t *w1;
    310         display_wnd_params_t params;
    311         bool called_cb = false;
    312         errno_t rc;
    313 
    314         rc = ds_display_create(NULL, df_none, &disp);
    315         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    316 
    317         rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
    318         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    319 
    320         rc = ds_seat_create(disp, "Alice", &seat);
    321         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    322 
    323         display_wnd_params_init(&params);
    324         params.rect.p0.x = params.rect.p0.y = 0;
    325         params.rect.p1.x = params.rect.p1.y = 100;
    326 
    327         rc = ds_window_create(client, &params, &w0);
    328         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    329 
    330         rc = ds_window_create(client, &params, &w1);
    331         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    332 
    333         PCUT_ASSERT_EQUALS(w1, ds_display_first_window(disp));
    334         ds_display_window_to_top(w0);
    335         PCUT_ASSERT_EQUALS(w0, ds_display_first_window(disp));
    336 
    337         ds_window_destroy(w0);
    338         ds_window_destroy(w1);
    339         ds_seat_destroy(seat);
    340150        ds_client_destroy(client);
    341151        ds_display_destroy(disp);
     
    347157        ds_display_t *disp;
    348158        ds_client_t *client;
    349         ds_seat_t *seat;
    350159        ds_window_t *w0;
    351160        ds_window_t *w1;
     
    353162        display_wnd_params_t params;
    354163        gfx_coord2_t pos;
    355         bool called_cb = false;
    356         errno_t rc;
    357 
    358         rc = ds_display_create(NULL, df_none, &disp);
    359         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    360 
    361         rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
    362         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    363 
    364         rc = ds_seat_create(disp, "Alice", &seat);
     164        errno_t rc;
     165
     166        rc = ds_display_create(NULL, df_none, &disp);
     167        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     168
     169        rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
    365170        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    366171
     
    393198        ds_window_destroy(w0);
    394199        ds_window_destroy(w1);
    395         ds_seat_destroy(seat);
    396         ds_client_destroy(client);
    397         ds_display_destroy(disp);
    398 }
    399 
    400 /** Basic idevcfg operation */
    401 PCUT_TEST(display_idevcfg)
    402 {
    403         ds_display_t *disp;
    404         ds_seat_t *seat;
    405         ds_idevcfg_t *idevcfg;
    406         errno_t rc;
    407 
    408         rc = ds_display_create(NULL, df_none, &disp);
    409         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    410 
    411         rc = ds_seat_create(disp, "Alice", &seat);
    412         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    413 
    414         rc = ds_idevcfg_create(disp, 42, seat, &idevcfg);
    415         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    416 
    417         ds_idevcfg_destroy(idevcfg);
    418 
    419         ds_seat_destroy(seat);
     200        ds_client_destroy(client);
    420201        ds_display_destroy(disp);
    421202}
     
    426207        ds_display_t *disp;
    427208        ds_seat_t *seat;
    428         ds_seat_t *s0, *s1, *s2;
    429         errno_t rc;
    430 
    431         rc = ds_display_create(NULL, df_none, &disp);
    432         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    433 
    434         rc = ds_seat_create(disp, "Alice", &seat);
     209        ds_seat_t *s0, *s1;
     210        errno_t rc;
     211
     212        rc = ds_display_create(NULL, df_none, &disp);
     213        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     214
     215        rc = ds_seat_create(disp, &seat);
    435216        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    436217
     
    441222        PCUT_ASSERT_NULL(s1);
    442223
    443         s2 = ds_display_find_seat(disp, seat->id);
    444         PCUT_ASSERT_EQUALS(s2, seat);
    445 
    446224        ds_seat_destroy(seat);
    447225        ds_display_destroy(disp);
    448 }
    449 
    450 /** ds_display_seat_by_idev() returns the correct seat. */
    451 PCUT_TEST(display_seat_by_idev)
    452 {
    453         // XXX TODO
    454226}
    455227
     
    470242        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    471243
    472         rc = ds_seat_create(disp, "Alice", &seat);
     244        rc = ds_seat_create(disp, &seat);
    473245        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    474246
     
    518290        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    519291
    520         rc = ds_seat_create(disp, "Alice", &seat);
     292        rc = ds_seat_create(disp, &seat);
    521293        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    522294
     
    586358        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    587359
    588         rc = ds_seat_create(disp, "Alice", &seat);
     360        rc = ds_seat_create(disp, &seat);
    589361        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    590362
     
    658430}
    659431
    660 /** ds_display_update_max_rect() updates maximization rectangle */
    661 PCUT_TEST(display_update_max_rect)
    662 {
    663         ds_display_t *disp;
    664         ds_seat_t *seat;
    665         ds_client_t *client;
    666         ds_window_t *wnd;
    667         display_wnd_params_t params;
    668         errno_t rc;
    669 
    670         rc = ds_display_create(NULL, df_none, &disp);
    671         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    672 
    673         rc = ds_seat_create(disp, "Alice", &seat);
    674         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    675 
    676         rc = ds_client_create(disp, NULL, NULL, &client);
    677         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    678 
    679         /*
    680          * We need to set display dimensions Here we do it directly
    681          * instead of adding a display device.
    682          */
    683         disp->rect.p0.x = 0;
    684         disp->rect.p0.y = 0;
    685         disp->rect.p1.x = 500;
    686         disp->rect.p1.y = 500;
    687 
    688         /* Set maximize rectangle as well */
    689         disp->max_rect = disp->rect;
    690 
    691         /* A panel-like window at the bottom */
    692         display_wnd_params_init(&params);
    693         params.flags |= wndf_setpos;
    694         params.pos.x = 0;
    695         params.pos.y = 450;
    696         params.rect.p0.x = 0;
    697         params.rect.p0.y = 0;
    698         params.rect.p1.x = 500;
    699         params.rect.p1.y = 50;
    700 
    701         rc = ds_window_create(client, &params, &wnd);
    702         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    703 
    704         /*
    705          * At this point the maximize rect should be unaltered because
    706          * the avoid flag has not been set.
    707          */
    708         PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.x);
    709         PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.y);
    710         PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.x);
    711         PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.y);
    712 
    713         wnd->flags |= wndf_avoid;
    714 
    715         /* Update maximize rectangle */
    716         ds_display_update_max_rect(disp);
    717 
    718         /* Verify maximize rectangle */
    719         PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.x);
    720         PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.y);
    721         PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.x);
    722         PCUT_ASSERT_INT_EQUALS(450, disp->max_rect.p1.y);
    723 
    724         ds_window_destroy(wnd);
    725         ds_client_destroy(client);
    726         ds_seat_destroy(seat);
    727         ds_display_destroy(disp);
    728 }
    729 
    730 /** Cropping maximization rectangle from the top */
    731 PCUT_TEST(display_crop_max_rect_top)
    732 {
    733         gfx_rect_t arect;
    734         gfx_rect_t mrect;
    735 
    736         arect.p0.x = 10;
    737         arect.p0.y = 20;
    738         arect.p1.x = 30;
    739         arect.p1.y = 5;
    740 
    741         mrect.p0.x = 10;
    742         mrect.p0.y = 20;
    743         mrect.p1.x = 30;
    744         mrect.p1.y = 40;
    745 
    746         ds_display_crop_max_rect(&arect, &mrect);
    747 
    748         PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x);
    749         PCUT_ASSERT_INT_EQUALS(5, mrect.p0.y);
    750         PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x);
    751         PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y);
    752 }
    753 
    754 /** Cropping maximization rectangle from the bottom */
    755 PCUT_TEST(display_crop_max_rect_bottom)
    756 {
    757         gfx_rect_t arect;
    758         gfx_rect_t mrect;
    759 
    760         arect.p0.x = 10;
    761         arect.p0.y = 35;
    762         arect.p1.x = 30;
    763         arect.p1.y = 40;
    764 
    765         mrect.p0.x = 10;
    766         mrect.p0.y = 20;
    767         mrect.p1.x = 30;
    768         mrect.p1.y = 40;
    769 
    770         ds_display_crop_max_rect(&arect, &mrect);
    771 
    772         PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x);
    773         PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y);
    774         PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x);
    775         PCUT_ASSERT_INT_EQUALS(35, mrect.p1.y);
    776 }
    777 
    778 /** Cropping maximization rectangle from the left */
    779 PCUT_TEST(display_crop_max_rect_left)
    780 {
    781         gfx_rect_t arect;
    782         gfx_rect_t mrect;
    783 
    784         arect.p0.x = 10;
    785         arect.p0.y = 20;
    786         arect.p1.x = 15;
    787         arect.p1.y = 40;
    788 
    789         mrect.p0.x = 10;
    790         mrect.p0.y = 20;
    791         mrect.p1.x = 30;
    792         mrect.p1.y = 40;
    793 
    794         ds_display_crop_max_rect(&arect, &mrect);
    795 
    796         PCUT_ASSERT_INT_EQUALS(15, mrect.p0.x);
    797         PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y);
    798         PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x);
    799         PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y);
    800 }
    801 
    802 /** Cropping maximization rectangle from the right */
    803 PCUT_TEST(display_crop_max_rect_right)
    804 {
    805         gfx_rect_t arect;
    806         gfx_rect_t mrect;
    807 
    808         arect.p0.x = 25;
    809         arect.p0.y = 20;
    810         arect.p1.x = 30;
    811         arect.p1.y = 40;
    812 
    813         mrect.p0.x = 10;
    814         mrect.p0.y = 20;
    815         mrect.p1.x = 30;
    816         mrect.p1.y = 40;
    817 
    818         ds_display_crop_max_rect(&arect, &mrect);
    819 
    820         PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x);
    821         PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y);
    822         PCUT_ASSERT_INT_EQUALS(25, mrect.p1.x);
    823         PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y);
    824 }
    825 
    826432PCUT_EXPORT(display);
Note: See TracChangeset for help on using the changeset viewer.