Changeset f2cb80a in mainline for uspace/lib


Ignore:
Timestamp:
2024-02-23T17:57:23Z (20 months ago)
Author:
GitHub <noreply@…>
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)
Message:

Merge branch 'HelenOS:master' into topic/packet-capture

Location:
uspace/lib
Files:
14 edited
4 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/meson.build

    r86f862c rf2cb80a  
    5353        _sdir = meson.current_source_dir() / idir
    5454        uspace_lib_devel_install_script_text += 'cp -R -L -T "@0@" "${DESTDIR}include/libc"'.format(_sdir)
     55        exported_devel_files += ['include', _sdir, 'libc']
    5556endforeach
    5657
     
    209210        pic: false,
    210211)
     212exported_devel_files += ['staticlib', libstartfiles, 'libstartfiles.a']
    211213
    212214if CONFIG_DEVEL_FILES
  • uspace/lib/clui/meson.build

    r86f862c rf2cb80a  
    2929deps = [ 'clipboard', 'console' ]
    3030src = files(
    31         'nchoice.c',
    32         'tinput.c',
     31        'src/nchoice.c',
     32        'src/tinput.c',
    3333)
  • uspace/lib/meson.build

    r86f862c rf2cb80a  
    181181                if run_command('[', '-d', incdir, ']').returncode() == 0
    182182                        includes += include_directories(incdir)
     183                        _sdir = meson.current_source_dir() / l / 'include'
    183184
    184185                        if installed_libs.contains(l)
    185                                 _sdir = meson.current_source_dir() / l / 'include'
    186186                                uspace_lib_devel_install_script_text += 'cp -R -L -T "@0@" "${DESTDIR}include/lib@1@"'.format(_sdir, l)
    187187                        endif
     188
     189                        exported_devel_files += ['include', _sdir, 'lib' + l]
    188190                else
    189191                        includes += include_directories(l)
     
    294296                        install_deps += [ _static_lib ]
    295297                endif
     298
     299                exported_devel_files += ['staticlib', _static_lib, 'lib' + l + '.a']
    296300
    297301                _static_dep = declare_dependency(
  • uspace/lib/posix/meson.build

    r86f862c rf2cb80a  
    6767uspace_lib_devel_install_script_text += 'cp -R -L -T "@0@" "${DESTDIR}include/libposix"'.format(_sdir)
    6868uspace_lib_devel_install_script_text += 'ln -s -r "${DESTDIR}include/libc" "${DESTDIR}/include/common"'
     69
     70exported_devel_files += [ 'include', meson.current_source_dir() / 'include' / 'posix', 'libposix' ]
     71exported_devel_files += [ 'includesymlink', 'libc', 'libposix' ]
  • uspace/lib/tbarcfg/include/tbarcfg/tbarcfg.h

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939#include <errno.h>
    4040#include <sif.h>
     41#include <stdbool.h>
    4142#include <types/tbarcfg/tbarcfg.h>
    4243
     
    4647extern smenu_entry_t *tbarcfg_smenu_first(tbarcfg_t *);
    4748extern smenu_entry_t *tbarcfg_smenu_next(smenu_entry_t *);
     49extern smenu_entry_t *tbarcfg_smenu_last(tbarcfg_t *);
     50extern smenu_entry_t *tbarcfg_smenu_prev(smenu_entry_t *);
    4851extern const char *smenu_entry_get_caption(smenu_entry_t *);
    4952extern const char *smenu_entry_get_cmd(smenu_entry_t *);
     53extern bool smenu_entry_get_terminal(smenu_entry_t *);
     54extern bool smenu_entry_get_separator(smenu_entry_t *);
    5055extern errno_t smenu_entry_set_caption(smenu_entry_t *, const char *);
    5156extern errno_t smenu_entry_set_cmd(smenu_entry_t *, const char *);
     57extern void smenu_entry_set_terminal(smenu_entry_t *, bool);
    5258extern errno_t smenu_entry_save(smenu_entry_t *);
    53 extern errno_t smenu_entry_create(tbarcfg_t *, const char *, const char *);
     59extern errno_t smenu_entry_create(tbarcfg_t *, const char *, const char *,
     60    bool, smenu_entry_t **);
     61extern errno_t smenu_entry_sep_create(tbarcfg_t *, smenu_entry_t **);
    5462extern errno_t smenu_entry_destroy(smenu_entry_t *);
     63extern errno_t smenu_entry_move_up(smenu_entry_t *);
     64extern errno_t smenu_entry_move_down(smenu_entry_t *);
    5565
    5666#endif
  • uspace/lib/tbarcfg/private/tbarcfg.h

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4040#include <adt/list.h>
    4141#include <sif.h>
     42#include <stdbool.h>
    4243#include <types/tbarcfg/tbarcfg.h>
    4344
     
    6061        /** SIF node (persistent storage) */
    6162        sif_node_t *nentry;
     63        /** Is this a separator entry */
     64        bool separator;
    6265        /** Entry caption (with accelerator markup) */
    6366        char *caption;
    6467        /** Command to run */
    6568        char *cmd;
     69        /** Start in terminal */
     70        bool terminal;
    6671};
    6772
    6873extern errno_t smenu_entry_new(tbarcfg_t *, sif_node_t *, const char *,
    69     const char *);
     74    const char *, bool, smenu_entry_t **);
     75extern errno_t smenu_entry_sep_new(tbarcfg_t *, sif_node_t *, smenu_entry_t **);
    7076extern void smenu_entry_delete(smenu_entry_t *);
    7177
  • uspace/lib/tbarcfg/src/tbarcfg.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    108108        sif_node_t *nentry;
    109109        const char *ntype;
     110        const char *separator;
    110111        const char *caption;
    111112        const char *cmd;
     113        const char *terminal = NULL;
    112114        errno_t rc;
    113115
     
    142144                }
    143145
    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) {
    146148                        rc = EIO;
    147149                        goto error;
    148150                }
    149151
    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;
    154177                }
    155 
    156                 rc = smenu_entry_new(tbcfg, nentry, caption, cmd);
    157                 if (rc != EOK)
    158                         goto error;
    159178
    160179                nentry = sif_node_next_child(nentry);
     
    221240}
    222241
     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 */
     247smenu_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 */
     263smenu_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
    223274/** Get start menu entry caption.
    224275 *
     
    228279const char *smenu_entry_get_caption(smenu_entry_t *entry)
    229280{
     281        assert(!entry->separator);
    230282        return entry->caption;
    231283}
     
    233285/** Get start menu entry command.
    234286 *
    235  * @param entr Start menu entry
     287 * @param entry Start menu entry
    236288 * @return Command to run
    237289 */
    238290const char *smenu_entry_get_cmd(smenu_entry_t *entry)
    239291{
     292        assert(!entry->separator);
    240293        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 */
     301bool 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 */
     312bool smenu_entry_get_separator(smenu_entry_t *entry)
     313{
     314        return entry->separator;
    241315}
    242316
     
    253327{
    254328        char *dcap;
     329
     330        assert(!entry->separator);
    255331
    256332        dcap = str_dup(caption);
     
    276352        char *dcmd;
    277353
     354        assert(!entry->separator);
     355
    278356        dcmd = str_dup(cmd);
    279357        if (dcmd == NULL)
     
    285363}
    286364
     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 */
     373void 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 */
     384static 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;
     411error:
     412        return rc;
     413}
     414
    287415/** Save any changes to start menu entry.
    288416 *
     
    298426                goto error;
    299427
    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);
    305429        if (rc != EOK)
    306430                goto error;
     
    325449 * @param caption Caption
    326450 * @param cmd Command to run
     451 * @param terminal Start in terminal
     452 * @param rentry Place to store pointer to new entry or @c NULL
    327453 */
    328454errno_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)
    330456{
    331457        smenu_entry_t *entry;
     
    352478        }
    353479
     480        entry->terminal = terminal;
     481
    354482        entry->smenu = smenu;
    355483        list_append(&entry->lentries, &smenu->entries);
     484        if (rentry != NULL)
     485                *rentry = entry;
    356486        return EOK;
    357487error:
     
    367497}
    368498
     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 */
     508errno_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;
     529error:
     530        return rc;
     531}
     532
    369533/** Delete start menu entry.
    370534 *
     
    377541{
    378542        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);
    381547        free(entry);
    382548}
     
    388554 * @param caption Caption
    389555 * @param cmd Command to run
     556 * @param terminal Start in terminal
     557 * @param rentry Place to store pointer to new entry or @c NULL
    390558 */
    391559errno_t smenu_entry_create(tbarcfg_t *smenu, const char *caption,
    392     const char *cmd)
     560    const char *cmd, bool terminal, smenu_entry_t **rentry)
    393561{
    394562        sif_node_t *nentry;
     563        smenu_entry_t *entry;
    395564        errno_t rc;
    396565        sif_trans_t *trans = NULL;
     
    413582                goto error;
    414583
    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);
    416589        if (rc != EOK)
    417590                goto error;
     
    421594                goto error;
    422595
     596        if (rentry != NULL)
     597                *rentry = entry;
    423598        return EOK;
    424599error:
     
    428603}
    429604
    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 */
     611errno_t smenu_entry_sep_create(tbarcfg_t *smenu, smenu_entry_t **rentry)
     612{
     613        sif_node_t *nentry;
     614        smenu_entry_t *entry;
    437615        errno_t rc;
    438616        sif_trans_t *trans = NULL;
    439617
    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;
    445634
    446635        rc = sif_trans_end(trans);
     
    448637                goto error;
    449638
    450         smenu_entry_delete(entry);
     639        if (rentry != NULL)
     640                *rentry = entry;
    451641        return EOK;
    452642error:
     
    456646}
    457647
     648/** Destroy start menu entry.
     649 *
     650 * @param entry Start menu entry
     651 * @return EOK on success or an error code
     652 */
     653errno_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;
     670error:
     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 */
     681errno_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;
     723error:
     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 */
     736errno_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;
     778error:
     779        if (nnode != NULL)
     780                sif_node_destroy(trans, nnode);
     781        if (trans != NULL)
     782                sif_trans_abort(trans);
     783        return rc;
     784}
     785
    458786/** @}
    459787 */
  • uspace/lib/tbarcfg/test/tbarcfg.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6767        tbarcfg_t *tbcfg;
    6868        char fname[L_tmpnam], *p;
     69        smenu_entry_t *e1 = NULL, *e2 = NULL;
    6970        smenu_entry_t *e;
    7071
     
    7576        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    7677
    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);
    8188        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    8289
    8390        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);
    8594        e = tbarcfg_smenu_next(e);
    8695        PCUT_ASSERT_NOT_NULL(e);
     
    92101}
    93102
     103/** Iterating over start menu entries backwards */
     104PCUT_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 */
     138PCUT_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
    94191/** Getting menu entry properties */
    95 PCUT_TEST(get_caption_cmd)
     192PCUT_TEST(get_caption_cmd_term)
    96193{
    97194        errno_t rc;
     
    101198        const char *caption;
    102199        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);
    115210
    116211        caption = smenu_entry_get_caption(e);
     
    118213        cmd = smenu_entry_get_cmd(e);
    119214        PCUT_ASSERT_STR_EQUALS("a", cmd);
     215        terminal = smenu_entry_get_terminal(e);
     216        PCUT_ASSERT_FALSE(terminal);
    120217
    121218        tbarcfg_close(tbcfg);
     
    124221
    125222/** Setting menu entry properties */
    126 PCUT_TEST(set_caption_cmd)
     223PCUT_TEST(set_caption_cmd_term)
    127224{
    128225        errno_t rc;
     
    132229        const char *caption;
    133230        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);
    146241
    147242        caption = smenu_entry_get_caption(e);
     
    149244        cmd = smenu_entry_get_cmd(e);
    150245        PCUT_ASSERT_STR_EQUALS("a", cmd);
     246        terminal = smenu_entry_get_terminal(e);
     247        PCUT_ASSERT_FALSE(terminal);
    151248
    152249        /* Set properties */
     
    155252        rc = smenu_entry_set_cmd(e, "b");
    156253        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     254        smenu_entry_set_terminal(e, true);
    157255
    158256        rc = smenu_entry_save(e);
     
    164262        cmd = smenu_entry_get_cmd(e);
    165263        PCUT_ASSERT_STR_EQUALS("b", cmd);
     264        terminal = smenu_entry_get_terminal(e);
     265        PCUT_ASSERT_TRUE(terminal);
    166266
    167267        tbarcfg_close(tbcfg);
     
    194294        const char *caption;
    195295        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);
    207306        PCUT_ASSERT_NOT_NULL(e);
    208307
     
    211310        cmd = smenu_entry_get_cmd(e);
    212311        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);
    213329
    214330        tbarcfg_close(tbcfg);
     
    222338        tbarcfg_t *tbcfg;
    223339        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);
    237353
    238354        rc = smenu_entry_destroy(e);
    239355        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    240356
    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 */
     365PCUT_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 */
     461PCUT_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);
    243551
    244552        tbarcfg_close(tbcfg);
  • uspace/lib/ui/include/ui/checkbox.h

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5252extern void ui_checkbox_set_cb(ui_checkbox_t *, ui_checkbox_cb_t *, void *);
    5353extern void ui_checkbox_set_rect(ui_checkbox_t *, gfx_rect_t *);
     54extern bool ui_checkbox_get_checked(ui_checkbox_t *);
     55extern void ui_checkbox_set_checked(ui_checkbox_t *, bool);
    5456extern errno_t ui_checkbox_paint(ui_checkbox_t *);
    5557extern void ui_checkbox_press(ui_checkbox_t *);
  • uspace/lib/ui/include/ui/list.h

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5757extern errno_t ui_list_entry_append(ui_list_t *,
    5858    ui_list_entry_attr_t *, ui_list_entry_t **);
     59extern void ui_list_entry_move_up(ui_list_entry_t *);
     60extern void ui_list_entry_move_down(ui_list_entry_t *);
    5961extern void ui_list_entry_delete(ui_list_entry_t *);
    6062extern void *ui_list_entry_get_arg(ui_list_entry_t *);
  • uspace/lib/ui/src/checkbox.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    139139}
    140140
    141 /** Set button rectangle.
    142  *
    143  * @param checkbox Button
    144  * @param rect New button rectangle
     141/** Set check box rectangle.
     142 *
     143 * @param checkbox Check box
     144 * @param rect New check box rectangle
    145145 */
    146146void ui_checkbox_set_rect(ui_checkbox_t *checkbox, gfx_rect_t *rect)
    147147{
    148148        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 */
     156bool 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 */
     166void ui_checkbox_set_checked(ui_checkbox_t *checkbox, bool checked)
     167{
     168        checkbox->checked = checked;
    149169}
    150170
  • uspace/lib/ui/src/list.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    711711}
    712712
     713/** Move UI list entry one position up.
     714 *
     715 * @parm entry UI list entry
     716 */
     717void 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 */
     756void 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
    713791/** Destroy UI list entry.
    714792 *
  • uspace/lib/ui/test/checkbox.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    151151}
    152152
     153/** Get check box checked returns internal field */
     154PCUT_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 */
     171PCUT_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
    153187/** Paint check box in graphics mode */
    154188PCUT_TEST(paint_gfx)
  • uspace/lib/ui/test/list.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    904904}
    905905
     906/** ui_list_entry_move_up() moves entry up */
     907PCUT_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(&params);
     922        params.caption = "Test";
     923
     924        rc = ui_window_create(ui, &params, &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 */
     988PCUT_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(&params);
     1003        params.caption = "Test";
     1004
     1005        rc = ui_window_create(ui, &params, &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
    9061068/** ui_list_entry_delete() deletes entry */
    9071069PCUT_TEST(entry_delete)
Note: See TracChangeset for help on using the changeset viewer.