| 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 "../cfgclient.h"
|
|---|
| 35 | #include "../client.h"
|
|---|
| 36 | #include "../display.h"
|
|---|
| 37 | #include "../seat.h"
|
|---|
| 38 | #include "../window.h"
|
|---|
| 39 | #include "../wmclient.h"
|
|---|
| 40 |
|
|---|
| 41 | PCUT_INIT;
|
|---|
| 42 |
|
|---|
| 43 | PCUT_TEST_SUITE(display);
|
|---|
| 44 |
|
|---|
| 45 | static void test_ds_ev_pending(void *);
|
|---|
| 46 |
|
|---|
| 47 | static ds_client_cb_t test_ds_client_cb = {
|
|---|
| 48 | .ev_pending = test_ds_ev_pending
|
|---|
| 49 | };
|
|---|
| 50 |
|
|---|
| 51 | static void test_ds_wmev_pending(void *);
|
|---|
| 52 |
|
|---|
| 53 | static ds_wmclient_cb_t test_ds_wmclient_cb = {
|
|---|
| 54 | .ev_pending = test_ds_wmev_pending
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| 57 | static void test_ds_cfgev_pending(void *);
|
|---|
| 58 |
|
|---|
| 59 | static ds_cfgclient_cb_t test_ds_cfgclient_cb = {
|
|---|
| 60 | .ev_pending = test_ds_cfgev_pending
|
|---|
| 61 | };
|
|---|
| 62 |
|
|---|
| 63 | static void test_ds_ev_pending(void *arg)
|
|---|
| 64 | {
|
|---|
| 65 | bool *called_cb = (bool *) arg;
|
|---|
| 66 | *called_cb = true;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | static void test_ds_wmev_pending(void *arg)
|
|---|
| 70 | {
|
|---|
| 71 | bool *called_cb = (bool *) arg;
|
|---|
| 72 | *called_cb = true;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | static void test_ds_cfgev_pending(void *arg)
|
|---|
| 76 | {
|
|---|
| 77 | bool *called_cb = (bool *) arg;
|
|---|
| 78 | *called_cb = true;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | /** Display creation and destruction. */
|
|---|
| 82 | PCUT_TEST(display_create_destroy)
|
|---|
| 83 | {
|
|---|
| 84 | ds_display_t *disp;
|
|---|
| 85 | errno_t rc;
|
|---|
| 86 |
|
|---|
| 87 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 88 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 89 |
|
|---|
| 90 | ds_display_destroy(disp);
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | /** Basic client operation. */
|
|---|
| 94 | PCUT_TEST(display_client)
|
|---|
| 95 | {
|
|---|
| 96 | ds_display_t *disp;
|
|---|
| 97 | ds_client_t *client;
|
|---|
| 98 | ds_client_t *c0, *c1;
|
|---|
| 99 | errno_t rc;
|
|---|
| 100 |
|
|---|
| 101 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 102 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 103 |
|
|---|
| 104 | rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
|
|---|
| 105 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 106 |
|
|---|
| 107 | c0 = ds_display_first_client(disp);
|
|---|
| 108 | PCUT_ASSERT_EQUALS(c0, client);
|
|---|
| 109 |
|
|---|
| 110 | c1 = ds_display_next_client(c0);
|
|---|
| 111 | PCUT_ASSERT_NULL(c1);
|
|---|
| 112 |
|
|---|
| 113 | ds_client_destroy(client);
|
|---|
| 114 | ds_display_destroy(disp);
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | /** Basic WM client operation. */
|
|---|
| 118 | PCUT_TEST(display_wmclient)
|
|---|
| 119 | {
|
|---|
| 120 | ds_display_t *disp;
|
|---|
| 121 | ds_wmclient_t *wmclient;
|
|---|
| 122 | ds_wmclient_t *c0, *c1;
|
|---|
| 123 | errno_t rc;
|
|---|
| 124 |
|
|---|
| 125 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 126 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 127 |
|
|---|
| 128 | rc = ds_wmclient_create(disp, &test_ds_wmclient_cb, NULL, &wmclient);
|
|---|
| 129 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 130 |
|
|---|
| 131 | c0 = ds_display_first_wmclient(disp);
|
|---|
| 132 | PCUT_ASSERT_EQUALS(c0, wmclient);
|
|---|
| 133 |
|
|---|
| 134 | c1 = ds_display_next_wmclient(c0);
|
|---|
| 135 | PCUT_ASSERT_NULL(c1);
|
|---|
| 136 |
|
|---|
| 137 | ds_wmclient_destroy(wmclient);
|
|---|
| 138 | ds_display_destroy(disp);
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | /** Basic CFG client operation. */
|
|---|
| 142 | PCUT_TEST(display_cfgclient)
|
|---|
| 143 | {
|
|---|
| 144 | ds_display_t *disp;
|
|---|
| 145 | ds_cfgclient_t *cfgclient;
|
|---|
| 146 | errno_t rc;
|
|---|
| 147 |
|
|---|
| 148 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 149 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 150 |
|
|---|
| 151 | rc = ds_cfgclient_create(disp, &test_ds_cfgclient_cb, NULL, &cfgclient);
|
|---|
| 152 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 153 |
|
|---|
| 154 | ds_cfgclient_destroy(cfgclient);
|
|---|
| 155 | ds_display_destroy(disp);
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | /** Test ds_display_find_window(). */
|
|---|
| 159 | PCUT_TEST(display_find_window)
|
|---|
| 160 | {
|
|---|
| 161 | ds_display_t *disp;
|
|---|
| 162 | ds_client_t *client;
|
|---|
| 163 | ds_seat_t *seat;
|
|---|
| 164 | ds_window_t *w0;
|
|---|
| 165 | ds_window_t *w1;
|
|---|
| 166 | ds_window_t *wnd;
|
|---|
| 167 | display_wnd_params_t params;
|
|---|
| 168 | bool called_cb = false;
|
|---|
| 169 | errno_t rc;
|
|---|
| 170 |
|
|---|
| 171 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 172 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 173 |
|
|---|
| 174 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 175 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 176 |
|
|---|
| 177 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 178 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 179 |
|
|---|
| 180 | display_wnd_params_init(¶ms);
|
|---|
| 181 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 182 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 183 |
|
|---|
| 184 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 185 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 186 |
|
|---|
| 187 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 188 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 189 |
|
|---|
| 190 | wnd = ds_display_first_window(disp);
|
|---|
| 191 | PCUT_ASSERT_EQUALS(w0, wnd);
|
|---|
| 192 |
|
|---|
| 193 | wnd = ds_display_next_window(wnd);
|
|---|
| 194 | PCUT_ASSERT_EQUALS(w1, wnd);
|
|---|
| 195 |
|
|---|
| 196 | wnd = ds_display_next_window(wnd);
|
|---|
| 197 | PCUT_ASSERT_NULL(wnd);
|
|---|
| 198 |
|
|---|
| 199 | wnd = ds_display_last_window(disp);
|
|---|
| 200 | PCUT_ASSERT_EQUALS(w1, wnd);
|
|---|
| 201 |
|
|---|
| 202 | wnd = ds_display_prev_window(wnd);
|
|---|
| 203 | PCUT_ASSERT_EQUALS(w0, wnd);
|
|---|
| 204 |
|
|---|
| 205 | wnd = ds_display_prev_window(wnd);
|
|---|
| 206 | PCUT_ASSERT_NULL(wnd);
|
|---|
| 207 |
|
|---|
| 208 | wnd = ds_display_find_window(disp, w0->id);
|
|---|
| 209 | PCUT_ASSERT_EQUALS(w0, wnd);
|
|---|
| 210 |
|
|---|
| 211 | wnd = ds_display_find_window(disp, w1->id);
|
|---|
| 212 | PCUT_ASSERT_EQUALS(w1, wnd);
|
|---|
| 213 |
|
|---|
| 214 | wnd = ds_display_find_window(disp, 0);
|
|---|
| 215 | PCUT_ASSERT_NULL(wnd);
|
|---|
| 216 |
|
|---|
| 217 | wnd = ds_display_find_window(disp, w0->id + 1);
|
|---|
| 218 | PCUT_ASSERT_NULL(wnd);
|
|---|
| 219 |
|
|---|
| 220 | ds_window_destroy(w0);
|
|---|
| 221 | ds_window_destroy(w1);
|
|---|
| 222 | ds_seat_destroy(seat);
|
|---|
| 223 | ds_client_destroy(client);
|
|---|
| 224 | ds_display_destroy(disp);
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | /** Test ds_display_enlist_window() */
|
|---|
| 228 | PCUT_TEST(display_enlist_window)
|
|---|
| 229 | {
|
|---|
| 230 | ds_display_t *disp;
|
|---|
| 231 | ds_client_t *client;
|
|---|
| 232 | ds_seat_t *seat;
|
|---|
| 233 | ds_window_t *w0;
|
|---|
| 234 | ds_window_t *w1;
|
|---|
| 235 | ds_window_t *w2;
|
|---|
| 236 | ds_window_t *w3;
|
|---|
| 237 | ds_window_t *w;
|
|---|
| 238 | display_wnd_params_t params;
|
|---|
| 239 | bool called_cb = false;
|
|---|
| 240 | errno_t rc;
|
|---|
| 241 |
|
|---|
| 242 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 243 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 244 |
|
|---|
| 245 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 246 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 247 |
|
|---|
| 248 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 249 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 250 |
|
|---|
| 251 | display_wnd_params_init(¶ms);
|
|---|
| 252 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 253 | params.rect.p1.x = params.rect.p1.y = 100;
|
|---|
| 254 |
|
|---|
| 255 | /* Regular windows */
|
|---|
| 256 |
|
|---|
| 257 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 258 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 259 |
|
|---|
| 260 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 261 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 262 |
|
|---|
| 263 | /* Topmost windows */
|
|---|
| 264 |
|
|---|
| 265 | params.flags |= wndf_topmost;
|
|---|
| 266 |
|
|---|
| 267 | rc = ds_window_create(client, ¶ms, &w2);
|
|---|
| 268 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 269 |
|
|---|
| 270 | rc = ds_window_create(client, ¶ms, &w3);
|
|---|
| 271 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 272 |
|
|---|
| 273 | /* Delist w1 and w2 */
|
|---|
| 274 | list_remove(&w1->ldwindows);
|
|---|
| 275 | list_remove(&w2->ldwindows);
|
|---|
| 276 |
|
|---|
| 277 | /* Enlist the windows back and check their order */
|
|---|
| 278 | ds_display_enlist_window(disp, w1);
|
|---|
| 279 | ds_display_enlist_window(disp, w2);
|
|---|
| 280 |
|
|---|
| 281 | w = ds_display_first_window(disp);
|
|---|
| 282 | PCUT_ASSERT_EQUALS(w2, w);
|
|---|
| 283 | w = ds_display_next_window(w);
|
|---|
| 284 | PCUT_ASSERT_EQUALS(w3, w);
|
|---|
| 285 | w = ds_display_next_window(w);
|
|---|
| 286 | PCUT_ASSERT_EQUALS(w1, w);
|
|---|
| 287 | w = ds_display_next_window(w);
|
|---|
| 288 | PCUT_ASSERT_EQUALS(w0, w);
|
|---|
| 289 | w = ds_display_next_window(w);
|
|---|
| 290 | PCUT_ASSERT_EQUALS(NULL, w);
|
|---|
| 291 |
|
|---|
| 292 | ds_window_destroy(w0);
|
|---|
| 293 | ds_window_destroy(w1);
|
|---|
| 294 | ds_window_destroy(w2);
|
|---|
| 295 | ds_window_destroy(w3);
|
|---|
| 296 | ds_seat_destroy(seat);
|
|---|
| 297 | ds_client_destroy(client);
|
|---|
| 298 | ds_display_destroy(disp);
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | /** Test ds_display_window_to_top() */
|
|---|
| 302 | PCUT_TEST(display_window_to_top)
|
|---|
| 303 | {
|
|---|
| 304 | ds_display_t *disp;
|
|---|
| 305 | ds_client_t *client;
|
|---|
| 306 | ds_seat_t *seat;
|
|---|
| 307 | ds_window_t *w0;
|
|---|
| 308 | ds_window_t *w1;
|
|---|
| 309 | display_wnd_params_t params;
|
|---|
| 310 | bool called_cb = false;
|
|---|
| 311 | errno_t rc;
|
|---|
| 312 |
|
|---|
| 313 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 314 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 315 |
|
|---|
| 316 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 317 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 318 |
|
|---|
| 319 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 320 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 321 |
|
|---|
| 322 | display_wnd_params_init(¶ms);
|
|---|
| 323 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 324 | params.rect.p1.x = params.rect.p1.y = 100;
|
|---|
| 325 |
|
|---|
| 326 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 327 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 328 |
|
|---|
| 329 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 330 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 331 |
|
|---|
| 332 | PCUT_ASSERT_EQUALS(w1, ds_display_first_window(disp));
|
|---|
| 333 | ds_display_window_to_top(w0);
|
|---|
| 334 | PCUT_ASSERT_EQUALS(w0, ds_display_first_window(disp));
|
|---|
| 335 |
|
|---|
| 336 | ds_window_destroy(w0);
|
|---|
| 337 | ds_window_destroy(w1);
|
|---|
| 338 | ds_seat_destroy(seat);
|
|---|
| 339 | ds_client_destroy(client);
|
|---|
| 340 | ds_display_destroy(disp);
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | /** Test ds_display_window_by_pos(). */
|
|---|
| 344 | PCUT_TEST(display_window_by_pos)
|
|---|
| 345 | {
|
|---|
| 346 | ds_display_t *disp;
|
|---|
| 347 | ds_client_t *client;
|
|---|
| 348 | ds_seat_t *seat;
|
|---|
| 349 | ds_window_t *w0;
|
|---|
| 350 | ds_window_t *w1;
|
|---|
| 351 | ds_window_t *wnd;
|
|---|
| 352 | display_wnd_params_t params;
|
|---|
| 353 | gfx_coord2_t pos;
|
|---|
| 354 | bool called_cb = false;
|
|---|
| 355 | errno_t rc;
|
|---|
| 356 |
|
|---|
| 357 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 358 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 359 |
|
|---|
| 360 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 361 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 362 |
|
|---|
| 363 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 364 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 365 |
|
|---|
| 366 | display_wnd_params_init(¶ms);
|
|---|
| 367 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 368 | params.rect.p1.x = params.rect.p1.y = 100;
|
|---|
| 369 |
|
|---|
| 370 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 371 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 372 |
|
|---|
| 373 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 374 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 375 |
|
|---|
| 376 | w0->dpos.x = 10;
|
|---|
| 377 | w0->dpos.y = 10;
|
|---|
| 378 |
|
|---|
| 379 | w1->dpos.x = 400;
|
|---|
| 380 | w1->dpos.y = 400;
|
|---|
| 381 |
|
|---|
| 382 | pos.x = 10;
|
|---|
| 383 | pos.y = 10;
|
|---|
| 384 | wnd = ds_display_window_by_pos(disp, &pos);
|
|---|
| 385 | PCUT_ASSERT_EQUALS(w0, wnd);
|
|---|
| 386 |
|
|---|
| 387 | pos.x = 400;
|
|---|
| 388 | pos.y = 400;
|
|---|
| 389 | wnd = ds_display_window_by_pos(disp, &pos);
|
|---|
| 390 | PCUT_ASSERT_EQUALS(w1, wnd);
|
|---|
| 391 |
|
|---|
| 392 | ds_window_destroy(w0);
|
|---|
| 393 | ds_window_destroy(w1);
|
|---|
| 394 | ds_seat_destroy(seat);
|
|---|
| 395 | ds_client_destroy(client);
|
|---|
| 396 | ds_display_destroy(disp);
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 | /** Basic seat operation. */
|
|---|
| 400 | PCUT_TEST(display_seat)
|
|---|
| 401 | {
|
|---|
| 402 | ds_display_t *disp;
|
|---|
| 403 | ds_seat_t *seat;
|
|---|
| 404 | ds_seat_t *s0, *s1, *s2;
|
|---|
| 405 | errno_t rc;
|
|---|
| 406 |
|
|---|
| 407 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 408 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 409 |
|
|---|
| 410 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 411 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 412 |
|
|---|
| 413 | s0 = ds_display_first_seat(disp);
|
|---|
| 414 | PCUT_ASSERT_EQUALS(s0, seat);
|
|---|
| 415 |
|
|---|
| 416 | s1 = ds_display_next_seat(s0);
|
|---|
| 417 | PCUT_ASSERT_NULL(s1);
|
|---|
| 418 |
|
|---|
| 419 | s2 = ds_display_find_seat(disp, seat->id);
|
|---|
| 420 | PCUT_ASSERT_EQUALS(s2, seat);
|
|---|
| 421 |
|
|---|
| 422 | ds_seat_destroy(seat);
|
|---|
| 423 | ds_display_destroy(disp);
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | /** ds_display_seat_by_idev() returns the correct seat. */
|
|---|
| 427 | PCUT_TEST(display_seat_by_idev)
|
|---|
| 428 | {
|
|---|
| 429 | // XXX TODO
|
|---|
| 430 | }
|
|---|
| 431 |
|
|---|
| 432 | /** Test ds_display_post_kbd_event() delivers event to client callback.
|
|---|
| 433 | */
|
|---|
| 434 | PCUT_TEST(display_post_kbd_event)
|
|---|
| 435 | {
|
|---|
| 436 | ds_display_t *disp;
|
|---|
| 437 | ds_seat_t *seat;
|
|---|
| 438 | ds_client_t *client;
|
|---|
| 439 | ds_window_t *wnd;
|
|---|
| 440 | display_wnd_params_t params;
|
|---|
| 441 | kbd_event_t event;
|
|---|
| 442 | bool called_cb = false;
|
|---|
| 443 | errno_t rc;
|
|---|
| 444 |
|
|---|
| 445 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 446 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 447 |
|
|---|
| 448 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 449 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 450 |
|
|---|
| 451 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 452 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 453 |
|
|---|
| 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 |
|
|---|
| 461 | ds_seat_set_focus(seat, wnd);
|
|---|
| 462 |
|
|---|
| 463 | event.type = KEY_PRESS;
|
|---|
| 464 | event.key = KC_ENTER;
|
|---|
| 465 | event.mods = 0;
|
|---|
| 466 | event.c = L'\0';
|
|---|
| 467 |
|
|---|
| 468 | called_cb = false;
|
|---|
| 469 |
|
|---|
| 470 | rc = ds_display_post_kbd_event(disp, &event);
|
|---|
| 471 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 472 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 473 |
|
|---|
| 474 | ds_window_destroy(wnd);
|
|---|
| 475 | ds_client_destroy(client);
|
|---|
| 476 | ds_seat_destroy(seat);
|
|---|
| 477 | ds_display_destroy(disp);
|
|---|
| 478 | }
|
|---|
| 479 |
|
|---|
| 480 | /** Test ds_display_post_kbd_event() with Alt-Tab switches focus.
|
|---|
| 481 | */
|
|---|
| 482 | PCUT_TEST(display_post_kbd_event_alt_tab)
|
|---|
| 483 | {
|
|---|
| 484 | ds_display_t *disp;
|
|---|
| 485 | ds_seat_t *seat;
|
|---|
| 486 | ds_client_t *client;
|
|---|
| 487 | ds_window_t *w0, *w1;
|
|---|
| 488 | display_wnd_params_t params;
|
|---|
| 489 | kbd_event_t event;
|
|---|
| 490 | bool called_cb = false;
|
|---|
| 491 | errno_t rc;
|
|---|
| 492 |
|
|---|
| 493 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 494 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 495 |
|
|---|
| 496 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 497 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 498 |
|
|---|
| 499 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 500 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 501 |
|
|---|
| 502 | display_wnd_params_init(¶ms);
|
|---|
| 503 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 504 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 505 |
|
|---|
| 506 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 507 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 508 |
|
|---|
| 509 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 510 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 511 |
|
|---|
| 512 | ds_seat_set_focus(seat, w0);
|
|---|
| 513 |
|
|---|
| 514 | event.type = KEY_PRESS;
|
|---|
| 515 | event.key = KC_TAB;
|
|---|
| 516 | event.mods = KM_ALT;
|
|---|
| 517 | event.c = L'\0';
|
|---|
| 518 |
|
|---|
| 519 | called_cb = false;
|
|---|
| 520 |
|
|---|
| 521 | rc = ds_display_post_kbd_event(disp, &event);
|
|---|
| 522 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 523 |
|
|---|
| 524 | /* Got gocus/unfocus events */
|
|---|
| 525 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 526 |
|
|---|
| 527 | /* Next window should be focused */
|
|---|
| 528 | PCUT_ASSERT_EQUALS(w1, seat->focus);
|
|---|
| 529 |
|
|---|
| 530 | called_cb = false;
|
|---|
| 531 |
|
|---|
| 532 | rc = ds_display_post_kbd_event(disp, &event);
|
|---|
| 533 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 534 |
|
|---|
| 535 | /* Got gocus/unfocus events */
|
|---|
| 536 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 537 |
|
|---|
| 538 | /* Focus should be back to the first window */
|
|---|
| 539 | PCUT_ASSERT_EQUALS(w0, seat->focus);
|
|---|
| 540 |
|
|---|
| 541 | ds_window_destroy(w0);
|
|---|
| 542 | ds_window_destroy(w1);
|
|---|
| 543 | ds_client_destroy(client);
|
|---|
| 544 | ds_seat_destroy(seat);
|
|---|
| 545 | ds_display_destroy(disp);
|
|---|
| 546 | }
|
|---|
| 547 |
|
|---|
| 548 | /** Test ds_display_post_ptd_event() with click on window switches focus
|
|---|
| 549 | */
|
|---|
| 550 | PCUT_TEST(display_post_ptd_event_wnd_switch)
|
|---|
| 551 | {
|
|---|
| 552 | ds_display_t *disp;
|
|---|
| 553 | ds_seat_t *seat;
|
|---|
| 554 | ds_client_t *client;
|
|---|
| 555 | ds_window_t *w0, *w1;
|
|---|
| 556 | display_wnd_params_t params;
|
|---|
| 557 | ptd_event_t event;
|
|---|
| 558 | bool called_cb = false;
|
|---|
| 559 | errno_t rc;
|
|---|
| 560 |
|
|---|
| 561 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 562 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 563 |
|
|---|
| 564 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 565 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 566 |
|
|---|
| 567 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
|---|
| 568 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 569 |
|
|---|
| 570 | /*
|
|---|
| 571 | * For PTD_MOVE to work we need to set display dimensions (as pointer
|
|---|
| 572 | * move is clipped to the display rectangle. Here we do it directly
|
|---|
| 573 | * instead of adding a display device.
|
|---|
| 574 | */
|
|---|
| 575 | disp->rect.p0.x = 0;
|
|---|
| 576 | disp->rect.p0.y = 0;
|
|---|
| 577 | disp->rect.p1.x = 500;
|
|---|
| 578 | disp->rect.p1.y = 500;
|
|---|
| 579 |
|
|---|
| 580 | display_wnd_params_init(¶ms);
|
|---|
| 581 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 582 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 583 |
|
|---|
| 584 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 585 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 586 |
|
|---|
| 587 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 588 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 589 |
|
|---|
| 590 | w0->dpos.x = 10;
|
|---|
| 591 | w0->dpos.y = 10;
|
|---|
| 592 |
|
|---|
| 593 | w1->dpos.x = 400;
|
|---|
| 594 | w1->dpos.y = 400;
|
|---|
| 595 |
|
|---|
| 596 | ds_seat_set_focus(seat, w0);
|
|---|
| 597 |
|
|---|
| 598 | event.type = PTD_MOVE;
|
|---|
| 599 | event.dmove.x = 400;
|
|---|
| 600 | event.dmove.y = 400;
|
|---|
| 601 | rc = ds_display_post_ptd_event(disp, &event);
|
|---|
| 602 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 603 |
|
|---|
| 604 | event.type = PTD_PRESS;
|
|---|
| 605 | event.btn_num = 1;
|
|---|
| 606 | rc = ds_display_post_ptd_event(disp, &event);
|
|---|
| 607 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 608 |
|
|---|
| 609 | PCUT_ASSERT_EQUALS(w1, seat->focus);
|
|---|
| 610 |
|
|---|
| 611 | event.type = PTD_RELEASE;
|
|---|
| 612 | event.btn_num = 1;
|
|---|
| 613 | rc = ds_display_post_ptd_event(disp, &event);
|
|---|
| 614 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 615 |
|
|---|
| 616 | event.type = PTD_MOVE;
|
|---|
| 617 | event.dmove.x = -400 + 10;
|
|---|
| 618 | event.dmove.y = -400 + 10;
|
|---|
| 619 | rc = ds_display_post_ptd_event(disp, &event);
|
|---|
| 620 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 621 |
|
|---|
| 622 | event.type = PTD_PRESS;
|
|---|
| 623 | event.btn_num = 1;
|
|---|
| 624 | rc = ds_display_post_ptd_event(disp, &event);
|
|---|
| 625 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 626 |
|
|---|
| 627 | PCUT_ASSERT_EQUALS(w0, seat->focus);
|
|---|
| 628 |
|
|---|
| 629 | ds_window_destroy(w0);
|
|---|
| 630 | ds_window_destroy(w1);
|
|---|
| 631 | ds_client_destroy(client);
|
|---|
| 632 | ds_seat_destroy(seat);
|
|---|
| 633 | ds_display_destroy(disp);
|
|---|
| 634 | }
|
|---|
| 635 |
|
|---|
| 636 | /** ds_display_update_max_rect() updates maximization rectangle */
|
|---|
| 637 | PCUT_TEST(display_update_max_rect)
|
|---|
| 638 | {
|
|---|
| 639 | ds_display_t *disp;
|
|---|
| 640 | ds_seat_t *seat;
|
|---|
| 641 | ds_client_t *client;
|
|---|
| 642 | ds_window_t *wnd;
|
|---|
| 643 | display_wnd_params_t params;
|
|---|
| 644 | errno_t rc;
|
|---|
| 645 |
|
|---|
| 646 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 647 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 648 |
|
|---|
| 649 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 650 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 651 |
|
|---|
| 652 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 653 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 654 |
|
|---|
| 655 | /*
|
|---|
| 656 | * We need to set display dimensions Here we do it directly
|
|---|
| 657 | * instead of adding a display device.
|
|---|
| 658 | */
|
|---|
| 659 | disp->rect.p0.x = 0;
|
|---|
| 660 | disp->rect.p0.y = 0;
|
|---|
| 661 | disp->rect.p1.x = 500;
|
|---|
| 662 | disp->rect.p1.y = 500;
|
|---|
| 663 |
|
|---|
| 664 | /* Set maximize rectangle as well */
|
|---|
| 665 | disp->max_rect = disp->rect;
|
|---|
| 666 |
|
|---|
| 667 | /* A panel-like window at the bottom */
|
|---|
| 668 | display_wnd_params_init(¶ms);
|
|---|
| 669 | params.flags |= wndf_setpos;
|
|---|
| 670 | params.pos.x = 0;
|
|---|
| 671 | params.pos.y = 450;
|
|---|
| 672 | params.rect.p0.x = 0;
|
|---|
| 673 | params.rect.p0.y = 0;
|
|---|
| 674 | params.rect.p1.x = 500;
|
|---|
| 675 | params.rect.p1.y = 50;
|
|---|
| 676 |
|
|---|
| 677 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 678 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 679 |
|
|---|
| 680 | /*
|
|---|
| 681 | * At this point the maximize rect should be unaltered because
|
|---|
| 682 | * the avoid flag has not been set.
|
|---|
| 683 | */
|
|---|
| 684 | PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.x);
|
|---|
| 685 | PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.y);
|
|---|
| 686 | PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.x);
|
|---|
| 687 | PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.y);
|
|---|
| 688 |
|
|---|
| 689 | wnd->flags |= wndf_avoid;
|
|---|
| 690 |
|
|---|
| 691 | /* Update maximize rectangle */
|
|---|
| 692 | ds_display_update_max_rect(disp);
|
|---|
| 693 |
|
|---|
| 694 | /* Verify maximize rectangle */
|
|---|
| 695 | PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.x);
|
|---|
| 696 | PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.y);
|
|---|
| 697 | PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.x);
|
|---|
| 698 | PCUT_ASSERT_INT_EQUALS(450, disp->max_rect.p1.y);
|
|---|
| 699 |
|
|---|
| 700 | ds_window_destroy(wnd);
|
|---|
| 701 | ds_client_destroy(client);
|
|---|
| 702 | ds_seat_destroy(seat);
|
|---|
| 703 | ds_display_destroy(disp);
|
|---|
| 704 | }
|
|---|
| 705 |
|
|---|
| 706 | /** Cropping maximization rectangle from the top */
|
|---|
| 707 | PCUT_TEST(display_crop_max_rect_top)
|
|---|
| 708 | {
|
|---|
| 709 | gfx_rect_t arect;
|
|---|
| 710 | gfx_rect_t mrect;
|
|---|
| 711 |
|
|---|
| 712 | arect.p0.x = 10;
|
|---|
| 713 | arect.p0.y = 20;
|
|---|
| 714 | arect.p1.x = 30;
|
|---|
| 715 | arect.p1.y = 5;
|
|---|
| 716 |
|
|---|
| 717 | mrect.p0.x = 10;
|
|---|
| 718 | mrect.p0.y = 20;
|
|---|
| 719 | mrect.p1.x = 30;
|
|---|
| 720 | mrect.p1.y = 40;
|
|---|
| 721 |
|
|---|
| 722 | ds_display_crop_max_rect(&arect, &mrect);
|
|---|
| 723 |
|
|---|
| 724 | PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x);
|
|---|
| 725 | PCUT_ASSERT_INT_EQUALS(5, mrect.p0.y);
|
|---|
| 726 | PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x);
|
|---|
| 727 | PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y);
|
|---|
| 728 | }
|
|---|
| 729 |
|
|---|
| 730 | /** Cropping maximization rectangle from the bottom */
|
|---|
| 731 | PCUT_TEST(display_crop_max_rect_bottom)
|
|---|
| 732 | {
|
|---|
| 733 | gfx_rect_t arect;
|
|---|
| 734 | gfx_rect_t mrect;
|
|---|
| 735 |
|
|---|
| 736 | arect.p0.x = 10;
|
|---|
| 737 | arect.p0.y = 35;
|
|---|
| 738 | arect.p1.x = 30;
|
|---|
| 739 | arect.p1.y = 40;
|
|---|
| 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(20, mrect.p0.y);
|
|---|
| 750 | PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x);
|
|---|
| 751 | PCUT_ASSERT_INT_EQUALS(35, mrect.p1.y);
|
|---|
| 752 | }
|
|---|
| 753 |
|
|---|
| 754 | /** Cropping maximization rectangle from the left */
|
|---|
| 755 | PCUT_TEST(display_crop_max_rect_left)
|
|---|
| 756 | {
|
|---|
| 757 | gfx_rect_t arect;
|
|---|
| 758 | gfx_rect_t mrect;
|
|---|
| 759 |
|
|---|
| 760 | arect.p0.x = 10;
|
|---|
| 761 | arect.p0.y = 20;
|
|---|
| 762 | arect.p1.x = 15;
|
|---|
| 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(15, 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(40, mrect.p1.y);
|
|---|
| 776 | }
|
|---|
| 777 |
|
|---|
| 778 | /** Cropping maximization rectangle from the right */
|
|---|
| 779 | PCUT_TEST(display_crop_max_rect_right)
|
|---|
| 780 | {
|
|---|
| 781 | gfx_rect_t arect;
|
|---|
| 782 | gfx_rect_t mrect;
|
|---|
| 783 |
|
|---|
| 784 | arect.p0.x = 25;
|
|---|
| 785 | arect.p0.y = 20;
|
|---|
| 786 | arect.p1.x = 30;
|
|---|
| 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(10, mrect.p0.x);
|
|---|
| 797 | PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y);
|
|---|
| 798 | PCUT_ASSERT_INT_EQUALS(25, mrect.p1.x);
|
|---|
| 799 | PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y);
|
|---|
| 800 | }
|
|---|
| 801 |
|
|---|
| 802 | PCUT_EXPORT(display);
|
|---|