Changeset bfddc62 in mainline
- Timestamp:
- 2019-11-08T08:52:04Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bac129a
- Parents:
- e422ff6
- git-author:
- Jiri Svoboda <jiri@…> (2019-10-07 18:50:38)
- git-committer:
- Jiri Svoboda <jiri@…> (2019-11-08 08:52:04)
- Location:
- uspace
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/display/test/display.c
re422ff6 rbfddc62 31 31 #include <display.h> 32 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> 33 37 #include <loc.h> 34 38 #include <pcut/pcut.h> … … 42 46 43 47 static void test_display_conn(ipc_call_t *, void *); 44 45 static display_ops_t test_display_srv_ops; 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; 46 82 47 83 /** display_open(), display_close() work for valid display service */ … … 72 108 PCUT_TEST(window_create_failure) 73 109 { 74 // TODO 75 } 76 77 /** display_window_create() with server returning success */ 78 PCUT_TEST(window_create_success) 79 { 80 // TODO 81 } 82 83 /** display_window_create() with server returning error response works */ 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. */ 84 184 PCUT_TEST(window_destroy_failure) 85 185 { 86 // TODO 87 } 88 89 /** display_window_create() with server returning success */ 90 PCUT_TEST(window_destroy_success) 91 { 92 // TODO 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); 93 220 } 94 221 … … 96 223 PCUT_TEST(window_get_gc_failure) 97 224 { 98 // TODO 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); 99 264 } 100 265 … … 102 267 PCUT_TEST(window_get_gc_success) 103 268 { 104 // TODO 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); 105 316 } 106 317 107 318 static void test_display_conn(ipc_call_t *icall, void *arg) 108 319 { 320 test_response_t *resp = (test_response_t *) arg; 109 321 display_srv_t srv; 110 111 display_srv_initialize(&srv); 112 srv.ops = &test_display_srv_ops; 113 srv.arg = NULL; 114 115 display_conn(icall, &srv); 116 } 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 } 363 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; 375 376 return resp->rc; 377 } 378 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 117 408 118 409 PCUT_EXPORT(display); -
uspace/srv/hid/display/main.c
re422ff6 rbfddc62 176 176 gc_conn(icall, gc); 177 177 } 178 179 178 } 180 179
Note:
See TracChangeset
for help on using the changeset viewer.