Changes in uspace/lib/ui/test/control.c [7481ee19:1eaead4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/control.c
r7481ee19 r1eaead4 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 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 *);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 } test_resp_t;82 43 83 44 /** Allocate and deallocate control */ … … 87 48 errno_t rc; 88 49 89 rc = ui_control_new(& test_ctl_ops, NULL, &control);50 rc = ui_control_new(&ui_test_ctl_ops, NULL, &control); 90 51 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 91 52 PCUT_ASSERT_NOT_NULL(control); … … 103 64 PCUT_TEST(destroy) 104 65 { 105 ui_ control_t *control = NULL;106 test_resp_t resp;66 ui_test_ctl_t *testctl = NULL; 67 ui_tc_resp_t resp; 107 68 errno_t rc; 108 69 109 rc = ui_ control_new(&test_ctl_ops, &resp, &control);70 rc = ui_test_ctl_create(&resp, &testctl); 110 71 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 111 PCUT_ASSERT_NOT_NULL( control);72 PCUT_ASSERT_NOT_NULL(testctl); 112 73 113 74 resp.rc = EOK; 114 75 resp.destroy = false; 115 76 116 ui_control_destroy( control);77 ui_control_destroy(ui_test_ctl_ctl(testctl)); 117 78 PCUT_ASSERT_TRUE(resp.destroy); 118 79 } … … 121 82 PCUT_TEST(paint) 122 83 { 123 ui_ control_t *control = NULL;124 test_resp_t resp;84 ui_test_ctl_t *testctl = NULL; 85 ui_tc_resp_t resp; 125 86 errno_t rc; 126 87 127 rc = ui_ control_new(&test_ctl_ops, &resp, &control);88 rc = ui_test_ctl_create(&resp, &testctl); 128 89 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 129 PCUT_ASSERT_NOT_NULL( control);90 PCUT_ASSERT_NOT_NULL(testctl); 130 91 131 92 resp.rc = EOK; 132 93 resp.paint = false; 133 94 134 rc = ui_control_paint( control);95 rc = ui_control_paint(ui_test_ctl_ctl(testctl)); 135 96 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 136 97 PCUT_ASSERT_TRUE(resp.paint); … … 139 100 resp.paint = false; 140 101 141 rc = ui_control_paint( control);102 rc = ui_control_paint(ui_test_ctl_ctl(testctl)); 142 103 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 143 104 PCUT_ASSERT_TRUE(resp.paint); 144 105 145 ui_ control_delete(control);106 ui_test_ctl_destroy(testctl); 146 107 } 147 108 … … 149 110 PCUT_TEST(kbd_event) 150 111 { 151 ui_ control_t *control = NULL;152 test_resp_t resp;112 ui_test_ctl_t *testctl = NULL; 113 ui_tc_resp_t resp; 153 114 kbd_event_t event; 154 115 ui_evclaim_t claim; 155 116 errno_t rc; 156 117 157 rc = ui_ control_new(&test_ctl_ops, &resp, &control);118 rc = ui_test_ctl_create(&resp, &testctl); 158 119 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 159 PCUT_ASSERT_NOT_NULL( control);120 PCUT_ASSERT_NOT_NULL(testctl); 160 121 161 122 resp.claim = ui_claimed; … … 166 127 event.c = '@'; 167 128 168 claim = ui_control_kbd_event( control, &event);129 claim = ui_control_kbd_event(ui_test_ctl_ctl(testctl), &event); 169 130 PCUT_ASSERT_EQUALS(resp.claim, claim); 170 131 PCUT_ASSERT_TRUE(resp.kbd); … … 174 135 PCUT_ASSERT_INT_EQUALS(resp.kevent.c, event.c); 175 136 176 ui_ control_delete(control);137 ui_test_ctl_destroy(testctl); 177 138 } 178 139 … … 180 141 PCUT_TEST(pos_event) 181 142 { 182 ui_ control_t *control = NULL;183 test_resp_t resp;143 ui_test_ctl_t *testctl = NULL; 144 ui_tc_resp_t resp; 184 145 pos_event_t event; 185 146 ui_evclaim_t claim; 186 147 errno_t rc; 187 148 188 rc = ui_ control_new(&test_ctl_ops, &resp, &control);149 rc = ui_test_ctl_create(&resp, &testctl); 189 150 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 190 PCUT_ASSERT_NOT_NULL( control);151 PCUT_ASSERT_NOT_NULL(testctl); 191 152 192 153 resp.claim = ui_claimed; … … 198 159 event.vpos = 4; 199 160 200 claim = ui_control_pos_event( control, &event);161 claim = ui_control_pos_event(ui_test_ctl_ctl(testctl), &event); 201 162 PCUT_ASSERT_EQUALS(resp.claim, claim); 202 163 PCUT_ASSERT_TRUE(resp.pos); … … 207 168 PCUT_ASSERT_INT_EQUALS(resp.pevent.vpos, event.vpos); 208 169 209 ui_ control_delete(control);170 ui_test_ctl_destroy(testctl); 210 171 } 211 172 … … 213 174 PCUT_TEST(unfocus) 214 175 { 215 ui_ control_t *control = NULL;216 test_resp_t resp;176 ui_test_ctl_t *testctl = NULL; 177 ui_tc_resp_t resp; 217 178 errno_t rc; 218 179 219 rc = ui_ control_new(&test_ctl_ops, &resp, &control);180 rc = ui_test_ctl_create(&resp, &testctl); 220 181 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 221 PCUT_ASSERT_NOT_NULL( control);182 PCUT_ASSERT_NOT_NULL(testctl); 222 183 223 184 resp.unfocus = false; 224 185 225 ui_control_unfocus( control);186 ui_control_unfocus(ui_test_ctl_ctl(testctl), 42); 226 187 PCUT_ASSERT_TRUE(resp.unfocus); 188 PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus); 227 189 228 ui_control_delete(control); 229 } 230 231 static void test_ctl_destroy(void *arg) 232 { 233 test_resp_t *resp = (test_resp_t *) arg; 234 235 resp->destroy = true; 236 } 237 238 static errno_t test_ctl_paint(void *arg) 239 { 240 test_resp_t *resp = (test_resp_t *) arg; 241 242 resp->paint = true; 243 return resp->rc; 244 } 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 256 static ui_evclaim_t test_ctl_pos_event(void *arg, pos_event_t *event) 257 { 258 test_resp_t *resp = (test_resp_t *) arg; 259 260 resp->pos = true; 261 resp->pevent = *event; 262 263 return resp->claim; 264 } 265 266 static void test_ctl_unfocus(void *arg) 267 { 268 test_resp_t *resp = (test_resp_t *) arg; 269 270 resp->unfocus = true; 190 ui_test_ctl_destroy(testctl); 271 191 } 272 192
Note:
See TracChangeset
for help on using the changeset viewer.