Ignore:
File:
1 edited

Legend:

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

    r9e84d2c r29a5a99  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#include "../seat.h"
    3737#include "../window.h"
     38#include "../wmclient.h"
    3839
    3940PCUT_INIT;
     
    4748};
    4849
     50static void test_ds_wmev_pending(void *);
     51
     52static ds_wmclient_cb_t test_ds_wmclient_cb = {
     53        .ev_pending = test_ds_wmev_pending
     54};
     55
    4956static void test_ds_ev_pending(void *arg)
    5057{
     
    5360}
    5461
     62static void test_ds_wmev_pending(void *arg)
     63{
     64        bool *called_cb = (bool *) arg;
     65        *called_cb = true;
     66}
     67
    5568/** Display creation and destruction. */
    5669PCUT_TEST(display_create_destroy)
     
    8699
    87100        ds_client_destroy(client);
     101        ds_display_destroy(disp);
     102}
     103
     104/** Basic WM client operation. */
     105PCUT_TEST(display_wmclient)
     106{
     107        ds_display_t *disp;
     108        ds_wmclient_t *wmclient;
     109        ds_wmclient_t *c0, *c1;
     110        errno_t rc;
     111
     112        rc = ds_display_create(NULL, df_none, &disp);
     113        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     114
     115        rc = ds_wmclient_create(disp, &test_ds_wmclient_cb, NULL, &wmclient);
     116        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     117
     118        c0 = ds_display_first_wmclient(disp);
     119        PCUT_ASSERT_EQUALS(c0, wmclient);
     120
     121        c1 = ds_display_next_wmclient(c0);
     122        PCUT_ASSERT_NULL(c1);
     123
     124        ds_wmclient_destroy(wmclient);
    88125        ds_display_destroy(disp);
    89126}
     
    150187        wnd = ds_display_find_window(disp, w0->id + 1);
    151188        PCUT_ASSERT_NULL(wnd);
     189
     190        ds_window_destroy(w0);
     191        ds_window_destroy(w1);
     192        ds_seat_destroy(seat);
     193        ds_client_destroy(client);
     194        ds_display_destroy(disp);
     195}
     196
     197/** Test ds_display_enlist_window() */
     198PCUT_TEST(display_enlist_window)
     199{
     200        ds_display_t *disp;
     201        ds_client_t *client;
     202        ds_seat_t *seat;
     203        ds_window_t *w0;
     204        ds_window_t *w1;
     205        ds_window_t *w2;
     206        ds_window_t *w3;
     207        ds_window_t *w;
     208        display_wnd_params_t params;
     209        bool called_cb = false;
     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_client_create(disp, &test_ds_client_cb, &called_cb, &client);
     216        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     217
     218        rc = ds_seat_create(disp, &seat);
     219        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     220
     221        display_wnd_params_init(&params);
     222        params.rect.p0.x = params.rect.p0.y = 0;
     223        params.rect.p1.x = params.rect.p1.y = 100;
     224
     225        /* Regular windows */
     226
     227        rc = ds_window_create(client, &params, &w0);
     228        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     229
     230        rc = ds_window_create(client, &params, &w1);
     231        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     232
     233        /* Topmost windows */
     234
     235        params.flags |= wndf_topmost;
     236
     237        rc = ds_window_create(client, &params, &w2);
     238        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     239
     240        rc = ds_window_create(client, &params, &w3);
     241        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     242
     243        /* Delist w1 and w2 */
     244        list_remove(&w1->ldwindows);
     245        list_remove(&w2->ldwindows);
     246
     247        /* Enlist the windows back and check their order */
     248        ds_display_enlist_window(disp, w1);
     249        ds_display_enlist_window(disp, w2);
     250
     251        w = ds_display_first_window(disp);
     252        PCUT_ASSERT_EQUALS(w2, w);
     253        w = ds_display_next_window(w);
     254        PCUT_ASSERT_EQUALS(w3, w);
     255        w = ds_display_next_window(w);
     256        PCUT_ASSERT_EQUALS(w1, w);
     257        w = ds_display_next_window(w);
     258        PCUT_ASSERT_EQUALS(w0, w);
     259        w = ds_display_next_window(w);
     260        PCUT_ASSERT_EQUALS(NULL, w);
     261
     262        ds_window_destroy(w0);
     263        ds_window_destroy(w1);
     264        ds_window_destroy(w2);
     265        ds_window_destroy(w3);
     266        ds_seat_destroy(seat);
     267        ds_client_destroy(client);
     268        ds_display_destroy(disp);
     269}
     270
     271/** Test ds_display_window_to_top() */
     272PCUT_TEST(display_window_to_top)
     273{
     274        ds_display_t *disp;
     275        ds_client_t *client;
     276        ds_seat_t *seat;
     277        ds_window_t *w0;
     278        ds_window_t *w1;
     279        display_wnd_params_t params;
     280        bool called_cb = false;
     281        errno_t rc;
     282
     283        rc = ds_display_create(NULL, df_none, &disp);
     284        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     285
     286        rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
     287        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     288
     289        rc = ds_seat_create(disp, &seat);
     290        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     291
     292        display_wnd_params_init(&params);
     293        params.rect.p0.x = params.rect.p0.y = 0;
     294        params.rect.p1.x = params.rect.p1.y = 100;
     295
     296        rc = ds_window_create(client, &params, &w0);
     297        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     298
     299        rc = ds_window_create(client, &params, &w1);
     300        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     301
     302        PCUT_ASSERT_EQUALS(w1, ds_display_first_window(disp));
     303        ds_display_window_to_top(w0);
     304        PCUT_ASSERT_EQUALS(w0, ds_display_first_window(disp));
    152305
    153306        ds_window_destroy(w0);
     
    236389        ds_seat_destroy(seat);
    237390        ds_display_destroy(disp);
     391}
     392
     393/** ds_display_seat_by_idev() returns the correct seat. */
     394PCUT_TEST(display_seat_by_idev)
     395{
     396        // XXX TODO
    238397}
    239398
     
    442601}
    443602
     603/** ds_display_update_max_rect() updates maximization rectangle */
     604PCUT_TEST(display_update_max_rect)
     605{
     606        ds_display_t *disp;
     607        ds_seat_t *seat;
     608        ds_client_t *client;
     609        ds_window_t *wnd;
     610        display_wnd_params_t params;
     611        errno_t rc;
     612
     613        rc = ds_display_create(NULL, df_none, &disp);
     614        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     615
     616        rc = ds_seat_create(disp, &seat);
     617        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     618
     619        rc = ds_client_create(disp, NULL, NULL, &client);
     620        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     621
     622        /*
     623         * We need to set display dimensions Here we do it directly
     624         * instead of adding a display device.
     625         */
     626        disp->rect.p0.x = 0;
     627        disp->rect.p0.y = 0;
     628        disp->rect.p1.x = 500;
     629        disp->rect.p1.y = 500;
     630
     631        /* Set maximize rectangle as well */
     632        disp->max_rect = disp->rect;
     633
     634        /* A panel-like window at the bottom */
     635        display_wnd_params_init(&params);
     636        params.flags |= wndf_setpos;
     637        params.pos.x = 0;
     638        params.pos.y = 450;
     639        params.rect.p0.x = 0;
     640        params.rect.p0.y = 0;
     641        params.rect.p1.x = 500;
     642        params.rect.p1.y = 50;
     643
     644        rc = ds_window_create(client, &params, &wnd);
     645        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     646
     647        /*
     648         * At this point the maximize rect should be unaltered because
     649         * the avoid flag has not been set.
     650         */
     651        PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.x);
     652        PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.y);
     653        PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.x);
     654        PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.y);
     655
     656        wnd->flags |= wndf_avoid;
     657
     658        /* Update maximize rectangle */
     659        ds_display_update_max_rect(disp);
     660
     661        /* Verify maximize rectangle */
     662        PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.x);
     663        PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.y);
     664        PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.x);
     665        PCUT_ASSERT_INT_EQUALS(450, disp->max_rect.p1.y);
     666
     667        ds_window_destroy(wnd);
     668        ds_client_destroy(client);
     669        ds_seat_destroy(seat);
     670        ds_display_destroy(disp);
     671}
     672
     673/** Cropping maximization rectangle from the top */
     674PCUT_TEST(display_crop_max_rect_top)
     675{
     676        gfx_rect_t arect;
     677        gfx_rect_t mrect;
     678
     679        arect.p0.x = 10;
     680        arect.p0.y = 20;
     681        arect.p1.x = 30;
     682        arect.p1.y = 5;
     683
     684        mrect.p0.x = 10;
     685        mrect.p0.y = 20;
     686        mrect.p1.x = 30;
     687        mrect.p1.y = 40;
     688
     689        ds_display_crop_max_rect(&arect, &mrect);
     690
     691        PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x);
     692        PCUT_ASSERT_INT_EQUALS(5, mrect.p0.y);
     693        PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x);
     694        PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y);
     695}
     696
     697/** Cropping maximization rectangle from the bottom */
     698PCUT_TEST(display_crop_max_rect_bottom)
     699{
     700        gfx_rect_t arect;
     701        gfx_rect_t mrect;
     702
     703        arect.p0.x = 10;
     704        arect.p0.y = 35;
     705        arect.p1.x = 30;
     706        arect.p1.y = 40;
     707
     708        mrect.p0.x = 10;
     709        mrect.p0.y = 20;
     710        mrect.p1.x = 30;
     711        mrect.p1.y = 40;
     712
     713        ds_display_crop_max_rect(&arect, &mrect);
     714
     715        PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x);
     716        PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y);
     717        PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x);
     718        PCUT_ASSERT_INT_EQUALS(35, mrect.p1.y);
     719}
     720
     721/** Cropping maximization rectangle from the left */
     722PCUT_TEST(display_crop_max_rect_left)
     723{
     724        gfx_rect_t arect;
     725        gfx_rect_t mrect;
     726
     727        arect.p0.x = 10;
     728        arect.p0.y = 20;
     729        arect.p1.x = 15;
     730        arect.p1.y = 40;
     731
     732        mrect.p0.x = 10;
     733        mrect.p0.y = 20;
     734        mrect.p1.x = 30;
     735        mrect.p1.y = 40;
     736
     737        ds_display_crop_max_rect(&arect, &mrect);
     738
     739        PCUT_ASSERT_INT_EQUALS(15, mrect.p0.x);
     740        PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y);
     741        PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x);
     742        PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y);
     743}
     744
     745/** Cropping maximization rectangle from the right */
     746PCUT_TEST(display_crop_max_rect_right)
     747{
     748        gfx_rect_t arect;
     749        gfx_rect_t mrect;
     750
     751        arect.p0.x = 25;
     752        arect.p0.y = 20;
     753        arect.p1.x = 30;
     754        arect.p1.y = 40;
     755
     756        mrect.p0.x = 10;
     757        mrect.p0.y = 20;
     758        mrect.p1.x = 30;
     759        mrect.p1.y = 40;
     760
     761        ds_display_crop_max_rect(&arect, &mrect);
     762
     763        PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x);
     764        PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y);
     765        PCUT_ASSERT_INT_EQUALS(25, mrect.p1.x);
     766        PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y);
     767}
     768
    444769PCUT_EXPORT(display);
Note: See TracChangeset for help on using the changeset viewer.