| 1 | /*
|
|---|
| 2 | * Copyright (c) 2019 Jiri Svoboda
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | #include <disp_srv.h>
|
|---|
| 30 | #include <errno.h>
|
|---|
| 31 | #include <pcut/pcut.h>
|
|---|
| 32 | #include <stdio.h>
|
|---|
| 33 | #include <str.h>
|
|---|
| 34 |
|
|---|
| 35 | #include "../client.h"
|
|---|
| 36 | #include "../display.h"
|
|---|
| 37 | #include "../seat.h"
|
|---|
| 38 | #include "../window.h"
|
|---|
| 39 |
|
|---|
| 40 | PCUT_INIT;
|
|---|
| 41 |
|
|---|
| 42 | PCUT_TEST_SUITE(seat);
|
|---|
| 43 |
|
|---|
| 44 | static void test_ds_ev_pending(void *);
|
|---|
| 45 |
|
|---|
| 46 | static ds_client_cb_t test_ds_client_cb = {
|
|---|
| 47 | .ev_pending = test_ds_ev_pending
|
|---|
| 48 | };
|
|---|
| 49 |
|
|---|
| 50 | static void test_ds_ev_pending(void *arg)
|
|---|
| 51 | {
|
|---|
| 52 | bool *called_cb = (bool *) arg;
|
|---|
| 53 | printf("test_ds_ev_pending\n");
|
|---|
| 54 | *called_cb = true;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | /** Set focus. */
|
|---|
| 58 | PCUT_TEST(set_focus)
|
|---|
| 59 | {
|
|---|
| 60 | ds_display_t *disp;
|
|---|
| 61 | ds_client_t *client;
|
|---|
| 62 | ds_seat_t *seat;
|
|---|
| 63 | ds_window_t *wnd;
|
|---|
| 64 | display_wnd_params_t params;
|
|---|
| 65 | bool called_cb = false;
|
|---|
| 66 | errno_t rc;
|
|---|
| 67 |
|
|---|
| 68 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 69 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 70 |
|
|---|
| 71 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 72 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 73 |
|
|---|
| 74 | rc = ds_seat_create(disp, &seat);
|
|---|
| 75 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 76 |
|
|---|
| 77 | display_wnd_params_init(¶ms);
|
|---|
| 78 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 79 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 80 |
|
|---|
| 81 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 82 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 83 |
|
|---|
| 84 | ds_seat_set_focus(seat, wnd);
|
|---|
| 85 | PCUT_ASSERT_EQUALS(wnd, seat->focus);
|
|---|
| 86 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 87 |
|
|---|
| 88 | ds_window_destroy(wnd);
|
|---|
| 89 | ds_seat_destroy(seat);
|
|---|
| 90 | ds_client_destroy(client);
|
|---|
| 91 | ds_display_destroy(disp);
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | /** Evacuate focus. */
|
|---|
| 95 | PCUT_TEST(evac_focus)
|
|---|
| 96 | {
|
|---|
| 97 | ds_display_t *disp;
|
|---|
| 98 | ds_client_t *client;
|
|---|
| 99 | ds_seat_t *seat;
|
|---|
| 100 | ds_window_t *w0;
|
|---|
| 101 | ds_window_t *w1;
|
|---|
| 102 | display_wnd_params_t params;
|
|---|
| 103 | bool called_cb = false;
|
|---|
| 104 | errno_t rc;
|
|---|
| 105 |
|
|---|
| 106 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 107 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 108 |
|
|---|
| 109 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 110 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 111 |
|
|---|
| 112 | rc = ds_seat_create(disp, &seat);
|
|---|
| 113 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 114 |
|
|---|
| 115 | display_wnd_params_init(¶ms);
|
|---|
| 116 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 117 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 118 |
|
|---|
| 119 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 120 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 121 |
|
|---|
| 122 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 123 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 124 |
|
|---|
| 125 | ds_seat_set_focus(seat, w1);
|
|---|
| 126 | PCUT_ASSERT_EQUALS(w1, seat->focus);
|
|---|
| 127 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 128 | called_cb = false;
|
|---|
| 129 |
|
|---|
| 130 | ds_seat_evac_focus(seat, w1);
|
|---|
| 131 | PCUT_ASSERT_EQUALS(w0, seat->focus);
|
|---|
| 132 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 133 |
|
|---|
| 134 | ds_window_destroy(w0);
|
|---|
| 135 | ds_window_destroy(w1);
|
|---|
| 136 | ds_seat_destroy(seat);
|
|---|
| 137 | ds_client_destroy(client);
|
|---|
| 138 | ds_display_destroy(disp);
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | /** Test ds_seat_post_kbd_event() with Alt-Tab switches focus */
|
|---|
| 142 | PCUT_TEST(post_kbd_event_alt_tab)
|
|---|
| 143 | {
|
|---|
| 144 | ds_display_t *disp;
|
|---|
| 145 | ds_client_t *client;
|
|---|
| 146 | ds_seat_t *seat;
|
|---|
| 147 | ds_window_t *w0;
|
|---|
| 148 | ds_window_t *w1;
|
|---|
| 149 | display_wnd_params_t params;
|
|---|
| 150 | bool called_cb = false;
|
|---|
| 151 | kbd_event_t event;
|
|---|
| 152 | errno_t rc;
|
|---|
| 153 |
|
|---|
| 154 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 155 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 156 |
|
|---|
| 157 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 158 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 159 |
|
|---|
| 160 | rc = ds_seat_create(disp, &seat);
|
|---|
| 161 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 162 |
|
|---|
| 163 | display_wnd_params_init(¶ms);
|
|---|
| 164 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 165 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 166 |
|
|---|
| 167 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 168 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 169 |
|
|---|
| 170 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 171 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 172 |
|
|---|
| 173 | ds_seat_set_focus(seat, w1);
|
|---|
| 174 | PCUT_ASSERT_EQUALS(w1, seat->focus);
|
|---|
| 175 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 176 | called_cb = false;
|
|---|
| 177 |
|
|---|
| 178 | event.type = KEY_PRESS;
|
|---|
| 179 | event.mods = KM_ALT;
|
|---|
| 180 | event.key = KC_TAB;
|
|---|
| 181 | rc = ds_seat_post_kbd_event(seat, &event);
|
|---|
| 182 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 183 | PCUT_ASSERT_EQUALS(w0, seat->focus);
|
|---|
| 184 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 185 |
|
|---|
| 186 | ds_window_destroy(w0);
|
|---|
| 187 | ds_window_destroy(w1);
|
|---|
| 188 | ds_seat_destroy(seat);
|
|---|
| 189 | ds_client_destroy(client);
|
|---|
| 190 | ds_display_destroy(disp);
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | /** Test ds_seat_post_kbd_event() with regular key press delivers to client queue */
|
|---|
| 194 | PCUT_TEST(post_kbd_event_regular)
|
|---|
| 195 | {
|
|---|
| 196 | ds_display_t *disp;
|
|---|
| 197 | ds_client_t *client;
|
|---|
| 198 | ds_seat_t *seat;
|
|---|
| 199 | ds_window_t *wnd;
|
|---|
| 200 | display_wnd_params_t params;
|
|---|
| 201 | kbd_event_t event;
|
|---|
| 202 | ds_window_t *rwindow;
|
|---|
| 203 | display_wnd_ev_t revent;
|
|---|
| 204 | bool called_cb = false;
|
|---|
| 205 | errno_t rc;
|
|---|
| 206 |
|
|---|
| 207 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 208 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 209 |
|
|---|
| 210 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 211 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 212 |
|
|---|
| 213 | rc = ds_seat_create(disp, &seat);
|
|---|
| 214 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 215 |
|
|---|
| 216 | display_wnd_params_init(¶ms);
|
|---|
| 217 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 218 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 219 |
|
|---|
| 220 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 221 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 222 |
|
|---|
| 223 | ds_seat_set_focus(seat, wnd);
|
|---|
| 224 | PCUT_ASSERT_EQUALS(wnd, seat->focus);
|
|---|
| 225 |
|
|---|
| 226 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 227 | rc = ds_client_get_event(client, &rwindow, &revent);
|
|---|
| 228 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 229 | called_cb = false;
|
|---|
| 230 |
|
|---|
| 231 | event.type = KEY_PRESS;
|
|---|
| 232 | event.key = KC_ENTER;
|
|---|
| 233 | event.mods = 0;
|
|---|
| 234 | event.c = L'\0';
|
|---|
| 235 |
|
|---|
| 236 | rc = ds_client_get_event(client, &rwindow, &revent);
|
|---|
| 237 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
|---|
| 238 |
|
|---|
| 239 | rc = ds_seat_post_kbd_event(seat, &event);
|
|---|
| 240 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 241 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 242 |
|
|---|
| 243 | rc = ds_client_get_event(client, &rwindow, &revent);
|
|---|
| 244 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 245 | PCUT_ASSERT_EQUALS(wnd, rwindow);
|
|---|
| 246 | PCUT_ASSERT_EQUALS(wev_kbd, revent.etype);
|
|---|
| 247 | PCUT_ASSERT_EQUALS(event.type, revent.ev.kbd.type);
|
|---|
| 248 | PCUT_ASSERT_EQUALS(event.key, revent.ev.kbd.key);
|
|---|
| 249 | PCUT_ASSERT_EQUALS(event.mods, revent.ev.kbd.mods);
|
|---|
| 250 | PCUT_ASSERT_EQUALS(event.c, revent.ev.kbd.c);
|
|---|
| 251 |
|
|---|
| 252 | rc = ds_client_get_event(client, &rwindow, &revent);
|
|---|
| 253 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
|---|
| 254 |
|
|---|
| 255 | ds_window_destroy(wnd);
|
|---|
| 256 | ds_seat_destroy(seat);
|
|---|
| 257 | ds_client_destroy(client);
|
|---|
| 258 | ds_display_destroy(disp);
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | /** Test ds_seat_post_ptd_event() with click on window switches focus
|
|---|
| 262 | */
|
|---|
| 263 | PCUT_TEST(post_ptd_event_wnd_switch)
|
|---|
| 264 | {
|
|---|
| 265 | ds_display_t *disp;
|
|---|
| 266 | ds_seat_t *seat;
|
|---|
| 267 | ds_client_t *client;
|
|---|
| 268 | ds_window_t *w0, *w1;
|
|---|
| 269 | display_wnd_params_t params;
|
|---|
| 270 | ptd_event_t event;
|
|---|
| 271 | bool called_cb = false;
|
|---|
| 272 | errno_t rc;
|
|---|
| 273 |
|
|---|
| 274 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 275 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 276 |
|
|---|
| 277 | rc = ds_seat_create(disp, &seat);
|
|---|
| 278 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 279 |
|
|---|
| 280 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 281 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 282 |
|
|---|
| 283 | /* Set up display size to allow the pointer a range of movement */
|
|---|
| 284 | disp->rect.p1.x = 500;
|
|---|
| 285 | disp->rect.p1.y = 500;
|
|---|
| 286 |
|
|---|
| 287 | display_wnd_params_init(¶ms);
|
|---|
| 288 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 289 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 290 |
|
|---|
| 291 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 292 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 293 |
|
|---|
| 294 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 295 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 296 |
|
|---|
| 297 | w0->dpos.x = 10;
|
|---|
| 298 | w0->dpos.y = 10;
|
|---|
| 299 |
|
|---|
| 300 | w1->dpos.x = 400;
|
|---|
| 301 | w1->dpos.y = 400;
|
|---|
| 302 |
|
|---|
| 303 | PCUT_ASSERT_FALSE(called_cb);
|
|---|
| 304 |
|
|---|
| 305 | ds_seat_set_focus(seat, w0);
|
|---|
| 306 |
|
|---|
| 307 | event.type = PTD_MOVE;
|
|---|
| 308 | event.dmove.x = 400;
|
|---|
| 309 | event.dmove.y = 400;
|
|---|
| 310 | rc = ds_seat_post_ptd_event(seat, &event);
|
|---|
| 311 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 312 |
|
|---|
| 313 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 314 | called_cb = false;
|
|---|
| 315 |
|
|---|
| 316 | event.type = PTD_PRESS;
|
|---|
| 317 | event.btn_num = 1;
|
|---|
| 318 | rc = ds_seat_post_ptd_event(seat, &event);
|
|---|
| 319 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 320 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 321 | called_cb = false;
|
|---|
| 322 |
|
|---|
| 323 | PCUT_ASSERT_EQUALS(w1, seat->focus);
|
|---|
| 324 |
|
|---|
| 325 | event.type = PTD_MOVE;
|
|---|
| 326 | event.dmove.x = -400 + 10;
|
|---|
| 327 | event.dmove.y = -400 + 10;
|
|---|
| 328 | rc = ds_seat_post_ptd_event(seat, &event);
|
|---|
| 329 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 330 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 331 | called_cb = false;
|
|---|
| 332 |
|
|---|
| 333 | event.type = PTD_PRESS;
|
|---|
| 334 | event.btn_num = 1;
|
|---|
| 335 | rc = ds_seat_post_ptd_event(seat, &event);
|
|---|
| 336 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 337 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 338 | called_cb = false;
|
|---|
| 339 |
|
|---|
| 340 | PCUT_ASSERT_EQUALS(w0, seat->focus);
|
|---|
| 341 |
|
|---|
| 342 | ds_window_destroy(w0);
|
|---|
| 343 | ds_window_destroy(w1);
|
|---|
| 344 | ds_client_destroy(client);
|
|---|
| 345 | ds_seat_destroy(seat);
|
|---|
| 346 | ds_display_destroy(disp);
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|
| 349 | /** Test ds_seat_post_pos_event() */
|
|---|
| 350 | PCUT_TEST(post_pos_event)
|
|---|
| 351 | {
|
|---|
| 352 | // XXX
|
|---|
| 353 | }
|
|---|
| 354 |
|
|---|
| 355 | /** Set WM cursor */
|
|---|
| 356 | PCUT_TEST(set_wm_cursor)
|
|---|
| 357 | {
|
|---|
| 358 | ds_display_t *disp;
|
|---|
| 359 | ds_client_t *client;
|
|---|
| 360 | ds_seat_t *seat;
|
|---|
| 361 | bool called_cb = false;
|
|---|
| 362 | errno_t rc;
|
|---|
| 363 |
|
|---|
| 364 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 365 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 366 |
|
|---|
| 367 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 368 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 369 |
|
|---|
| 370 | rc = ds_seat_create(disp, &seat);
|
|---|
| 371 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 372 |
|
|---|
| 373 | ds_seat_set_wm_cursor(seat, disp->cursor[dcurs_size_ud]);
|
|---|
| 374 | ds_seat_set_wm_cursor(seat, NULL);
|
|---|
| 375 |
|
|---|
| 376 | ds_seat_destroy(seat);
|
|---|
| 377 | ds_client_destroy(client);
|
|---|
| 378 | ds_display_destroy(disp);
|
|---|
| 379 | }
|
|---|
| 380 |
|
|---|
| 381 | PCUT_EXPORT(seat);
|
|---|