Changeset 1eaead4 in mainline for uspace/lib/ui/test
- Timestamp:
- 2023-02-07T16:11:53Z (3 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0366d09d
- Parents:
- 7c5320c
- Location:
- uspace/lib/ui/test
- Files:
-
- 3 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/control.c
r7c5320c r1eaead4 33 33 #include <pcut/pcut.h> 34 34 #include <ui/control.h> 35 #include <ui/testctl.h> 35 36 #include <stdbool.h> 36 37 #include <types/ui/event.h> 38 #include "../private/testctl.h" 37 39 38 40 PCUT_INIT; 39 41 40 42 PCUT_TEST_SUITE(control); 41 42 static void test_ctl_destroy(void *);43 static errno_t test_ctl_paint(void *);44 static ui_evclaim_t test_ctl_kbd_event(void *, kbd_event_t *);45 static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);46 static void test_ctl_unfocus(void *, unsigned);47 48 static ui_control_ops_t test_ctl_ops = {49 .destroy = test_ctl_destroy,50 .paint = test_ctl_paint,51 .kbd_event = test_ctl_kbd_event,52 .pos_event = test_ctl_pos_event,53 .unfocus = test_ctl_unfocus54 };55 56 /** Test response */57 typedef struct {58 /** Claim to return */59 ui_evclaim_t claim;60 /** Result code to return */61 errno_t rc;62 63 /** @c true iff destroy was called */64 bool destroy;65 66 /** @c true iff paint was called */67 bool paint;68 69 /** @c true iff kbd_event was called */70 bool kbd;71 /** Keyboard event that was sent */72 kbd_event_t kevent;73 74 /** @c true iff pos_event was called */75 bool pos;76 /** Position event that was sent */77 pos_event_t pevent;78 79 /** @c true iff unfocus was called */80 bool unfocus;81 /** Number of remaining foci that was sent */82 unsigned unfocus_nfocus;83 } test_resp_t;84 43 85 44 /** Allocate and deallocate control */ … … 89 48 errno_t rc; 90 49 91 rc = ui_control_new(& test_ctl_ops, NULL, &control);50 rc = ui_control_new(&ui_test_ctl_ops, NULL, &control); 92 51 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 93 52 PCUT_ASSERT_NOT_NULL(control); … … 105 64 PCUT_TEST(destroy) 106 65 { 107 ui_ control_t *control = NULL;108 test_resp_t resp;66 ui_test_ctl_t *testctl = NULL; 67 ui_tc_resp_t resp; 109 68 errno_t rc; 110 69 111 rc = ui_ control_new(&test_ctl_ops, &resp, &control);70 rc = ui_test_ctl_create(&resp, &testctl); 112 71 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 113 PCUT_ASSERT_NOT_NULL( control);72 PCUT_ASSERT_NOT_NULL(testctl); 114 73 115 74 resp.rc = EOK; 116 75 resp.destroy = false; 117 76 118 ui_control_destroy( control);77 ui_control_destroy(ui_test_ctl_ctl(testctl)); 119 78 PCUT_ASSERT_TRUE(resp.destroy); 120 79 } … … 123 82 PCUT_TEST(paint) 124 83 { 125 ui_ control_t *control = NULL;126 test_resp_t resp;84 ui_test_ctl_t *testctl = NULL; 85 ui_tc_resp_t resp; 127 86 errno_t rc; 128 87 129 rc = ui_ control_new(&test_ctl_ops, &resp, &control);88 rc = ui_test_ctl_create(&resp, &testctl); 130 89 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 131 PCUT_ASSERT_NOT_NULL( control);90 PCUT_ASSERT_NOT_NULL(testctl); 132 91 133 92 resp.rc = EOK; 134 93 resp.paint = false; 135 94 136 rc = ui_control_paint( control);95 rc = ui_control_paint(ui_test_ctl_ctl(testctl)); 137 96 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 138 97 PCUT_ASSERT_TRUE(resp.paint); … … 141 100 resp.paint = false; 142 101 143 rc = ui_control_paint( control);102 rc = ui_control_paint(ui_test_ctl_ctl(testctl)); 144 103 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 145 104 PCUT_ASSERT_TRUE(resp.paint); 146 105 147 ui_ control_delete(control);106 ui_test_ctl_destroy(testctl); 148 107 } 149 108 … … 151 110 PCUT_TEST(kbd_event) 152 111 { 153 ui_ control_t *control = NULL;154 test_resp_t resp;112 ui_test_ctl_t *testctl = NULL; 113 ui_tc_resp_t resp; 155 114 kbd_event_t event; 156 115 ui_evclaim_t claim; 157 116 errno_t rc; 158 117 159 rc = ui_ control_new(&test_ctl_ops, &resp, &control);118 rc = ui_test_ctl_create(&resp, &testctl); 160 119 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 161 PCUT_ASSERT_NOT_NULL( control);120 PCUT_ASSERT_NOT_NULL(testctl); 162 121 163 122 resp.claim = ui_claimed; … … 168 127 event.c = '@'; 169 128 170 claim = ui_control_kbd_event( control, &event);129 claim = ui_control_kbd_event(ui_test_ctl_ctl(testctl), &event); 171 130 PCUT_ASSERT_EQUALS(resp.claim, claim); 172 131 PCUT_ASSERT_TRUE(resp.kbd); … … 176 135 PCUT_ASSERT_INT_EQUALS(resp.kevent.c, event.c); 177 136 178 ui_ control_delete(control);137 ui_test_ctl_destroy(testctl); 179 138 } 180 139 … … 182 141 PCUT_TEST(pos_event) 183 142 { 184 ui_ control_t *control = NULL;185 test_resp_t resp;143 ui_test_ctl_t *testctl = NULL; 144 ui_tc_resp_t resp; 186 145 pos_event_t event; 187 146 ui_evclaim_t claim; 188 147 errno_t rc; 189 148 190 rc = ui_ control_new(&test_ctl_ops, &resp, &control);149 rc = ui_test_ctl_create(&resp, &testctl); 191 150 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 192 PCUT_ASSERT_NOT_NULL( control);151 PCUT_ASSERT_NOT_NULL(testctl); 193 152 194 153 resp.claim = ui_claimed; … … 200 159 event.vpos = 4; 201 160 202 claim = ui_control_pos_event( control, &event);161 claim = ui_control_pos_event(ui_test_ctl_ctl(testctl), &event); 203 162 PCUT_ASSERT_EQUALS(resp.claim, claim); 204 163 PCUT_ASSERT_TRUE(resp.pos); … … 209 168 PCUT_ASSERT_INT_EQUALS(resp.pevent.vpos, event.vpos); 210 169 211 ui_ control_delete(control);170 ui_test_ctl_destroy(testctl); 212 171 } 213 172 … … 215 174 PCUT_TEST(unfocus) 216 175 { 217 ui_ control_t *control = NULL;218 test_resp_t resp;176 ui_test_ctl_t *testctl = NULL; 177 ui_tc_resp_t resp; 219 178 errno_t rc; 220 179 221 rc = ui_ control_new(&test_ctl_ops, &resp, &control);180 rc = ui_test_ctl_create(&resp, &testctl); 222 181 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 223 PCUT_ASSERT_NOT_NULL( control);182 PCUT_ASSERT_NOT_NULL(testctl); 224 183 225 184 resp.unfocus = false; 226 185 227 ui_control_unfocus( control, 42);186 ui_control_unfocus(ui_test_ctl_ctl(testctl), 42); 228 187 PCUT_ASSERT_TRUE(resp.unfocus); 229 188 PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus); 230 189 231 ui_control_delete(control); 232 } 233 234 static void test_ctl_destroy(void *arg) 235 { 236 test_resp_t *resp = (test_resp_t *) arg; 237 238 resp->destroy = true; 239 } 240 241 static errno_t test_ctl_paint(void *arg) 242 { 243 test_resp_t *resp = (test_resp_t *) arg; 244 245 resp->paint = true; 246 return resp->rc; 247 } 248 249 static ui_evclaim_t test_ctl_kbd_event(void *arg, kbd_event_t *event) 250 { 251 test_resp_t *resp = (test_resp_t *) arg; 252 253 resp->kbd = true; 254 resp->kevent = *event; 255 256 return resp->claim; 257 } 258 259 static ui_evclaim_t test_ctl_pos_event(void *arg, pos_event_t *event) 260 { 261 test_resp_t *resp = (test_resp_t *) arg; 262 263 resp->pos = true; 264 resp->pevent = *event; 265 266 return resp->claim; 267 } 268 269 static void test_ctl_unfocus(void *arg, unsigned nfocus) 270 { 271 test_resp_t *resp = (test_resp_t *) arg; 272 273 resp->unfocus = true; 274 resp->unfocus_nfocus = nfocus; 190 ui_test_ctl_destroy(testctl); 275 191 } 276 192 -
uspace/lib/ui/test/main.c
r7c5320c r1eaead4 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 52 52 PCUT_IMPORT(scrollbar); 53 53 PCUT_IMPORT(slider); 54 PCUT_IMPORT(tab); 55 PCUT_IMPORT(tabset); 56 PCUT_IMPORT(testctl); 54 57 PCUT_IMPORT(ui); 55 58 PCUT_IMPORT(wdecor); -
uspace/lib/ui/test/paint.c
r7c5320c r1eaead4 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 75 75 } testgc_bitmap_t; 76 76 77 /** Test box characters */ 78 static ui_box_chars_t test_box_chars = { 79 { 80 { "A", "B", "C" }, 81 { "D", " ", "E" }, 82 { "F", "G", "H" } 83 } 84 }; 85 77 86 /** Paint bevel */ 78 87 PCUT_TEST(bevel) … … 466 475 /* Paint text box */ 467 476 rc = ui_paint_text_box(resource, &rect, ui_box_single, color); 477 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 478 479 gfx_color_delete(color); 480 ui_resource_destroy(resource); 481 rc = gfx_context_delete(gc); 482 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 483 } 484 485 /** Paint custom text box */ 486 PCUT_TEST(text_box_custom) 487 { 488 errno_t rc; 489 gfx_context_t *gc = NULL; 490 ui_resource_t *resource = NULL; 491 gfx_color_t *color = NULL; 492 test_gc_t tgc; 493 gfx_rect_t rect; 494 495 memset(&tgc, 0, sizeof(tgc)); 496 rc = gfx_context_new(&ops, &tgc, &gc); 497 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 498 499 rc = ui_resource_create(gc, false, &resource); 500 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 501 PCUT_ASSERT_NOT_NULL(resource); 502 503 rc = gfx_color_new_rgb_i16(1, 2, 3, &color); 504 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 505 506 rect.p0.x = 10; 507 rect.p0.y = 20; 508 rect.p1.x = 30; 509 rect.p1.y = 40; 510 511 /* Paint text box */ 512 rc = ui_paint_text_box_custom(resource, &rect, &test_box_chars, color); 468 513 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 469 514 -
uspace/lib/ui/test/wdecor.c
r7c5320c r1eaead4 137 137 PCUT_TEST(set_rect) 138 138 { 139 gfx_context_t *gc = NULL; 140 test_gc_t tgc; 141 ui_resource_t *resource = NULL; 139 142 ui_wdecor_t *wdecor; 140 143 gfx_rect_t rect; 141 144 errno_t rc; 142 145 143 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 146 memset(&tgc, 0, sizeof(tgc)); 147 rc = gfx_context_new(&ops, &tgc, &gc); 148 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 149 150 rc = ui_resource_create(gc, false, &resource); 151 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 152 PCUT_ASSERT_NOT_NULL(resource); 153 154 rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor); 144 155 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 145 156 … … 156 167 157 168 ui_wdecor_destroy(wdecor); 169 ui_resource_destroy(resource); 170 171 rc = gfx_context_delete(gc); 172 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 158 173 } 159 174 … … 445 460 PCUT_TEST(close_btn_clicked) 446 461 { 462 gfx_context_t *gc = NULL; 463 test_gc_t tgc; 464 ui_resource_t *resource = NULL; 447 465 ui_wdecor_t *wdecor; 448 466 gfx_rect_t rect; … … 450 468 errno_t rc; 451 469 452 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 470 memset(&tgc, 0, sizeof(tgc)); 471 rc = gfx_context_new(&ops, &tgc, &gc); 472 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 473 474 rc = ui_resource_create(gc, false, &resource); 475 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 476 PCUT_ASSERT_NOT_NULL(resource); 477 478 rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor); 453 479 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 454 480 … … 468 494 469 495 ui_wdecor_destroy(wdecor); 496 ui_resource_destroy(resource); 497 498 rc = gfx_context_delete(gc); 499 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 470 500 } 471 501 … … 788 818 PCUT_TEST(get_rsztype) 789 819 { 820 gfx_context_t *gc = NULL; 821 test_gc_t tgc; 822 ui_resource_t *resource = NULL; 790 823 ui_wdecor_t *wdecor; 791 824 gfx_rect_t rect; … … 794 827 errno_t rc; 795 828 796 rc = ui_wdecor_create(NULL, "Hello", ui_wds_resizable, &wdecor); 829 memset(&tgc, 0, sizeof(tgc)); 830 rc = gfx_context_new(&ops, &tgc, &gc); 831 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 832 833 rc = ui_resource_create(gc, false, &resource); 834 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 835 PCUT_ASSERT_NOT_NULL(resource); 836 837 rc = ui_wdecor_create(resource, "Hello", ui_wds_resizable, &wdecor); 797 838 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 798 839 … … 874 915 /* Non-resizable window */ 875 916 876 rc = ui_wdecor_create( NULL, "Hello", ui_wds_none, &wdecor);917 rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor); 877 918 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 878 919 … … 890 931 891 932 ui_wdecor_destroy(wdecor); 933 ui_resource_destroy(resource); 934 935 rc = gfx_context_delete(gc); 936 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 892 937 } 893 938 … … 918 963 PCUT_TEST(frame_pos_event) 919 964 { 965 gfx_context_t *gc = NULL; 966 test_gc_t tgc; 967 ui_resource_t *resource = NULL; 920 968 ui_wdecor_t *wdecor; 921 969 gfx_rect_t rect; … … 924 972 errno_t rc; 925 973 926 rc = ui_wdecor_create(NULL, "Hello", ui_wds_resizable, &wdecor); 974 memset(&tgc, 0, sizeof(tgc)); 975 rc = gfx_context_new(&ops, &tgc, &gc); 976 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 977 978 rc = ui_resource_create(gc, false, &resource); 979 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 980 PCUT_ASSERT_NOT_NULL(resource); 981 982 rc = ui_wdecor_create(resource, "Hello", ui_wds_resizable, &wdecor); 927 983 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 928 984 … … 960 1016 961 1017 ui_wdecor_destroy(wdecor); 1018 ui_resource_destroy(resource); 1019 1020 rc = gfx_context_delete(gc); 1021 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 962 1022 } 963 1023
Note:
See TracChangeset
for help on using the changeset viewer.