Changeset f03d1308 in mainline for uspace/lib/ui/test/window.c
- Timestamp:
- 2020-10-28T12:42:11Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8009dc27
- Parents:
- d284ce9
- git-author:
- Jiri Svoboda <jiri@…> (2020-10-28 12:41:11)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-10-28 12:42:11)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/window.c
rd284ce9 rf03d1308 29 29 #include <gfx/context.h> 30 30 #include <gfx/coord.h> 31 #include <io/kbd_event.h> 31 32 #include <io/pos_event.h> 32 33 #include <mem.h> … … 43 44 44 45 static void test_window_close(ui_window_t *, void *); 46 static void test_window_focus(ui_window_t *, void *); 47 static void test_window_kbd(ui_window_t *, void *, kbd_event_t *); 45 48 static void test_window_pos(ui_window_t *, void *, pos_event_t *); 49 static void test_window_unfocus(ui_window_t *, void *); 46 50 47 51 static ui_window_cb_t test_window_cb = { 48 52 .close = test_window_close, 49 .pos = test_window_pos 53 .focus = test_window_focus, 54 .kbd = test_window_kbd, 55 .pos = test_window_pos, 56 .unfocus = test_window_unfocus 50 57 }; 51 58 … … 55 62 typedef struct { 56 63 bool close; 64 bool focus; 65 bool kbd; 66 kbd_event_t kbd_event; 57 67 bool pos; 58 68 pos_event_t pos_event; 69 bool unfocus; 59 70 } test_cb_resp_t; 60 71 … … 151 162 ui_window_close(window); 152 163 PCUT_ASSERT_TRUE(resp.close); 164 165 ui_window_destroy(window); 166 ui_destroy(ui); 167 } 168 169 /** ui_window_focus() calls focus callback set via ui_window_set_cb() */ 170 PCUT_TEST(focus) 171 { 172 errno_t rc; 173 ui_t *ui = NULL; 174 ui_wnd_params_t params; 175 ui_window_t *window = NULL; 176 test_cb_resp_t resp; 177 178 rc = ui_create_disp(NULL, &ui); 179 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 180 181 ui_wnd_params_init(¶ms); 182 params.caption = "Hello"; 183 184 rc = ui_window_create(ui, ¶ms, &window); 185 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 186 PCUT_ASSERT_NOT_NULL(window); 187 188 /* Focus callback with no callbacks set */ 189 ui_window_focus(window); 190 191 /* Focus callback with focus callback not implemented */ 192 ui_window_set_cb(window, &dummy_window_cb, NULL); 193 ui_window_focus(window); 194 195 /* Focus callback with real callback set */ 196 resp.close = false; 197 ui_window_set_cb(window, &test_window_cb, &resp); 198 ui_window_focus(window); 199 PCUT_ASSERT_TRUE(resp.focus); 200 201 ui_window_destroy(window); 202 ui_destroy(ui); 203 } 204 205 /** ui_window_kbd() calls kbd callback set via ui_window_set_cb() */ 206 PCUT_TEST(kbd) 207 { 208 errno_t rc; 209 ui_t *ui = NULL; 210 ui_wnd_params_t params; 211 ui_window_t *window = NULL; 212 kbd_event_t kbd_event; 213 test_cb_resp_t resp; 214 215 rc = ui_create_disp(NULL, &ui); 216 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 217 218 ui_wnd_params_init(¶ms); 219 params.caption = "Hello"; 220 221 rc = ui_window_create(ui, ¶ms, &window); 222 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 223 PCUT_ASSERT_NOT_NULL(window); 224 225 kbd_event.type = POS_PRESS; 226 kbd_event.key = KC_X; 227 kbd_event.mods = 0; 228 kbd_event.c = 'x'; 229 230 /* Kbd callback with no callbacks set */ 231 ui_window_kbd(window, &kbd_event); 232 233 /* Kbd callback with kbd callback not implemented */ 234 ui_window_set_cb(window, &dummy_window_cb, NULL); 235 ui_window_kbd(window, &kbd_event); 236 237 /* Kbd callback with real callback set */ 238 resp.kbd = false; 239 ui_window_set_cb(window, &test_window_cb, &resp); 240 ui_window_kbd(window, &kbd_event); 241 PCUT_ASSERT_TRUE(resp.kbd); 242 PCUT_ASSERT_EQUALS(kbd_event.type, resp.kbd_event.type); 243 PCUT_ASSERT_INT_EQUALS(kbd_event.key, resp.kbd_event.key); 244 PCUT_ASSERT_INT_EQUALS(kbd_event.mods, resp.kbd_event.mods); 245 PCUT_ASSERT_INT_EQUALS(kbd_event.c, resp.kbd_event.c); 153 246 154 247 ui_window_destroy(window); … … 204 297 } 205 298 299 /** ui_window_unfocus() calls unfocus callback set via ui_window_set_cb() */ 300 PCUT_TEST(unfocus) 301 { 302 errno_t rc; 303 ui_t *ui = NULL; 304 ui_wnd_params_t params; 305 ui_window_t *window = NULL; 306 test_cb_resp_t resp; 307 308 rc = ui_create_disp(NULL, &ui); 309 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 310 311 ui_wnd_params_init(¶ms); 312 params.caption = "Hello"; 313 314 rc = ui_window_create(ui, ¶ms, &window); 315 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 316 PCUT_ASSERT_NOT_NULL(window); 317 318 /* Unfocus callback with no callbacks set */ 319 ui_window_unfocus(window); 320 321 /* Unfocus callback with unfocus callback not implemented */ 322 ui_window_set_cb(window, &dummy_window_cb, NULL); 323 ui_window_unfocus(window); 324 325 /* Unfocus callback with real callback set */ 326 resp.close = false; 327 ui_window_set_cb(window, &test_window_cb, &resp); 328 ui_window_unfocus(window); 329 PCUT_ASSERT_TRUE(resp.unfocus); 330 331 ui_window_destroy(window); 332 ui_destroy(ui); 333 } 334 206 335 static void test_window_close(ui_window_t *window, void *arg) 207 336 { … … 209 338 210 339 resp->close = true; 340 } 341 342 static void test_window_focus(ui_window_t *window, void *arg) 343 { 344 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 345 346 resp->focus = true; 347 } 348 349 static void test_window_kbd(ui_window_t *window, void *arg, 350 kbd_event_t *event) 351 { 352 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 353 354 resp->kbd = true; 355 resp->kbd_event = *event; 211 356 } 212 357 … … 220 365 } 221 366 367 static void test_window_unfocus(ui_window_t *window, void *arg) 368 { 369 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 370 371 resp->unfocus = true; 372 } 373 222 374 PCUT_EXPORT(window);
Note:
See TracChangeset
for help on using the changeset viewer.