| 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 | 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 | {
|
|---|
| 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);
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | /** display_window_create() and display_window_destroy() with success
|
|---|
| 142 | *
|
|---|
| 143 | * with server returning success,
|
|---|
| 144 | */
|
|---|
| 145 | PCUT_TEST(window_create_destroy_success)
|
|---|
| 146 | {
|
|---|
| 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);
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | /** display_window_create() with server returning error response works. */
|
|---|
| 184 | PCUT_TEST(window_destroy_failure)
|
|---|
| 185 | {
|
|---|
| 186 | errno_t rc;
|
|---|
| 187 | service_id_t sid;
|
|---|
| 188 | display_t *disp = NULL;
|
|---|
| 189 | display_window_t *wnd;
|
|---|
| 190 | test_response_t resp;
|
|---|
| 191 |
|
|---|
| 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);
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | /** display_window_get_gc with server returning failure */
|
|---|
| 223 | PCUT_TEST(window_get_gc_failure)
|
|---|
| 224 | {
|
|---|
| 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);
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | /** display_window_get_gc with server returning success */
|
|---|
| 267 | PCUT_TEST(window_get_gc_success)
|
|---|
| 268 | {
|
|---|
| 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);
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| 318 | static void test_display_conn(ipc_call_t *icall, void *arg)
|
|---|
| 319 | {
|
|---|
| 320 | test_response_t *resp = (test_response_t *) arg;
|
|---|
| 321 | display_srv_t srv;
|
|---|
| 322 | sysarg_t wnd_id;
|
|---|
| 323 | sysarg_t svc_id;
|
|---|
| 324 | gfx_context_t *gc;
|
|---|
| 325 | errno_t rc;
|
|---|
| 326 |
|
|---|
| 327 | svc_id = ipc_get_arg2(icall);
|
|---|
| 328 | wnd_id = ipc_get_arg3(icall);
|
|---|
| 329 |
|
|---|
| 330 | if (svc_id != 0) {
|
|---|
| 331 | /* Set up protocol structure */
|
|---|
| 332 | display_srv_initialize(&srv);
|
|---|
| 333 | srv.ops = &test_display_srv_ops;
|
|---|
| 334 | srv.arg = arg;
|
|---|
| 335 |
|
|---|
| 336 | /* Handle connection */
|
|---|
| 337 | display_conn(icall, &srv);
|
|---|
| 338 | } else {
|
|---|
| 339 | (void) wnd_id;
|
|---|
| 340 |
|
|---|
| 341 | if (resp->rc != EOK) {
|
|---|
| 342 | async_answer_0(icall, resp->rc);
|
|---|
| 343 | return;
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | rc = gfx_context_new(&test_gc_ops, arg, &gc);
|
|---|
| 347 | if (rc != EOK) {
|
|---|
| 348 | async_answer_0(icall, ENOMEM);
|
|---|
| 349 | return;
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | /* Window GC connection */
|
|---|
| 353 | gc_conn(icall, gc);
|
|---|
| 354 | }
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | static void test_kbd_event(void *arg, kbd_event_t *event)
|
|---|
| 358 | {
|
|---|
| 359 | }
|
|---|
| 360 |
|
|---|
| 361 | static errno_t test_window_create(void *arg, sysarg_t *rwnd_id)
|
|---|
| 362 | {
|
|---|
| 363 | test_response_t *resp = (test_response_t *) arg;
|
|---|
| 364 |
|
|---|
| 365 | resp->window_create_called = true;
|
|---|
| 366 | if (resp->rc == EOK)
|
|---|
| 367 | *rwnd_id = resp->wnd_id;
|
|---|
| 368 |
|
|---|
| 369 | return resp->rc;
|
|---|
| 370 | }
|
|---|
| 371 |
|
|---|
| 372 | static errno_t test_window_destroy(void *arg, sysarg_t wnd_id)
|
|---|
| 373 | {
|
|---|
| 374 | test_response_t *resp = (test_response_t *) arg;
|
|---|
| 375 |
|
|---|
| 376 | resp->window_destroy_called = true;
|
|---|
| 377 | return resp->rc;
|
|---|
| 378 | }
|
|---|
| 379 |
|
|---|
| 380 | static errno_t test_get_event(void *arg, sysarg_t *wnd_id, display_wnd_ev_t *event)
|
|---|
| 381 | {
|
|---|
| 382 | test_response_t *resp = (test_response_t *) arg;
|
|---|
| 383 |
|
|---|
| 384 | resp->get_event_called = true;
|
|---|
| 385 | if (resp->rc == EOK) {
|
|---|
| 386 | *wnd_id = resp->wnd_id;
|
|---|
| 387 | *event = resp->event;
|
|---|
| 388 | }
|
|---|
| 389 |
|
|---|
| 390 | return resp->rc;
|
|---|
| 391 | }
|
|---|
| 392 |
|
|---|
| 393 | static errno_t test_gc_set_color(void *arg, gfx_color_t *color)
|
|---|
| 394 | {
|
|---|
| 395 | test_response_t *resp = (test_response_t *) arg;
|
|---|
| 396 |
|
|---|
| 397 | resp->set_color_called = true;
|
|---|
| 398 | return resp->rc;
|
|---|
| 399 | }
|
|---|
| 400 |
|
|---|
| 401 | PCUT_EXPORT(display);
|
|---|