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(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 |
|
---|
62 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
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;
|
---|
81 | ds_seat_t *seat;
|
---|
82 | ds_window_t *w0;
|
---|
83 | ds_window_t *w1;
|
---|
84 | ds_window_t *wnd;
|
---|
85 | display_wnd_params_t params;
|
---|
86 | bool called_cb = NULL;
|
---|
87 | errno_t rc;
|
---|
88 |
|
---|
89 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
90 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
91 |
|
---|
92 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
93 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
94 |
|
---|
95 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
96 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
97 |
|
---|
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);
|
---|
103 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
104 |
|
---|
105 | rc = ds_window_create(client, ¶ms, &w1);
|
---|
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 |
|
---|
120 | ds_window_destroy(w0);
|
---|
121 | ds_window_destroy(w1);
|
---|
122 | ds_seat_destroy(seat);
|
---|
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;
|
---|
132 | ds_seat_t *seat;
|
---|
133 | ds_window_t *w0;
|
---|
134 | ds_window_t *w1;
|
---|
135 | ds_window_t *wnd;
|
---|
136 | display_wnd_params_t params;
|
---|
137 | bool called_cb = NULL;
|
---|
138 | errno_t rc;
|
---|
139 |
|
---|
140 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
141 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
142 |
|
---|
143 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
144 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
145 |
|
---|
146 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
147 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
148 |
|
---|
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);
|
---|
154 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
155 |
|
---|
156 | rc = ds_window_create(client, ¶ms, &w1);
|
---|
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 |
|
---|
168 | ds_window_destroy(w0);
|
---|
169 | ds_window_destroy(w1);
|
---|
170 | ds_seat_destroy(seat);
|
---|
171 | ds_client_destroy(client);
|
---|
172 | ds_display_destroy(disp);
|
---|
173 | }
|
---|
174 |
|
---|
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;
|
---|
180 | ds_seat_t *seat;
|
---|
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 |
|
---|
188 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
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 |
|
---|
194 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
195 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
196 |
|
---|
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 |
|
---|
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;
|
---|
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);
|
---|
228 | ds_seat_destroy(seat);
|
---|
229 | ds_client_destroy(client);
|
---|
230 | ds_display_destroy(disp);
|
---|
231 | }
|
---|
232 |
|
---|
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;
|
---|
238 | ds_seat_t *seat;
|
---|
239 | ds_window_t *wnd;
|
---|
240 | display_wnd_params_t params;
|
---|
241 | ds_window_t *rwindow;
|
---|
242 | display_wnd_focus_ev_t efocus;
|
---|
243 | display_wnd_ev_t revent;
|
---|
244 | bool called_cb = NULL;
|
---|
245 | errno_t rc;
|
---|
246 |
|
---|
247 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
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 |
|
---|
253 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
254 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
255 |
|
---|
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 |
|
---|
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;
|
---|
270 |
|
---|
271 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
272 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
273 |
|
---|
274 | efocus.nfocus = 42;
|
---|
275 |
|
---|
276 | rc = ds_client_post_focus_event(client, wnd, &efocus);
|
---|
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);
|
---|
284 | PCUT_ASSERT_INT_EQUALS(efocus.nfocus, revent.ev.focus.nfocus);
|
---|
285 |
|
---|
286 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
287 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
288 |
|
---|
289 | ds_window_destroy(wnd);
|
---|
290 | ds_seat_destroy(seat);
|
---|
291 | ds_client_destroy(client);
|
---|
292 | ds_display_destroy(disp);
|
---|
293 | }
|
---|
294 |
|
---|
295 | /** Test ds_client_get_event(), ds_client_post_kbd_event(). */
|
---|
296 | PCUT_TEST(client_get_post_kbd_event)
|
---|
297 | {
|
---|
298 | ds_display_t *disp;
|
---|
299 | ds_client_t *client;
|
---|
300 | ds_seat_t *seat;
|
---|
301 | ds_window_t *wnd;
|
---|
302 | display_wnd_params_t params;
|
---|
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 |
|
---|
309 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
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 |
|
---|
315 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
316 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
317 |
|
---|
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);
|
---|
323 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
324 |
|
---|
325 | /* New window gets focused event */
|
---|
326 | PCUT_ASSERT_TRUE(called_cb);
|
---|
327 |
|
---|
328 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
329 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
330 |
|
---|
331 | called_cb = false;
|
---|
332 |
|
---|
333 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
334 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
335 |
|
---|
336 | event.type = KEY_PRESS;
|
---|
337 | event.key = KC_ENTER;
|
---|
338 | event.mods = 0;
|
---|
339 | event.c = L'\0';
|
---|
340 |
|
---|
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);
|
---|
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);
|
---|
358 | ds_seat_destroy(seat);
|
---|
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;
|
---|
368 | ds_seat_t *seat;
|
---|
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 |
|
---|
377 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
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 |
|
---|
383 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
384 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
385 |
|
---|
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 |
|
---|
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;
|
---|
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 |
|
---|
406 | event.type = POS_PRESS;
|
---|
407 | event.hpos = 1;
|
---|
408 | event.vpos = 2;
|
---|
409 |
|
---|
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);
|
---|
421 |
|
---|
422 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
423 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
424 |
|
---|
425 | ds_window_destroy(wnd);
|
---|
426 | ds_seat_destroy(seat);
|
---|
427 | ds_client_destroy(client);
|
---|
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;
|
---|
436 | ds_seat_t *seat;
|
---|
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 |
|
---|
445 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
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 |
|
---|
451 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
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 | /* 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;
|
---|
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 |
|
---|
474 | rect.p0.x = 1;
|
---|
475 | rect.p0.y = 2;
|
---|
476 | rect.p1.x = 3;
|
---|
477 | rect.p1.y = 4;
|
---|
478 |
|
---|
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);
|
---|
496 | ds_seat_destroy(seat);
|
---|
497 | ds_client_destroy(client);
|
---|
498 | ds_display_destroy(disp);
|
---|
499 | }
|
---|
500 |
|
---|
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;
|
---|
506 | ds_seat_t *seat;
|
---|
507 | ds_window_t *wnd;
|
---|
508 | display_wnd_params_t params;
|
---|
509 | ds_window_t *rwindow;
|
---|
510 | display_wnd_unfocus_ev_t eunfocus;
|
---|
511 | display_wnd_ev_t revent;
|
---|
512 | bool called_cb = NULL;
|
---|
513 | errno_t rc;
|
---|
514 |
|
---|
515 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
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 |
|
---|
521 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
522 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
523 |
|
---|
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 |
|
---|
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;
|
---|
538 |
|
---|
539 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
540 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
541 |
|
---|
542 | eunfocus.nfocus = 42;
|
---|
543 |
|
---|
544 | rc = ds_client_post_unfocus_event(client, wnd, &eunfocus);
|
---|
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);
|
---|
552 | PCUT_ASSERT_INT_EQUALS(eunfocus.nfocus, revent.ev.unfocus.nfocus);
|
---|
553 |
|
---|
554 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
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 |
|
---|
582 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
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);
|
---|
600 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
601 |
|
---|
602 | ds_window_destroy(wnd);
|
---|
603 | ds_seat_destroy(seat);
|
---|
604 | ds_client_destroy(client);
|
---|
605 | ds_display_destroy(disp);
|
---|
606 | }
|
---|
607 |
|
---|
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;
|
---|
617 | ds_seat_t *seat;
|
---|
618 | ds_window_t *wnd;
|
---|
619 | display_wnd_params_t params;
|
---|
620 | errno_t rc;
|
---|
621 |
|
---|
622 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
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 |
|
---|
628 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
629 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
630 |
|
---|
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);
|
---|
636 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
637 |
|
---|
638 | ds_seat_destroy(seat);
|
---|
639 | ds_client_destroy(client);
|
---|
640 | ds_display_destroy(disp);
|
---|
641 | }
|
---|
642 |
|
---|
643 | PCUT_EXPORT(client);
|
---|