Changes in uspace/lib/ui/test/pbutton.c [7470d97:3c54869] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/pbutton.c
r7470d97 r3c54869 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 63 63 64 64 static void test_pbutton_clicked(ui_pbutton_t *, void *); 65 static void test_pbutton_down(ui_pbutton_t *, void *); 66 static void test_pbutton_up(ui_pbutton_t *, void *); 65 67 66 68 static ui_pbutton_cb_t test_pbutton_cb = { 67 .clicked = test_pbutton_clicked 69 .clicked = test_pbutton_clicked, 70 .down = test_pbutton_down, 71 .up = test_pbutton_up 68 72 }; 69 73 … … 90 94 typedef struct { 91 95 bool clicked; 96 bool down; 97 bool up; 92 98 } test_cb_resp_t; 93 99 … … 125 131 126 132 ui_control_destroy(control); 133 } 134 135 /** Set flags sets internal field */ 136 PCUT_TEST(set_flags) 137 { 138 ui_pbutton_t *pbutton; 139 errno_t rc; 140 141 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 142 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 143 144 ui_pbutton_set_flags(pbutton, ui_pbf_no_text_depress); 145 PCUT_ASSERT_INT_EQUALS(ui_pbf_no_text_depress, pbutton->flags); 146 147 ui_pbutton_destroy(pbutton); 127 148 } 128 149 … … 169 190 } 170 191 192 /** Get light gets internal field */ 193 PCUT_TEST(get_light) 194 { 195 ui_pbutton_t *pbutton; 196 errno_t rc; 197 198 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 199 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 200 201 pbutton->light = true; 202 PCUT_ASSERT_TRUE(ui_pbutton_get_light(pbutton)); 203 204 pbutton->light = false; 205 PCUT_ASSERT_FALSE(ui_pbutton_get_light(pbutton)); 206 207 ui_pbutton_destroy(pbutton); 208 } 209 210 /** Set light sets internal field */ 211 PCUT_TEST(set_light) 212 { 213 ui_pbutton_t *pbutton; 214 errno_t rc; 215 216 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 217 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 218 219 ui_pbutton_set_light(pbutton, true); 220 PCUT_ASSERT_TRUE(pbutton->light); 221 222 ui_pbutton_set_light(pbutton, false); 223 PCUT_ASSERT_FALSE(pbutton->light); 224 225 ui_pbutton_destroy(pbutton); 226 } 227 228 /** Set caption sets internal field */ 229 PCUT_TEST(set_caption) 230 { 231 ui_pbutton_t *pbutton; 232 errno_t rc; 233 234 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 235 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 236 237 PCUT_ASSERT_STR_EQUALS("Hello", pbutton->caption); 238 239 rc = ui_pbutton_set_caption(pbutton, "World"); 240 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 241 242 PCUT_ASSERT_STR_EQUALS("World", pbutton->caption); 243 244 ui_pbutton_destroy(pbutton); 245 } 246 171 247 /** Paint button */ 172 248 PCUT_TEST(paint) … … 225 301 } 226 302 303 /** Test ui_pbutton_down() */ 304 PCUT_TEST(down) 305 { 306 errno_t rc; 307 ui_pbutton_t *pbutton; 308 test_cb_resp_t resp; 309 310 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 311 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 312 313 /* Down with no callbacks set */ 314 ui_pbutton_clicked(pbutton); 315 316 /* Down with callback not implementing down */ 317 ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL); 318 ui_pbutton_down(pbutton); 319 320 /* Down with real callback set */ 321 resp.down = false; 322 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp); 323 ui_pbutton_down(pbutton); 324 PCUT_ASSERT_TRUE(resp.down); 325 326 ui_pbutton_destroy(pbutton); 327 } 328 329 /** Test ui_pbutton_up() */ 330 PCUT_TEST(up) 331 { 332 errno_t rc; 333 ui_pbutton_t *pbutton; 334 test_cb_resp_t resp; 335 336 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 337 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 338 339 /* Up with no callbacks set */ 340 ui_pbutton_clicked(pbutton); 341 342 /* Up with callback not implementing up */ 343 ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL); 344 ui_pbutton_up(pbutton); 345 346 /* Up with real callback set */ 347 resp.up = false; 348 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp); 349 ui_pbutton_up(pbutton); 350 PCUT_ASSERT_TRUE(resp.up); 351 352 ui_pbutton_destroy(pbutton); 353 } 354 227 355 /** Press and release button */ 228 356 PCUT_TEST(press_release) … … 247 375 248 376 resp.clicked = false; 377 resp.down = false; 378 resp.up = false; 249 379 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp); 250 380 … … 255 385 PCUT_ASSERT_TRUE(pbutton->held); 256 386 PCUT_ASSERT_TRUE(pbutton->inside); 387 PCUT_ASSERT_TRUE(resp.down); 388 PCUT_ASSERT_FALSE(resp.up); 257 389 PCUT_ASSERT_FALSE(resp.clicked); 258 390 … … 260 392 PCUT_ASSERT_FALSE(pbutton->held); 261 393 PCUT_ASSERT_TRUE(pbutton->inside); 394 PCUT_ASSERT_TRUE(resp.up); 262 395 PCUT_ASSERT_TRUE(resp.clicked); 263 396 … … 588 721 } 589 722 723 static void test_pbutton_down(ui_pbutton_t *pbutton, void *arg) 724 { 725 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 726 727 resp->down = true; 728 } 729 730 static void test_pbutton_up(ui_pbutton_t *pbutton, void *arg) 731 { 732 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 733 734 resp->up = true; 735 } 736 590 737 PCUT_EXPORT(pbutton);
Note:
See TracChangeset
for help on using the changeset viewer.