Changeset f2cb80a in mainline for uspace/lib
- Timestamp:
- 2024-02-23T17:57:23Z (20 months ago)
- Children:
- 192019f
- Parents:
- 86f862c (diff), 90ba06c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- boba-buba <120932204+boba-buba@…> (2024-02-23 17:57:23)
- git-committer:
- GitHub <noreply@…> (2024-02-23 17:57:23)
- Location:
- uspace/lib
- Files:
-
- 14 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/meson.build
r86f862c rf2cb80a 53 53 _sdir = meson.current_source_dir() / idir 54 54 uspace_lib_devel_install_script_text += 'cp -R -L -T "@0@" "${DESTDIR}include/libc"'.format(_sdir) 55 exported_devel_files += ['include', _sdir, 'libc'] 55 56 endforeach 56 57 … … 209 210 pic: false, 210 211 ) 212 exported_devel_files += ['staticlib', libstartfiles, 'libstartfiles.a'] 211 213 212 214 if CONFIG_DEVEL_FILES -
uspace/lib/clui/meson.build
r86f862c rf2cb80a 29 29 deps = [ 'clipboard', 'console' ] 30 30 src = files( 31 ' nchoice.c',32 ' tinput.c',31 'src/nchoice.c', 32 'src/tinput.c', 33 33 ) -
uspace/lib/meson.build
r86f862c rf2cb80a 181 181 if run_command('[', '-d', incdir, ']').returncode() == 0 182 182 includes += include_directories(incdir) 183 _sdir = meson.current_source_dir() / l / 'include' 183 184 184 185 if installed_libs.contains(l) 185 _sdir = meson.current_source_dir() / l / 'include'186 186 uspace_lib_devel_install_script_text += 'cp -R -L -T "@0@" "${DESTDIR}include/lib@1@"'.format(_sdir, l) 187 187 endif 188 189 exported_devel_files += ['include', _sdir, 'lib' + l] 188 190 else 189 191 includes += include_directories(l) … … 294 296 install_deps += [ _static_lib ] 295 297 endif 298 299 exported_devel_files += ['staticlib', _static_lib, 'lib' + l + '.a'] 296 300 297 301 _static_dep = declare_dependency( -
uspace/lib/posix/meson.build
r86f862c rf2cb80a 67 67 uspace_lib_devel_install_script_text += 'cp -R -L -T "@0@" "${DESTDIR}include/libposix"'.format(_sdir) 68 68 uspace_lib_devel_install_script_text += 'ln -s -r "${DESTDIR}include/libc" "${DESTDIR}/include/common"' 69 70 exported_devel_files += [ 'include', meson.current_source_dir() / 'include' / 'posix', 'libposix' ] 71 exported_devel_files += [ 'includesymlink', 'libc', 'libposix' ] -
uspace/lib/tbarcfg/include/tbarcfg/tbarcfg.h
r86f862c rf2cb80a 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 39 39 #include <errno.h> 40 40 #include <sif.h> 41 #include <stdbool.h> 41 42 #include <types/tbarcfg/tbarcfg.h> 42 43 … … 46 47 extern smenu_entry_t *tbarcfg_smenu_first(tbarcfg_t *); 47 48 extern smenu_entry_t *tbarcfg_smenu_next(smenu_entry_t *); 49 extern smenu_entry_t *tbarcfg_smenu_last(tbarcfg_t *); 50 extern smenu_entry_t *tbarcfg_smenu_prev(smenu_entry_t *); 48 51 extern const char *smenu_entry_get_caption(smenu_entry_t *); 49 52 extern const char *smenu_entry_get_cmd(smenu_entry_t *); 53 extern bool smenu_entry_get_terminal(smenu_entry_t *); 54 extern bool smenu_entry_get_separator(smenu_entry_t *); 50 55 extern errno_t smenu_entry_set_caption(smenu_entry_t *, const char *); 51 56 extern errno_t smenu_entry_set_cmd(smenu_entry_t *, const char *); 57 extern void smenu_entry_set_terminal(smenu_entry_t *, bool); 52 58 extern errno_t smenu_entry_save(smenu_entry_t *); 53 extern errno_t smenu_entry_create(tbarcfg_t *, const char *, const char *); 59 extern errno_t smenu_entry_create(tbarcfg_t *, const char *, const char *, 60 bool, smenu_entry_t **); 61 extern errno_t smenu_entry_sep_create(tbarcfg_t *, smenu_entry_t **); 54 62 extern errno_t smenu_entry_destroy(smenu_entry_t *); 63 extern errno_t smenu_entry_move_up(smenu_entry_t *); 64 extern errno_t smenu_entry_move_down(smenu_entry_t *); 55 65 56 66 #endif -
uspace/lib/tbarcfg/private/tbarcfg.h
r86f862c rf2cb80a 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 40 40 #include <adt/list.h> 41 41 #include <sif.h> 42 #include <stdbool.h> 42 43 #include <types/tbarcfg/tbarcfg.h> 43 44 … … 60 61 /** SIF node (persistent storage) */ 61 62 sif_node_t *nentry; 63 /** Is this a separator entry */ 64 bool separator; 62 65 /** Entry caption (with accelerator markup) */ 63 66 char *caption; 64 67 /** Command to run */ 65 68 char *cmd; 69 /** Start in terminal */ 70 bool terminal; 66 71 }; 67 72 68 73 extern errno_t smenu_entry_new(tbarcfg_t *, sif_node_t *, const char *, 69 const char *); 74 const char *, bool, smenu_entry_t **); 75 extern errno_t smenu_entry_sep_new(tbarcfg_t *, sif_node_t *, smenu_entry_t **); 70 76 extern void smenu_entry_delete(smenu_entry_t *); 71 77 -
uspace/lib/tbarcfg/src/tbarcfg.c
r86f862c rf2cb80a 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 108 108 sif_node_t *nentry; 109 109 const char *ntype; 110 const char *separator; 110 111 const char *caption; 111 112 const char *cmd; 113 const char *terminal = NULL; 112 114 errno_t rc; 113 115 … … 142 144 } 143 145 144 caption = sif_node_get_attr(nentry, "caption");145 if ( caption == NULL) {146 separator = sif_node_get_attr(nentry, "separator"); 147 if (separator != NULL && str_cmp(separator, "y") != 0) { 146 148 rc = EIO; 147 149 goto error; 148 150 } 149 151 150 cmd = sif_node_get_attr(nentry, "cmd"); 151 if (cmd == NULL) { 152 rc = EIO; 153 goto error; 152 if (separator == NULL) { 153 caption = sif_node_get_attr(nentry, "caption"); 154 if (caption == NULL) { 155 rc = EIO; 156 goto error; 157 } 158 159 cmd = sif_node_get_attr(nentry, "cmd"); 160 if (cmd == NULL) { 161 rc = EIO; 162 goto error; 163 } 164 165 terminal = sif_node_get_attr(nentry, "terminal"); 166 if (terminal == NULL) 167 terminal = "n"; 168 169 rc = smenu_entry_new(tbcfg, nentry, caption, cmd, 170 str_cmp(terminal, "y") == 0, NULL); 171 if (rc != EOK) 172 goto error; 173 } else { 174 rc = smenu_entry_sep_new(tbcfg, nentry, NULL); 175 if (rc != EOK) 176 goto error; 154 177 } 155 156 rc = smenu_entry_new(tbcfg, nentry, caption, cmd);157 if (rc != EOK)158 goto error;159 178 160 179 nentry = sif_node_next_child(nentry); … … 221 240 } 222 241 242 /** Get last start menu entry. 243 * 244 * @param tbcfg Taskbar configuration 245 * @return Previous entry or @c NULL if the menu is empty 246 */ 247 smenu_entry_t *tbarcfg_smenu_last(tbarcfg_t *tbcfg) 248 { 249 link_t *link; 250 251 link = list_last(&tbcfg->entries); 252 if (link == NULL) 253 return NULL; 254 255 return list_get_instance(link, smenu_entry_t, lentries); 256 } 257 258 /** Get previous start menu entry. 259 * 260 * @param cur Current entry 261 * @return Previous entry or @c NULL if @a cur is the last entry 262 */ 263 smenu_entry_t *tbarcfg_smenu_prev(smenu_entry_t *cur) 264 { 265 link_t *link; 266 267 link = list_prev(&cur->lentries, &cur->smenu->entries); 268 if (link == NULL) 269 return NULL; 270 271 return list_get_instance(link, smenu_entry_t, lentries); 272 } 273 223 274 /** Get start menu entry caption. 224 275 * … … 228 279 const char *smenu_entry_get_caption(smenu_entry_t *entry) 229 280 { 281 assert(!entry->separator); 230 282 return entry->caption; 231 283 } … … 233 285 /** Get start menu entry command. 234 286 * 235 * @param entr Start menu entry287 * @param entry Start menu entry 236 288 * @return Command to run 237 289 */ 238 290 const char *smenu_entry_get_cmd(smenu_entry_t *entry) 239 291 { 292 assert(!entry->separator); 240 293 return entry->cmd; 294 } 295 296 /** Get start menu entry start in terminal flag. 297 * 298 * @param entry Start menu entry 299 * @return Start in terminal flag 300 */ 301 bool smenu_entry_get_terminal(smenu_entry_t *entry) 302 { 303 assert(!entry->separator); 304 return entry->terminal; 305 } 306 307 /** Get start menu entry separator flag. 308 * 309 * @param entry Start menu entry 310 * @return Separator flag 311 */ 312 bool smenu_entry_get_separator(smenu_entry_t *entry) 313 { 314 return entry->separator; 241 315 } 242 316 … … 253 327 { 254 328 char *dcap; 329 330 assert(!entry->separator); 255 331 256 332 dcap = str_dup(caption); … … 276 352 char *dcmd; 277 353 354 assert(!entry->separator); 355 278 356 dcmd = str_dup(cmd); 279 357 if (dcmd == NULL) … … 285 363 } 286 364 365 /** Set start menu entry start in terminal flag. 366 * 367 * Note: To make the change visible to others and persistent, 368 * you must call @c smenu_entry_save() 369 * 370 * @param entry Start menu entry 371 * @param terminal Start in terminal flag 372 */ 373 void smenu_entry_set_terminal(smenu_entry_t *entry, bool terminal) 374 { 375 assert(!entry->separator); 376 entry->terminal = terminal; 377 } 378 379 /** Save start menu entry using transaction. 380 * 381 * @param entry Start menu entry 382 * @param trans Transaction 383 */ 384 static errno_t smenu_entry_save_trans(smenu_entry_t *entry, sif_trans_t *trans) 385 { 386 errno_t rc; 387 388 if (entry->separator) { 389 rc = sif_node_set_attr(trans, entry->nentry, "separator", "y"); 390 if (rc != EOK) 391 goto error; 392 } else { 393 sif_node_unset_attr(trans, entry->nentry, "separator"); 394 395 rc = sif_node_set_attr(trans, entry->nentry, "cmd", entry->cmd); 396 if (rc != EOK) 397 goto error; 398 399 rc = sif_node_set_attr(trans, entry->nentry, "caption", 400 entry->caption); 401 if (rc != EOK) 402 goto error; 403 404 rc = sif_node_set_attr(trans, entry->nentry, "terminal", 405 entry->terminal ? "y" : "n"); 406 if (rc != EOK) 407 goto error; 408 } 409 410 return EOK; 411 error: 412 return rc; 413 } 414 287 415 /** Save any changes to start menu entry. 288 416 * … … 298 426 goto error; 299 427 300 rc = sif_node_set_attr(trans, entry->nentry, "cmd", entry->cmd); 301 if (rc != EOK) 302 goto error; 303 304 rc = sif_node_set_attr(trans, entry->nentry, "caption", entry->caption); 428 rc = smenu_entry_save_trans(entry, trans); 305 429 if (rc != EOK) 306 430 goto error; … … 325 449 * @param caption Caption 326 450 * @param cmd Command to run 451 * @param terminal Start in terminal 452 * @param rentry Place to store pointer to new entry or @c NULL 327 453 */ 328 454 errno_t smenu_entry_new(tbarcfg_t *smenu, sif_node_t *nentry, 329 const char *caption, const char *cmd )455 const char *caption, const char *cmd, bool terminal, smenu_entry_t **rentry) 330 456 { 331 457 smenu_entry_t *entry; … … 352 478 } 353 479 480 entry->terminal = terminal; 481 354 482 entry->smenu = smenu; 355 483 list_append(&entry->lentries, &smenu->entries); 484 if (rentry != NULL) 485 *rentry = entry; 356 486 return EOK; 357 487 error: … … 367 497 } 368 498 499 /** Allocate a start menu separator entry and append it to the start menu 500 * (internal). 501 * 502 * This only creates the entry in memory, but does not update the repository. 503 * 504 * @param smenu Start menu 505 * @param nentry Backing SIF node 506 * @param rentry Place to store pointer to new entry or @c NULL 507 */ 508 errno_t smenu_entry_sep_new(tbarcfg_t *smenu, sif_node_t *nentry, 509 smenu_entry_t **rentry) 510 { 511 smenu_entry_t *entry; 512 errno_t rc; 513 514 entry = calloc(1, sizeof(smenu_entry_t)); 515 if (entry == NULL) { 516 rc = ENOMEM; 517 goto error; 518 } 519 520 entry->nentry = nentry; 521 entry->separator = true; 522 523 entry->smenu = smenu; 524 list_append(&entry->lentries, &smenu->entries); 525 if (rentry != NULL) 526 *rentry = entry; 527 528 return EOK; 529 error: 530 return rc; 531 } 532 369 533 /** Delete start menu entry. 370 534 * … … 377 541 { 378 542 list_remove(&entry->lentries); 379 free(entry->caption); 380 free(entry->cmd); 543 if (entry->caption != NULL) 544 free(entry->caption); 545 if (entry->cmd != NULL) 546 free(entry->cmd); 381 547 free(entry); 382 548 } … … 388 554 * @param caption Caption 389 555 * @param cmd Command to run 556 * @param terminal Start in terminal 557 * @param rentry Place to store pointer to new entry or @c NULL 390 558 */ 391 559 errno_t smenu_entry_create(tbarcfg_t *smenu, const char *caption, 392 const char *cmd )560 const char *cmd, bool terminal, smenu_entry_t **rentry) 393 561 { 394 562 sif_node_t *nentry; 563 smenu_entry_t *entry; 395 564 errno_t rc; 396 565 sif_trans_t *trans = NULL; … … 413 582 goto error; 414 583 415 rc = smenu_entry_new(smenu, nentry, caption, cmd); 584 rc = sif_node_set_attr(trans, nentry, "terminal", terminal ? "y" : "n"); 585 if (rc != EOK) 586 goto error; 587 588 rc = smenu_entry_new(smenu, nentry, caption, cmd, terminal, &entry); 416 589 if (rc != EOK) 417 590 goto error; … … 421 594 goto error; 422 595 596 if (rentry != NULL) 597 *rentry = entry; 423 598 return EOK; 424 599 error: … … 428 603 } 429 604 430 /** Destroy start menu entry.. 431 * 432 * @param entry Start menu entry 433 * @return EOK on success or an error code 434 */ 435 errno_t smenu_entry_destroy(smenu_entry_t *entry) 436 { 605 /** Create new start menu separator entry. 606 * 607 * @param smenu Start menu 608 * @param nentry Backing SIF node 609 * @param rentry Place to store pointer to new entry or @c NULL 610 */ 611 errno_t smenu_entry_sep_create(tbarcfg_t *smenu, smenu_entry_t **rentry) 612 { 613 sif_node_t *nentry; 614 smenu_entry_t *entry; 437 615 errno_t rc; 438 616 sif_trans_t *trans = NULL; 439 617 440 rc = sif_trans_begin(entry->smenu->repo, &trans); 441 if (rc != EOK) 442 goto error; 443 444 sif_node_destroy(trans, entry->nentry); 618 rc = sif_trans_begin(smenu->repo, &trans); 619 if (rc != EOK) 620 goto error; 621 622 rc = sif_node_append_child(trans, smenu->nentries, "entry", 623 &nentry); 624 if (rc != EOK) 625 goto error; 626 627 rc = sif_node_set_attr(trans, nentry, "separator", "y"); 628 if (rc != EOK) 629 goto error; 630 631 rc = smenu_entry_sep_new(smenu, nentry, &entry); 632 if (rc != EOK) 633 goto error; 445 634 446 635 rc = sif_trans_end(trans); … … 448 637 goto error; 449 638 450 smenu_entry_delete(entry); 639 if (rentry != NULL) 640 *rentry = entry; 451 641 return EOK; 452 642 error: … … 456 646 } 457 647 648 /** Destroy start menu entry. 649 * 650 * @param entry Start menu entry 651 * @return EOK on success or an error code 652 */ 653 errno_t smenu_entry_destroy(smenu_entry_t *entry) 654 { 655 errno_t rc; 656 sif_trans_t *trans = NULL; 657 658 rc = sif_trans_begin(entry->smenu->repo, &trans); 659 if (rc != EOK) 660 goto error; 661 662 sif_node_destroy(trans, entry->nentry); 663 664 rc = sif_trans_end(trans); 665 if (rc != EOK) 666 goto error; 667 668 smenu_entry_delete(entry); 669 return EOK; 670 error: 671 if (trans != NULL) 672 sif_trans_abort(trans); 673 return rc; 674 } 675 676 /** Move start menu entry up. 677 * 678 * @param entry Start menu entry 679 * @return EOK on success or an error code 680 */ 681 errno_t smenu_entry_move_up(smenu_entry_t *entry) 682 { 683 errno_t rc; 684 sif_trans_t *trans = NULL; 685 sif_node_t *nnode = NULL; 686 sif_node_t *old_node; 687 smenu_entry_t *prev; 688 689 rc = sif_trans_begin(entry->smenu->repo, &trans); 690 if (rc != EOK) 691 goto error; 692 693 prev = tbarcfg_smenu_prev(entry); 694 if (prev == NULL) { 695 /* Entry is already at first position, nothing to do. */ 696 return EOK; 697 } 698 699 rc = sif_node_insert_before(trans, prev->nentry, "entry", &nnode); 700 if (rc != EOK) 701 goto error; 702 703 old_node = entry->nentry; 704 entry->nentry = nnode; 705 706 rc = smenu_entry_save_trans(entry, trans); 707 if (rc != EOK) { 708 entry->nentry = old_node; 709 goto error; 710 } 711 712 sif_node_destroy(trans, old_node); 713 714 rc = sif_trans_end(trans); 715 if (rc != EOK) { 716 entry->nentry = old_node; 717 goto error; 718 } 719 720 list_remove(&entry->lentries); 721 list_insert_before(&entry->lentries, &prev->lentries); 722 return EOK; 723 error: 724 if (nnode != NULL) 725 sif_node_destroy(trans, nnode); 726 if (trans != NULL) 727 sif_trans_abort(trans); 728 return rc; 729 } 730 731 /** Move start menu entry down. 732 * 733 * @param entry Start menu entry 734 * @return EOK on success or an error code 735 */ 736 errno_t smenu_entry_move_down(smenu_entry_t *entry) 737 { 738 errno_t rc; 739 sif_trans_t *trans = NULL; 740 sif_node_t *nnode = NULL; 741 sif_node_t *old_node; 742 smenu_entry_t *next; 743 744 rc = sif_trans_begin(entry->smenu->repo, &trans); 745 if (rc != EOK) 746 goto error; 747 748 next = tbarcfg_smenu_next(entry); 749 if (next == NULL) { 750 /* Entry is already at last position, nothing to do. */ 751 return EOK; 752 } 753 754 rc = sif_node_insert_after(trans, next->nentry, "entry", &nnode); 755 if (rc != EOK) 756 goto error; 757 758 old_node = entry->nentry; 759 entry->nentry = nnode; 760 761 rc = smenu_entry_save_trans(entry, trans); 762 if (rc != EOK) { 763 entry->nentry = old_node; 764 goto error; 765 } 766 767 sif_node_destroy(trans, old_node); 768 769 rc = sif_trans_end(trans); 770 if (rc != EOK) { 771 entry->nentry = old_node; 772 goto error; 773 } 774 775 list_remove(&entry->lentries); 776 list_insert_after(&entry->lentries, &next->lentries); 777 return EOK; 778 error: 779 if (nnode != NULL) 780 sif_node_destroy(trans, nnode); 781 if (trans != NULL) 782 sif_trans_abort(trans); 783 return rc; 784 } 785 458 786 /** @} 459 787 */ -
uspace/lib/tbarcfg/test/tbarcfg.c
r86f862c rf2cb80a 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 67 67 tbarcfg_t *tbcfg; 68 68 char fname[L_tmpnam], *p; 69 smenu_entry_t *e1 = NULL, *e2 = NULL; 69 70 smenu_entry_t *e; 70 71 … … 75 76 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 76 77 77 rc = smenu_entry_create(tbcfg, "A", "a"); 78 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 79 80 rc = smenu_entry_create(tbcfg, "B", "b"); 78 rc = smenu_entry_create(tbcfg, "A", "a", false, &e1); 79 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 80 PCUT_ASSERT_NOT_NULL(e1); 81 82 rc = smenu_entry_create(tbcfg, "B", "b", false, &e2); 83 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 84 PCUT_ASSERT_NOT_NULL(e2); 85 86 /* Create entry without getting a pointer to it */ 87 rc = smenu_entry_create(tbcfg, "C", "c", false, NULL); 81 88 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 82 89 83 90 e = tbarcfg_smenu_first(tbcfg); 84 PCUT_ASSERT_NOT_NULL(e); 91 PCUT_ASSERT_EQUALS(e1, e); 92 e = tbarcfg_smenu_next(e); 93 PCUT_ASSERT_EQUALS(e2, e); 85 94 e = tbarcfg_smenu_next(e); 86 95 PCUT_ASSERT_NOT_NULL(e); … … 92 101 } 93 102 103 /** Iterating over start menu entries backwards */ 104 PCUT_TEST(last_prev) 105 { 106 errno_t rc; 107 tbarcfg_t *tbcfg; 108 char fname[L_tmpnam], *p; 109 smenu_entry_t *e1 = NULL, *e2 = NULL; 110 smenu_entry_t *e; 111 112 p = tmpnam(fname); 113 PCUT_ASSERT_NOT_NULL(p); 114 115 rc = tbarcfg_create(fname, &tbcfg); 116 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 117 118 rc = smenu_entry_create(tbcfg, "A", "a", false, &e1); 119 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 120 PCUT_ASSERT_NOT_NULL(e1); 121 122 rc = smenu_entry_create(tbcfg, "B", "b", false, &e2); 123 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 124 PCUT_ASSERT_NOT_NULL(e2); 125 126 e = tbarcfg_smenu_last(tbcfg); 127 PCUT_ASSERT_EQUALS(e2, e); 128 e = tbarcfg_smenu_prev(e); 129 PCUT_ASSERT_EQUALS(e1, e); 130 e = tbarcfg_smenu_prev(e); 131 PCUT_ASSERT_NULL(e); 132 133 tbarcfg_close(tbcfg); 134 remove(fname); 135 } 136 137 /** Separator entry */ 138 PCUT_TEST(separator) 139 { 140 errno_t rc; 141 tbarcfg_t *tbcfg; 142 char fname[L_tmpnam], *p; 143 const char *caption; 144 const char *cmd; 145 smenu_entry_t *e1 = NULL, *e2 = NULL; 146 smenu_entry_t *e; 147 148 p = tmpnam(fname); 149 PCUT_ASSERT_NOT_NULL(p); 150 151 rc = tbarcfg_create(fname, &tbcfg); 152 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 153 154 rc = smenu_entry_create(tbcfg, "A", "a", false, &e1); 155 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 156 PCUT_ASSERT_NOT_NULL(e1); 157 158 rc = smenu_entry_sep_create(tbcfg, &e2); 159 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 160 PCUT_ASSERT_NOT_NULL(e2); 161 162 PCUT_ASSERT_FALSE(smenu_entry_get_separator(e1)); 163 PCUT_ASSERT_TRUE(smenu_entry_get_separator(e2)); 164 165 tbarcfg_close(tbcfg); 166 167 /* Re-open repository */ 168 169 rc = tbarcfg_open(fname, &tbcfg); 170 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 171 172 e = tbarcfg_smenu_first(tbcfg); 173 PCUT_ASSERT_NOT_NULL(e); 174 175 /* Check that new values of properties have persisted */ 176 PCUT_ASSERT_FALSE(smenu_entry_get_separator(e)); 177 caption = smenu_entry_get_caption(e); 178 PCUT_ASSERT_STR_EQUALS("A", caption); 179 cmd = smenu_entry_get_cmd(e); 180 PCUT_ASSERT_STR_EQUALS("a", cmd); 181 182 e = tbarcfg_smenu_next(e); 183 184 /* Check that entry is still a separator */ 185 PCUT_ASSERT_TRUE(smenu_entry_get_separator(e)); 186 187 tbarcfg_close(tbcfg); 188 remove(fname); 189 } 190 94 191 /** Getting menu entry properties */ 95 PCUT_TEST(get_caption_cmd )192 PCUT_TEST(get_caption_cmd_term) 96 193 { 97 194 errno_t rc; … … 101 198 const char *caption; 102 199 const char *cmd; 103 104 p = tmpnam(fname); 105 PCUT_ASSERT_NOT_NULL(p); 106 107 rc = tbarcfg_create(fname, &tbcfg); 108 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 109 110 rc = smenu_entry_create(tbcfg, "A", "a"); 111 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 112 113 e = tbarcfg_smenu_first(tbcfg); 114 PCUT_ASSERT_NOT_NULL(e); 200 bool terminal; 201 202 p = tmpnam(fname); 203 PCUT_ASSERT_NOT_NULL(p); 204 205 rc = tbarcfg_create(fname, &tbcfg); 206 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 207 208 rc = smenu_entry_create(tbcfg, "A", "a", false, &e); 209 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 115 210 116 211 caption = smenu_entry_get_caption(e); … … 118 213 cmd = smenu_entry_get_cmd(e); 119 214 PCUT_ASSERT_STR_EQUALS("a", cmd); 215 terminal = smenu_entry_get_terminal(e); 216 PCUT_ASSERT_FALSE(terminal); 120 217 121 218 tbarcfg_close(tbcfg); … … 124 221 125 222 /** Setting menu entry properties */ 126 PCUT_TEST(set_caption_cmd )223 PCUT_TEST(set_caption_cmd_term) 127 224 { 128 225 errno_t rc; … … 132 229 const char *caption; 133 230 const char *cmd; 134 135 p = tmpnam(fname); 136 PCUT_ASSERT_NOT_NULL(p); 137 138 rc = tbarcfg_create(fname, &tbcfg); 139 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 140 141 rc = smenu_entry_create(tbcfg, "A", "a"); 142 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 143 144 e = tbarcfg_smenu_first(tbcfg); 145 PCUT_ASSERT_NOT_NULL(e); 231 bool terminal; 232 233 p = tmpnam(fname); 234 PCUT_ASSERT_NOT_NULL(p); 235 236 rc = tbarcfg_create(fname, &tbcfg); 237 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 238 239 rc = smenu_entry_create(tbcfg, "A", "a", false, &e); 240 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 146 241 147 242 caption = smenu_entry_get_caption(e); … … 149 244 cmd = smenu_entry_get_cmd(e); 150 245 PCUT_ASSERT_STR_EQUALS("a", cmd); 246 terminal = smenu_entry_get_terminal(e); 247 PCUT_ASSERT_FALSE(terminal); 151 248 152 249 /* Set properties */ … … 155 252 rc = smenu_entry_set_cmd(e, "b"); 156 253 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 254 smenu_entry_set_terminal(e, true); 157 255 158 256 rc = smenu_entry_save(e); … … 164 262 cmd = smenu_entry_get_cmd(e); 165 263 PCUT_ASSERT_STR_EQUALS("b", cmd); 264 terminal = smenu_entry_get_terminal(e); 265 PCUT_ASSERT_TRUE(terminal); 166 266 167 267 tbarcfg_close(tbcfg); … … 194 294 const char *caption; 195 295 const char *cmd; 196 197 p = tmpnam(fname); 198 PCUT_ASSERT_NOT_NULL(p); 199 200 rc = tbarcfg_create(fname, &tbcfg); 201 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 202 203 rc = smenu_entry_create(tbcfg, "A", "a"); 204 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 205 206 e = tbarcfg_smenu_first(tbcfg); 296 bool terminal; 297 298 p = tmpnam(fname); 299 PCUT_ASSERT_NOT_NULL(p); 300 301 rc = tbarcfg_create(fname, &tbcfg); 302 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 303 304 rc = smenu_entry_create(tbcfg, "A", "a", false, &e); 305 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 207 306 PCUT_ASSERT_NOT_NULL(e); 208 307 … … 211 310 cmd = smenu_entry_get_cmd(e); 212 311 PCUT_ASSERT_STR_EQUALS("a", cmd); 312 terminal = smenu_entry_get_terminal(e); 313 PCUT_ASSERT_FALSE(terminal); 314 315 smenu_entry_destroy(e); 316 317 rc = smenu_entry_create(tbcfg, "B", "b", true, &e); 318 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 319 PCUT_ASSERT_NOT_NULL(e); 320 321 caption = smenu_entry_get_caption(e); 322 PCUT_ASSERT_STR_EQUALS("B", caption); 323 cmd = smenu_entry_get_cmd(e); 324 PCUT_ASSERT_STR_EQUALS("b", cmd); 325 terminal = smenu_entry_get_terminal(e); 326 PCUT_ASSERT_TRUE(terminal); 327 328 smenu_entry_destroy(e); 213 329 214 330 tbarcfg_close(tbcfg); … … 222 338 tbarcfg_t *tbcfg; 223 339 char fname[L_tmpnam], *p; 224 smenu_entry_t *e ;225 226 p = tmpnam(fname); 227 PCUT_ASSERT_NOT_NULL(p); 228 229 rc = tbarcfg_create(fname, &tbcfg); 230 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 231 232 rc = smenu_entry_create(tbcfg, "A", "a" );233 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 234 235 e= tbarcfg_smenu_first(tbcfg);236 PCUT_ASSERT_ NOT_NULL(e);340 smenu_entry_t *e, *f; 341 342 p = tmpnam(fname); 343 PCUT_ASSERT_NOT_NULL(p); 344 345 rc = tbarcfg_create(fname, &tbcfg); 346 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 347 348 rc = smenu_entry_create(tbcfg, "A", "a", false, &e); 349 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 350 351 f = tbarcfg_smenu_first(tbcfg); 352 PCUT_ASSERT_EQUALS(e, f); 237 353 238 354 rc = smenu_entry_destroy(e); 239 355 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 240 356 241 e = tbarcfg_smenu_first(tbcfg); 242 PCUT_ASSERT_NULL(e); 357 f = tbarcfg_smenu_first(tbcfg); 358 PCUT_ASSERT_NULL(f); 359 360 tbarcfg_close(tbcfg); 361 remove(fname); 362 } 363 364 /** Move start menu entry up */ 365 PCUT_TEST(entry_move_up) 366 { 367 errno_t rc; 368 tbarcfg_t *tbcfg; 369 char fname[L_tmpnam], *p; 370 smenu_entry_t *e1, *e2, *e3; 371 smenu_entry_t *f; 372 const char *caption; 373 const char *cmd; 374 375 p = tmpnam(fname); 376 PCUT_ASSERT_NOT_NULL(p); 377 378 rc = tbarcfg_create(fname, &tbcfg); 379 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 380 381 rc = smenu_entry_create(tbcfg, "A", "a", false, &e1); 382 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 383 384 rc = smenu_entry_create(tbcfg, "B", "b", false, &e2); 385 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 386 387 rc = smenu_entry_create(tbcfg, "C", "c", false, &e3); 388 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 389 390 f = tbarcfg_smenu_first(tbcfg); 391 PCUT_ASSERT_EQUALS(e1, f); 392 393 /* Moving the first entry up should have no effect */ 394 395 rc = smenu_entry_move_up(e1); 396 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 397 398 f = tbarcfg_smenu_first(tbcfg); 399 PCUT_ASSERT_EQUALS(e1, f); 400 401 /* Moving the second entry up should move it to first position */ 402 403 rc = smenu_entry_move_up(e2); 404 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 405 406 f = tbarcfg_smenu_first(tbcfg); 407 PCUT_ASSERT_EQUALS(e2, f); 408 409 /* Moving the last entry up should move it to second position */ 410 411 rc = smenu_entry_move_up(e3); 412 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 413 414 f = tbarcfg_smenu_first(tbcfg); 415 PCUT_ASSERT_EQUALS(e2, f); 416 417 f = tbarcfg_smenu_next(f); 418 PCUT_ASSERT_EQUALS(e3, f); 419 420 f = tbarcfg_smenu_next(f); 421 PCUT_ASSERT_EQUALS(e1, f); 422 423 tbarcfg_close(tbcfg); 424 425 /* Re-open repository */ 426 427 rc = tbarcfg_open(fname, &tbcfg); 428 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 429 430 /* Check that new order of entries persisted */ 431 432 f = tbarcfg_smenu_first(tbcfg); 433 PCUT_ASSERT_NOT_NULL(f); 434 435 caption = smenu_entry_get_caption(f); 436 PCUT_ASSERT_STR_EQUALS("B", caption); 437 cmd = smenu_entry_get_cmd(f); 438 PCUT_ASSERT_STR_EQUALS("b", cmd); 439 440 f = tbarcfg_smenu_next(f); 441 PCUT_ASSERT_NOT_NULL(f); 442 443 caption = smenu_entry_get_caption(f); 444 PCUT_ASSERT_STR_EQUALS("C", caption); 445 cmd = smenu_entry_get_cmd(f); 446 PCUT_ASSERT_STR_EQUALS("c", cmd); 447 448 f = tbarcfg_smenu_next(f); 449 PCUT_ASSERT_NOT_NULL(f); 450 451 caption = smenu_entry_get_caption(f); 452 PCUT_ASSERT_STR_EQUALS("A", caption); 453 cmd = smenu_entry_get_cmd(f); 454 PCUT_ASSERT_STR_EQUALS("a", cmd); 455 456 tbarcfg_close(tbcfg); 457 remove(fname); 458 } 459 460 /** Move start menu entry down */ 461 PCUT_TEST(entry_move_down) 462 { 463 errno_t rc; 464 tbarcfg_t *tbcfg; 465 char fname[L_tmpnam], *p; 466 smenu_entry_t *e1, *e2, *e3; 467 smenu_entry_t *f; 468 const char *caption; 469 const char *cmd; 470 471 p = tmpnam(fname); 472 PCUT_ASSERT_NOT_NULL(p); 473 474 rc = tbarcfg_create(fname, &tbcfg); 475 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 476 477 rc = smenu_entry_create(tbcfg, "A", "a", false, &e1); 478 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 479 480 rc = smenu_entry_create(tbcfg, "B", "b", false, &e2); 481 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 482 483 rc = smenu_entry_create(tbcfg, "C", "c", false, &e3); 484 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 485 486 f = tbarcfg_smenu_last(tbcfg); 487 PCUT_ASSERT_EQUALS(e3, f); 488 489 /* Moving the last entry down should have no effect */ 490 491 rc = smenu_entry_move_down(e3); 492 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 493 494 f = tbarcfg_smenu_last(tbcfg); 495 PCUT_ASSERT_EQUALS(e3, f); 496 497 /* Moving the second entry down should move it to last position */ 498 499 rc = smenu_entry_move_down(e2); 500 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 501 502 f = tbarcfg_smenu_last(tbcfg); 503 PCUT_ASSERT_EQUALS(e2, f); 504 505 /* Moving the first entry down should move it to second position */ 506 507 rc = smenu_entry_move_down(e1); 508 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 509 510 f = tbarcfg_smenu_last(tbcfg); 511 PCUT_ASSERT_EQUALS(e2, f); 512 513 f = tbarcfg_smenu_prev(f); 514 PCUT_ASSERT_EQUALS(e1, f); 515 516 f = tbarcfg_smenu_prev(f); 517 PCUT_ASSERT_EQUALS(e3, f); 518 519 tbarcfg_close(tbcfg); 520 521 /* Re-open repository */ 522 523 rc = tbarcfg_open(fname, &tbcfg); 524 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 525 526 /* Check that new order of entries persisted */ 527 528 f = tbarcfg_smenu_first(tbcfg); 529 PCUT_ASSERT_NOT_NULL(f); 530 531 caption = smenu_entry_get_caption(f); 532 PCUT_ASSERT_STR_EQUALS("C", caption); 533 cmd = smenu_entry_get_cmd(f); 534 PCUT_ASSERT_STR_EQUALS("c", cmd); 535 536 f = tbarcfg_smenu_next(f); 537 PCUT_ASSERT_NOT_NULL(f); 538 539 caption = smenu_entry_get_caption(f); 540 PCUT_ASSERT_STR_EQUALS("A", caption); 541 cmd = smenu_entry_get_cmd(f); 542 PCUT_ASSERT_STR_EQUALS("a", cmd); 543 544 f = tbarcfg_smenu_next(f); 545 PCUT_ASSERT_NOT_NULL(f); 546 547 caption = smenu_entry_get_caption(f); 548 PCUT_ASSERT_STR_EQUALS("B", caption); 549 cmd = smenu_entry_get_cmd(f); 550 PCUT_ASSERT_STR_EQUALS("b", cmd); 243 551 244 552 tbarcfg_close(tbcfg); -
uspace/lib/ui/include/ui/checkbox.h
r86f862c rf2cb80a 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 52 52 extern void ui_checkbox_set_cb(ui_checkbox_t *, ui_checkbox_cb_t *, void *); 53 53 extern void ui_checkbox_set_rect(ui_checkbox_t *, gfx_rect_t *); 54 extern bool ui_checkbox_get_checked(ui_checkbox_t *); 55 extern void ui_checkbox_set_checked(ui_checkbox_t *, bool); 54 56 extern errno_t ui_checkbox_paint(ui_checkbox_t *); 55 57 extern void ui_checkbox_press(ui_checkbox_t *); -
uspace/lib/ui/include/ui/list.h
r86f862c rf2cb80a 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 57 57 extern errno_t ui_list_entry_append(ui_list_t *, 58 58 ui_list_entry_attr_t *, ui_list_entry_t **); 59 extern void ui_list_entry_move_up(ui_list_entry_t *); 60 extern void ui_list_entry_move_down(ui_list_entry_t *); 59 61 extern void ui_list_entry_delete(ui_list_entry_t *); 60 62 extern void *ui_list_entry_get_arg(ui_list_entry_t *); -
uspace/lib/ui/src/checkbox.c
r86f862c rf2cb80a 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 139 139 } 140 140 141 /** Set buttonrectangle.142 * 143 * @param checkbox Button144 * @param rect New buttonrectangle141 /** Set check box rectangle. 142 * 143 * @param checkbox Check box 144 * @param rect New check box rectangle 145 145 */ 146 146 void ui_checkbox_set_rect(ui_checkbox_t *checkbox, gfx_rect_t *rect) 147 147 { 148 148 checkbox->rect = *rect; 149 } 150 151 /** Return if check box is checked. 152 * 153 * @param checkbox Check box 154 * @return @c true iff check box is checked 155 */ 156 bool ui_checkbox_get_checked(ui_checkbox_t *checkbox) 157 { 158 return checkbox->checked; 159 } 160 161 /** Set check box checked state. 162 * 163 * @param checkbox Check box 164 * @param checked @c true iff checkbox should be checked 165 */ 166 void ui_checkbox_set_checked(ui_checkbox_t *checkbox, bool checked) 167 { 168 checkbox->checked = checked; 149 169 } 150 170 -
uspace/lib/ui/src/list.c
r86f862c rf2cb80a 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 711 711 } 712 712 713 /** Move UI list entry one position up. 714 * 715 * @parm entry UI list entry 716 */ 717 void ui_list_entry_move_up(ui_list_entry_t *entry) 718 { 719 ui_list_t *list = entry->list; 720 ui_list_entry_t *prev; 721 722 prev = ui_list_prev(entry); 723 if (prev == NULL) { 724 /* Entry is already on first position, nothing to do. */ 725 return; 726 } 727 728 list_remove(&entry->lentries); 729 list_insert_before(&entry->lentries, &prev->lentries); 730 731 /* Make sure page stays on the same position/idx as it was before */ 732 if (list->page == entry) { 733 list->page = prev; 734 } else if (list->page == prev) { 735 list->page = entry; 736 } 737 738 /* 739 * Return cursor to the same position/idx as it was before, 740 * but then move it using ui_list_cursor_move() to the new 741 * position (this ensures scrolling when needed). 742 */ 743 if (list->cursor == entry) { 744 list->cursor = prev; 745 ui_list_cursor_move(list, entry, list->cursor_idx - 1); 746 } else if (list->cursor == prev) { 747 list->cursor = entry; 748 ui_list_cursor_move(list, prev, list->cursor_idx + 1); 749 } 750 } 751 752 /** Move UI list entry one position down. 753 * 754 * @parm entry UI list entry 755 */ 756 void ui_list_entry_move_down(ui_list_entry_t *entry) 757 { 758 ui_list_t *list = entry->list; 759 ui_list_entry_t *next; 760 761 next = ui_list_next(entry); 762 if (next == NULL) { 763 /* Entry is already on last position, nothing to do. */ 764 return; 765 } 766 767 list_remove(&entry->lentries); 768 list_insert_after(&entry->lentries, &next->lentries); 769 770 /* Make sure page stays on the same position/idx as it was before */ 771 if (list->page == entry) { 772 list->page = next; 773 } else if (list->page == next) { 774 list->page = entry; 775 } 776 777 /* 778 * Return cursor to the same position/idx as it was before, 779 * but then move it using ui_list_cursor_move() to the new 780 * position (this ensures scrolling when needed). 781 */ 782 if (list->cursor == entry) { 783 list->cursor = next; 784 ui_list_cursor_move(list, entry, list->cursor_idx + 1); 785 } else if (list->cursor == next) { 786 list->cursor = entry; 787 ui_list_cursor_move(list, next, list->cursor_idx - 1); 788 } 789 } 790 713 791 /** Destroy UI list entry. 714 792 * -
uspace/lib/ui/test/checkbox.c
r86f862c rf2cb80a 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 151 151 } 152 152 153 /** Get check box checked returns internal field */ 154 PCUT_TEST(get_checked) 155 { 156 ui_checkbox_t *checkbox; 157 errno_t rc; 158 159 rc = ui_checkbox_create(NULL, "Hello", &checkbox); 160 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 161 162 checkbox->checked = false; 163 PCUT_ASSERT_FALSE(ui_checkbox_get_checked(checkbox)); 164 checkbox->checked = true; 165 PCUT_ASSERT_TRUE(ui_checkbox_get_checked(checkbox)); 166 167 ui_checkbox_destroy(checkbox); 168 } 169 170 /** Set check box checked sets internal field */ 171 PCUT_TEST(set_checked) 172 { 173 ui_checkbox_t *checkbox; 174 errno_t rc; 175 176 rc = ui_checkbox_create(NULL, "Hello", &checkbox); 177 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 178 179 ui_checkbox_set_checked(checkbox, true); 180 PCUT_ASSERT_TRUE(checkbox->checked); 181 ui_checkbox_set_checked(checkbox, false); 182 PCUT_ASSERT_FALSE(checkbox->checked); 183 184 ui_checkbox_destroy(checkbox); 185 } 186 153 187 /** Paint check box in graphics mode */ 154 188 PCUT_TEST(paint_gfx) -
uspace/lib/ui/test/list.c
r86f862c rf2cb80a 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 904 904 } 905 905 906 /** ui_list_entry_move_up() moves entry up */ 907 PCUT_TEST(entry_move_up) 908 { 909 ui_t *ui; 910 ui_window_t *window; 911 ui_wnd_params_t params; 912 ui_list_t *list; 913 ui_list_entry_attr_t attr; 914 ui_list_entry_t *e1, *e2, *e3; 915 ui_list_entry_t *e; 916 errno_t rc; 917 918 rc = ui_create_disp(NULL, &ui); 919 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 920 921 ui_wnd_params_init(¶ms); 922 params.caption = "Test"; 923 924 rc = ui_window_create(ui, ¶ms, &window); 925 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 926 927 rc = ui_list_create(window, true, &list); 928 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 929 930 ui_list_entry_attr_init(&attr); 931 932 /* Create entries */ 933 934 attr.caption = "a"; 935 attr.arg = (void *)1; 936 rc = ui_list_entry_append(list, &attr, &e1); 937 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 938 939 attr.caption = "b"; 940 attr.arg = (void *)2; 941 rc = ui_list_entry_append(list, &attr, &e2); 942 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 943 944 attr.caption = "c"; 945 attr.arg = (void *)3; 946 rc = ui_list_entry_append(list, &attr, &e3); 947 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 948 949 e = ui_list_first(list); 950 PCUT_ASSERT_EQUALS(e1, e); 951 952 /* Moving first entry up should have no effect */ 953 ui_list_entry_move_up(e1); 954 955 e = ui_list_first(list); 956 PCUT_ASSERT_EQUALS(e1, e); 957 958 e = ui_list_next(e); 959 PCUT_ASSERT_EQUALS(e2, e); 960 961 e = ui_list_next(e); 962 PCUT_ASSERT_EQUALS(e3, e); 963 964 e = ui_list_next(e); 965 PCUT_ASSERT_NULL(e); 966 967 /* Move second entry up */ 968 ui_list_entry_move_up(e2); 969 970 e = ui_list_first(list); 971 PCUT_ASSERT_EQUALS(e2, e); 972 973 e = ui_list_next(e); 974 PCUT_ASSERT_EQUALS(e1, e); 975 976 e = ui_list_next(e); 977 PCUT_ASSERT_EQUALS(e3, e); 978 979 e = ui_list_next(e); 980 PCUT_ASSERT_NULL(e); 981 982 ui_list_destroy(list); 983 ui_window_destroy(window); 984 ui_destroy(ui); 985 } 986 987 /** ui_list_entry_move_down() moves entry down */ 988 PCUT_TEST(entry_move_down) 989 { 990 ui_t *ui; 991 ui_window_t *window; 992 ui_wnd_params_t params; 993 ui_list_t *list; 994 ui_list_entry_attr_t attr; 995 ui_list_entry_t *e1, *e2, *e3; 996 ui_list_entry_t *e; 997 errno_t rc; 998 999 rc = ui_create_disp(NULL, &ui); 1000 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1001 1002 ui_wnd_params_init(¶ms); 1003 params.caption = "Test"; 1004 1005 rc = ui_window_create(ui, ¶ms, &window); 1006 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1007 1008 rc = ui_list_create(window, true, &list); 1009 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1010 1011 ui_list_entry_attr_init(&attr); 1012 1013 /* Create entries */ 1014 1015 attr.caption = "a"; 1016 attr.arg = (void *)1; 1017 rc = ui_list_entry_append(list, &attr, &e1); 1018 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1019 1020 attr.caption = "b"; 1021 attr.arg = (void *)2; 1022 rc = ui_list_entry_append(list, &attr, &e2); 1023 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1024 1025 attr.caption = "c"; 1026 attr.arg = (void *)3; 1027 rc = ui_list_entry_append(list, &attr, &e3); 1028 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1029 1030 e = ui_list_first(list); 1031 PCUT_ASSERT_EQUALS(e1, e); 1032 1033 /* Moving last entry down should have no effect */ 1034 ui_list_entry_move_down(e3); 1035 1036 e = ui_list_first(list); 1037 PCUT_ASSERT_EQUALS(e1, e); 1038 1039 e = ui_list_next(e); 1040 PCUT_ASSERT_EQUALS(e2, e); 1041 1042 e = ui_list_next(e); 1043 PCUT_ASSERT_EQUALS(e3, e); 1044 1045 e = ui_list_next(e); 1046 PCUT_ASSERT_NULL(e); 1047 1048 /* Move second-to-last entry down */ 1049 ui_list_entry_move_down(e2); 1050 1051 e = ui_list_first(list); 1052 PCUT_ASSERT_EQUALS(e1, e); 1053 1054 e = ui_list_next(e); 1055 PCUT_ASSERT_EQUALS(e3, e); 1056 1057 e = ui_list_next(e); 1058 PCUT_ASSERT_EQUALS(e2, e); 1059 1060 e = ui_list_next(e); 1061 PCUT_ASSERT_NULL(e); 1062 1063 ui_list_destroy(list); 1064 ui_window_destroy(window); 1065 ui_destroy(ui); 1066 } 1067 906 1068 /** ui_list_entry_delete() deletes entry */ 907 1069 PCUT_TEST(entry_delete)
Note:
See TracChangeset
for help on using the changeset viewer.