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 <async.h>
|
---|
30 | #include <errno.h>
|
---|
31 | #include <display.h>
|
---|
32 | #include <disp_srv.h>
|
---|
33 | #include <fibril_synch.h>
|
---|
34 | #include <gfx/color.h>
|
---|
35 | #include <gfx/context.h>
|
---|
36 | #include <gfx/render.h>
|
---|
37 | #include <ipcgfx/server.h>
|
---|
38 | #include <loc.h>
|
---|
39 | #include <pcut/pcut.h>
|
---|
40 |
|
---|
41 | PCUT_INIT;
|
---|
42 |
|
---|
43 | PCUT_TEST_SUITE(display);
|
---|
44 |
|
---|
45 | static const char *test_display_server = "test-display";
|
---|
46 | static const char *test_display_svc = "test/display";
|
---|
47 |
|
---|
48 | static void test_display_conn(ipc_call_t *, void *);
|
---|
49 | static void test_kbd_event(void *, kbd_event_t *);
|
---|
50 | static void test_pos_event(void *, pos_event_t *);
|
---|
51 |
|
---|
52 | static errno_t test_window_create(void *, display_wnd_params_t *, sysarg_t *);
|
---|
53 | static errno_t test_window_destroy(void *, sysarg_t);
|
---|
54 | static errno_t test_get_event(void *, sysarg_t *, display_wnd_ev_t *);
|
---|
55 |
|
---|
56 | static errno_t test_gc_set_color(void *, gfx_color_t *);
|
---|
57 |
|
---|
58 | static display_ops_t test_display_srv_ops = {
|
---|
59 | .window_create = test_window_create,
|
---|
60 | .window_destroy = test_window_destroy,
|
---|
61 | .get_event = test_get_event
|
---|
62 | };
|
---|
63 |
|
---|
64 | static display_wnd_cb_t test_display_wnd_cb = {
|
---|
65 | .kbd_event = test_kbd_event,
|
---|
66 | .pos_event = test_pos_event
|
---|
67 | };
|
---|
68 |
|
---|
69 | static gfx_context_ops_t test_gc_ops = {
|
---|
70 | .set_color = test_gc_set_color
|
---|
71 | };
|
---|
72 |
|
---|
73 | /** Describes to the server how to respond to our request and pass tracking
|
---|
74 | * data back to the client.
|
---|
75 | */
|
---|
76 | typedef struct {
|
---|
77 | errno_t rc;
|
---|
78 | sysarg_t wnd_id;
|
---|
79 | display_wnd_ev_t event;
|
---|
80 | display_wnd_ev_t revent;
|
---|
81 | int event_cnt;
|
---|
82 | bool window_create_called;
|
---|
83 | gfx_rect_t create_rect;
|
---|
84 | bool window_destroy_called;
|
---|
85 | bool get_event_called;
|
---|
86 | bool set_color_called;
|
---|
87 | bool kbd_event_called;
|
---|
88 | bool pos_event_called;
|
---|
89 | fibril_condvar_t event_cv;
|
---|
90 | fibril_mutex_t event_lock;
|
---|
91 | display_srv_t *srv;
|
---|
92 | } test_response_t;
|
---|
93 |
|
---|
94 | /** display_open(), display_close() work for valid display service */
|
---|
95 | PCUT_TEST(open_close)
|
---|
96 | {
|
---|
97 | errno_t rc;
|
---|
98 | service_id_t sid;
|
---|
99 | display_t *disp = NULL;
|
---|
100 | test_response_t resp;
|
---|
101 |
|
---|
102 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
103 |
|
---|
104 | // FIXME This causes this test to be non-reentrant!
|
---|
105 | rc = loc_server_register(test_display_server);
|
---|
106 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
107 |
|
---|
108 | rc = loc_service_register(test_display_svc, &sid);
|
---|
109 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
110 |
|
---|
111 | rc = display_open(test_display_svc, &disp);
|
---|
112 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
113 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
114 |
|
---|
115 | display_close(disp);
|
---|
116 | rc = loc_service_unregister(sid);
|
---|
117 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
118 | }
|
---|
119 |
|
---|
120 | /** display_window_create() with server returning error response works */
|
---|
121 | PCUT_TEST(window_create_failure)
|
---|
122 | {
|
---|
123 | errno_t rc;
|
---|
124 | service_id_t sid;
|
---|
125 | display_t *disp = NULL;
|
---|
126 | display_wnd_params_t params;
|
---|
127 | display_window_t *wnd;
|
---|
128 | test_response_t resp;
|
---|
129 |
|
---|
130 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
131 |
|
---|
132 | // FIXME This causes this test to be non-reentrant!
|
---|
133 | rc = loc_server_register(test_display_server);
|
---|
134 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
135 |
|
---|
136 | rc = loc_service_register(test_display_svc, &sid);
|
---|
137 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
138 |
|
---|
139 | rc = display_open(test_display_svc, &disp);
|
---|
140 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
141 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
142 |
|
---|
143 | wnd = NULL;
|
---|
144 | resp.rc = ENOMEM;
|
---|
145 | resp.window_create_called = false;
|
---|
146 | display_wnd_params_init(¶ms);
|
---|
147 | params.rect.p0.x = 0;
|
---|
148 | params.rect.p0.y = 0;
|
---|
149 | params.rect.p0.x = 100;
|
---|
150 | params.rect.p0.y = 100;
|
---|
151 |
|
---|
152 | rc = display_window_create(disp, ¶ms, &test_display_wnd_cb,
|
---|
153 | (void *) &resp, &wnd);
|
---|
154 | PCUT_ASSERT_TRUE(resp.window_create_called);
|
---|
155 | PCUT_ASSERT_EQUALS(params.rect.p0.x, resp.create_rect.p0.x);
|
---|
156 | PCUT_ASSERT_EQUALS(params.rect.p0.y, resp.create_rect.p0.y);
|
---|
157 | PCUT_ASSERT_EQUALS(params.rect.p1.x, resp.create_rect.p1.x);
|
---|
158 | PCUT_ASSERT_EQUALS(params.rect.p1.y, resp.create_rect.p1.y);
|
---|
159 | PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
|
---|
160 | PCUT_ASSERT_NULL(wnd);
|
---|
161 |
|
---|
162 | display_close(disp);
|
---|
163 | rc = loc_service_unregister(sid);
|
---|
164 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
165 | }
|
---|
166 |
|
---|
167 | /** display_window_create() and display_window_destroy() with success
|
---|
168 | *
|
---|
169 | * with server returning success,
|
---|
170 | */
|
---|
171 | PCUT_TEST(window_create_destroy_success)
|
---|
172 | {
|
---|
173 | errno_t rc;
|
---|
174 | service_id_t sid;
|
---|
175 | display_t *disp = NULL;
|
---|
176 | display_wnd_params_t params;
|
---|
177 | display_window_t *wnd;
|
---|
178 | test_response_t resp;
|
---|
179 |
|
---|
180 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
181 |
|
---|
182 | // FIXME This causes this test to be non-reentrant!
|
---|
183 | rc = loc_server_register(test_display_server);
|
---|
184 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
185 |
|
---|
186 | rc = loc_service_register(test_display_svc, &sid);
|
---|
187 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
188 |
|
---|
189 | rc = display_open(test_display_svc, &disp);
|
---|
190 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
191 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
192 |
|
---|
193 | wnd = NULL;
|
---|
194 | resp.rc = EOK;
|
---|
195 | resp.window_create_called = false;
|
---|
196 | display_wnd_params_init(¶ms);
|
---|
197 | params.rect.p0.x = 0;
|
---|
198 | params.rect.p0.y = 0;
|
---|
199 | params.rect.p0.x = 100;
|
---|
200 | params.rect.p0.y = 100;
|
---|
201 |
|
---|
202 | rc = display_window_create(disp, ¶ms, &test_display_wnd_cb,
|
---|
203 | (void *) &resp, &wnd);
|
---|
204 | PCUT_ASSERT_TRUE(resp.window_create_called);
|
---|
205 | PCUT_ASSERT_EQUALS(params.rect.p0.x, resp.create_rect.p0.x);
|
---|
206 | PCUT_ASSERT_EQUALS(params.rect.p0.y, resp.create_rect.p0.y);
|
---|
207 | PCUT_ASSERT_EQUALS(params.rect.p1.x, resp.create_rect.p1.x);
|
---|
208 | PCUT_ASSERT_EQUALS(params.rect.p1.y, resp.create_rect.p1.y);
|
---|
209 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
210 | PCUT_ASSERT_NOT_NULL(wnd);
|
---|
211 |
|
---|
212 | resp.window_destroy_called = false;
|
---|
213 | rc = display_window_destroy(wnd);
|
---|
214 | PCUT_ASSERT_TRUE(resp.window_destroy_called);
|
---|
215 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
216 |
|
---|
217 | display_close(disp);
|
---|
218 | rc = loc_service_unregister(sid);
|
---|
219 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
220 | }
|
---|
221 |
|
---|
222 | /** display_window_create() with server returning error response works. */
|
---|
223 | PCUT_TEST(window_destroy_failure)
|
---|
224 | {
|
---|
225 | errno_t rc;
|
---|
226 | service_id_t sid;
|
---|
227 | display_t *disp = NULL;
|
---|
228 | display_wnd_params_t params;
|
---|
229 | display_window_t *wnd;
|
---|
230 | test_response_t resp;
|
---|
231 |
|
---|
232 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
233 |
|
---|
234 | // FIXME This causes this test to be non-reentrant!
|
---|
235 | rc = loc_server_register(test_display_server);
|
---|
236 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
237 |
|
---|
238 | rc = loc_service_register(test_display_svc, &sid);
|
---|
239 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
240 |
|
---|
241 | rc = display_open(test_display_svc, &disp);
|
---|
242 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
243 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
244 |
|
---|
245 | resp.rc = EOK;
|
---|
246 | resp.window_create_called = false;
|
---|
247 | display_wnd_params_init(¶ms);
|
---|
248 | params.rect.p0.x = 0;
|
---|
249 | params.rect.p0.y = 0;
|
---|
250 | params.rect.p0.x = 100;
|
---|
251 | params.rect.p0.y = 100;
|
---|
252 |
|
---|
253 | rc = display_window_create(disp, ¶ms, &test_display_wnd_cb,
|
---|
254 | (void *) &resp, &wnd);
|
---|
255 | PCUT_ASSERT_TRUE(resp.window_create_called);
|
---|
256 | PCUT_ASSERT_EQUALS(params.rect.p0.x, resp.create_rect.p0.x);
|
---|
257 | PCUT_ASSERT_EQUALS(params.rect.p0.y, resp.create_rect.p0.y);
|
---|
258 | PCUT_ASSERT_EQUALS(params.rect.p1.x, resp.create_rect.p1.x);
|
---|
259 | PCUT_ASSERT_EQUALS(params.rect.p1.y, resp.create_rect.p1.y);
|
---|
260 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
261 | PCUT_ASSERT_NOT_NULL(wnd);
|
---|
262 |
|
---|
263 | resp.rc = EIO;
|
---|
264 | resp.window_destroy_called = false;
|
---|
265 | rc = display_window_destroy(wnd);
|
---|
266 | PCUT_ASSERT_TRUE(resp.window_destroy_called);
|
---|
267 | PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
|
---|
268 |
|
---|
269 | display_close(disp);
|
---|
270 | rc = loc_service_unregister(sid);
|
---|
271 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
272 | }
|
---|
273 |
|
---|
274 | /** display_window_get_gc with server returning failure */
|
---|
275 | PCUT_TEST(window_get_gc_failure)
|
---|
276 | {
|
---|
277 | errno_t rc;
|
---|
278 | service_id_t sid;
|
---|
279 | display_t *disp = NULL;
|
---|
280 | display_wnd_params_t params;
|
---|
281 | display_window_t *wnd;
|
---|
282 | test_response_t resp;
|
---|
283 | gfx_context_t *gc;
|
---|
284 |
|
---|
285 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
286 |
|
---|
287 | // FIXME This causes this test to be non-reentrant!
|
---|
288 | rc = loc_server_register(test_display_server);
|
---|
289 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
290 |
|
---|
291 | rc = loc_service_register(test_display_svc, &sid);
|
---|
292 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
293 |
|
---|
294 | rc = display_open(test_display_svc, &disp);
|
---|
295 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
296 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
297 |
|
---|
298 | wnd = NULL;
|
---|
299 | resp.rc = EOK;
|
---|
300 | display_wnd_params_init(¶ms);
|
---|
301 | params.rect.p0.x = 0;
|
---|
302 | params.rect.p0.y = 0;
|
---|
303 | params.rect.p0.x = 100;
|
---|
304 | params.rect.p0.y = 100;
|
---|
305 |
|
---|
306 | rc = display_window_create(disp, ¶ms, &test_display_wnd_cb,
|
---|
307 | (void *) &resp, &wnd);
|
---|
308 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
309 | PCUT_ASSERT_NOT_NULL(wnd);
|
---|
310 |
|
---|
311 | gc = NULL;
|
---|
312 | resp.rc = ENOMEM;
|
---|
313 | rc = display_window_get_gc(wnd, &gc);
|
---|
314 | /* async_connect_me_to() does not return specific error */
|
---|
315 | PCUT_ASSERT_ERRNO_VAL(EIO, rc);
|
---|
316 | PCUT_ASSERT_NULL(gc);
|
---|
317 |
|
---|
318 | resp.rc = EOK;
|
---|
319 | rc = display_window_destroy(wnd);
|
---|
320 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
321 |
|
---|
322 | display_close(disp);
|
---|
323 | rc = loc_service_unregister(sid);
|
---|
324 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
325 | }
|
---|
326 |
|
---|
327 | /** display_window_get_gc with server returning success */
|
---|
328 | PCUT_TEST(window_get_gc_success)
|
---|
329 | {
|
---|
330 | errno_t rc;
|
---|
331 | service_id_t sid;
|
---|
332 | display_t *disp = NULL;
|
---|
333 | display_wnd_params_t params;
|
---|
334 | display_window_t *wnd;
|
---|
335 | test_response_t resp;
|
---|
336 | gfx_context_t *gc;
|
---|
337 | gfx_color_t *color;
|
---|
338 |
|
---|
339 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
340 |
|
---|
341 | // FIXME This causes this test to be non-reentrant!
|
---|
342 | rc = loc_server_register(test_display_server);
|
---|
343 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
344 |
|
---|
345 | rc = loc_service_register(test_display_svc, &sid);
|
---|
346 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
347 |
|
---|
348 | rc = display_open(test_display_svc, &disp);
|
---|
349 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
350 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
351 |
|
---|
352 | wnd = NULL;
|
---|
353 | resp.rc = EOK;
|
---|
354 | display_wnd_params_init(¶ms);
|
---|
355 | params.rect.p0.x = 0;
|
---|
356 | params.rect.p0.y = 0;
|
---|
357 | params.rect.p0.x = 100;
|
---|
358 | params.rect.p0.y = 100;
|
---|
359 |
|
---|
360 | rc = display_window_create(disp, ¶ms, &test_display_wnd_cb,
|
---|
361 | (void *) &resp, &wnd);
|
---|
362 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
363 | PCUT_ASSERT_NOT_NULL(wnd);
|
---|
364 |
|
---|
365 | gc = NULL;
|
---|
366 | rc = display_window_get_gc(wnd, &gc);
|
---|
367 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
368 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
369 |
|
---|
370 | rc = gfx_color_new_rgb_i16(0, 0, 0, &color);
|
---|
371 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
372 |
|
---|
373 | resp.set_color_called = false;
|
---|
374 | rc = gfx_set_color(gc, color);
|
---|
375 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
376 | PCUT_ASSERT_TRUE(resp.set_color_called);
|
---|
377 |
|
---|
378 | gfx_color_delete(color);
|
---|
379 |
|
---|
380 | rc = display_window_destroy(wnd);
|
---|
381 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
382 |
|
---|
383 | display_close(disp);
|
---|
384 | rc = loc_service_unregister(sid);
|
---|
385 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
386 | }
|
---|
387 |
|
---|
388 | /** Keyboard event can be delivered from server to client callback function */
|
---|
389 | PCUT_TEST(kbd_event_deliver)
|
---|
390 | {
|
---|
391 | errno_t rc;
|
---|
392 | service_id_t sid;
|
---|
393 | display_t *disp = NULL;
|
---|
394 | display_wnd_params_t params;
|
---|
395 | display_window_t *wnd;
|
---|
396 | test_response_t resp;
|
---|
397 |
|
---|
398 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
399 |
|
---|
400 | // FIXME This causes this test to be non-reentrant!
|
---|
401 | rc = loc_server_register(test_display_server);
|
---|
402 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
403 |
|
---|
404 | rc = loc_service_register(test_display_svc, &sid);
|
---|
405 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
406 |
|
---|
407 | rc = display_open(test_display_svc, &disp);
|
---|
408 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
409 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
410 | PCUT_ASSERT_NOT_NULL(resp.srv);
|
---|
411 |
|
---|
412 | wnd = NULL;
|
---|
413 | resp.rc = EOK;
|
---|
414 | display_wnd_params_init(¶ms);
|
---|
415 | params.rect.p0.x = 0;
|
---|
416 | params.rect.p0.y = 0;
|
---|
417 | params.rect.p0.x = 100;
|
---|
418 | params.rect.p0.y = 100;
|
---|
419 |
|
---|
420 | rc = display_window_create(disp, ¶ms, &test_display_wnd_cb,
|
---|
421 | (void *) &resp, &wnd);
|
---|
422 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
423 | PCUT_ASSERT_NOT_NULL(wnd);
|
---|
424 |
|
---|
425 | resp.event_cnt = 1;
|
---|
426 | resp.event.etype = wev_kbd;
|
---|
427 | resp.event.ev.kbd.type = KEY_PRESS;
|
---|
428 | resp.event.ev.kbd.key = KC_ENTER;
|
---|
429 | resp.event.ev.kbd.mods = 0;
|
---|
430 | resp.event.ev.kbd.c = L'\0';
|
---|
431 | resp.wnd_id = wnd->id;
|
---|
432 | resp.kbd_event_called = false;
|
---|
433 | fibril_mutex_initialize(&resp.event_lock);
|
---|
434 | fibril_condvar_initialize(&resp.event_cv);
|
---|
435 | display_srv_ev_pending(resp.srv);
|
---|
436 |
|
---|
437 | /* Wait for the event handler to be called. */
|
---|
438 | fibril_mutex_lock(&resp.event_lock);
|
---|
439 | while (!resp.kbd_event_called) {
|
---|
440 | fibril_condvar_wait(&resp.event_cv, &resp.event_lock);
|
---|
441 | }
|
---|
442 | fibril_mutex_unlock(&resp.event_lock);
|
---|
443 |
|
---|
444 | /* Verify that the event was delivered correctly */
|
---|
445 | PCUT_ASSERT_EQUALS(resp.event.etype,
|
---|
446 | resp.revent.etype);
|
---|
447 | PCUT_ASSERT_EQUALS(resp.event.ev.kbd.type,
|
---|
448 | resp.revent.ev.kbd.type);
|
---|
449 | PCUT_ASSERT_EQUALS(resp.event.ev.kbd.key,
|
---|
450 | resp.revent.ev.kbd.key);
|
---|
451 | PCUT_ASSERT_EQUALS(resp.event.ev.kbd.mods,
|
---|
452 | resp.revent.ev.kbd.mods);
|
---|
453 | PCUT_ASSERT_EQUALS(resp.event.ev.kbd.c,
|
---|
454 | resp.revent.ev.kbd.c);
|
---|
455 |
|
---|
456 | rc = display_window_destroy(wnd);
|
---|
457 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
458 |
|
---|
459 | display_close(disp);
|
---|
460 |
|
---|
461 | rc = loc_service_unregister(sid);
|
---|
462 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
463 | }
|
---|
464 |
|
---|
465 | /** Position event can be delivered from server to client callback function */
|
---|
466 | PCUT_TEST(pos_event_deliver)
|
---|
467 | {
|
---|
468 | errno_t rc;
|
---|
469 | service_id_t sid;
|
---|
470 | display_t *disp = NULL;
|
---|
471 | display_wnd_params_t params;
|
---|
472 | display_window_t *wnd;
|
---|
473 | test_response_t resp;
|
---|
474 |
|
---|
475 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
476 |
|
---|
477 | // FIXME This causes this test to be non-reentrant!
|
---|
478 | rc = loc_server_register(test_display_server);
|
---|
479 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
480 |
|
---|
481 | rc = loc_service_register(test_display_svc, &sid);
|
---|
482 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
483 |
|
---|
484 | rc = display_open(test_display_svc, &disp);
|
---|
485 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
486 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
487 | PCUT_ASSERT_NOT_NULL(resp.srv);
|
---|
488 |
|
---|
489 | wnd = NULL;
|
---|
490 | resp.rc = EOK;
|
---|
491 | display_wnd_params_init(¶ms);
|
---|
492 | params.rect.p0.x = 0;
|
---|
493 | params.rect.p0.y = 0;
|
---|
494 | params.rect.p0.x = 100;
|
---|
495 | params.rect.p0.y = 100;
|
---|
496 |
|
---|
497 | rc = display_window_create(disp, ¶ms, &test_display_wnd_cb,
|
---|
498 | (void *) &resp, &wnd);
|
---|
499 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
500 | PCUT_ASSERT_NOT_NULL(wnd);
|
---|
501 |
|
---|
502 | resp.event_cnt = 1;
|
---|
503 | resp.event.etype = wev_pos;
|
---|
504 | resp.event.ev.pos.type = POS_PRESS;
|
---|
505 | resp.event.ev.pos.btn_num = 1;
|
---|
506 | resp.event.ev.pos.hpos = 2;
|
---|
507 | resp.event.ev.pos.vpos = 3;
|
---|
508 | resp.wnd_id = wnd->id;
|
---|
509 | resp.pos_event_called = false;
|
---|
510 | fibril_mutex_initialize(&resp.event_lock);
|
---|
511 | fibril_condvar_initialize(&resp.event_cv);
|
---|
512 | display_srv_ev_pending(resp.srv);
|
---|
513 |
|
---|
514 | /* Wait for the event handler to be called. */
|
---|
515 | fibril_mutex_lock(&resp.event_lock);
|
---|
516 | while (!resp.pos_event_called) {
|
---|
517 | fibril_condvar_wait(&resp.event_cv, &resp.event_lock);
|
---|
518 | }
|
---|
519 | fibril_mutex_unlock(&resp.event_lock);
|
---|
520 |
|
---|
521 | /* Verify that the event was delivered correctly */
|
---|
522 | PCUT_ASSERT_EQUALS(resp.event.etype,
|
---|
523 | resp.revent.etype);
|
---|
524 | PCUT_ASSERT_EQUALS(resp.event.ev.pos.type,
|
---|
525 | resp.revent.ev.pos.type);
|
---|
526 | PCUT_ASSERT_EQUALS(resp.event.ev.pos.btn_num,
|
---|
527 | resp.revent.ev.pos.btn_num);
|
---|
528 | PCUT_ASSERT_EQUALS(resp.event.ev.pos.hpos,
|
---|
529 | resp.revent.ev.pos.hpos);
|
---|
530 | PCUT_ASSERT_EQUALS(resp.event.ev.pos.vpos,
|
---|
531 | resp.revent.ev.pos.vpos);
|
---|
532 |
|
---|
533 | rc = display_window_destroy(wnd);
|
---|
534 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
535 |
|
---|
536 | display_close(disp);
|
---|
537 |
|
---|
538 | rc = loc_service_unregister(sid);
|
---|
539 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
540 | }
|
---|
541 |
|
---|
542 | /** Test display service connection.
|
---|
543 | *
|
---|
544 | * This is very similar to connection handler in the display server.
|
---|
545 | * XXX This should be folded into display_srv, if possible
|
---|
546 | */
|
---|
547 | static void test_display_conn(ipc_call_t *icall, void *arg)
|
---|
548 | {
|
---|
549 | test_response_t *resp = (test_response_t *) arg;
|
---|
550 | display_srv_t srv;
|
---|
551 | sysarg_t wnd_id;
|
---|
552 | sysarg_t svc_id;
|
---|
553 | gfx_context_t *gc;
|
---|
554 | errno_t rc;
|
---|
555 |
|
---|
556 | svc_id = ipc_get_arg2(icall);
|
---|
557 | wnd_id = ipc_get_arg3(icall);
|
---|
558 |
|
---|
559 | if (svc_id != 0) {
|
---|
560 | /* Set up protocol structure */
|
---|
561 | display_srv_initialize(&srv);
|
---|
562 | srv.ops = &test_display_srv_ops;
|
---|
563 | srv.arg = arg;
|
---|
564 | resp->srv = &srv;
|
---|
565 |
|
---|
566 | /* Handle connection */
|
---|
567 | display_conn(icall, &srv);
|
---|
568 |
|
---|
569 | resp->srv = NULL;
|
---|
570 | } else {
|
---|
571 | (void) wnd_id;
|
---|
572 |
|
---|
573 | if (resp->rc != EOK) {
|
---|
574 | async_answer_0(icall, resp->rc);
|
---|
575 | return;
|
---|
576 | }
|
---|
577 |
|
---|
578 | rc = gfx_context_new(&test_gc_ops, arg, &gc);
|
---|
579 | if (rc != EOK) {
|
---|
580 | async_answer_0(icall, ENOMEM);
|
---|
581 | return;
|
---|
582 | }
|
---|
583 |
|
---|
584 | /* Window GC connection */
|
---|
585 | gc_conn(icall, gc);
|
---|
586 | }
|
---|
587 | }
|
---|
588 |
|
---|
589 | static void test_kbd_event(void *arg, kbd_event_t *event)
|
---|
590 | {
|
---|
591 | test_response_t *resp = (test_response_t *) arg;
|
---|
592 |
|
---|
593 | resp->revent.etype = wev_kbd;
|
---|
594 | resp->revent.ev.kbd = *event;
|
---|
595 |
|
---|
596 | fibril_mutex_lock(&resp->event_lock);
|
---|
597 | resp->kbd_event_called = true;
|
---|
598 | fibril_condvar_broadcast(&resp->event_cv);
|
---|
599 | fibril_mutex_unlock(&resp->event_lock);
|
---|
600 | }
|
---|
601 |
|
---|
602 | static void test_pos_event(void *arg, pos_event_t *event)
|
---|
603 | {
|
---|
604 | test_response_t *resp = (test_response_t *) arg;
|
---|
605 |
|
---|
606 | resp->revent.etype = wev_pos;
|
---|
607 | resp->revent.ev.pos = *event;
|
---|
608 |
|
---|
609 | fibril_mutex_lock(&resp->event_lock);
|
---|
610 | resp->pos_event_called = true;
|
---|
611 | fibril_condvar_broadcast(&resp->event_cv);
|
---|
612 | fibril_mutex_unlock(&resp->event_lock);
|
---|
613 | }
|
---|
614 |
|
---|
615 | static errno_t test_window_create(void *arg, display_wnd_params_t *params,
|
---|
616 | sysarg_t *rwnd_id)
|
---|
617 | {
|
---|
618 | test_response_t *resp = (test_response_t *) arg;
|
---|
619 |
|
---|
620 | resp->window_create_called = true;
|
---|
621 | resp->create_rect = params->rect;
|
---|
622 | if (resp->rc == EOK)
|
---|
623 | *rwnd_id = resp->wnd_id;
|
---|
624 |
|
---|
625 | return resp->rc;
|
---|
626 | }
|
---|
627 |
|
---|
628 | static errno_t test_window_destroy(void *arg, sysarg_t wnd_id)
|
---|
629 | {
|
---|
630 | test_response_t *resp = (test_response_t *) arg;
|
---|
631 |
|
---|
632 | resp->window_destroy_called = true;
|
---|
633 | return resp->rc;
|
---|
634 | }
|
---|
635 |
|
---|
636 | static errno_t test_get_event(void *arg, sysarg_t *wnd_id, display_wnd_ev_t *event)
|
---|
637 | {
|
---|
638 | test_response_t *resp = (test_response_t *) arg;
|
---|
639 |
|
---|
640 | resp->get_event_called = true;
|
---|
641 | if (resp->event_cnt > 0) {
|
---|
642 | --resp->event_cnt;
|
---|
643 | *wnd_id = resp->wnd_id;
|
---|
644 | *event = resp->event;
|
---|
645 | return EOK;
|
---|
646 | }
|
---|
647 |
|
---|
648 | return ENOENT;
|
---|
649 | }
|
---|
650 |
|
---|
651 | static errno_t test_gc_set_color(void *arg, gfx_color_t *color)
|
---|
652 | {
|
---|
653 | test_response_t *resp = (test_response_t *) arg;
|
---|
654 |
|
---|
655 | resp->set_color_called = true;
|
---|
656 | return resp->rc;
|
---|
657 | }
|
---|
658 |
|
---|
659 | PCUT_EXPORT(display);
|
---|