Changeset b71c0fc in mainline for uspace/lib/ui/test/window.c
- Timestamp:
- 2020-11-07T16:07:22Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d55ab823
- Parents:
- fa01c05
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/window.c
rfa01c05 rb71c0fc 34 34 #include <pcut/pcut.h> 35 35 #include <stdbool.h> 36 #include <ui/control.h> 36 37 #include <ui/resource.h> 37 38 #include <ui/ui.h> … … 60 61 61 62 static ui_window_cb_t dummy_window_cb = { 63 }; 64 65 static errno_t test_ctl_paint(void *); 66 static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *); 67 68 static ui_control_ops_t test_ctl_ops = { 69 .paint = test_ctl_paint, 70 .pos_event = test_ctl_pos_event 62 71 }; 63 72 … … 74 83 } test_cb_resp_t; 75 84 85 typedef struct { 86 errno_t rc; 87 ui_evclaim_t claim; 88 bool paint; 89 bool pos; 90 pos_event_t pos_event; 91 } test_ctl_resp_t; 92 76 93 /** Create and destroy window */ 77 94 PCUT_TEST(create_destroy) … … 100 117 { 101 118 ui_window_destroy(NULL); 119 } 120 121 /** ui_window_add()/ui_window_remove() ... */ 122 PCUT_TEST(add_remove) 123 { 124 errno_t rc; 125 ui_t *ui = NULL; 126 ui_wnd_params_t params; 127 ui_window_t *window = NULL; 128 ui_control_t *control = NULL; 129 test_ctl_resp_t resp; 130 131 rc = ui_create_disp(NULL, &ui); 132 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 133 134 ui_wnd_params_init(¶ms); 135 params.caption = "Hello"; 136 137 rc = ui_window_create(ui, ¶ms, &window); 138 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 139 PCUT_ASSERT_NOT_NULL(window); 140 141 rc = ui_control_new(&test_ctl_ops, &resp, &control); 142 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 143 144 /* Control not called since it hasn't been added yet */ 145 resp.rc = ENOMEM; 146 resp.paint = false; 147 rc = ui_window_def_paint(window); 148 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 149 PCUT_ASSERT_FALSE(resp.paint); 150 151 ui_window_add(window, control); 152 153 /* Now paint request should be delivered to control */ 154 resp.rc = EOK; 155 resp.paint = false; 156 rc = ui_window_def_paint(window); 157 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 158 PCUT_ASSERT_TRUE(resp.paint); 159 160 ui_window_remove(window, control); 161 162 /* 163 * After having removed the control the request should no longer 164 * be delivered to it. 165 */ 166 resp.rc = ENOMEM; 167 resp.paint = false; 168 rc = ui_window_def_paint(window); 169 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 170 PCUT_ASSERT_FALSE(resp.paint); 171 172 ui_window_destroy(window); 173 ui_destroy(ui); 102 174 } 103 175 … … 166 238 ui_wnd_params_t params; 167 239 ui_window_t *window = NULL; 168 169 rc = ui_create_disp(NULL, &ui); 170 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 171 172 ui_wnd_params_init(¶ms); 173 params.caption = "Hello"; 174 175 rc = ui_window_create(ui, ¶ms, &window); 176 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 177 PCUT_ASSERT_NOT_NULL(window); 178 179 ui_window_def_paint(window); 240 ui_control_t *control = NULL; 241 test_ctl_resp_t resp; 242 243 rc = ui_create_disp(NULL, &ui); 244 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 245 246 ui_wnd_params_init(¶ms); 247 params.caption = "Hello"; 248 249 rc = ui_window_create(ui, ¶ms, &window); 250 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 251 PCUT_ASSERT_NOT_NULL(window); 252 253 rc = ui_control_new(&test_ctl_ops, &resp, &control); 254 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 255 256 ui_window_add(window, control); 257 258 resp.rc = EOK; 259 resp.paint = false; 260 rc = ui_window_def_paint(window); 261 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 262 PCUT_ASSERT_TRUE(resp.paint); 263 264 resp.rc = ENOMEM; 265 resp.paint = false; 266 rc = ui_window_def_paint(window); 267 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 268 PCUT_ASSERT_TRUE(resp.paint); 269 270 PCUT_ASSERT_TRUE(resp.paint); 271 272 /* Need to remove first because we didn't implement the destructor */ 273 ui_window_remove(window, control); 274 275 ui_window_destroy(window); 276 ui_destroy(ui); 277 } 278 279 /** ui_window_def_pos() delivers position event to control in window */ 280 PCUT_TEST(def_pos) 281 { 282 errno_t rc; 283 ui_t *ui = NULL; 284 ui_wnd_params_t params; 285 ui_window_t *window = NULL; 286 ui_control_t *control = NULL; 287 test_ctl_resp_t resp; 288 pos_event_t event; 289 290 rc = ui_create_disp(NULL, &ui); 291 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 292 293 ui_wnd_params_init(¶ms); 294 params.caption = "Hello"; 295 296 rc = ui_window_create(ui, ¶ms, &window); 297 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 298 299 rc = ui_control_new(&test_ctl_ops, &resp, &control); 300 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 301 302 ui_window_add(window, control); 303 304 event.pos_id = 1; 305 event.type = POS_PRESS; 306 event.btn_num = 2; 307 event.hpos = 3; 308 event.vpos = 4; 309 310 resp.pos = false; 311 resp.claim = ui_claimed; 312 313 ui_window_def_pos(window, &event); 314 315 PCUT_ASSERT_TRUE(resp.pos); 316 PCUT_ASSERT_INT_EQUALS(event.pos_id, resp.pos_event.pos_id); 317 PCUT_ASSERT_INT_EQUALS(event.type, resp.pos_event.type); 318 PCUT_ASSERT_INT_EQUALS(event.btn_num, resp.pos_event.btn_num); 319 PCUT_ASSERT_INT_EQUALS(event.hpos, resp.pos_event.hpos); 320 PCUT_ASSERT_INT_EQUALS(event.vpos, resp.pos_event.vpos); 321 322 /* Need to remove first because we didn't implement the destructor */ 323 ui_window_remove(window, control); 180 324 181 325 ui_window_destroy(window); … … 470 614 } 471 615 616 static errno_t test_ctl_paint(void *arg) 617 { 618 test_ctl_resp_t *resp = (test_ctl_resp_t *) arg; 619 620 resp->paint = true; 621 return resp->rc; 622 } 623 624 static ui_evclaim_t test_ctl_pos_event(void *arg, pos_event_t *event) 625 { 626 test_ctl_resp_t *resp = (test_ctl_resp_t *) arg; 627 628 resp->pos = true; 629 resp->pos_event = *event; 630 631 return resp->claim; 632 } 633 472 634 PCUT_EXPORT(window);
Note:
See TracChangeset
for help on using the changeset viewer.