Changeset 1eaead4 in mainline for uspace/lib/ui/test/control.c
- Timestamp:
- 2023-02-07T16:11:53Z (14 months ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0366d09d
- Parents:
- 7c5320c
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.