[959b7ec] | 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>
|
---|
[bfddc62] | 33 | #include <gfx/color.h>
|
---|
| 34 | #include <gfx/context.h>
|
---|
| 35 | #include <gfx/render.h>
|
---|
| 36 | #include <ipcgfx/server.h>
|
---|
[959b7ec] | 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 *);
|
---|
[bfddc62] | 48 | static void test_kbd_event(void *, kbd_event_t *);
|
---|
[959b7ec] | 49 |
|
---|
[bfddc62] | 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;
|
---|
[959b7ec] | 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 | rc = loc_server_register(test_display_server);
|
---|
| 93 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 94 |
|
---|
| 95 | rc = loc_service_register(test_display_svc, &sid);
|
---|
| 96 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 97 |
|
---|
| 98 | rc = display_open(test_display_svc, &disp);
|
---|
| 99 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 100 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
| 101 |
|
---|
| 102 | display_close(disp);
|
---|
| 103 | rc = loc_service_unregister(sid);
|
---|
| 104 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | /** display_window_create() with server returning error response works */
|
---|
| 108 | PCUT_TEST(window_create_failure)
|
---|
| 109 | {
|
---|
[bfddc62] | 110 | errno_t rc;
|
---|
| 111 | service_id_t sid;
|
---|
| 112 | display_t *disp = NULL;
|
---|
| 113 | display_window_t *wnd;
|
---|
| 114 | test_response_t resp;
|
---|
| 115 |
|
---|
| 116 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
| 117 |
|
---|
| 118 | rc = loc_server_register(test_display_server);
|
---|
| 119 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 120 |
|
---|
| 121 | rc = loc_service_register(test_display_svc, &sid);
|
---|
| 122 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 123 |
|
---|
| 124 | rc = display_open(test_display_svc, &disp);
|
---|
| 125 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 126 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
| 127 |
|
---|
| 128 | wnd = NULL;
|
---|
| 129 | resp.rc = ENOMEM;
|
---|
| 130 | resp.window_create_called = false;
|
---|
| 131 | rc = display_window_create(disp, &test_display_wnd_cb, NULL, &wnd);
|
---|
| 132 | PCUT_ASSERT_TRUE(resp.window_create_called);
|
---|
| 133 | PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
|
---|
| 134 | PCUT_ASSERT_NULL(wnd);
|
---|
| 135 |
|
---|
| 136 | display_close(disp);
|
---|
| 137 | rc = loc_service_unregister(sid);
|
---|
| 138 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
[959b7ec] | 139 | }
|
---|
| 140 |
|
---|
[bfddc62] | 141 | /** display_window_create() and display_window_destroy() with success
|
---|
| 142 | *
|
---|
| 143 | * with server returning success,
|
---|
| 144 | */
|
---|
| 145 | PCUT_TEST(window_create_destroy_success)
|
---|
[959b7ec] | 146 | {
|
---|
[bfddc62] | 147 | errno_t rc;
|
---|
| 148 | service_id_t sid;
|
---|
| 149 | display_t *disp = NULL;
|
---|
| 150 | display_window_t *wnd;
|
---|
| 151 | test_response_t resp;
|
---|
| 152 |
|
---|
| 153 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
| 154 |
|
---|
| 155 | rc = loc_server_register(test_display_server);
|
---|
| 156 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 157 |
|
---|
| 158 | rc = loc_service_register(test_display_svc, &sid);
|
---|
| 159 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 160 |
|
---|
| 161 | rc = display_open(test_display_svc, &disp);
|
---|
| 162 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 163 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
| 164 |
|
---|
| 165 | wnd = NULL;
|
---|
| 166 | resp.rc = EOK;
|
---|
| 167 | resp.window_create_called = false;
|
---|
| 168 | rc = display_window_create(disp, &test_display_wnd_cb, NULL, &wnd);
|
---|
| 169 | PCUT_ASSERT_TRUE(resp.window_create_called);
|
---|
| 170 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 171 | PCUT_ASSERT_NOT_NULL(wnd);
|
---|
| 172 |
|
---|
| 173 | resp.window_destroy_called = false;
|
---|
| 174 | rc = display_window_destroy(wnd);
|
---|
| 175 | PCUT_ASSERT_TRUE(resp.window_destroy_called);
|
---|
| 176 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 177 |
|
---|
| 178 | display_close(disp);
|
---|
| 179 | rc = loc_service_unregister(sid);
|
---|
| 180 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
[959b7ec] | 181 | }
|
---|
| 182 |
|
---|
[bfddc62] | 183 | /** display_window_create() with server returning error response works. */
|
---|
[959b7ec] | 184 | PCUT_TEST(window_destroy_failure)
|
---|
| 185 | {
|
---|
[bfddc62] | 186 | errno_t rc;
|
---|
| 187 | service_id_t sid;
|
---|
| 188 | display_t *disp = NULL;
|
---|
| 189 | display_window_t *wnd;
|
---|
| 190 | test_response_t resp;
|
---|
[959b7ec] | 191 |
|
---|
[bfddc62] | 192 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
| 193 |
|
---|
| 194 | rc = loc_server_register(test_display_server);
|
---|
| 195 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 196 |
|
---|
| 197 | rc = loc_service_register(test_display_svc, &sid);
|
---|
| 198 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 199 |
|
---|
| 200 | rc = display_open(test_display_svc, &disp);
|
---|
| 201 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 202 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
| 203 |
|
---|
| 204 | resp.rc = EOK;
|
---|
| 205 | resp.window_create_called = false;
|
---|
| 206 | rc = display_window_create(disp, &test_display_wnd_cb, NULL, &wnd);
|
---|
| 207 | PCUT_ASSERT_TRUE(resp.window_create_called);
|
---|
| 208 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 209 | PCUT_ASSERT_NOT_NULL(wnd);
|
---|
| 210 |
|
---|
| 211 | resp.rc = EIO;
|
---|
| 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(resp.rc, rc);
|
---|
| 216 |
|
---|
| 217 | display_close(disp);
|
---|
| 218 | rc = loc_service_unregister(sid);
|
---|
| 219 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
[959b7ec] | 220 | }
|
---|
| 221 |
|
---|
| 222 | /** display_window_get_gc with server returning failure */
|
---|
| 223 | PCUT_TEST(window_get_gc_failure)
|
---|
| 224 | {
|
---|
[bfddc62] | 225 | errno_t rc;
|
---|
| 226 | service_id_t sid;
|
---|
| 227 | display_t *disp = NULL;
|
---|
| 228 | display_window_t *wnd;
|
---|
| 229 | test_response_t resp;
|
---|
| 230 | gfx_context_t *gc;
|
---|
| 231 |
|
---|
| 232 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
| 233 |
|
---|
| 234 | rc = loc_server_register(test_display_server);
|
---|
| 235 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 236 |
|
---|
| 237 | rc = loc_service_register(test_display_svc, &sid);
|
---|
| 238 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 239 |
|
---|
| 240 | rc = display_open(test_display_svc, &disp);
|
---|
| 241 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 242 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
| 243 |
|
---|
| 244 | wnd = NULL;
|
---|
| 245 | resp.rc = EOK;
|
---|
| 246 | rc = display_window_create(disp, &test_display_wnd_cb, NULL, &wnd);
|
---|
| 247 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 248 | PCUT_ASSERT_NOT_NULL(wnd);
|
---|
| 249 |
|
---|
| 250 | gc = NULL;
|
---|
| 251 | resp.rc = ENOMEM;
|
---|
| 252 | rc = display_window_get_gc(wnd, &gc);
|
---|
| 253 | /* async_connect_me_to() does not return specific error */
|
---|
| 254 | PCUT_ASSERT_ERRNO_VAL(EIO, rc);
|
---|
| 255 | PCUT_ASSERT_NULL(gc);
|
---|
| 256 |
|
---|
| 257 | resp.rc = EOK;
|
---|
| 258 | rc = display_window_destroy(wnd);
|
---|
| 259 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 260 |
|
---|
| 261 | display_close(disp);
|
---|
| 262 | rc = loc_service_unregister(sid);
|
---|
| 263 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
[959b7ec] | 264 | }
|
---|
| 265 |
|
---|
| 266 | /** display_window_get_gc with server returning success */
|
---|
| 267 | PCUT_TEST(window_get_gc_success)
|
---|
| 268 | {
|
---|
[bfddc62] | 269 | errno_t rc;
|
---|
| 270 | service_id_t sid;
|
---|
| 271 | display_t *disp = NULL;
|
---|
| 272 | display_window_t *wnd;
|
---|
| 273 | test_response_t resp;
|
---|
| 274 | gfx_context_t *gc;
|
---|
| 275 | gfx_color_t *color;
|
---|
| 276 |
|
---|
| 277 | async_set_fallback_port_handler(test_display_conn, &resp);
|
---|
| 278 |
|
---|
| 279 | rc = loc_server_register(test_display_server);
|
---|
| 280 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 281 |
|
---|
| 282 | rc = loc_service_register(test_display_svc, &sid);
|
---|
| 283 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 284 |
|
---|
| 285 | rc = display_open(test_display_svc, &disp);
|
---|
| 286 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 287 | PCUT_ASSERT_NOT_NULL(disp);
|
---|
| 288 |
|
---|
| 289 | wnd = NULL;
|
---|
| 290 | resp.rc = EOK;
|
---|
| 291 | rc = display_window_create(disp, &test_display_wnd_cb, NULL, &wnd);
|
---|
| 292 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 293 | PCUT_ASSERT_NOT_NULL(wnd);
|
---|
| 294 |
|
---|
| 295 | gc = NULL;
|
---|
| 296 | rc = display_window_get_gc(wnd, &gc);
|
---|
| 297 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 298 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
| 299 |
|
---|
| 300 | rc = gfx_color_new_rgb_i16(0, 0, 0, &color);
|
---|
| 301 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 302 |
|
---|
| 303 | resp.set_color_called = false;
|
---|
| 304 | rc = gfx_set_color(gc, color);
|
---|
| 305 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 306 | PCUT_ASSERT_TRUE(resp.set_color_called);
|
---|
| 307 |
|
---|
| 308 | gfx_color_delete(color);
|
---|
| 309 |
|
---|
| 310 | rc = display_window_destroy(wnd);
|
---|
| 311 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 312 |
|
---|
| 313 | display_close(disp);
|
---|
| 314 | rc = loc_service_unregister(sid);
|
---|
| 315 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
[959b7ec] | 316 | }
|
---|
| 317 |
|
---|
| 318 | static void test_display_conn(ipc_call_t *icall, void *arg)
|
---|
| 319 | {
|
---|
[bfddc62] | 320 | test_response_t *resp = (test_response_t *) arg;
|
---|
[959b7ec] | 321 | display_srv_t srv;
|
---|
[bfddc62] | 322 | sysarg_t wnd_id;
|
---|
| 323 | sysarg_t svc_id;
|
---|
| 324 | gfx_context_t *gc;
|
---|
| 325 | errno_t rc;
|
---|
| 326 |
|
---|
| 327 | /* log_msg(LOG_DEFAULT, LVL_NOTE, "test_display_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
|
---|
| 328 | ipc_get_arg1(icall), ipc_get_arg2(icall), ipc_get_arg3(icall),
|
---|
| 329 | ipc_get_arg4(icall));
|
---|
| 330 | */
|
---|
| 331 | (void) icall;
|
---|
| 332 | (void) arg;
|
---|
| 333 |
|
---|
| 334 | svc_id = ipc_get_arg2(icall);
|
---|
| 335 | wnd_id = ipc_get_arg3(icall);
|
---|
| 336 |
|
---|
| 337 | if (svc_id != 0) {
|
---|
| 338 | /* Set up protocol structure */
|
---|
| 339 | display_srv_initialize(&srv);
|
---|
| 340 | srv.ops = &test_display_srv_ops;
|
---|
| 341 | srv.arg = arg;
|
---|
| 342 |
|
---|
| 343 | /* Handle connection */
|
---|
| 344 | display_conn(icall, &srv);
|
---|
| 345 | } else {
|
---|
| 346 | (void) wnd_id;
|
---|
| 347 |
|
---|
| 348 | if (resp->rc != EOK) {
|
---|
| 349 | async_answer_0(icall, resp->rc);
|
---|
| 350 | return;
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | rc = gfx_context_new(&test_gc_ops, arg, &gc);
|
---|
| 354 | if (rc != EOK) {
|
---|
| 355 | async_answer_0(icall, ENOMEM);
|
---|
| 356 | return;
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | /* Window GC connection */
|
---|
| 360 | gc_conn(icall, gc);
|
---|
| 361 | }
|
---|
| 362 | }
|
---|
[959b7ec] | 363 |
|
---|
[bfddc62] | 364 | static void test_kbd_event(void *arg, kbd_event_t *event)
|
---|
| 365 | {
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | static errno_t test_window_create(void *arg, sysarg_t *rwnd_id)
|
---|
| 369 | {
|
---|
| 370 | test_response_t *resp = (test_response_t *) arg;
|
---|
| 371 |
|
---|
| 372 | resp->window_create_called = true;
|
---|
| 373 | if (resp->rc == EOK)
|
---|
| 374 | *rwnd_id = resp->wnd_id;
|
---|
[959b7ec] | 375 |
|
---|
[bfddc62] | 376 | return resp->rc;
|
---|
[959b7ec] | 377 | }
|
---|
| 378 |
|
---|
[bfddc62] | 379 | static errno_t test_window_destroy(void *arg, sysarg_t wnd_id)
|
---|
| 380 | {
|
---|
| 381 | test_response_t *resp = (test_response_t *) arg;
|
---|
| 382 |
|
---|
| 383 | resp->window_destroy_called = true;
|
---|
| 384 | return resp->rc;
|
---|
| 385 | }
|
---|
| 386 |
|
---|
| 387 | static errno_t test_get_event(void *arg, sysarg_t *wnd_id, display_wnd_ev_t *event)
|
---|
| 388 | {
|
---|
| 389 | test_response_t *resp = (test_response_t *) arg;
|
---|
| 390 |
|
---|
| 391 | resp->get_event_called = true;
|
---|
| 392 | if (resp->rc == EOK) {
|
---|
| 393 | *wnd_id = resp->wnd_id;
|
---|
| 394 | *event = resp->event;
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 | return resp->rc;
|
---|
| 398 | }
|
---|
| 399 |
|
---|
| 400 | static errno_t test_gc_set_color(void *arg, gfx_color_t *color)
|
---|
| 401 | {
|
---|
| 402 | test_response_t *resp = (test_response_t *) arg;
|
---|
| 403 |
|
---|
| 404 | resp->set_color_called = true;
|
---|
| 405 | return resp->rc;
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 |
|
---|
[959b7ec] | 409 | PCUT_EXPORT(display);
|
---|