[b2d1df3] | 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 |
|
---|
[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"
|
---|
| 36 | #include "../window.h"
|
---|
| 37 |
|
---|
| 38 | PCUT_INIT;
|
---|
| 39 |
|
---|
| 40 | PCUT_TEST_SUITE(client);
|
---|
| 41 |
|
---|
| 42 | static void test_ds_ev_pending(void *);
|
---|
| 43 |
|
---|
| 44 | static ds_client_cb_t test_ds_client_cb = {
|
---|
| 45 | .ev_pending = test_ds_ev_pending
|
---|
| 46 | };
|
---|
| 47 |
|
---|
| 48 | static void test_ds_ev_pending(void *arg)
|
---|
| 49 | {
|
---|
| 50 | bool *called_cb = (bool *) arg;
|
---|
| 51 | *called_cb = true;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | /** Client creation and destruction. */
|
---|
| 55 | PCUT_TEST(client_create_destroy)
|
---|
| 56 | {
|
---|
| 57 | ds_display_t *disp;
|
---|
| 58 | ds_client_t *client;
|
---|
| 59 | errno_t rc;
|
---|
| 60 |
|
---|
[8aef01c] | 61 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[b2d1df3] | 62 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 63 |
|
---|
| 64 | rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
|
---|
| 65 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 66 |
|
---|
| 67 | ds_client_destroy(client);
|
---|
| 68 | ds_display_destroy(disp);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | /** Test ds_client_find_window().
|
---|
| 72 | *
|
---|
| 73 | * ds_client_add_window() and ds_client_remove_window() are indirectly
|
---|
| 74 | * tested too as part of creating and destroying the window
|
---|
| 75 | */
|
---|
| 76 | PCUT_TEST(client_find_window)
|
---|
| 77 | {
|
---|
| 78 | ds_display_t *disp;
|
---|
| 79 | ds_client_t *client;
|
---|
| 80 | ds_window_t *w0;
|
---|
| 81 | ds_window_t *w1;
|
---|
| 82 | ds_window_t *wnd;
|
---|
[3434233] | 83 | display_wnd_params_t params;
|
---|
[b2d1df3] | 84 | errno_t rc;
|
---|
| 85 |
|
---|
[8aef01c] | 86 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[b2d1df3] | 87 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 88 |
|
---|
| 89 | rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
|
---|
| 90 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 91 |
|
---|
[3434233] | 92 | display_wnd_params_init(¶ms);
|
---|
| 93 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 94 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 95 |
|
---|
| 96 | rc = ds_window_create(client, ¶ms, &w0);
|
---|
[b2d1df3] | 97 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 98 |
|
---|
[3434233] | 99 | rc = ds_window_create(client, ¶ms, &w1);
|
---|
[b2d1df3] | 100 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 101 |
|
---|
| 102 | wnd = ds_client_find_window(client, w0->id);
|
---|
| 103 | PCUT_ASSERT_EQUALS(w0, wnd);
|
---|
| 104 |
|
---|
| 105 | wnd = ds_client_find_window(client, w1->id);
|
---|
| 106 | PCUT_ASSERT_EQUALS(w1, wnd);
|
---|
| 107 |
|
---|
| 108 | wnd = ds_client_find_window(client, 0);
|
---|
| 109 | PCUT_ASSERT_NULL(wnd);
|
---|
| 110 |
|
---|
| 111 | wnd = ds_client_find_window(client, w1->id + 1);
|
---|
| 112 | PCUT_ASSERT_NULL(wnd);
|
---|
| 113 |
|
---|
[648e2ac] | 114 | ds_window_destroy(w0);
|
---|
| 115 | ds_window_destroy(w1);
|
---|
[b2d1df3] | 116 | ds_client_destroy(client);
|
---|
| 117 | ds_display_destroy(disp);
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | /** Test ds_client_first_window() / ds_client_next_window. */
|
---|
| 121 | PCUT_TEST(client_first_next_window)
|
---|
| 122 | {
|
---|
| 123 | ds_display_t *disp;
|
---|
| 124 | ds_client_t *client;
|
---|
| 125 | ds_window_t *w0;
|
---|
| 126 | ds_window_t *w1;
|
---|
| 127 | ds_window_t *wnd;
|
---|
[3434233] | 128 | display_wnd_params_t params;
|
---|
[b2d1df3] | 129 | errno_t rc;
|
---|
| 130 |
|
---|
[8aef01c] | 131 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[b2d1df3] | 132 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 133 |
|
---|
| 134 | rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
|
---|
| 135 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 136 |
|
---|
[3434233] | 137 | display_wnd_params_init(¶ms);
|
---|
| 138 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 139 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 140 |
|
---|
| 141 | rc = ds_window_create(client, ¶ms, &w0);
|
---|
[b2d1df3] | 142 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 143 |
|
---|
[3434233] | 144 | rc = ds_window_create(client, ¶ms, &w1);
|
---|
[b2d1df3] | 145 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 146 |
|
---|
| 147 | wnd = ds_client_first_window(client);
|
---|
| 148 | PCUT_ASSERT_EQUALS(w0, wnd);
|
---|
| 149 |
|
---|
| 150 | wnd = ds_client_next_window(w0);
|
---|
| 151 | PCUT_ASSERT_EQUALS(w1, wnd);
|
---|
| 152 |
|
---|
| 153 | wnd = ds_client_next_window(w1);
|
---|
| 154 | PCUT_ASSERT_NULL(wnd);
|
---|
| 155 |
|
---|
[648e2ac] | 156 | ds_window_destroy(w0);
|
---|
| 157 | ds_window_destroy(w1);
|
---|
[b2d1df3] | 158 | ds_client_destroy(client);
|
---|
| 159 | ds_display_destroy(disp);
|
---|
| 160 | }
|
---|
| 161 |
|
---|
[338d0935] | 162 | /** Test ds_client_get_event(), ds_client_post_close_event(). */
|
---|
| 163 | PCUT_TEST(client_get_post_close_event)
|
---|
| 164 | {
|
---|
| 165 | ds_display_t *disp;
|
---|
| 166 | ds_client_t *client;
|
---|
| 167 | ds_window_t *wnd;
|
---|
| 168 | display_wnd_params_t params;
|
---|
| 169 | ds_window_t *rwindow;
|
---|
| 170 | display_wnd_ev_t revent;
|
---|
| 171 | bool called_cb = NULL;
|
---|
| 172 | errno_t rc;
|
---|
| 173 |
|
---|
[8aef01c] | 174 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[338d0935] | 175 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 176 |
|
---|
| 177 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 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, &wnd);
|
---|
| 185 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 186 |
|
---|
| 187 | PCUT_ASSERT_FALSE(called_cb);
|
---|
| 188 |
|
---|
| 189 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 190 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 191 |
|
---|
| 192 | rc = ds_client_post_close_event(client, wnd);
|
---|
| 193 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 194 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 195 |
|
---|
| 196 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 197 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 198 | PCUT_ASSERT_EQUALS(wnd, rwindow);
|
---|
| 199 | PCUT_ASSERT_EQUALS(wev_close, revent.etype);
|
---|
| 200 |
|
---|
| 201 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 202 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 203 |
|
---|
| 204 | ds_window_destroy(wnd);
|
---|
| 205 | ds_client_destroy(client);
|
---|
| 206 | ds_display_destroy(disp);
|
---|
| 207 | }
|
---|
| 208 |
|
---|
[b0a94854] | 209 | /** Test ds_client_get_event(), ds_client_post_focus_event(). */
|
---|
| 210 | PCUT_TEST(client_get_post_focus_event)
|
---|
| 211 | {
|
---|
| 212 | ds_display_t *disp;
|
---|
| 213 | ds_client_t *client;
|
---|
| 214 | ds_window_t *wnd;
|
---|
| 215 | display_wnd_params_t params;
|
---|
| 216 | ds_window_t *rwindow;
|
---|
| 217 | display_wnd_ev_t revent;
|
---|
| 218 | bool called_cb = NULL;
|
---|
| 219 | errno_t rc;
|
---|
| 220 |
|
---|
[8aef01c] | 221 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[b0a94854] | 222 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 223 |
|
---|
| 224 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 225 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 226 |
|
---|
| 227 | display_wnd_params_init(¶ms);
|
---|
| 228 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 229 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 230 |
|
---|
| 231 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
| 232 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 233 |
|
---|
| 234 | PCUT_ASSERT_FALSE(called_cb);
|
---|
| 235 |
|
---|
| 236 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 237 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 238 |
|
---|
| 239 | rc = ds_client_post_focus_event(client, wnd);
|
---|
| 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_focus, revent.etype);
|
---|
| 247 |
|
---|
| 248 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 249 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 250 |
|
---|
| 251 | ds_window_destroy(wnd);
|
---|
| 252 | ds_client_destroy(client);
|
---|
| 253 | ds_display_destroy(disp);
|
---|
| 254 | }
|
---|
| 255 |
|
---|
[b2d1df3] | 256 | /** Test ds_client_get_event(), ds_client_post_kbd_event(). */
|
---|
[a40ae0d] | 257 | PCUT_TEST(client_get_post_kbd_event)
|
---|
[b2d1df3] | 258 | {
|
---|
| 259 | ds_display_t *disp;
|
---|
| 260 | ds_client_t *client;
|
---|
| 261 | ds_window_t *wnd;
|
---|
[3434233] | 262 | display_wnd_params_t params;
|
---|
[b2d1df3] | 263 | kbd_event_t event;
|
---|
| 264 | ds_window_t *rwindow;
|
---|
| 265 | display_wnd_ev_t revent;
|
---|
| 266 | bool called_cb = NULL;
|
---|
| 267 | errno_t rc;
|
---|
| 268 |
|
---|
[8aef01c] | 269 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[b2d1df3] | 270 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 271 |
|
---|
| 272 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 273 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 274 |
|
---|
[3434233] | 275 | display_wnd_params_init(¶ms);
|
---|
| 276 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 277 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 278 |
|
---|
| 279 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
[b2d1df3] | 280 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 281 |
|
---|
| 282 | event.type = KEY_PRESS;
|
---|
| 283 | event.key = KC_ENTER;
|
---|
| 284 | event.mods = 0;
|
---|
| 285 | event.c = L'\0';
|
---|
| 286 |
|
---|
| 287 | PCUT_ASSERT_FALSE(called_cb);
|
---|
| 288 |
|
---|
| 289 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 290 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 291 |
|
---|
| 292 | rc = ds_client_post_kbd_event(client, wnd, &event);
|
---|
| 293 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 294 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 295 |
|
---|
| 296 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 297 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 298 | PCUT_ASSERT_EQUALS(wnd, rwindow);
|
---|
[f7fb2b21] | 299 | PCUT_ASSERT_EQUALS(wev_kbd, revent.etype);
|
---|
| 300 | PCUT_ASSERT_EQUALS(event.type, revent.ev.kbd.type);
|
---|
| 301 | PCUT_ASSERT_EQUALS(event.key, revent.ev.kbd.key);
|
---|
| 302 | PCUT_ASSERT_EQUALS(event.mods, revent.ev.kbd.mods);
|
---|
| 303 | PCUT_ASSERT_EQUALS(event.c, revent.ev.kbd.c);
|
---|
| 304 |
|
---|
| 305 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 306 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 307 |
|
---|
| 308 | ds_window_destroy(wnd);
|
---|
| 309 | ds_client_destroy(client);
|
---|
| 310 | ds_display_destroy(disp);
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | /** Test ds_client_get_event(), ds_client_post_pos_event(). */
|
---|
| 314 | PCUT_TEST(client_get_post_pos_event)
|
---|
| 315 | {
|
---|
| 316 | ds_display_t *disp;
|
---|
| 317 | ds_client_t *client;
|
---|
| 318 | ds_window_t *wnd;
|
---|
| 319 | display_wnd_params_t params;
|
---|
| 320 | pos_event_t event;
|
---|
| 321 | ds_window_t *rwindow;
|
---|
| 322 | display_wnd_ev_t revent;
|
---|
| 323 | bool called_cb = NULL;
|
---|
| 324 | errno_t rc;
|
---|
| 325 |
|
---|
[8aef01c] | 326 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[f7fb2b21] | 327 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 328 |
|
---|
| 329 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 330 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 331 |
|
---|
| 332 | display_wnd_params_init(¶ms);
|
---|
| 333 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 334 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 335 |
|
---|
| 336 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
| 337 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 338 |
|
---|
| 339 | event.type = POS_PRESS;
|
---|
| 340 | event.hpos = 1;
|
---|
| 341 | event.vpos = 2;
|
---|
| 342 |
|
---|
| 343 | PCUT_ASSERT_FALSE(called_cb);
|
---|
| 344 |
|
---|
| 345 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 346 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 347 |
|
---|
| 348 | rc = ds_client_post_pos_event(client, wnd, &event);
|
---|
| 349 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 350 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 351 |
|
---|
| 352 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 353 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 354 | PCUT_ASSERT_EQUALS(wnd, rwindow);
|
---|
| 355 | PCUT_ASSERT_EQUALS(wev_pos, revent.etype);
|
---|
| 356 | PCUT_ASSERT_EQUALS(event.type, revent.ev.pos.type);
|
---|
| 357 | PCUT_ASSERT_EQUALS(event.hpos, revent.ev.pos.hpos);
|
---|
| 358 | PCUT_ASSERT_EQUALS(event.vpos, revent.ev.pos.vpos);
|
---|
[b2d1df3] | 359 |
|
---|
[dcac756] | 360 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 361 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 362 |
|
---|
[648e2ac] | 363 | ds_window_destroy(wnd);
|
---|
[b2d1df3] | 364 | ds_client_destroy(client);
|
---|
[e022819] | 365 | ds_display_destroy(disp);
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | /** Test ds_client_get_event(), ds_client_post_resize_event(). */
|
---|
| 369 | PCUT_TEST(client_get_post_resize_event)
|
---|
| 370 | {
|
---|
| 371 | ds_display_t *disp;
|
---|
| 372 | ds_client_t *client;
|
---|
| 373 | ds_window_t *wnd;
|
---|
| 374 | display_wnd_params_t params;
|
---|
| 375 | gfx_rect_t rect;
|
---|
| 376 | ds_window_t *rwindow;
|
---|
| 377 | display_wnd_ev_t revent;
|
---|
| 378 | bool called_cb = NULL;
|
---|
| 379 | errno_t rc;
|
---|
| 380 |
|
---|
[8aef01c] | 381 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[e022819] | 382 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 383 |
|
---|
| 384 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 385 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 386 |
|
---|
| 387 | display_wnd_params_init(¶ms);
|
---|
| 388 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 389 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 390 |
|
---|
| 391 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
| 392 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 393 |
|
---|
| 394 | rect.p0.x = 1;
|
---|
| 395 | rect.p0.y = 2;
|
---|
| 396 | rect.p1.x = 3;
|
---|
| 397 | rect.p1.y = 4;
|
---|
| 398 |
|
---|
| 399 | PCUT_ASSERT_FALSE(called_cb);
|
---|
| 400 |
|
---|
| 401 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 402 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 403 |
|
---|
| 404 | rc = ds_client_post_resize_event(client, wnd, &rect);
|
---|
| 405 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 406 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 407 |
|
---|
| 408 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 409 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 410 | PCUT_ASSERT_EQUALS(wnd, rwindow);
|
---|
| 411 | PCUT_ASSERT_EQUALS(wev_resize, revent.etype);
|
---|
| 412 | PCUT_ASSERT_EQUALS(rect.p0.x, revent.ev.resize.rect.p0.x);
|
---|
| 413 | PCUT_ASSERT_EQUALS(rect.p0.y, revent.ev.resize.rect.p0.y);
|
---|
| 414 | PCUT_ASSERT_EQUALS(rect.p1.x, revent.ev.resize.rect.p1.x);
|
---|
| 415 | PCUT_ASSERT_EQUALS(rect.p1.y, revent.ev.resize.rect.p1.y);
|
---|
| 416 |
|
---|
| 417 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 418 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 419 |
|
---|
| 420 | ds_window_destroy(wnd);
|
---|
| 421 | ds_client_destroy(client);
|
---|
[b2d1df3] | 422 | ds_display_destroy(disp);
|
---|
| 423 | }
|
---|
| 424 |
|
---|
[b0a94854] | 425 | /** Test ds_client_get_event(), ds_client_post_unfocus_event(). */
|
---|
| 426 | PCUT_TEST(client_get_post_unfocus_event)
|
---|
| 427 | {
|
---|
| 428 | ds_display_t *disp;
|
---|
| 429 | ds_client_t *client;
|
---|
| 430 | ds_window_t *wnd;
|
---|
| 431 | display_wnd_params_t params;
|
---|
| 432 | ds_window_t *rwindow;
|
---|
| 433 | display_wnd_ev_t revent;
|
---|
| 434 | bool called_cb = NULL;
|
---|
| 435 | errno_t rc;
|
---|
| 436 |
|
---|
[8aef01c] | 437 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[b0a94854] | 438 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 439 |
|
---|
| 440 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 441 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 442 |
|
---|
| 443 | display_wnd_params_init(¶ms);
|
---|
| 444 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 445 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 446 |
|
---|
| 447 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
| 448 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 449 |
|
---|
| 450 | PCUT_ASSERT_FALSE(called_cb);
|
---|
| 451 |
|
---|
| 452 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 453 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 454 |
|
---|
| 455 | rc = ds_client_post_unfocus_event(client, wnd);
|
---|
| 456 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 457 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 458 |
|
---|
| 459 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 460 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 461 | PCUT_ASSERT_EQUALS(wnd, rwindow);
|
---|
| 462 | PCUT_ASSERT_EQUALS(wev_unfocus, revent.etype);
|
---|
| 463 |
|
---|
| 464 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
| 465 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
| 466 |
|
---|
| 467 | ds_window_destroy(wnd);
|
---|
| 468 | ds_client_destroy(client);
|
---|
| 469 | ds_display_destroy(disp);
|
---|
| 470 | }
|
---|
| 471 |
|
---|
[da412547] | 472 | /** Test client being destroyed while still having a window.
|
---|
| 473 | *
|
---|
| 474 | * This can happen if client forgets to destroy window or if the client
|
---|
| 475 | * is disconnected (or terminated).
|
---|
| 476 | */
|
---|
| 477 | PCUT_TEST(client_leftover_window)
|
---|
| 478 | {
|
---|
| 479 | ds_display_t *disp;
|
---|
| 480 | ds_client_t *client;
|
---|
| 481 | ds_window_t *wnd;
|
---|
[3434233] | 482 | display_wnd_params_t params;
|
---|
[da412547] | 483 | errno_t rc;
|
---|
| 484 |
|
---|
[8aef01c] | 485 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
[da412547] | 486 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 487 |
|
---|
| 488 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
| 489 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 490 |
|
---|
[3434233] | 491 | display_wnd_params_init(¶ms);
|
---|
| 492 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
| 493 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
| 494 |
|
---|
| 495 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
[da412547] | 496 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 497 |
|
---|
| 498 | ds_client_destroy(client);
|
---|
| 499 | ds_display_destroy(disp);
|
---|
| 500 | }
|
---|
| 501 |
|
---|
[b2d1df3] | 502 | PCUT_EXPORT(client);
|
---|