Changes in uspace/lib/ui/test/control.c [1eaead4:7481ee19] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/control.c
r1eaead4 r7481ee19 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2021 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>36 35 #include <stdbool.h> 37 36 #include <types/ui/event.h> 38 #include "../private/testctl.h"39 37 40 38 PCUT_INIT; 41 39 42 40 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_unfocus 54 }; 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; 43 82 44 83 /** Allocate and deallocate control */ … … 48 87 errno_t rc; 49 88 50 rc = ui_control_new(& ui_test_ctl_ops, NULL, &control);89 rc = ui_control_new(&test_ctl_ops, NULL, &control); 51 90 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 52 91 PCUT_ASSERT_NOT_NULL(control); … … 64 103 PCUT_TEST(destroy) 65 104 { 66 ui_ test_ctl_t *testctl = NULL;67 ui_tc_resp_t resp;68 errno_t rc; 69 70 rc = ui_ test_ctl_create(&resp, &testctl);71 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 72 PCUT_ASSERT_NOT_NULL( testctl);105 ui_control_t *control = NULL; 106 test_resp_t resp; 107 errno_t rc; 108 109 rc = ui_control_new(&test_ctl_ops, &resp, &control); 110 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 111 PCUT_ASSERT_NOT_NULL(control); 73 112 74 113 resp.rc = EOK; 75 114 resp.destroy = false; 76 115 77 ui_control_destroy( ui_test_ctl_ctl(testctl));116 ui_control_destroy(control); 78 117 PCUT_ASSERT_TRUE(resp.destroy); 79 118 } … … 82 121 PCUT_TEST(paint) 83 122 { 84 ui_ test_ctl_t *testctl = NULL;85 ui_tc_resp_t resp;86 errno_t rc; 87 88 rc = ui_ test_ctl_create(&resp, &testctl);89 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 90 PCUT_ASSERT_NOT_NULL( testctl);123 ui_control_t *control = NULL; 124 test_resp_t resp; 125 errno_t rc; 126 127 rc = ui_control_new(&test_ctl_ops, &resp, &control); 128 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 129 PCUT_ASSERT_NOT_NULL(control); 91 130 92 131 resp.rc = EOK; 93 132 resp.paint = false; 94 133 95 rc = ui_control_paint( ui_test_ctl_ctl(testctl));134 rc = ui_control_paint(control); 96 135 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 97 136 PCUT_ASSERT_TRUE(resp.paint); … … 100 139 resp.paint = false; 101 140 102 rc = ui_control_paint( ui_test_ctl_ctl(testctl));141 rc = ui_control_paint(control); 103 142 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 104 143 PCUT_ASSERT_TRUE(resp.paint); 105 144 106 ui_ test_ctl_destroy(testctl);145 ui_control_delete(control); 107 146 } 108 147 … … 110 149 PCUT_TEST(kbd_event) 111 150 { 112 ui_ test_ctl_t *testctl = NULL;113 ui_tc_resp_t resp;151 ui_control_t *control = NULL; 152 test_resp_t resp; 114 153 kbd_event_t event; 115 154 ui_evclaim_t claim; 116 155 errno_t rc; 117 156 118 rc = ui_ test_ctl_create(&resp, &testctl);119 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 120 PCUT_ASSERT_NOT_NULL( testctl);157 rc = ui_control_new(&test_ctl_ops, &resp, &control); 158 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 159 PCUT_ASSERT_NOT_NULL(control); 121 160 122 161 resp.claim = ui_claimed; … … 127 166 event.c = '@'; 128 167 129 claim = ui_control_kbd_event( ui_test_ctl_ctl(testctl), &event);168 claim = ui_control_kbd_event(control, &event); 130 169 PCUT_ASSERT_EQUALS(resp.claim, claim); 131 170 PCUT_ASSERT_TRUE(resp.kbd); … … 135 174 PCUT_ASSERT_INT_EQUALS(resp.kevent.c, event.c); 136 175 137 ui_ test_ctl_destroy(testctl);176 ui_control_delete(control); 138 177 } 139 178 … … 141 180 PCUT_TEST(pos_event) 142 181 { 143 ui_ test_ctl_t *testctl = NULL;144 ui_tc_resp_t resp;182 ui_control_t *control = NULL; 183 test_resp_t resp; 145 184 pos_event_t event; 146 185 ui_evclaim_t claim; 147 186 errno_t rc; 148 187 149 rc = ui_ test_ctl_create(&resp, &testctl);150 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 151 PCUT_ASSERT_NOT_NULL( testctl);188 rc = ui_control_new(&test_ctl_ops, &resp, &control); 189 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 190 PCUT_ASSERT_NOT_NULL(control); 152 191 153 192 resp.claim = ui_claimed; … … 159 198 event.vpos = 4; 160 199 161 claim = ui_control_pos_event( ui_test_ctl_ctl(testctl), &event);200 claim = ui_control_pos_event(control, &event); 162 201 PCUT_ASSERT_EQUALS(resp.claim, claim); 163 202 PCUT_ASSERT_TRUE(resp.pos); … … 168 207 PCUT_ASSERT_INT_EQUALS(resp.pevent.vpos, event.vpos); 169 208 170 ui_ test_ctl_destroy(testctl);209 ui_control_delete(control); 171 210 } 172 211 … … 174 213 PCUT_TEST(unfocus) 175 214 { 176 ui_ test_ctl_t *testctl = NULL;177 ui_tc_resp_t resp;178 errno_t rc; 179 180 rc = ui_ test_ctl_create(&resp, &testctl);181 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 182 PCUT_ASSERT_NOT_NULL( testctl);215 ui_control_t *control = NULL; 216 test_resp_t resp; 217 errno_t rc; 218 219 rc = ui_control_new(&test_ctl_ops, &resp, &control); 220 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 221 PCUT_ASSERT_NOT_NULL(control); 183 222 184 223 resp.unfocus = false; 185 224 186 ui_control_unfocus( ui_test_ctl_ctl(testctl), 42);225 ui_control_unfocus(control); 187 226 PCUT_ASSERT_TRUE(resp.unfocus); 188 PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus); 189 190 ui_test_ctl_destroy(testctl); 227 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; 191 271 } 192 272
Note:
See TracChangeset
for help on using the changeset viewer.