Changes in uspace/lib/ui/test/pbutton.c [3583ffb:3c54869] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/pbutton.c
r3583ffb r3c54869 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 41 41 PCUT_TEST_SUITE(pbutton); 42 42 43 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *); 43 44 static errno_t testgc_set_color(void *, gfx_color_t *); 44 45 static errno_t testgc_fill_rect(void *, gfx_rect_t *); 46 static errno_t testgc_update(void *); 45 47 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *, 46 48 gfx_bitmap_alloc_t *, void **); … … 50 52 51 53 static gfx_context_ops_t ops = { 54 .set_clip_rect = testgc_set_clip_rect, 52 55 .set_color = testgc_set_color, 53 56 .fill_rect = testgc_fill_rect, 57 .update = testgc_update, 54 58 .bitmap_create = testgc_bitmap_create, 55 59 .bitmap_destroy = testgc_bitmap_destroy, … … 59 63 60 64 static void test_pbutton_clicked(ui_pbutton_t *, void *); 65 static void test_pbutton_down(ui_pbutton_t *, void *); 66 static void test_pbutton_up(ui_pbutton_t *, void *); 61 67 62 68 static ui_pbutton_cb_t test_pbutton_cb = { 63 .clicked = test_pbutton_clicked 69 .clicked = test_pbutton_clicked, 70 .down = test_pbutton_down, 71 .up = test_pbutton_up 64 72 }; 65 73 … … 86 94 typedef struct { 87 95 bool clicked; 96 bool down; 97 bool up; 88 98 } test_cb_resp_t; 89 99 … … 121 131 122 132 ui_control_destroy(control); 133 } 134 135 /** Set flags sets internal field */ 136 PCUT_TEST(set_flags) 137 { 138 ui_pbutton_t *pbutton; 139 errno_t rc; 140 141 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 142 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 143 144 ui_pbutton_set_flags(pbutton, ui_pbf_no_text_depress); 145 PCUT_ASSERT_INT_EQUALS(ui_pbf_no_text_depress, pbutton->flags); 146 147 ui_pbutton_destroy(pbutton); 123 148 } 124 149 … … 165 190 } 166 191 192 /** Get light gets internal field */ 193 PCUT_TEST(get_light) 194 { 195 ui_pbutton_t *pbutton; 196 errno_t rc; 197 198 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 199 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 200 201 pbutton->light = true; 202 PCUT_ASSERT_TRUE(ui_pbutton_get_light(pbutton)); 203 204 pbutton->light = false; 205 PCUT_ASSERT_FALSE(ui_pbutton_get_light(pbutton)); 206 207 ui_pbutton_destroy(pbutton); 208 } 209 210 /** Set light sets internal field */ 211 PCUT_TEST(set_light) 212 { 213 ui_pbutton_t *pbutton; 214 errno_t rc; 215 216 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 217 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 218 219 ui_pbutton_set_light(pbutton, true); 220 PCUT_ASSERT_TRUE(pbutton->light); 221 222 ui_pbutton_set_light(pbutton, false); 223 PCUT_ASSERT_FALSE(pbutton->light); 224 225 ui_pbutton_destroy(pbutton); 226 } 227 228 /** Set caption sets internal field */ 229 PCUT_TEST(set_caption) 230 { 231 ui_pbutton_t *pbutton; 232 errno_t rc; 233 234 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 235 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 236 237 PCUT_ASSERT_STR_EQUALS("Hello", pbutton->caption); 238 239 rc = ui_pbutton_set_caption(pbutton, "World"); 240 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 241 242 PCUT_ASSERT_STR_EQUALS("World", pbutton->caption); 243 244 ui_pbutton_destroy(pbutton); 245 } 246 167 247 /** Paint button */ 168 248 PCUT_TEST(paint) … … 178 258 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 179 259 180 rc = ui_resource_create(gc, &resource);260 rc = ui_resource_create(gc, false, &resource); 181 261 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 182 262 PCUT_ASSERT_NOT_NULL(resource); … … 221 301 } 222 302 303 /** Test ui_pbutton_down() */ 304 PCUT_TEST(down) 305 { 306 errno_t rc; 307 ui_pbutton_t *pbutton; 308 test_cb_resp_t resp; 309 310 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 311 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 312 313 /* Down with no callbacks set */ 314 ui_pbutton_clicked(pbutton); 315 316 /* Down with callback not implementing down */ 317 ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL); 318 ui_pbutton_down(pbutton); 319 320 /* Down with real callback set */ 321 resp.down = false; 322 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp); 323 ui_pbutton_down(pbutton); 324 PCUT_ASSERT_TRUE(resp.down); 325 326 ui_pbutton_destroy(pbutton); 327 } 328 329 /** Test ui_pbutton_up() */ 330 PCUT_TEST(up) 331 { 332 errno_t rc; 333 ui_pbutton_t *pbutton; 334 test_cb_resp_t resp; 335 336 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 337 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 338 339 /* Up with no callbacks set */ 340 ui_pbutton_clicked(pbutton); 341 342 /* Up with callback not implementing up */ 343 ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL); 344 ui_pbutton_up(pbutton); 345 346 /* Up with real callback set */ 347 resp.up = false; 348 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp); 349 ui_pbutton_up(pbutton); 350 PCUT_ASSERT_TRUE(resp.up); 351 352 ui_pbutton_destroy(pbutton); 353 } 354 223 355 /** Press and release button */ 224 356 PCUT_TEST(press_release) … … 235 367 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 236 368 237 rc = ui_resource_create(gc, &resource); 369 rc = ui_resource_create(gc, false, &resource); 370 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 371 PCUT_ASSERT_NOT_NULL(resource); 372 373 rc = ui_pbutton_create(resource, "Hello", &pbutton); 374 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 375 376 resp.clicked = false; 377 resp.down = false; 378 resp.up = false; 379 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp); 380 381 PCUT_ASSERT_FALSE(pbutton->held); 382 PCUT_ASSERT_FALSE(pbutton->inside); 383 384 ui_pbutton_press(pbutton); 385 PCUT_ASSERT_TRUE(pbutton->held); 386 PCUT_ASSERT_TRUE(pbutton->inside); 387 PCUT_ASSERT_TRUE(resp.down); 388 PCUT_ASSERT_FALSE(resp.up); 389 PCUT_ASSERT_FALSE(resp.clicked); 390 391 ui_pbutton_release(pbutton); 392 PCUT_ASSERT_FALSE(pbutton->held); 393 PCUT_ASSERT_TRUE(pbutton->inside); 394 PCUT_ASSERT_TRUE(resp.up); 395 PCUT_ASSERT_TRUE(resp.clicked); 396 397 ui_pbutton_destroy(pbutton); 398 ui_resource_destroy(resource); 399 400 rc = gfx_context_delete(gc); 401 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 402 } 403 404 /** Press, leave and release button */ 405 PCUT_TEST(press_leave_release) 406 { 407 errno_t rc; 408 gfx_context_t *gc = NULL; 409 test_gc_t tgc; 410 ui_resource_t *resource = NULL; 411 ui_pbutton_t *pbutton; 412 test_cb_resp_t resp; 413 414 memset(&tgc, 0, sizeof(tgc)); 415 rc = gfx_context_new(&ops, &tgc, &gc); 416 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 417 418 rc = ui_resource_create(gc, false, &resource); 238 419 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 239 420 PCUT_ASSERT_NOT_NULL(resource); … … 253 434 PCUT_ASSERT_FALSE(resp.clicked); 254 435 436 ui_pbutton_leave(pbutton); 437 PCUT_ASSERT_TRUE(pbutton->held); 438 PCUT_ASSERT_FALSE(pbutton->inside); 439 PCUT_ASSERT_FALSE(resp.clicked); 440 255 441 ui_pbutton_release(pbutton); 256 442 PCUT_ASSERT_FALSE(pbutton->held); 257 PCUT_ASSERT_ TRUE(pbutton->inside);258 PCUT_ASSERT_ TRUE(resp.clicked);443 PCUT_ASSERT_FALSE(pbutton->inside); 444 PCUT_ASSERT_FALSE(resp.clicked); 259 445 260 446 ui_pbutton_destroy(pbutton); … … 265 451 } 266 452 267 /** Press, leave and release button */268 PCUT_TEST(press_leave_ release)453 /** Press, leave, enter and release button */ 454 PCUT_TEST(press_leave_enter_release) 269 455 { 270 456 errno_t rc; … … 279 465 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 280 466 281 rc = ui_resource_create(gc, &resource);467 rc = ui_resource_create(gc, false, &resource); 282 468 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 283 469 PCUT_ASSERT_NOT_NULL(resource); … … 302 488 PCUT_ASSERT_FALSE(resp.clicked); 303 489 304 ui_pbutton_release(pbutton);305 PCUT_ASSERT_FALSE(pbutton->held);306 PCUT_ASSERT_FALSE(pbutton->inside);307 PCUT_ASSERT_FALSE(resp.clicked);308 309 ui_pbutton_destroy(pbutton);310 ui_resource_destroy(resource);311 312 rc = gfx_context_delete(gc);313 PCUT_ASSERT_ERRNO_VAL(EOK, rc);314 }315 316 /** Press, leave, enter and release button */317 PCUT_TEST(press_leave_enter_release)318 {319 errno_t rc;320 gfx_context_t *gc = NULL;321 test_gc_t tgc;322 ui_resource_t *resource = NULL;323 ui_pbutton_t *pbutton;324 test_cb_resp_t resp;325 326 memset(&tgc, 0, sizeof(tgc));327 rc = gfx_context_new(&ops, &tgc, &gc);328 PCUT_ASSERT_ERRNO_VAL(EOK, rc);329 330 rc = ui_resource_create(gc, &resource);331 PCUT_ASSERT_ERRNO_VAL(EOK, rc);332 PCUT_ASSERT_NOT_NULL(resource);333 334 rc = ui_pbutton_create(resource, "Hello", &pbutton);335 PCUT_ASSERT_ERRNO_VAL(EOK, rc);336 337 resp.clicked = false;338 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);339 340 PCUT_ASSERT_FALSE(pbutton->held);341 PCUT_ASSERT_FALSE(pbutton->inside);342 343 ui_pbutton_press(pbutton);344 PCUT_ASSERT_TRUE(pbutton->held);345 PCUT_ASSERT_TRUE(pbutton->inside);346 PCUT_ASSERT_FALSE(resp.clicked);347 348 ui_pbutton_leave(pbutton);349 PCUT_ASSERT_TRUE(pbutton->held);350 PCUT_ASSERT_FALSE(pbutton->inside);351 PCUT_ASSERT_FALSE(resp.clicked);352 353 490 ui_pbutton_enter(pbutton); 354 491 PCUT_ASSERT_TRUE(pbutton->held); … … 384 521 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 385 522 386 rc = ui_resource_create(gc, &resource);523 rc = ui_resource_create(gc, false, &resource); 387 524 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 388 525 PCUT_ASSERT_NOT_NULL(resource); … … 445 582 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 446 583 447 rc = ui_resource_create(gc, &resource);584 rc = ui_resource_create(gc, false, &resource); 448 585 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 449 586 PCUT_ASSERT_NOT_NULL(resource); … … 488 625 } 489 626 627 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect) 628 { 629 (void) arg; 630 (void) rect; 631 return EOK; 632 } 633 490 634 static errno_t testgc_set_color(void *arg, gfx_color_t *color) 491 635 { … … 499 643 (void) arg; 500 644 (void) rect; 645 return EOK; 646 } 647 648 static errno_t testgc_update(void *arg) 649 { 650 (void) arg; 501 651 return EOK; 502 652 } … … 571 721 } 572 722 723 static void test_pbutton_down(ui_pbutton_t *pbutton, void *arg) 724 { 725 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 726 727 resp->down = true; 728 } 729 730 static void test_pbutton_up(ui_pbutton_t *pbutton, void *arg) 731 { 732 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 733 734 resp->up = true; 735 } 736 573 737 PCUT_EXPORT(pbutton);
Note:
See TracChangeset
for help on using the changeset viewer.