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 <gfx/color.h>
|
---|
34 | #include <gfx/context.h>
|
---|
35 | #include <gfx/render.h>
|
---|
36 | #include <ipcgfx/server.h>
|
---|
37 | #include <loc.h>
|
---|
38 | #include <pcut/pcut.h>
|
---|
39 |
|
---|
40 | PCUT_INIT;
|
---|
41 |
|
---|
42 | PCUT_TEST_SUITE(display);
|
---|
43 |
|
---|
44 | static const char *test_display_server = "test-display";
|
---|
45 | static const char *test_display_svc = "test/display";
|
---|
46 |
|
---|
47 | static void test_display_conn(ipc_call_t *, void *);
|
---|
48 | static void test_kbd_event(void *, kbd_event_t *);
|
---|
49 |
|
---|
50 | static errno_t test_window_create(void *, sysarg_t *);
|
---|
51 | static errno_t test_window_destroy(void *, sysarg_t);
|
---|
52 | static errno_t test_get_event(void *, sysarg_t *, display_wnd_ev_t *);
|
---|
53 |
|
---|
54 | static errno_t test_gc_set_color(void *, gfx_color_t *);
|
---|
55 |
|
---|
56 | static display_ops_t test_display_srv_ops = {
|
---|
57 | .window_create = test_window_create,
|
---|
58 | .window_destroy = test_window_destroy,
|
---|
59 | .get_event = test_get_event
|
---|
60 | };
|
---|
61 |
|
---|
62 | static display_wnd_cb_t test_display_wnd_cb = {
|
---|
63 | .kbd_event = test_kbd_event
|
---|
64 | };
|
---|
65 |
|
---|
66 | static gfx_context_ops_t test_gc_ops = {
|
---|
67 | .set_color = test_gc_set_color
|
---|
68 | };
|
---|
69 |
|
---|
70 | /** Describes to the server how to respond to our request and pass tracking
|
---|
71 | * data back to the client.
|
---|
72 | */
|
---|
73 | typedef struct {
|
---|
74 | errno_t rc;
|
---|
75 | sysarg_t wnd_id;
|
---|
76 | display_wnd_ev_t event;
|
---|
77 | bool window_create_called;
|
---|
78 | bool window_destroy_called;
|
---|
79 | bool get_event_called;
|
---|
80 | bool set_color_called;
|
---|
81 | } test_response_t;
|
---|
82 |
|
---|
83 | /** display_open(), display_close() work for valid display service */
|
---|
84 | PCUT_TEST(open_close)
|
---|
85 | {
|
---|
86 | errno_t rc;
|
---|
87 | service_id_t sid;
|
---|
88 | display_t *disp = NULL;
|
---|
89 |
|
---|
90 | async_set_fallback_port_handler(test_display_conn, disp);
|
---|
91 |
|
---|
92 | // FIXME This causes this test to be non-reentrant!
|
---|
93 | rc = loc_server_register(test_display_server);
|
---|
94 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
95 |
|
---|
96 | rc = loc_service_register(test_display_svc, &sid);
|
---|
97 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
98 |
|
---|
99 | rc = display_open(test_display_svc, &disp);
|
---|
100 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
101 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
102 |
|
---|
103 | display_close(disp);
|
---|
104 | rc = loc_service_unregister(sid);
|
---|
105 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
106 | }
|
---|
107 |
|
---|
108 | /** display_window_create() with server returning error response works */
|
---|
109 | PCUT_TEST(window_create_failure)
|
---|
110 | {
|
---|
111 | errno_t rc;
|
---|
112 | service_id_t sid;
|
---|
113 | display_t *disp = NULL;
|
---|
114 | display_window_t *wnd;
|
---|
115 | test_response_t resp;
|
---|
116 |
|
---|
117 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
118 |
|
---|
119 | // FIXME This causes this test to be non-reentrant!
|
---|
120 | rc = loc_server_register(test_display_server);
|
---|
121 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
122 |
|
---|
123 | rc = loc_service_register(test_display_svc, &sid);
|
---|
124 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
125 |
|
---|
126 | rc = display_open(test_display_svc, &disp);
|
---|
127 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
128 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
129 |
|
---|
130 | wnd = NULL;
|
---|
131 | resp.rc = ENOMEM;
|
---|
132 | resp.window_create_called = false;
|
---|
133 | rc = display_window_create(disp, &test_display_wnd_cb, NULL, &wnd);
|
---|
134 | PCUT_ASSERT_TRUE(resp.window_create_called);
|
---|
135 | PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
|
---|
136 | PCUT_ASSERT_NULL(wnd);
|
---|
137 |
|
---|
138 | display_close(disp);
|
---|
139 | rc = loc_service_unregister(sid);
|
---|
140 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
141 | }
|
---|
142 |
|
---|
143 | /** display_window_create() and display_window_destroy() with success
|
---|
144 | *
|
---|
145 | * with server returning success,
|
---|
146 | */
|
---|
147 | PCUT_TEST(window_create_destroy_success)
|
---|
148 | {
|
---|
149 | errno_t rc;
|
---|
150 | service_id_t sid;
|
---|
151 | display_t *disp = NULL;
|
---|
152 | display_window_t *wnd;
|
---|
153 | test_response_t resp;
|
---|
154 |
|
---|
155 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
156 |
|
---|
157 | // FIXME This causes this test to be non-reentrant!
|
---|
158 | rc = loc_server_register(test_display_server);
|
---|
159 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
160 |
|
---|
161 | rc = loc_service_register(test_display_svc, &sid);
|
---|
162 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
163 |
|
---|
164 | rc = display_open(test_display_svc, &disp);
|
---|
165 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
166 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
167 |
|
---|
168 | wnd = NULL;
|
---|
169 | resp.rc = EOK;
|
---|
170 | resp.window_create_called = false;
|
---|
171 | rc = display_window_create(disp, &test_display_wnd_cb, NULL, &wnd);
|
---|
172 | PCUT_ASSERT_TRUE(resp.window_create_called);
|
---|
173 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
174 | PCUT_ASSERT_NOT_NULL(wnd);
|
---|
175 |
|
---|
176 | resp.window_destroy_called = false;
|
---|
177 | rc = display_window_destroy(wnd);
|
---|
178 | PCUT_ASSERT_TRUE(resp.window_destroy_called);
|
---|
179 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
180 |
|
---|
181 | display_close(disp);
|
---|
182 | rc = loc_service_unregister(sid);
|
---|
183 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
184 | }
|
---|
185 |
|
---|
186 | /** display_window_create() with server returning error response works. */
|
---|
187 | PCUT_TEST(window_destroy_failure)
|
---|
188 | {
|
---|
189 | errno_t rc;
|
---|
190 | service_id_t sid;
|
---|
191 | display_t *disp = NULL;
|
---|
192 | display_window_t *wnd;
|
---|
193 | test_response_t resp;
|
---|
194 |
|
---|
195 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
196 |
|
---|
197 | // FIXME This causes this test to be non-reentrant!
|
---|
198 | rc = loc_server_register(test_display_server);
|
---|
199 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
200 |
|
---|
201 | rc = loc_service_register(test_display_svc, &sid);
|
---|
202 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
203 |
|
---|
204 | rc = display_open(test_display_svc, &disp);
|
---|
205 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
206 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
207 |
|
---|
208 | resp.rc = EOK;
|
---|
209 | resp.window_create_called = false;
|
---|
210 | rc = display_window_create(disp, &test_display_wnd_cb, NULL, &wnd);
|
---|
211 | PCUT_ASSERT_TRUE(resp.window_create_called);
|
---|
212 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
213 | PCUT_ASSERT_NOT_NULL(wnd);
|
---|
214 |
|
---|
215 | resp.rc = EIO;
|
---|
216 | resp.window_destroy_called = false;
|
---|
217 | rc = display_window_destroy(wnd);
|
---|
218 | PCUT_ASSERT_TRUE(resp.window_destroy_called);
|
---|
219 | PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
|
---|
220 |
|
---|
221 | display_close(disp);
|
---|
222 | rc = loc_service_unregister(sid);
|
---|
223 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
224 | }
|
---|
225 |
|
---|
226 | /** display_window_get_gc with server returning failure */
|
---|
227 | PCUT_TEST(window_get_gc_failure)
|
---|
228 | {
|
---|
229 | errno_t rc;
|
---|
230 | service_id_t sid;
|
---|
231 | display_t *disp = NULL;
|
---|
232 | display_window_t *wnd;
|
---|
233 | test_response_t resp;
|
---|
234 | gfx_context_t *gc;
|
---|
235 |
|
---|
236 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
237 |
|
---|
238 | // FIXME This causes this test to be non-reentrant!
|
---|
239 | rc = loc_server_register(test_display_server);
|
---|
240 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
241 |
|
---|
242 | rc = loc_service_register(test_display_svc, &sid);
|
---|
243 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
244 |
|
---|
245 | rc = display_open(test_display_svc, &disp);
|
---|
246 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
247 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
248 |
|
---|
249 | wnd = NULL;
|
---|
250 | resp.rc = EOK;
|
---|
251 | rc = display_window_create(disp, &test_display_wnd_cb, NULL, &wnd);
|
---|
252 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
253 | PCUT_ASSERT_NOT_NULL(wnd);
|
---|
254 |
|
---|
255 | gc = NULL;
|
---|
256 | resp.rc = ENOMEM;
|
---|
257 | rc = display_window_get_gc(wnd, &gc);
|
---|
258 | /* async_connect_me_to() does not return specific error */
|
---|
259 | PCUT_ASSERT_ERRNO_VAL(EIO, rc);
|
---|
260 | PCUT_ASSERT_NULL(gc);
|
---|
261 |
|
---|
262 | resp.rc = EOK;
|
---|
263 | rc = display_window_destroy(wnd);
|
---|
264 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
265 |
|
---|
266 | display_close(disp);
|
---|
267 | rc = loc_service_unregister(sid);
|
---|
268 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
269 | }
|
---|
270 |
|
---|
271 | /** display_window_get_gc with server returning success */
|
---|
272 | PCUT_TEST(window_get_gc_success)
|
---|
273 | {
|
---|
274 | errno_t rc;
|
---|
275 | service_id_t sid;
|
---|
276 | display_t *disp = NULL;
|
---|
277 | display_window_t *wnd;
|
---|
278 | test_response_t resp;
|
---|
279 | gfx_context_t *gc;
|
---|
280 | gfx_color_t *color;
|
---|
281 |
|
---|
282 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
283 |
|
---|
284 | // FIXME This causes this test to be non-reentrant!
|
---|
285 | rc = loc_server_register(test_display_server);
|
---|
286 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
287 |
|
---|
288 | rc = loc_service_register(test_display_svc, &sid);
|
---|
289 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
290 |
|
---|
291 | rc = display_open(test_display_svc, &disp);
|
---|
292 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
293 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
294 |
|
---|
295 | wnd = NULL;
|
---|
296 | resp.rc = EOK;
|
---|
297 | rc = display_window_create(disp, &test_display_wnd_cb, NULL, &wnd);
|
---|
298 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
299 | PCUT_ASSERT_NOT_NULL(wnd);
|
---|
300 |
|
---|
301 | gc = NULL;
|
---|
302 | rc = display_window_get_gc(wnd, &gc);
|
---|
303 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
304 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
305 |
|
---|
306 | rc = gfx_color_new_rgb_i16(0, 0, 0, &color);
|
---|
307 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
308 |
|
---|
309 | resp.set_color_called = false;
|
---|
310 | rc = gfx_set_color(gc, color);
|
---|
311 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
312 | PCUT_ASSERT_TRUE(resp.set_color_called);
|
---|
313 |
|
---|
314 | gfx_color_delete(color);
|
---|
315 |
|
---|
316 | rc = display_window_destroy(wnd);
|
---|
317 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
318 |
|
---|
319 | display_close(disp);
|
---|
320 | rc = loc_service_unregister(sid);
|
---|
321 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
322 | }
|
---|
323 |
|
---|
324 | /** Test display service connection.
|
---|
325 | *
|
---|
326 | * This is very similar to connection handler in the display server.
|
---|
327 | * XXX This should be folded into display_srv, if possible
|
---|
328 | */
|
---|
329 | static void test_display_conn(ipc_call_t *icall, void *arg)
|
---|
330 | {
|
---|
331 | test_response_t *resp = (test_response_t *) arg;
|
---|
332 | display_srv_t srv;
|
---|
333 | sysarg_t wnd_id;
|
---|
334 | sysarg_t svc_id;
|
---|
335 | gfx_context_t *gc;
|
---|
336 | errno_t rc;
|
---|
337 |
|
---|
338 | svc_id = ipc_get_arg2(icall);
|
---|
339 | wnd_id = ipc_get_arg3(icall);
|
---|
340 |
|
---|
341 | if (svc_id != 0) {
|
---|
342 | /* Set up protocol structure */
|
---|
343 | display_srv_initialize(&srv);
|
---|
344 | srv.ops = &test_display_srv_ops;
|
---|
345 | srv.arg = arg;
|
---|
346 |
|
---|
347 | /* Handle connection */
|
---|
348 | display_conn(icall, &srv);
|
---|
349 | } else {
|
---|
350 | (void) wnd_id;
|
---|
351 |
|
---|
352 | if (resp->rc != EOK) {
|
---|
353 | async_answer_0(icall, resp->rc);
|
---|
354 | return;
|
---|
355 | }
|
---|
356 |
|
---|
357 | rc = gfx_context_new(&test_gc_ops, arg, &gc);
|
---|
358 | if (rc != EOK) {
|
---|
359 | async_answer_0(icall, ENOMEM);
|
---|
360 | return;
|
---|
361 | }
|
---|
362 |
|
---|
363 | /* Window GC connection */
|
---|
364 | gc_conn(icall, gc);
|
---|
365 | }
|
---|
366 | }
|
---|
367 |
|
---|
368 | static void test_kbd_event(void *arg, kbd_event_t *event)
|
---|
369 | {
|
---|
370 | }
|
---|
371 |
|
---|
372 | static errno_t test_window_create(void *arg, sysarg_t *rwnd_id)
|
---|
373 | {
|
---|
374 | test_response_t *resp = (test_response_t *) arg;
|
---|
375 |
|
---|
376 | resp->window_create_called = true;
|
---|
377 | if (resp->rc == EOK)
|
---|
378 | *rwnd_id = resp->wnd_id;
|
---|
379 |
|
---|
380 | return resp->rc;
|
---|
381 | }
|
---|
382 |
|
---|
383 | static errno_t test_window_destroy(void *arg, sysarg_t wnd_id)
|
---|
384 | {
|
---|
385 | test_response_t *resp = (test_response_t *) arg;
|
---|
386 |
|
---|
387 | resp->window_destroy_called = true;
|
---|
388 | return resp->rc;
|
---|
389 | }
|
---|
390 |
|
---|
391 | static errno_t test_get_event(void *arg, sysarg_t *wnd_id, display_wnd_ev_t *event)
|
---|
392 | {
|
---|
393 | test_response_t *resp = (test_response_t *) arg;
|
---|
394 |
|
---|
395 | resp->get_event_called = true;
|
---|
396 | if (resp->rc == EOK) {
|
---|
397 | *wnd_id = resp->wnd_id;
|
---|
398 | *event = resp->event;
|
---|
399 | }
|
---|
400 |
|
---|
401 | return resp->rc;
|
---|
402 | }
|
---|
403 |
|
---|
404 | static errno_t test_gc_set_color(void *arg, gfx_color_t *color)
|
---|
405 | {
|
---|
406 | test_response_t *resp = (test_response_t *) arg;
|
---|
407 |
|
---|
408 | resp->set_color_called = true;
|
---|
409 | return resp->rc;
|
---|
410 | }
|
---|
411 |
|
---|
412 | PCUT_EXPORT(display);
|
---|