source: mainline/uspace/srv/hid/display/test/seat.c@ a40ae0d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a40ae0d was a40ae0d, checked in by Jiri Svoboda <jiri@…>, 6 years ago

Moving windows by mouse drag

  • Property mode set to 100644
File size: 8.3 KB
Line 
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
29#include <disp_srv.h>
30#include <errno.h>
31#include <pcut/pcut.h>
32#include <stdio.h>
33#include <str.h>
34
35#include "../client.h"
36#include "../display.h"
37#include "../seat.h"
38#include "../window.h"
39
40PCUT_INIT;
41
42PCUT_TEST_SUITE(seat);
43
44static void test_ds_ev_pending(void *);
45
46static ds_client_cb_t test_ds_client_cb = {
47 .ev_pending = test_ds_ev_pending
48};
49
50static void test_ds_ev_pending(void *arg)
51{
52 bool *called_cb = (bool *) arg;
53 printf("test_ds_ev_pending\n");
54 *called_cb = true;
55
56}
57
58/** Set focus. */
59PCUT_TEST(set_focus)
60{
61 ds_display_t *disp;
62 ds_client_t *client;
63 ds_seat_t *seat;
64 ds_window_t *wnd;
65 display_wnd_params_t params;
66 errno_t rc;
67
68 rc = ds_display_create(NULL, &disp);
69 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
70
71 rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
72 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
73
74 rc = ds_seat_create(disp, &seat);
75 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
76
77 display_wnd_params_init(&params);
78 params.rect.p0.x = params.rect.p0.y = 0;
79 params.rect.p1.x = params.rect.p1.y = 1;
80
81 rc = ds_window_create(client, &params, &wnd);
82 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
83
84 ds_seat_set_focus(seat, wnd);
85 PCUT_ASSERT_EQUALS(wnd, seat->focus);
86
87 ds_window_destroy(wnd);
88 ds_seat_destroy(seat);
89 ds_client_destroy(client);
90 ds_display_destroy(disp);
91}
92
93/** Evacuate focus. */
94PCUT_TEST(evac_focus)
95{
96 ds_display_t *disp;
97 ds_client_t *client;
98 ds_seat_t *seat;
99 ds_window_t *w0;
100 ds_window_t *w1;
101 display_wnd_params_t params;
102 errno_t rc;
103
104 rc = ds_display_create(NULL, &disp);
105 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
106
107 rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
108 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
109
110 rc = ds_seat_create(disp, &seat);
111 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
112
113 display_wnd_params_init(&params);
114 params.rect.p0.x = params.rect.p0.y = 0;
115 params.rect.p1.x = params.rect.p1.y = 1;
116
117 rc = ds_window_create(client, &params, &w1);
118 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
119
120 rc = ds_window_create(client, &params, &w0);
121 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
122
123 ds_seat_set_focus(seat, w1);
124 PCUT_ASSERT_EQUALS(w1, seat->focus);
125
126 ds_seat_evac_focus(seat, w1);
127 PCUT_ASSERT_EQUALS(w0, seat->focus);
128
129 ds_window_destroy(w0);
130 ds_window_destroy(w1);
131 ds_seat_destroy(seat);
132 ds_client_destroy(client);
133 ds_display_destroy(disp);
134}
135
136/** Test ds_seat_post_kbd_event() with Alt-Tab switches focus */
137PCUT_TEST(post_kbd_event_alt_tab)
138{
139 ds_display_t *disp;
140 ds_client_t *client;
141 ds_seat_t *seat;
142 ds_window_t *w0;
143 ds_window_t *w1;
144 display_wnd_params_t params;
145 kbd_event_t event;
146 errno_t rc;
147
148 rc = ds_display_create(NULL, &disp);
149 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
150
151 rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
152 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
153
154 rc = ds_seat_create(disp, &seat);
155 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
156
157 display_wnd_params_init(&params);
158 params.rect.p0.x = params.rect.p0.y = 0;
159 params.rect.p1.x = params.rect.p1.y = 1;
160
161 rc = ds_window_create(client, &params, &w1);
162 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
163
164 rc = ds_window_create(client, &params, &w0);
165 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
166
167 ds_seat_set_focus(seat, w1);
168 PCUT_ASSERT_EQUALS(w1, seat->focus);
169
170 event.type = KEY_PRESS;
171 event.mods = KM_ALT;
172 event.key = KC_TAB;
173 rc = ds_seat_post_kbd_event(seat, &event);
174 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
175 PCUT_ASSERT_EQUALS(w0, seat->focus);
176
177 ds_window_destroy(w0);
178 ds_window_destroy(w1);
179 ds_seat_destroy(seat);
180 ds_client_destroy(client);
181 ds_display_destroy(disp);
182}
183
184/** Test ds_seat_post_kbd_event() with regular key press delivers to client queue */
185PCUT_TEST(post_kbd_event_regular)
186{
187 ds_display_t *disp;
188 ds_client_t *client;
189 ds_seat_t *seat;
190 ds_window_t *wnd;
191 display_wnd_params_t params;
192 kbd_event_t event;
193 ds_window_t *rwindow;
194 display_wnd_ev_t revent;
195 bool called_cb = NULL;
196 errno_t rc;
197
198 rc = ds_display_create(NULL, &disp);
199 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
200
201 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
202 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
203
204 rc = ds_seat_create(disp, &seat);
205 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
206
207 display_wnd_params_init(&params);
208 params.rect.p0.x = params.rect.p0.y = 0;
209 params.rect.p1.x = params.rect.p1.y = 1;
210
211 rc = ds_window_create(client, &params, &wnd);
212 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
213
214 ds_seat_set_focus(seat, wnd);
215 PCUT_ASSERT_EQUALS(wnd, seat->focus);
216
217 event.type = KEY_PRESS;
218 event.key = KC_ENTER;
219 event.mods = 0;
220 event.c = L'\0';
221
222 PCUT_ASSERT_FALSE(called_cb);
223
224 rc = ds_client_get_event(client, &rwindow, &revent);
225 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
226
227 rc = ds_seat_post_kbd_event(seat, &event);
228 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
229 PCUT_ASSERT_TRUE(called_cb);
230
231 rc = ds_client_get_event(client, &rwindow, &revent);
232 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
233 PCUT_ASSERT_EQUALS(wnd, rwindow);
234 PCUT_ASSERT_EQUALS(event.type, revent.kbd_event.type);
235 PCUT_ASSERT_EQUALS(event.key, revent.kbd_event.key);
236 PCUT_ASSERT_EQUALS(event.mods, revent.kbd_event.mods);
237 PCUT_ASSERT_EQUALS(event.c, revent.kbd_event.c);
238
239 rc = ds_client_get_event(client, &rwindow, &revent);
240 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
241
242 ds_window_destroy(wnd);
243 ds_client_destroy(client);
244 ds_display_destroy(disp);
245}
246
247/** Test ds_seat_post_ptd_event() with click on window switches focus
248 */
249PCUT_TEST(post_ptd_event_wnd_switch)
250{
251 ds_display_t *disp;
252 ds_seat_t *seat;
253 ds_client_t *client;
254 ds_window_t *w0, *w1;
255 display_wnd_params_t params;
256 ptd_event_t event;
257 bool called_cb = false;
258 errno_t rc;
259
260 rc = ds_display_create(NULL, &disp);
261 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
262
263 rc = ds_seat_create(disp, &seat);
264 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
265
266 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
267 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
268
269 display_wnd_params_init(&params);
270 params.rect.p0.x = params.rect.p0.y = 0;
271 params.rect.p1.x = params.rect.p1.y = 1;
272
273 rc = ds_window_create(client, &params, &w0);
274 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
275
276 rc = ds_window_create(client, &params, &w1);
277 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
278
279 w0->dpos.x = 10;
280 w0->dpos.y = 10;
281
282 w1->dpos.x = 400;
283 w1->dpos.y = 400;
284
285 PCUT_ASSERT_FALSE(called_cb);
286
287 ds_seat_set_focus(seat, w0);
288
289 event.type = PTD_MOVE;
290 event.dmove.x = 400;
291 event.dmove.y = 400;
292 rc = ds_seat_post_ptd_event(seat, &event);
293 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
294 PCUT_ASSERT_FALSE(called_cb);
295
296 event.type = PTD_PRESS;
297 event.btn_num = 1;
298 rc = ds_seat_post_ptd_event(seat, &event);
299 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
300 PCUT_ASSERT_FALSE(called_cb);
301
302 PCUT_ASSERT_EQUALS(w1, seat->focus);
303
304 event.type = PTD_MOVE;
305 event.dmove.x = -400 + 10;
306 event.dmove.y = -400 + 10;
307 rc = ds_seat_post_ptd_event(seat, &event);
308 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
309 PCUT_ASSERT_FALSE(called_cb);
310
311 event.type = PTD_PRESS;
312 event.btn_num = 1;
313 rc = ds_seat_post_ptd_event(seat, &event);
314 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
315 PCUT_ASSERT_FALSE(called_cb);
316
317 PCUT_ASSERT_EQUALS(w0, seat->focus);
318
319 ds_window_destroy(w0);
320 ds_window_destroy(w1);
321 ds_client_destroy(client);
322 ds_seat_destroy(seat);
323 ds_display_destroy(disp);
324}
325
326/** Test ds_seat_post_pos_event() */
327PCUT_TEST(post_pos_event)
328{
329 // XXX
330}
331
332PCUT_EXPORT(seat);
Note: See TracBrowser for help on using the repository browser.