| 1 | /*
|
|---|
| 2 | * Copyright (c) 2023 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 <str.h>
|
|---|
| 33 |
|
|---|
| 34 | #include "../client.h"
|
|---|
| 35 | #include "../display.h"
|
|---|
| 36 | #include "../seat.h"
|
|---|
| 37 | #include "../window.h"
|
|---|
| 38 |
|
|---|
| 39 | PCUT_INIT;
|
|---|
| 40 |
|
|---|
| 41 | PCUT_TEST_SUITE(seat);
|
|---|
| 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 | /** Set focus. */
|
|---|
| 56 | PCUT_TEST(set_focus)
|
|---|
| 57 | {
|
|---|
| 58 | ds_display_t *disp;
|
|---|
| 59 | ds_client_t *client;
|
|---|
| 60 | ds_seat_t *seat;
|
|---|
| 61 | ds_window_t *wnd;
|
|---|
| 62 | display_wnd_params_t params;
|
|---|
| 63 | bool called_cb = false;
|
|---|
| 64 | errno_t rc;
|
|---|
| 65 |
|
|---|
| 66 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 67 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 68 |
|
|---|
| 69 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 70 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 71 |
|
|---|
| 72 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 73 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 74 |
|
|---|
| 75 | display_wnd_params_init(¶ms);
|
|---|
| 76 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 77 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 78 |
|
|---|
| 79 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 80 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 81 |
|
|---|
| 82 | ds_seat_set_focus(seat, wnd);
|
|---|
| 83 | PCUT_ASSERT_EQUALS(wnd, seat->focus);
|
|---|
| 84 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 85 |
|
|---|
| 86 | ds_window_destroy(wnd);
|
|---|
| 87 | ds_seat_destroy(seat);
|
|---|
| 88 | ds_client_destroy(client);
|
|---|
| 89 | ds_display_destroy(disp);
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | /** Evacuate focus from window.
|
|---|
| 93 | *
|
|---|
| 94 | * After evacuating no window should be focused
|
|---|
| 95 | */
|
|---|
| 96 | PCUT_TEST(evac_focus_one_window)
|
|---|
| 97 | {
|
|---|
| 98 | ds_display_t *disp;
|
|---|
| 99 | ds_client_t *client;
|
|---|
| 100 | ds_seat_t *seat;
|
|---|
| 101 | ds_window_t *wnd;
|
|---|
| 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, "Alice", &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, &wnd);
|
|---|
| 120 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 121 |
|
|---|
| 122 | ds_seat_set_focus(seat, wnd);
|
|---|
| 123 | PCUT_ASSERT_EQUALS(wnd, seat->focus);
|
|---|
| 124 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 125 | called_cb = false;
|
|---|
| 126 |
|
|---|
| 127 | ds_seat_evac_wnd_refs(seat, wnd);
|
|---|
| 128 | PCUT_ASSERT_NULL(seat->focus);
|
|---|
| 129 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 130 |
|
|---|
| 131 | ds_window_destroy(wnd);
|
|---|
| 132 | ds_seat_destroy(seat);
|
|---|
| 133 | ds_client_destroy(client);
|
|---|
| 134 | ds_display_destroy(disp);
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | /** Evacuate popup reference from window.
|
|---|
| 138 | *
|
|---|
| 139 | * After evacuating no window should be set as the popup
|
|---|
| 140 | */
|
|---|
| 141 | PCUT_TEST(evac_popup)
|
|---|
| 142 | {
|
|---|
| 143 | ds_display_t *disp;
|
|---|
| 144 | ds_client_t *client;
|
|---|
| 145 | ds_seat_t *seat;
|
|---|
| 146 | ds_window_t *wnd;
|
|---|
| 147 | display_wnd_params_t params;
|
|---|
| 148 | bool called_cb = false;
|
|---|
| 149 | errno_t rc;
|
|---|
| 150 |
|
|---|
| 151 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 152 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 153 |
|
|---|
| 154 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 155 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 156 |
|
|---|
| 157 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 158 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 159 |
|
|---|
| 160 | display_wnd_params_init(¶ms);
|
|---|
| 161 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 162 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 163 | params.flags |= wndf_popup;
|
|---|
| 164 |
|
|---|
| 165 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 166 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 167 |
|
|---|
| 168 | PCUT_ASSERT_EQUALS(wnd, seat->popup);
|
|---|
| 169 |
|
|---|
| 170 | ds_seat_evac_wnd_refs(seat, wnd);
|
|---|
| 171 | PCUT_ASSERT_NULL(seat->popup);
|
|---|
| 172 |
|
|---|
| 173 | ds_window_destroy(wnd);
|
|---|
| 174 | ds_seat_destroy(seat);
|
|---|
| 175 | ds_client_destroy(client);
|
|---|
| 176 | ds_display_destroy(disp);
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | /** Unfocus window when three windows are available */
|
|---|
| 180 | PCUT_TEST(unfocus_wnd_three_windows)
|
|---|
| 181 | {
|
|---|
| 182 | ds_display_t *disp;
|
|---|
| 183 | ds_client_t *client;
|
|---|
| 184 | ds_seat_t *seat;
|
|---|
| 185 | ds_window_t *w0;
|
|---|
| 186 | ds_window_t *w1;
|
|---|
| 187 | ds_window_t *w2;
|
|---|
| 188 | display_wnd_params_t params;
|
|---|
| 189 | bool called_cb = false;
|
|---|
| 190 | errno_t rc;
|
|---|
| 191 |
|
|---|
| 192 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 193 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 194 |
|
|---|
| 195 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 196 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 197 |
|
|---|
| 198 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 199 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 200 |
|
|---|
| 201 | display_wnd_params_init(¶ms);
|
|---|
| 202 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 203 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 204 |
|
|---|
| 205 | rc = ds_window_create(client, ¶ms, &w2);
|
|---|
| 206 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 207 |
|
|---|
| 208 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 209 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 210 |
|
|---|
| 211 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 212 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 213 |
|
|---|
| 214 | /* w0 is at the top, then w1, then w2 */
|
|---|
| 215 |
|
|---|
| 216 | PCUT_ASSERT_EQUALS(w0, seat->focus);
|
|---|
| 217 |
|
|---|
| 218 | ds_window_unfocus(w0);
|
|---|
| 219 |
|
|---|
| 220 | /* The previous window, w1, should be focused now */
|
|---|
| 221 | PCUT_ASSERT_EQUALS(w1, seat->focus);
|
|---|
| 222 |
|
|---|
| 223 | ds_window_destroy(w0);
|
|---|
| 224 | ds_window_destroy(w1);
|
|---|
| 225 | ds_seat_destroy(seat);
|
|---|
| 226 | ds_client_destroy(client);
|
|---|
| 227 | ds_display_destroy(disp);
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | /** Unfocus window when two windows and one system window are available */
|
|---|
| 231 | PCUT_TEST(unfocus_wnd_two_windows_one_sys)
|
|---|
| 232 | {
|
|---|
| 233 | ds_display_t *disp;
|
|---|
| 234 | ds_client_t *client;
|
|---|
| 235 | ds_seat_t *seat;
|
|---|
| 236 | ds_window_t *w0;
|
|---|
| 237 | ds_window_t *w1;
|
|---|
| 238 | ds_window_t *w2;
|
|---|
| 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(¶ms);
|
|---|
| 253 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 254 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 255 |
|
|---|
| 256 | params.flags |= wndf_system;
|
|---|
| 257 | rc = ds_window_create(client, ¶ms, &w2);
|
|---|
| 258 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 259 |
|
|---|
| 260 | params.flags &= ~wndf_system;
|
|---|
| 261 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 262 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 263 |
|
|---|
| 264 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 265 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 266 |
|
|---|
| 267 | PCUT_ASSERT_EQUALS(w0, seat->focus);
|
|---|
| 268 |
|
|---|
| 269 | ds_window_unfocus(w0);
|
|---|
| 270 |
|
|---|
| 271 | /* The previous non-system window is w1, w2 should be skipped */
|
|---|
| 272 | PCUT_ASSERT_EQUALS(w1, seat->focus);
|
|---|
| 273 |
|
|---|
| 274 | ds_window_destroy(w0);
|
|---|
| 275 | ds_window_destroy(w1);
|
|---|
| 276 | ds_seat_destroy(seat);
|
|---|
| 277 | ds_client_destroy(client);
|
|---|
| 278 | ds_display_destroy(disp);
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | /** Unfocus window when one window and one system window is available */
|
|---|
| 282 | PCUT_TEST(unfocus_wnd_one_window_one_sys)
|
|---|
| 283 | {
|
|---|
| 284 | ds_display_t *disp;
|
|---|
| 285 | ds_client_t *client;
|
|---|
| 286 | ds_seat_t *seat;
|
|---|
| 287 | ds_window_t *w0;
|
|---|
| 288 | ds_window_t *w1;
|
|---|
| 289 | display_wnd_params_t params;
|
|---|
| 290 | bool called_cb = false;
|
|---|
| 291 | errno_t rc;
|
|---|
| 292 |
|
|---|
| 293 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 294 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 295 |
|
|---|
| 296 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 297 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 298 |
|
|---|
| 299 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 300 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 301 |
|
|---|
| 302 | display_wnd_params_init(¶ms);
|
|---|
| 303 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 304 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 305 |
|
|---|
| 306 | params.flags |= wndf_system;
|
|---|
| 307 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 308 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 309 |
|
|---|
| 310 | params.flags &= ~wndf_system;
|
|---|
| 311 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 312 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 313 |
|
|---|
| 314 | PCUT_ASSERT_EQUALS(w0, seat->focus);
|
|---|
| 315 |
|
|---|
| 316 | ds_window_unfocus(w0);
|
|---|
| 317 |
|
|---|
| 318 | /* Since no non-system window is available, w1 should be focused */
|
|---|
| 319 | PCUT_ASSERT_EQUALS(w1, seat->focus);
|
|---|
| 320 |
|
|---|
| 321 | ds_window_destroy(w0);
|
|---|
| 322 | ds_window_destroy(w1);
|
|---|
| 323 | ds_seat_destroy(seat);
|
|---|
| 324 | ds_client_destroy(client);
|
|---|
| 325 | ds_display_destroy(disp);
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | /** Unfocus window when one window is available */
|
|---|
| 329 | PCUT_TEST(unfocus_wnd_one_window)
|
|---|
| 330 | {
|
|---|
| 331 | ds_display_t *disp;
|
|---|
| 332 | ds_client_t *client;
|
|---|
| 333 | ds_seat_t *seat;
|
|---|
| 334 | ds_window_t *w0;
|
|---|
| 335 | display_wnd_params_t params;
|
|---|
| 336 | bool called_cb = false;
|
|---|
| 337 | errno_t rc;
|
|---|
| 338 |
|
|---|
| 339 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 340 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 341 |
|
|---|
| 342 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 343 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 344 |
|
|---|
| 345 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 346 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 347 |
|
|---|
| 348 | display_wnd_params_init(¶ms);
|
|---|
| 349 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 350 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 351 |
|
|---|
| 352 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 353 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 354 |
|
|---|
| 355 | PCUT_ASSERT_EQUALS(w0, seat->focus);
|
|---|
| 356 |
|
|---|
| 357 | ds_window_unfocus(w0);
|
|---|
| 358 |
|
|---|
| 359 | /* Since no other window is availabe, no window should be focused */
|
|---|
| 360 | PCUT_ASSERT_EQUALS(NULL, seat->focus);
|
|---|
| 361 |
|
|---|
| 362 | ds_window_destroy(w0);
|
|---|
| 363 | ds_seat_destroy(seat);
|
|---|
| 364 | ds_client_destroy(client);
|
|---|
| 365 | ds_display_destroy(disp);
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 | /** Switch focus when another window is available. */
|
|---|
| 369 | PCUT_TEST(switch_focus_two_windows)
|
|---|
| 370 | {
|
|---|
| 371 | ds_display_t *disp;
|
|---|
| 372 | ds_client_t *client;
|
|---|
| 373 | ds_seat_t *seat;
|
|---|
| 374 | ds_window_t *w0;
|
|---|
| 375 | ds_window_t *w1;
|
|---|
| 376 | display_wnd_params_t params;
|
|---|
| 377 | bool called_cb = false;
|
|---|
| 378 | errno_t rc;
|
|---|
| 379 |
|
|---|
| 380 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 381 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 382 |
|
|---|
| 383 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 384 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 385 |
|
|---|
| 386 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 387 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 388 |
|
|---|
| 389 | display_wnd_params_init(¶ms);
|
|---|
| 390 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 391 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 392 |
|
|---|
| 393 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 394 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 395 |
|
|---|
| 396 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 397 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 398 |
|
|---|
| 399 | ds_seat_set_focus(seat, w1);
|
|---|
| 400 | PCUT_ASSERT_EQUALS(w1, seat->focus);
|
|---|
| 401 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 402 | called_cb = false;
|
|---|
| 403 |
|
|---|
| 404 | ds_seat_switch_focus(seat);
|
|---|
| 405 | PCUT_ASSERT_EQUALS(w0, seat->focus);
|
|---|
| 406 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 407 |
|
|---|
| 408 | ds_window_destroy(w0);
|
|---|
| 409 | ds_window_destroy(w1);
|
|---|
| 410 | ds_seat_destroy(seat);
|
|---|
| 411 | ds_client_destroy(client);
|
|---|
| 412 | ds_display_destroy(disp);
|
|---|
| 413 | }
|
|---|
| 414 |
|
|---|
| 415 | /** Switch focus with just one existing window.
|
|---|
| 416 | *
|
|---|
| 417 | * After switching the focus should remain with the same window.
|
|---|
| 418 | */
|
|---|
| 419 | PCUT_TEST(switch_focus_one_window)
|
|---|
| 420 | {
|
|---|
| 421 | ds_display_t *disp;
|
|---|
| 422 | ds_client_t *client;
|
|---|
| 423 | ds_seat_t *seat;
|
|---|
| 424 | ds_window_t *wnd;
|
|---|
| 425 | display_wnd_params_t params;
|
|---|
| 426 | bool called_cb = false;
|
|---|
| 427 | errno_t rc;
|
|---|
| 428 |
|
|---|
| 429 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 430 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 431 |
|
|---|
| 432 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 433 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 434 |
|
|---|
| 435 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 436 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 437 |
|
|---|
| 438 | display_wnd_params_init(¶ms);
|
|---|
| 439 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 440 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 441 |
|
|---|
| 442 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 443 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 444 |
|
|---|
| 445 | ds_seat_set_focus(seat, wnd);
|
|---|
| 446 | PCUT_ASSERT_EQUALS(wnd, seat->focus);
|
|---|
| 447 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 448 | called_cb = false;
|
|---|
| 449 |
|
|---|
| 450 | ds_seat_switch_focus(seat);
|
|---|
| 451 | PCUT_ASSERT_EQUALS(wnd, seat->focus);
|
|---|
| 452 | PCUT_ASSERT_FALSE(called_cb);
|
|---|
| 453 |
|
|---|
| 454 | ds_window_destroy(wnd);
|
|---|
| 455 | ds_seat_destroy(seat);
|
|---|
| 456 | ds_client_destroy(client);
|
|---|
| 457 | ds_display_destroy(disp);
|
|---|
| 458 | }
|
|---|
| 459 |
|
|---|
| 460 | /** Test ds_seat_post_kbd_event() with Alt-Tab switches focus */
|
|---|
| 461 | PCUT_TEST(post_kbd_event_alt_tab)
|
|---|
| 462 | {
|
|---|
| 463 | ds_display_t *disp;
|
|---|
| 464 | ds_client_t *client;
|
|---|
| 465 | ds_seat_t *seat;
|
|---|
| 466 | ds_window_t *w0;
|
|---|
| 467 | ds_window_t *w1;
|
|---|
| 468 | display_wnd_params_t params;
|
|---|
| 469 | bool called_cb = false;
|
|---|
| 470 | kbd_event_t event;
|
|---|
| 471 | errno_t rc;
|
|---|
| 472 |
|
|---|
| 473 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 474 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 475 |
|
|---|
| 476 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 477 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 478 |
|
|---|
| 479 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 480 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 481 |
|
|---|
| 482 | display_wnd_params_init(¶ms);
|
|---|
| 483 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 484 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 485 |
|
|---|
| 486 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 487 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 488 |
|
|---|
| 489 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 490 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 491 |
|
|---|
| 492 | ds_seat_set_focus(seat, w1);
|
|---|
| 493 | PCUT_ASSERT_EQUALS(w1, seat->focus);
|
|---|
| 494 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 495 | called_cb = false;
|
|---|
| 496 |
|
|---|
| 497 | event.type = KEY_PRESS;
|
|---|
| 498 | event.mods = KM_ALT;
|
|---|
| 499 | event.key = KC_TAB;
|
|---|
| 500 | rc = ds_seat_post_kbd_event(seat, &event);
|
|---|
| 501 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 502 | PCUT_ASSERT_EQUALS(w0, seat->focus);
|
|---|
| 503 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 504 |
|
|---|
| 505 | ds_window_destroy(w0);
|
|---|
| 506 | ds_window_destroy(w1);
|
|---|
| 507 | ds_seat_destroy(seat);
|
|---|
| 508 | ds_client_destroy(client);
|
|---|
| 509 | ds_display_destroy(disp);
|
|---|
| 510 | }
|
|---|
| 511 |
|
|---|
| 512 | /** Test ds_seat_post_kbd_event() with regular key press delivers to client queue */
|
|---|
| 513 | PCUT_TEST(post_kbd_event_regular)
|
|---|
| 514 | {
|
|---|
| 515 | ds_display_t *disp;
|
|---|
| 516 | ds_client_t *client;
|
|---|
| 517 | ds_seat_t *seat;
|
|---|
| 518 | ds_window_t *wnd;
|
|---|
| 519 | display_wnd_params_t params;
|
|---|
| 520 | kbd_event_t event;
|
|---|
| 521 | ds_window_t *rwindow;
|
|---|
| 522 | display_wnd_ev_t revent;
|
|---|
| 523 | bool called_cb = false;
|
|---|
| 524 | errno_t rc;
|
|---|
| 525 |
|
|---|
| 526 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 527 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 528 |
|
|---|
| 529 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 530 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 531 |
|
|---|
| 532 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 533 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 534 |
|
|---|
| 535 | display_wnd_params_init(¶ms);
|
|---|
| 536 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 537 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 538 |
|
|---|
| 539 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 540 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 541 |
|
|---|
| 542 | ds_seat_set_focus(seat, wnd);
|
|---|
| 543 | PCUT_ASSERT_EQUALS(wnd, seat->focus);
|
|---|
| 544 |
|
|---|
| 545 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 546 | rc = ds_client_get_event(client, &rwindow, &revent);
|
|---|
| 547 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 548 | called_cb = false;
|
|---|
| 549 |
|
|---|
| 550 | event.type = KEY_PRESS;
|
|---|
| 551 | event.key = KC_ENTER;
|
|---|
| 552 | event.mods = 0;
|
|---|
| 553 | event.c = L'\0';
|
|---|
| 554 |
|
|---|
| 555 | rc = ds_client_get_event(client, &rwindow, &revent);
|
|---|
| 556 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
|---|
| 557 |
|
|---|
| 558 | rc = ds_seat_post_kbd_event(seat, &event);
|
|---|
| 559 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 560 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 561 |
|
|---|
| 562 | rc = ds_client_get_event(client, &rwindow, &revent);
|
|---|
| 563 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 564 | PCUT_ASSERT_EQUALS(wnd, rwindow);
|
|---|
| 565 | PCUT_ASSERT_EQUALS(wev_kbd, revent.etype);
|
|---|
| 566 | PCUT_ASSERT_EQUALS(event.type, revent.ev.kbd.type);
|
|---|
| 567 | PCUT_ASSERT_EQUALS(event.key, revent.ev.kbd.key);
|
|---|
| 568 | PCUT_ASSERT_EQUALS(event.mods, revent.ev.kbd.mods);
|
|---|
| 569 | PCUT_ASSERT_EQUALS(event.c, revent.ev.kbd.c);
|
|---|
| 570 |
|
|---|
| 571 | rc = ds_client_get_event(client, &rwindow, &revent);
|
|---|
| 572 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
|---|
| 573 |
|
|---|
| 574 | ds_window_destroy(wnd);
|
|---|
| 575 | ds_seat_destroy(seat);
|
|---|
| 576 | ds_client_destroy(client);
|
|---|
| 577 | ds_display_destroy(disp);
|
|---|
| 578 | }
|
|---|
| 579 |
|
|---|
| 580 | /** Test ds_seat_post_ptd_event() with click on window switches focus
|
|---|
| 581 | */
|
|---|
| 582 | PCUT_TEST(post_ptd_event_wnd_switch)
|
|---|
| 583 | {
|
|---|
| 584 | ds_display_t *disp;
|
|---|
| 585 | ds_seat_t *seat;
|
|---|
| 586 | ds_client_t *client;
|
|---|
| 587 | ds_window_t *w0, *w1;
|
|---|
| 588 | display_wnd_params_t params;
|
|---|
| 589 | ptd_event_t event;
|
|---|
| 590 | bool called_cb = false;
|
|---|
| 591 | errno_t rc;
|
|---|
| 592 |
|
|---|
| 593 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 594 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 595 |
|
|---|
| 596 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 597 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 598 |
|
|---|
| 599 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 600 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 601 |
|
|---|
| 602 | /* Set up display size to allow the pointer a range of movement */
|
|---|
| 603 | disp->rect.p1.x = 500;
|
|---|
| 604 | disp->rect.p1.y = 500;
|
|---|
| 605 |
|
|---|
| 606 | display_wnd_params_init(¶ms);
|
|---|
| 607 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 608 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 609 |
|
|---|
| 610 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 611 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 612 |
|
|---|
| 613 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 614 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 615 |
|
|---|
| 616 | w0->dpos.x = 10;
|
|---|
| 617 | w0->dpos.y = 10;
|
|---|
| 618 |
|
|---|
| 619 | w1->dpos.x = 400;
|
|---|
| 620 | w1->dpos.y = 400;
|
|---|
| 621 |
|
|---|
| 622 | /* New window gets focused event */
|
|---|
| 623 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 624 |
|
|---|
| 625 | called_cb = false;
|
|---|
| 626 |
|
|---|
| 627 | ds_seat_set_focus(seat, w0);
|
|---|
| 628 |
|
|---|
| 629 | event.type = PTD_MOVE;
|
|---|
| 630 | event.dmove.x = 400;
|
|---|
| 631 | event.dmove.y = 400;
|
|---|
| 632 | rc = ds_seat_post_ptd_event(seat, &event);
|
|---|
| 633 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 634 |
|
|---|
| 635 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 636 | called_cb = false;
|
|---|
| 637 |
|
|---|
| 638 | event.type = PTD_PRESS;
|
|---|
| 639 | event.btn_num = 1;
|
|---|
| 640 | rc = ds_seat_post_ptd_event(seat, &event);
|
|---|
| 641 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 642 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 643 | called_cb = false;
|
|---|
| 644 |
|
|---|
| 645 | PCUT_ASSERT_EQUALS(w1, seat->focus);
|
|---|
| 646 |
|
|---|
| 647 | event.type = PTD_MOVE;
|
|---|
| 648 | event.dmove.x = -400 + 10;
|
|---|
| 649 | event.dmove.y = -400 + 10;
|
|---|
| 650 | rc = ds_seat_post_ptd_event(seat, &event);
|
|---|
| 651 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 652 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 653 | called_cb = false;
|
|---|
| 654 |
|
|---|
| 655 | event.type = PTD_PRESS;
|
|---|
| 656 | event.btn_num = 1;
|
|---|
| 657 | rc = ds_seat_post_ptd_event(seat, &event);
|
|---|
| 658 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 659 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 660 | called_cb = false;
|
|---|
| 661 |
|
|---|
| 662 | PCUT_ASSERT_EQUALS(w0, seat->focus);
|
|---|
| 663 |
|
|---|
| 664 | ds_window_destroy(w0);
|
|---|
| 665 | ds_window_destroy(w1);
|
|---|
| 666 | ds_client_destroy(client);
|
|---|
| 667 | ds_seat_destroy(seat);
|
|---|
| 668 | ds_display_destroy(disp);
|
|---|
| 669 | }
|
|---|
| 670 |
|
|---|
| 671 | /** Test ds_seat_post_pos_event() */
|
|---|
| 672 | PCUT_TEST(post_pos_event)
|
|---|
| 673 | {
|
|---|
| 674 | // XXX
|
|---|
| 675 | }
|
|---|
| 676 |
|
|---|
| 677 | /** Set WM cursor */
|
|---|
| 678 | PCUT_TEST(set_wm_cursor)
|
|---|
| 679 | {
|
|---|
| 680 | ds_display_t *disp;
|
|---|
| 681 | ds_client_t *client;
|
|---|
| 682 | ds_seat_t *seat;
|
|---|
| 683 | bool called_cb = false;
|
|---|
| 684 | errno_t rc;
|
|---|
| 685 |
|
|---|
| 686 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 687 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 688 |
|
|---|
| 689 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 690 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 691 |
|
|---|
| 692 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 693 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 694 |
|
|---|
| 695 | ds_seat_set_wm_cursor(seat, disp->cursor[dcurs_size_ud]);
|
|---|
| 696 | ds_seat_set_wm_cursor(seat, NULL);
|
|---|
| 697 |
|
|---|
| 698 | ds_seat_destroy(seat);
|
|---|
| 699 | ds_client_destroy(client);
|
|---|
| 700 | ds_display_destroy(disp);
|
|---|
| 701 | }
|
|---|
| 702 |
|
|---|
| 703 | PCUT_EXPORT(seat);
|
|---|