[b2d1df3] | 1 | /*
|
---|
[d8503fd] | 2 | * Copyright (c) 2023 Jiri Svoboda
|
---|
[b2d1df3] | 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 |
|
---|
[3434233] | 29 | #include <disp_srv.h>
|
---|
[b2d1df3] | 30 | #include <errno.h>
|
---|
| 31 | #include <pcut/pcut.h>
|
---|
| 32 | #include <str.h>
|
---|
| 33 |
|
---|
| 34 | #include "../client.h"
|
---|
| 35 | #include "../display.h"
|
---|
[9e84d2c] | 36 | #include "../seat.h"
|
---|
[b2d1df3] | 37 | #include "../window.h"
|
---|
| 38 |
|
---|
| 39 | PCUT_INIT;
|
---|
| 40 |
|
---|
| 41 | PCUT_TEST_SUITE(client);
|
---|
| 42 |
|
---|
| 43 | static void test_ds_ev_pending(void *);
|
---|
| 44 |
|
---|
| 45 | static ds_client_cb_t test_ds_client_cb = {
|
---|
| 46 | .ev_pending = test_ds_ev_pending
|
---|
| 47 | };
|
---|
| 48 |
|
---|
| 49 | static void test_ds_ev_pending(void *arg)
|
---|
| 50 | {
|
---|
| 51 | bool *called_cb = (bool *) arg;
|
---|
| 52 | *called_cb = true;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | /** Client creation and destruction. */
|
---|
| 56 | PCUT_TEST(client_create_destroy)
|
---|
| 57 | {
|
---|
| 58 | ds_display_t *disp;
|
---|
| 59 | ds_client_t *client;
|
---|
| 60 | errno_t rc;
|
---|
| 61 |
|
---|
[8aef01c] | 62 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[b2d1df3] | 63 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 64 |
|
---|
| 65 | rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
|
---|
| 66 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 67 |
|
---|
| 68 | ds_client_destroy(client);
|
---|
| 69 | ds_display_destroy(disp);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /** Test ds_client_find_window().
|
---|
| 73 | *
|
---|
| 74 | * ds_client_add_window() and ds_client_remove_window() are indirectly
|
---|
| 75 | * tested too as part of creating and destroying the window
|
---|
| 76 | */
|
---|
| 77 | PCUT_TEST(client_find_window)
|
---|
| 78 | {
|
---|
| 79 | ds_display_t *disp;
|
---|
| 80 | ds_client_t *client;
|
---|
[9e84d2c] | 81 | ds_seat_t *seat;
|
---|
[b2d1df3] | 82 | ds_window_t *w0;
|
---|
| 83 | ds_window_t *w1;
|
---|
| 84 | ds_window_t *wnd;
|
---|
[3434233] | 85 | display_wnd_params_t params;
|
---|
[9e84d2c] | 86 | bool called_cb = NULL;
|
---|
[b2d1df3] | 87 | errno_t rc;
|
---|
| 88 |
|
---|
[8aef01c] | 89 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[b2d1df3] | 90 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 91 |
|
---|
[9e84d2c] | 92 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 93 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 94 |
|
---|
[d8503fd] | 95 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
[b2d1df3] | 96 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 97 |
|
---|
[3434233] | 98 | display_wnd_params_init(¶ms);
|
---|
| 99 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 100 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 101 |
|
---|
| 102 | rc = ds_window_create(client, ¶ms, &w0);
|
---|
[b2d1df3] | 103 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 104 |
|
---|
[3434233] | 105 | rc = ds_window_create(client, ¶ms, &w1);
|
---|
[b2d1df3] | 106 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 107 |
|
---|
| 108 | wnd = ds_client_find_window(client, w0->id);
|
---|
| 109 | PCUT_ASSERT_EQUALS(w0, wnd);
|
---|
| 110 |
|
---|
| 111 | wnd = ds_client_find_window(client, w1->id);
|
---|
| 112 | PCUT_ASSERT_EQUALS(w1, wnd);
|
---|
| 113 |
|
---|
| 114 | wnd = ds_client_find_window(client, 0);
|
---|
| 115 | PCUT_ASSERT_NULL(wnd);
|
---|
| 116 |
|
---|
| 117 | wnd = ds_client_find_window(client, w1->id + 1);
|
---|
| 118 | PCUT_ASSERT_NULL(wnd);
|
---|
| 119 |
|
---|
[648e2ac] | 120 | ds_window_destroy(w0);
|
---|
| 121 | ds_window_destroy(w1);
|
---|
[9e84d2c] | 122 | ds_seat_destroy(seat);
|
---|
[b2d1df3] | 123 | ds_client_destroy(client);
|
---|
| 124 | ds_display_destroy(disp);
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | /** Test ds_client_first_window() / ds_client_next_window. */
|
---|
| 128 | PCUT_TEST(client_first_next_window)
|
---|
| 129 | {
|
---|
| 130 | ds_display_t *disp;
|
---|
| 131 | ds_client_t *client;
|
---|
[9e84d2c] | 132 | ds_seat_t *seat;
|
---|
[b2d1df3] | 133 | ds_window_t *w0;
|
---|
| 134 | ds_window_t *w1;
|
---|
| 135 | ds_window_t *wnd;
|
---|
[3434233] | 136 | display_wnd_params_t params;
|
---|
[9e84d2c] | 137 | bool called_cb = NULL;
|
---|
[b2d1df3] | 138 | errno_t rc;
|
---|
| 139 |
|
---|
[8aef01c] | 140 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[b2d1df3] | 141 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 142 |
|
---|
[9e84d2c] | 143 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 144 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 145 |
|
---|
[d8503fd] | 146 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
[b2d1df3] | 147 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 148 |
|
---|
[3434233] | 149 | display_wnd_params_init(¶ms);
|
---|
| 150 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 151 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 152 |
|
---|
| 153 | rc = ds_window_create(client, ¶ms, &w0);
|
---|
[b2d1df3] | 154 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 155 |
|
---|
[3434233] | 156 | rc = ds_window_create(client, ¶ms, &w1);
|
---|
[b2d1df3] | 157 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 158 |
|
---|
| 159 | wnd = ds_client_first_window(client);
|
---|
| 160 | PCUT_ASSERT_EQUALS(w0, wnd);
|
---|
| 161 |
|
---|
| 162 | wnd = ds_client_next_window(w0);
|
---|
| 163 | PCUT_ASSERT_EQUALS(w1, wnd);
|
---|
| 164 |
|
---|
| 165 | wnd = ds_client_next_window(w1);
|
---|
| 166 | PCUT_ASSERT_NULL(wnd);
|
---|
| 167 |
|
---|
[648e2ac] | 168 | ds_window_destroy(w0);
|
---|
| 169 | ds_window_destroy(w1);
|
---|
[9e84d2c] | 170 | ds_seat_destroy(seat);
|
---|
[b2d1df3] | 171 | ds_client_destroy(client);
|
---|
| 172 | ds_display_destroy(disp);
|
---|
| 173 | }
|
---|
| 174 |
|
---|
[338d0935] | 175 | /** Test ds_client_get_event(), ds_client_post_close_event(). */
|
---|
| 176 | PCUT_TEST(client_get_post_close_event)
|
---|
| 177 | {
|
---|
| 178 | ds_display_t *disp;
|
---|
| 179 | ds_client_t *client;
|
---|
[9e84d2c] | 180 | ds_seat_t *seat;
|
---|
[338d0935] | 181 | ds_window_t *wnd;
|
---|
| 182 | display_wnd_params_t params;
|
---|
| 183 | ds_window_t *rwindow;
|
---|
| 184 | display_wnd_ev_t revent;
|
---|
| 185 | bool called_cb = NULL;
|
---|
| 186 | errno_t rc;
|
---|
| 187 |
|
---|
[8aef01c] | 188 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[338d0935] | 189 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 190 |
|
---|
| 191 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 192 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 193 |
|
---|
[d8503fd] | 194 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
[9e84d2c] | 195 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 196 |
|
---|
[338d0935] | 197 | display_wnd_params_init(¶ms);
|
---|
| 198 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 199 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 200 |
|
---|
| 201 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
| 202 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 203 |
|
---|
[9e84d2c] | 204 | /* New window gets focused event */
|
---|
| 205 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 206 |
|
---|
| 207 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 208 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 209 |
|
---|
| 210 | called_cb = false;
|
---|
[338d0935] | 211 |
|
---|
| 212 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 213 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 214 |
|
---|
| 215 | rc = ds_client_post_close_event(client, wnd);
|
---|
| 216 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 217 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 218 |
|
---|
| 219 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 220 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 221 | PCUT_ASSERT_EQUALS(wnd, rwindow);
|
---|
| 222 | PCUT_ASSERT_EQUALS(wev_close, revent.etype);
|
---|
| 223 |
|
---|
| 224 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 225 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 226 |
|
---|
| 227 | ds_window_destroy(wnd);
|
---|
[9e84d2c] | 228 | ds_seat_destroy(seat);
|
---|
[338d0935] | 229 | ds_client_destroy(client);
|
---|
| 230 | ds_display_destroy(disp);
|
---|
| 231 | }
|
---|
| 232 |
|
---|
[b0a94854] | 233 | /** Test ds_client_get_event(), ds_client_post_focus_event(). */
|
---|
| 234 | PCUT_TEST(client_get_post_focus_event)
|
---|
| 235 | {
|
---|
| 236 | ds_display_t *disp;
|
---|
| 237 | ds_client_t *client;
|
---|
[9e84d2c] | 238 | ds_seat_t *seat;
|
---|
[b0a94854] | 239 | ds_window_t *wnd;
|
---|
| 240 | display_wnd_params_t params;
|
---|
| 241 | ds_window_t *rwindow;
|
---|
[46a47c0] | 242 | display_wnd_focus_ev_t efocus;
|
---|
[b0a94854] | 243 | display_wnd_ev_t revent;
|
---|
| 244 | bool called_cb = NULL;
|
---|
| 245 | errno_t rc;
|
---|
| 246 |
|
---|
[8aef01c] | 247 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[b0a94854] | 248 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 249 |
|
---|
| 250 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 251 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 252 |
|
---|
[d8503fd] | 253 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
[9e84d2c] | 254 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 255 |
|
---|
[b0a94854] | 256 | display_wnd_params_init(¶ms);
|
---|
| 257 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 258 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 259 |
|
---|
| 260 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
| 261 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 262 |
|
---|
[9e84d2c] | 263 | /* New window gets focused event */
|
---|
| 264 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 265 |
|
---|
| 266 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 267 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 268 |
|
---|
| 269 | called_cb = false;
|
---|
[b0a94854] | 270 |
|
---|
| 271 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 272 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 273 |
|
---|
[46a47c0] | 274 | efocus.nfocus = 42;
|
---|
| 275 |
|
---|
| 276 | rc = ds_client_post_focus_event(client, wnd, &efocus);
|
---|
[b0a94854] | 277 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 278 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 279 |
|
---|
| 280 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 281 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 282 | PCUT_ASSERT_EQUALS(wnd, rwindow);
|
---|
| 283 | PCUT_ASSERT_EQUALS(wev_focus, revent.etype);
|
---|
[46a47c0] | 284 | PCUT_ASSERT_INT_EQUALS(efocus.nfocus, revent.ev.focus.nfocus);
|
---|
[b0a94854] | 285 |
|
---|
| 286 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 287 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 288 |
|
---|
| 289 | ds_window_destroy(wnd);
|
---|
[9e84d2c] | 290 | ds_seat_destroy(seat);
|
---|
[b0a94854] | 291 | ds_client_destroy(client);
|
---|
| 292 | ds_display_destroy(disp);
|
---|
| 293 | }
|
---|
| 294 |
|
---|
[b2d1df3] | 295 | /** Test ds_client_get_event(), ds_client_post_kbd_event(). */
|
---|
[a40ae0d] | 296 | PCUT_TEST(client_get_post_kbd_event)
|
---|
[b2d1df3] | 297 | {
|
---|
| 298 | ds_display_t *disp;
|
---|
| 299 | ds_client_t *client;
|
---|
[9e84d2c] | 300 | ds_seat_t *seat;
|
---|
[b2d1df3] | 301 | ds_window_t *wnd;
|
---|
[3434233] | 302 | display_wnd_params_t params;
|
---|
[b2d1df3] | 303 | kbd_event_t event;
|
---|
| 304 | ds_window_t *rwindow;
|
---|
| 305 | display_wnd_ev_t revent;
|
---|
| 306 | bool called_cb = NULL;
|
---|
| 307 | errno_t rc;
|
---|
| 308 |
|
---|
[8aef01c] | 309 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[b2d1df3] | 310 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 311 |
|
---|
| 312 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 313 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 314 |
|
---|
[d8503fd] | 315 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
[9e84d2c] | 316 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 317 |
|
---|
[3434233] | 318 | display_wnd_params_init(¶ms);
|
---|
| 319 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 320 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 321 |
|
---|
| 322 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
[b2d1df3] | 323 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 324 |
|
---|
[9e84d2c] | 325 | /* New window gets focused event */
|
---|
| 326 | PCUT_ASSERT_TRUE(called_cb);
|
---|
[b2d1df3] | 327 |
|
---|
[9e84d2c] | 328 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 329 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 330 |
|
---|
| 331 | called_cb = false;
|
---|
[b2d1df3] | 332 |
|
---|
| 333 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 334 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 335 |
|
---|
[9e84d2c] | 336 | event.type = KEY_PRESS;
|
---|
| 337 | event.key = KC_ENTER;
|
---|
| 338 | event.mods = 0;
|
---|
| 339 | event.c = L'\0';
|
---|
| 340 |
|
---|
[b2d1df3] | 341 | rc = ds_client_post_kbd_event(client, wnd, &event);
|
---|
| 342 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 343 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 344 |
|
---|
| 345 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 346 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 347 | PCUT_ASSERT_EQUALS(wnd, rwindow);
|
---|
[f7fb2b21] | 348 | PCUT_ASSERT_EQUALS(wev_kbd, revent.etype);
|
---|
| 349 | PCUT_ASSERT_EQUALS(event.type, revent.ev.kbd.type);
|
---|
| 350 | PCUT_ASSERT_EQUALS(event.key, revent.ev.kbd.key);
|
---|
| 351 | PCUT_ASSERT_EQUALS(event.mods, revent.ev.kbd.mods);
|
---|
| 352 | PCUT_ASSERT_EQUALS(event.c, revent.ev.kbd.c);
|
---|
| 353 |
|
---|
| 354 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 355 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 356 |
|
---|
| 357 | ds_window_destroy(wnd);
|
---|
[9e84d2c] | 358 | ds_seat_destroy(seat);
|
---|
[f7fb2b21] | 359 | ds_client_destroy(client);
|
---|
| 360 | ds_display_destroy(disp);
|
---|
| 361 | }
|
---|
| 362 |
|
---|
| 363 | /** Test ds_client_get_event(), ds_client_post_pos_event(). */
|
---|
| 364 | PCUT_TEST(client_get_post_pos_event)
|
---|
| 365 | {
|
---|
| 366 | ds_display_t *disp;
|
---|
| 367 | ds_client_t *client;
|
---|
[9e84d2c] | 368 | ds_seat_t *seat;
|
---|
[f7fb2b21] | 369 | ds_window_t *wnd;
|
---|
| 370 | display_wnd_params_t params;
|
---|
| 371 | pos_event_t event;
|
---|
| 372 | ds_window_t *rwindow;
|
---|
| 373 | display_wnd_ev_t revent;
|
---|
| 374 | bool called_cb = NULL;
|
---|
| 375 | errno_t rc;
|
---|
| 376 |
|
---|
[8aef01c] | 377 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[f7fb2b21] | 378 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 379 |
|
---|
| 380 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 381 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 382 |
|
---|
[d8503fd] | 383 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
[9e84d2c] | 384 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 385 |
|
---|
[f7fb2b21] | 386 | display_wnd_params_init(¶ms);
|
---|
| 387 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 388 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 389 |
|
---|
| 390 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
| 391 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 392 |
|
---|
[9e84d2c] | 393 | /* New window gets focused event */
|
---|
| 394 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 395 |
|
---|
| 396 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 397 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 398 |
|
---|
| 399 | called_cb = false;
|
---|
[f7fb2b21] | 400 |
|
---|
| 401 | PCUT_ASSERT_FALSE(called_cb);
|
---|
| 402 |
|
---|
| 403 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 404 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 405 |
|
---|
[9e84d2c] | 406 | event.type = POS_PRESS;
|
---|
| 407 | event.hpos = 1;
|
---|
| 408 | event.vpos = 2;
|
---|
| 409 |
|
---|
[f7fb2b21] | 410 | rc = ds_client_post_pos_event(client, wnd, &event);
|
---|
| 411 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 412 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 413 |
|
---|
| 414 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 415 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 416 | PCUT_ASSERT_EQUALS(wnd, rwindow);
|
---|
| 417 | PCUT_ASSERT_EQUALS(wev_pos, revent.etype);
|
---|
| 418 | PCUT_ASSERT_EQUALS(event.type, revent.ev.pos.type);
|
---|
| 419 | PCUT_ASSERT_EQUALS(event.hpos, revent.ev.pos.hpos);
|
---|
| 420 | PCUT_ASSERT_EQUALS(event.vpos, revent.ev.pos.vpos);
|
---|
[b2d1df3] | 421 |
|
---|
[dcac756] | 422 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 423 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 424 |
|
---|
[648e2ac] | 425 | ds_window_destroy(wnd);
|
---|
[9e84d2c] | 426 | ds_seat_destroy(seat);
|
---|
[b2d1df3] | 427 | ds_client_destroy(client);
|
---|
[e022819] | 428 | ds_display_destroy(disp);
|
---|
| 429 | }
|
---|
| 430 |
|
---|
| 431 | /** Test ds_client_get_event(), ds_client_post_resize_event(). */
|
---|
| 432 | PCUT_TEST(client_get_post_resize_event)
|
---|
| 433 | {
|
---|
| 434 | ds_display_t *disp;
|
---|
| 435 | ds_client_t *client;
|
---|
[9e84d2c] | 436 | ds_seat_t *seat;
|
---|
[e022819] | 437 | ds_window_t *wnd;
|
---|
| 438 | display_wnd_params_t params;
|
---|
| 439 | gfx_rect_t rect;
|
---|
| 440 | ds_window_t *rwindow;
|
---|
| 441 | display_wnd_ev_t revent;
|
---|
| 442 | bool called_cb = NULL;
|
---|
| 443 | errno_t rc;
|
---|
| 444 |
|
---|
[8aef01c] | 445 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[e022819] | 446 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 447 |
|
---|
| 448 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 449 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 450 |
|
---|
[d8503fd] | 451 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
[9e84d2c] | 452 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 453 |
|
---|
[e022819] | 454 | display_wnd_params_init(¶ms);
|
---|
| 455 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 456 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 457 |
|
---|
| 458 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
| 459 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 460 |
|
---|
[9e84d2c] | 461 | /* New window gets focused event */
|
---|
| 462 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 463 |
|
---|
| 464 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 465 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 466 |
|
---|
| 467 | called_cb = false;
|
---|
[e022819] | 468 |
|
---|
| 469 | PCUT_ASSERT_FALSE(called_cb);
|
---|
| 470 |
|
---|
| 471 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 472 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 473 |
|
---|
[9e84d2c] | 474 | rect.p0.x = 1;
|
---|
| 475 | rect.p0.y = 2;
|
---|
| 476 | rect.p1.x = 3;
|
---|
| 477 | rect.p1.y = 4;
|
---|
| 478 |
|
---|
[e022819] | 479 | rc = ds_client_post_resize_event(client, wnd, &rect);
|
---|
| 480 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 481 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 482 |
|
---|
| 483 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 484 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 485 | PCUT_ASSERT_EQUALS(wnd, rwindow);
|
---|
| 486 | PCUT_ASSERT_EQUALS(wev_resize, revent.etype);
|
---|
| 487 | PCUT_ASSERT_EQUALS(rect.p0.x, revent.ev.resize.rect.p0.x);
|
---|
| 488 | PCUT_ASSERT_EQUALS(rect.p0.y, revent.ev.resize.rect.p0.y);
|
---|
| 489 | PCUT_ASSERT_EQUALS(rect.p1.x, revent.ev.resize.rect.p1.x);
|
---|
| 490 | PCUT_ASSERT_EQUALS(rect.p1.y, revent.ev.resize.rect.p1.y);
|
---|
| 491 |
|
---|
| 492 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 493 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 494 |
|
---|
| 495 | ds_window_destroy(wnd);
|
---|
[9e84d2c] | 496 | ds_seat_destroy(seat);
|
---|
[e022819] | 497 | ds_client_destroy(client);
|
---|
[b2d1df3] | 498 | ds_display_destroy(disp);
|
---|
| 499 | }
|
---|
| 500 |
|
---|
[b0a94854] | 501 | /** Test ds_client_get_event(), ds_client_post_unfocus_event(). */
|
---|
| 502 | PCUT_TEST(client_get_post_unfocus_event)
|
---|
| 503 | {
|
---|
| 504 | ds_display_t *disp;
|
---|
| 505 | ds_client_t *client;
|
---|
[9e84d2c] | 506 | ds_seat_t *seat;
|
---|
[b0a94854] | 507 | ds_window_t *wnd;
|
---|
| 508 | display_wnd_params_t params;
|
---|
| 509 | ds_window_t *rwindow;
|
---|
[46a47c0] | 510 | display_wnd_unfocus_ev_t eunfocus;
|
---|
[b0a94854] | 511 | display_wnd_ev_t revent;
|
---|
| 512 | bool called_cb = NULL;
|
---|
| 513 | errno_t rc;
|
---|
| 514 |
|
---|
[8aef01c] | 515 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[b0a94854] | 516 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 517 |
|
---|
| 518 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 519 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 520 |
|
---|
[d8503fd] | 521 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
[9e84d2c] | 522 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 523 |
|
---|
[b0a94854] | 524 | display_wnd_params_init(¶ms);
|
---|
| 525 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 526 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 527 |
|
---|
| 528 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
| 529 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 530 |
|
---|
[9e84d2c] | 531 | /* New window gets focused event */
|
---|
| 532 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 533 |
|
---|
| 534 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 535 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 536 |
|
---|
| 537 | called_cb = false;
|
---|
[b0a94854] | 538 |
|
---|
| 539 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 540 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 541 |
|
---|
[46a47c0] | 542 | eunfocus.nfocus = 42;
|
---|
| 543 |
|
---|
| 544 | rc = ds_client_post_unfocus_event(client, wnd, &eunfocus);
|
---|
[b0a94854] | 545 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 546 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 547 |
|
---|
| 548 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 549 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 550 | PCUT_ASSERT_EQUALS(wnd, rwindow);
|
---|
| 551 | PCUT_ASSERT_EQUALS(wev_unfocus, revent.etype);
|
---|
[46a47c0] | 552 | PCUT_ASSERT_INT_EQUALS(eunfocus.nfocus, revent.ev.unfocus.nfocus);
|
---|
[b0a94854] | 553 |
|
---|
| 554 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
[98735eb] | 555 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 556 |
|
---|
| 557 | ds_window_destroy(wnd);
|
---|
| 558 | ds_seat_destroy(seat);
|
---|
| 559 | ds_client_destroy(client);
|
---|
| 560 | ds_display_destroy(disp);
|
---|
| 561 | }
|
---|
| 562 |
|
---|
| 563 | /** Test ds_client_purge_window_events() */
|
---|
| 564 | PCUT_TEST(client_purge_window_events)
|
---|
| 565 | {
|
---|
| 566 | ds_display_t *disp;
|
---|
| 567 | ds_client_t *client;
|
---|
| 568 | ds_seat_t *seat;
|
---|
| 569 | ds_window_t *wnd;
|
---|
| 570 | display_wnd_params_t params;
|
---|
| 571 | ds_window_t *rwindow;
|
---|
| 572 | display_wnd_ev_t revent;
|
---|
| 573 | bool called_cb = NULL;
|
---|
| 574 | errno_t rc;
|
---|
| 575 |
|
---|
| 576 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
| 577 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 578 |
|
---|
| 579 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 580 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 581 |
|
---|
[d8503fd] | 582 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
[98735eb] | 583 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 584 |
|
---|
| 585 | display_wnd_params_init(¶ms);
|
---|
| 586 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 587 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 588 |
|
---|
| 589 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
| 590 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 591 |
|
---|
| 592 | /* New window gets focused event */
|
---|
| 593 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 594 |
|
---|
| 595 | /* Purge it */
|
---|
| 596 | ds_client_purge_window_events(client, wnd);
|
---|
| 597 |
|
---|
| 598 | /* The queue should be empty now */
|
---|
| 599 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
[b0a94854] | 600 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 601 |
|
---|
| 602 | ds_window_destroy(wnd);
|
---|
[9e84d2c] | 603 | ds_seat_destroy(seat);
|
---|
[b0a94854] | 604 | ds_client_destroy(client);
|
---|
| 605 | ds_display_destroy(disp);
|
---|
| 606 | }
|
---|
| 607 |
|
---|
[da412547] | 608 | /** Test client being destroyed while still having a window.
|
---|
| 609 | *
|
---|
| 610 | * This can happen if client forgets to destroy window or if the client
|
---|
| 611 | * is disconnected (or terminated).
|
---|
| 612 | */
|
---|
| 613 | PCUT_TEST(client_leftover_window)
|
---|
| 614 | {
|
---|
| 615 | ds_display_t *disp;
|
---|
| 616 | ds_client_t *client;
|
---|
[9e84d2c] | 617 | ds_seat_t *seat;
|
---|
[da412547] | 618 | ds_window_t *wnd;
|
---|
[3434233] | 619 | display_wnd_params_t params;
|
---|
[da412547] | 620 | errno_t rc;
|
---|
| 621 |
|
---|
[8aef01c] | 622 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[da412547] | 623 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 624 |
|
---|
| 625 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
| 626 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 627 |
|
---|
[d8503fd] | 628 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
[9e84d2c] | 629 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 630 |
|
---|
[3434233] | 631 | display_wnd_params_init(¶ms);
|
---|
| 632 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 633 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 634 |
|
---|
| 635 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
[da412547] | 636 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 637 |
|
---|
[9e84d2c] | 638 | ds_seat_destroy(seat);
|
---|
[da412547] | 639 | ds_client_destroy(client);
|
---|
| 640 | ds_display_destroy(disp);
|
---|
| 641 | }
|
---|
| 642 |
|
---|
[b2d1df3] | 643 | PCUT_EXPORT(client);
|
---|