Changeset 9eb8d12 in mainline for uspace/lib/ui/test/entry.c
- Timestamp:
- 2021-07-19T22:35:19Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c9722c1
- Parents:
- ead72f2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/entry.c
read72f2 r9eb8d12 190 190 } 191 191 192 /** ui_entry_delete_sel() deletes selected text */ 193 PCUT_TEST(delete_sel) 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, "ABCDEF", &entry); 212 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 213 214 PCUT_ASSERT_STR_EQUALS("ABCDEF", entry->text); 215 216 ui_entry_activate(entry); 217 218 /* Select all but first and last character */ 219 ui_entry_seek_start(entry, false); 220 ui_entry_seek_next_char(entry, false); 221 ui_entry_seek_end(entry, true); 222 ui_entry_seek_prev_char(entry, true); 223 224 ui_entry_delete_sel(entry); 225 226 PCUT_ASSERT_STR_EQUALS("AF", entry->text); 227 228 ui_entry_destroy(entry); 229 ui_window_destroy(window); 230 ui_destroy(ui); 231 } 232 192 233 /** ui_entry_insert_str() inserts string at cursor. */ 193 234 PCUT_TEST(insert_str) … … 214 255 PCUT_ASSERT_STR_EQUALS("A", entry->text); 215 256 216 /* This moves the cursor to the end of the text */217 257 ui_entry_activate(entry); 258 ui_entry_seek_end(entry, false); 218 259 219 260 rc = ui_entry_insert_str(entry, "B"); … … 228 269 229 270 entry->pos = 2; 271 entry->sel_start = 2; 230 272 rc = ui_entry_insert_str(entry, "CD"); 231 273 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 232 274 233 275 PCUT_ASSERT_STR_EQUALS("ABCDEF", entry->text); 276 277 ui_entry_destroy(entry); 278 ui_window_destroy(window); 279 ui_destroy(ui); 280 } 281 282 /** ui_entry_insert_str() deletes selection before inserting string */ 283 PCUT_TEST(insert_str_with_sel) 284 { 285 errno_t rc; 286 ui_t *ui = NULL; 287 ui_window_t *window = NULL; 288 ui_wnd_params_t params; 289 ui_entry_t *entry; 290 291 rc = ui_create_disp(NULL, &ui); 292 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 293 294 ui_wnd_params_init(¶ms); 295 params.caption = "Hello"; 296 297 rc = ui_window_create(ui, ¶ms, &window); 298 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 299 PCUT_ASSERT_NOT_NULL(window); 300 301 rc = ui_entry_create(window, "ABCDE", &entry); 302 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 303 304 PCUT_ASSERT_STR_EQUALS("ABCDE", entry->text); 305 306 /* Select all but the first and last character */ 307 ui_entry_activate(entry); 308 ui_entry_seek_start(entry, false); 309 ui_entry_seek_next_char(entry, false); 310 ui_entry_seek_end(entry, true); 311 ui_entry_seek_prev_char(entry, true); 312 313 rc = ui_entry_insert_str(entry, "123"); 314 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 315 316 PCUT_ASSERT_STR_EQUALS("A123E", entry->text); 234 317 235 318 ui_entry_destroy(entry); … … 262 345 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text); 263 346 entry->pos = 3; 347 entry->sel_start = 3; 264 348 265 349 ui_entry_backspace(entry); … … 280 364 } 281 365 366 /** ui_entry_backspace() with selected text deletes selection. */ 367 PCUT_TEST(backspace_with_sel) 368 { 369 errno_t rc; 370 ui_t *ui = NULL; 371 ui_window_t *window = NULL; 372 ui_wnd_params_t params; 373 ui_entry_t *entry; 374 375 rc = ui_create_disp(NULL, &ui); 376 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 377 378 ui_wnd_params_init(¶ms); 379 params.caption = "Hello"; 380 381 rc = ui_window_create(ui, ¶ms, &window); 382 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 383 PCUT_ASSERT_NOT_NULL(window); 384 385 rc = ui_entry_create(window, "ABCDE", &entry); 386 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 387 388 PCUT_ASSERT_STR_EQUALS("ABCDE", entry->text); 389 390 /* Select all but the first and last character */ 391 ui_entry_activate(entry); 392 ui_entry_seek_start(entry, false); 393 ui_entry_seek_next_char(entry, false); 394 ui_entry_seek_end(entry, true); 395 ui_entry_seek_prev_char(entry, true); 396 397 ui_entry_backspace(entry); 398 399 PCUT_ASSERT_STR_EQUALS("AE", entry->text); 400 401 ui_entry_destroy(entry); 402 ui_window_destroy(window); 403 ui_destroy(ui); 404 } 405 282 406 /** ui_entry_delete() deletes character after cursor. */ 283 407 PCUT_TEST(delete) … … 304 428 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text); 305 429 entry->pos = 1; 430 entry->sel_start = 1; 306 431 307 432 ui_entry_delete(entry); … … 322 447 } 323 448 449 /** ui_entry_delete() with selected text deletes selection. */ 450 PCUT_TEST(delete_with_sel) 451 { 452 errno_t rc; 453 ui_t *ui = NULL; 454 ui_window_t *window = NULL; 455 ui_wnd_params_t params; 456 ui_entry_t *entry; 457 458 rc = ui_create_disp(NULL, &ui); 459 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 460 461 ui_wnd_params_init(¶ms); 462 params.caption = "Hello"; 463 464 rc = ui_window_create(ui, ¶ms, &window); 465 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 466 PCUT_ASSERT_NOT_NULL(window); 467 468 rc = ui_entry_create(window, "ABCDE", &entry); 469 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 470 471 PCUT_ASSERT_STR_EQUALS("ABCDE", entry->text); 472 473 /* Select all but the first and last character */ 474 ui_entry_activate(entry); 475 ui_entry_seek_start(entry, false); 476 ui_entry_seek_next_char(entry, false); 477 ui_entry_seek_end(entry, true); 478 ui_entry_seek_prev_char(entry, true); 479 480 ui_entry_delete(entry); 481 482 PCUT_ASSERT_STR_EQUALS("AE", entry->text); 483 484 ui_entry_destroy(entry); 485 ui_window_destroy(window); 486 ui_destroy(ui); 487 } 488 324 489 /** ui_entry_seek_start() moves cursor to beginning of text */ 325 490 PCUT_TEST(seek_start) … … 346 511 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text); 347 512 entry->pos = 2; 348 349 ui_entry_seek_start(entry); 513 entry->sel_start = 2; 514 515 ui_entry_seek_start(entry, true); 350 516 PCUT_ASSERT_INT_EQUALS(0, entry->pos); 517 PCUT_ASSERT_INT_EQUALS(2, entry->sel_start); 518 519 ui_entry_seek_start(entry, false); 520 PCUT_ASSERT_INT_EQUALS(0, entry->pos); 521 PCUT_ASSERT_INT_EQUALS(0, entry->sel_start); 351 522 352 523 ui_entry_destroy(entry); … … 379 550 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text); 380 551 entry->pos = 2; 381 382 ui_entry_seek_end(entry); 552 entry->sel_start = 2; 553 554 ui_entry_seek_end(entry, true); 383 555 PCUT_ASSERT_INT_EQUALS(4, entry->pos); 556 PCUT_ASSERT_INT_EQUALS(2, entry->sel_start); 557 ui_entry_seek_end(entry, false); 558 PCUT_ASSERT_INT_EQUALS(4, entry->pos); 559 PCUT_ASSERT_INT_EQUALS(4, entry->sel_start); 384 560 385 561 ui_entry_destroy(entry); … … 411 587 412 588 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text); 413 entry->pos = 2; 414 415 ui_entry_seek_prev_char(entry); 589 entry->pos = 3; 590 entry->sel_start = 3; 591 592 ui_entry_seek_prev_char(entry, true); 593 PCUT_ASSERT_INT_EQUALS(2, entry->pos); 594 PCUT_ASSERT_INT_EQUALS(3, entry->sel_start); 595 596 ui_entry_seek_prev_char(entry, false); 416 597 PCUT_ASSERT_INT_EQUALS(1, entry->pos); 598 PCUT_ASSERT_INT_EQUALS(1, entry->sel_start); 417 599 418 600 ui_entry_destroy(entry); … … 444 626 445 627 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text); 446 entry->pos = 2; 447 448 ui_entry_seek_next_char(entry); 628 entry->pos = 1; 629 entry->sel_start = 1; 630 631 ui_entry_seek_next_char(entry, true); 632 PCUT_ASSERT_INT_EQUALS(2, entry->pos); 633 PCUT_ASSERT_INT_EQUALS(1, entry->sel_start); 634 ui_entry_seek_next_char(entry, false); 449 635 PCUT_ASSERT_INT_EQUALS(3, entry->pos); 636 PCUT_ASSERT_INT_EQUALS(3, entry->sel_start); 450 637 451 638 ui_entry_destroy(entry);
Note:
See TracChangeset
for help on using the changeset viewer.