Changeset 7481ee19 in mainline for uspace/lib/ui/test
- Timestamp:
- 2021-06-23T08:15:00Z (4 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a977e37
- Parents:
- 034ce6bb
- git-author:
- Jiri Svoboda <jiri@…> (2021-06-22 17:14:40)
- git-committer:
- Jiri Svoboda <jiri@…> (2021-06-23 08:15:00)
- Location:
- uspace/lib/ui/test
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/control.c
r034ce6bb r7481ee19 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 29 29 #include <errno.h> 30 30 #include <mem.h> 31 #include <io/kbd_event.h> 31 32 #include <io/pos_event.h> 32 33 #include <pcut/pcut.h> … … 41 42 static void test_ctl_destroy(void *); 42 43 static errno_t test_ctl_paint(void *); 44 static ui_evclaim_t test_ctl_kbd_event(void *, kbd_event_t *); 43 45 static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *); 44 46 static void test_ctl_unfocus(void *); … … 47 49 .destroy = test_ctl_destroy, 48 50 .paint = test_ctl_paint, 51 .kbd_event = test_ctl_kbd_event, 49 52 .pos_event = test_ctl_pos_event, 50 53 .unfocus = test_ctl_unfocus … … 64 67 bool paint; 65 68 69 /** @c true iff kbd_event was called */ 70 bool kbd; 71 /** Keyboard event that was sent */ 72 kbd_event_t kevent; 73 66 74 /** @c true iff pos_event was called */ 67 75 bool pos; … … 134 142 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 135 143 PCUT_ASSERT_TRUE(resp.paint); 144 145 ui_control_delete(control); 146 } 147 148 /** Test sending keyboard event to control */ 149 PCUT_TEST(kbd_event) 150 { 151 ui_control_t *control = NULL; 152 test_resp_t resp; 153 kbd_event_t event; 154 ui_evclaim_t claim; 155 errno_t rc; 156 157 rc = ui_control_new(&test_ctl_ops, &resp, &control); 158 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 159 PCUT_ASSERT_NOT_NULL(control); 160 161 resp.claim = ui_claimed; 162 resp.kbd = false; 163 event.type = KEY_PRESS; 164 event.key = KC_2; 165 event.mods = KM_LSHIFT; 166 event.c = '@'; 167 168 claim = ui_control_kbd_event(control, &event); 169 PCUT_ASSERT_EQUALS(resp.claim, claim); 170 PCUT_ASSERT_TRUE(resp.kbd); 171 PCUT_ASSERT_EQUALS(resp.kevent.type, event.type); 172 PCUT_ASSERT_INT_EQUALS(resp.kevent.key, event.key); 173 PCUT_ASSERT_INT_EQUALS(resp.kevent.mods, event.mods); 174 PCUT_ASSERT_INT_EQUALS(resp.kevent.c, event.c); 136 175 137 176 ui_control_delete(control); … … 205 244 } 206 245 246 static ui_evclaim_t test_ctl_kbd_event(void *arg, kbd_event_t *event) 247 { 248 test_resp_t *resp = (test_resp_t *) arg; 249 250 resp->kbd = true; 251 resp->kevent = *event; 252 253 return resp->claim; 254 } 255 207 256 static ui_evclaim_t test_ctl_pos_event(void *arg, pos_event_t *event) 208 257 { -
uspace/lib/ui/test/entry.c
r034ce6bb r7481ee19 119 119 } 120 120 121 /** Set entry read only flag sets internal field */ 122 PCUT_TEST(set_read_only) 123 { 124 ui_entry_t *entry; 125 errno_t rc; 126 127 rc = ui_entry_create(NULL, "Hello", &entry); 128 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 129 130 ui_entry_set_read_only(entry, true); 131 PCUT_ASSERT_TRUE(entry->read_only); 132 ui_entry_set_read_only(entry, false); 133 PCUT_ASSERT_FALSE(entry->read_only); 134 135 ui_entry_destroy(entry); 136 } 137 121 138 /** Set text entry rectangle sets internal field */ 122 139 PCUT_TEST(set_text) … … 173 190 } 174 191 192 /** ui_entry_insert_str() inserts string at cursor. */ 193 PCUT_TEST(insert_str) 194 { 195 errno_t rc; 196 ui_t *ui = NULL; 197 ui_window_t *window = NULL; 198 ui_wnd_params_t params; 199 ui_entry_t *entry; 200 201 rc = ui_create_disp(NULL, &ui); 202 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 203 204 ui_wnd_params_init(¶ms); 205 params.caption = "Hello"; 206 207 rc = ui_window_create(ui, ¶ms, &window); 208 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 209 PCUT_ASSERT_NOT_NULL(window); 210 211 rc = ui_entry_create(window, "A", &entry); 212 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 213 214 PCUT_ASSERT_STR_EQUALS("A", entry->text); 215 216 rc = ui_entry_insert_str(entry, "B"); 217 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 218 219 PCUT_ASSERT_STR_EQUALS("AB", entry->text); 220 221 rc = ui_entry_insert_str(entry, "CD"); 222 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 223 224 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text); 225 226 ui_entry_destroy(entry); 227 ui_window_destroy(window); 228 ui_destroy(ui); 229 } 230 231 /** ui_entry_backspace() deletes character before cursor. */ 232 PCUT_TEST(backspace) 233 { 234 errno_t rc; 235 ui_t *ui = NULL; 236 ui_window_t *window = NULL; 237 ui_wnd_params_t params; 238 ui_entry_t *entry; 239 240 rc = ui_create_disp(NULL, &ui); 241 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 242 243 ui_wnd_params_init(¶ms); 244 params.caption = "Hello"; 245 246 rc = ui_window_create(ui, ¶ms, &window); 247 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 248 PCUT_ASSERT_NOT_NULL(window); 249 250 rc = ui_entry_create(window, "ABC", &entry); 251 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 252 253 PCUT_ASSERT_STR_EQUALS("ABC", entry->text); 254 255 ui_entry_backspace(entry); 256 PCUT_ASSERT_STR_EQUALS("AB", entry->text); 257 258 ui_entry_backspace(entry); 259 PCUT_ASSERT_STR_EQUALS("A", entry->text); 260 261 ui_entry_backspace(entry); 262 PCUT_ASSERT_STR_EQUALS("", entry->text); 263 264 ui_entry_backspace(entry); 265 PCUT_ASSERT_STR_EQUALS("", entry->text); 266 267 ui_entry_destroy(entry); 268 ui_window_destroy(window); 269 ui_destroy(ui); 270 } 271 175 272 PCUT_EXPORT(entry);
Note:
See TracChangeset
for help on using the changeset viewer.