Changeset 550ed86 in mainline for uspace/lib/tbarcfg/test/tbarcfg.c


Ignore:
Timestamp:
2023-12-19T17:25:58Z (14 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, topic/simplify-dev-export
Children:
7130754
Parents:
f87ff8e
git-author:
Jiri Svoboda <jiri@…> (2023-12-19 17:19:18)
git-committer:
Jiri Svoboda <jiri@…> (2023-12-19 17:25:58)
Message:

Need to add new start menu entry to editor's list

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/tbarcfg/test/tbarcfg.c

    rf87ff8e r550ed86  
    6767        tbarcfg_t *tbcfg;
    6868        char fname[L_tmpnam], *p;
    69         smenu_entry_t *e;
    70 
    71         p = tmpnam(fname);
    72         PCUT_ASSERT_NOT_NULL(p);
    73 
    74         rc = tbarcfg_create(fname, &tbcfg);
    75         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    76 
    77         rc = smenu_entry_create(tbcfg, "A", "a");
    78         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    79 
    80         rc = smenu_entry_create(tbcfg, "B", "b");
     69        smenu_entry_t *e1 = NULL, *e2 = NULL;
     70        smenu_entry_t *e;
     71
     72        p = tmpnam(fname);
     73        PCUT_ASSERT_NOT_NULL(p);
     74
     75        rc = tbarcfg_create(fname, &tbcfg);
     76        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     77
     78        rc = smenu_entry_create(tbcfg, "A", "a", &e1);
     79        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     80        PCUT_ASSERT_NOT_NULL(e1);
     81
     82        rc = smenu_entry_create(tbcfg, "B", "b", &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", 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);
     
    108117        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    109118
    110         rc = smenu_entry_create(tbcfg, "A", "a");
     119        rc = smenu_entry_create(tbcfg, "A", "a", &e);
     120        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     121
     122        caption = smenu_entry_get_caption(e);
     123        PCUT_ASSERT_STR_EQUALS("A", caption);
     124        cmd = smenu_entry_get_cmd(e);
     125        PCUT_ASSERT_STR_EQUALS("a", cmd);
     126
     127        tbarcfg_close(tbcfg);
     128        remove(fname);
     129}
     130
     131/** Setting menu entry properties */
     132PCUT_TEST(set_caption_cmd)
     133{
     134        errno_t rc;
     135        tbarcfg_t *tbcfg;
     136        char fname[L_tmpnam], *p;
     137        smenu_entry_t *e;
     138        const char *caption;
     139        const char *cmd;
     140
     141        p = tmpnam(fname);
     142        PCUT_ASSERT_NOT_NULL(p);
     143
     144        rc = tbarcfg_create(fname, &tbcfg);
     145        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     146
     147        rc = smenu_entry_create(tbcfg, "A", "a", &e);
     148        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     149
     150        caption = smenu_entry_get_caption(e);
     151        PCUT_ASSERT_STR_EQUALS("A", caption);
     152        cmd = smenu_entry_get_cmd(e);
     153        PCUT_ASSERT_STR_EQUALS("a", cmd);
     154
     155        /* Set properties */
     156        rc = smenu_entry_set_caption(e, "B");
     157        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     158        rc = smenu_entry_set_cmd(e, "b");
     159        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     160
     161        rc = smenu_entry_save(e);
     162        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     163
     164        /* Check that properties have been set */
     165        caption = smenu_entry_get_caption(e);
     166        PCUT_ASSERT_STR_EQUALS("B", caption);
     167        cmd = smenu_entry_get_cmd(e);
     168        PCUT_ASSERT_STR_EQUALS("b", cmd);
     169
     170        tbarcfg_close(tbcfg);
     171
     172        /* Re-open repository */
     173
     174        rc = tbarcfg_open(fname, &tbcfg);
    111175        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    112176
     
    114178        PCUT_ASSERT_NOT_NULL(e);
    115179
    116         caption = smenu_entry_get_caption(e);
    117         PCUT_ASSERT_STR_EQUALS("A", caption);
    118         cmd = smenu_entry_get_cmd(e);
    119         PCUT_ASSERT_STR_EQUALS("a", cmd);
    120 
    121         tbarcfg_close(tbcfg);
    122         remove(fname);
    123 }
    124 
    125 /** Setting menu entry properties */
    126 PCUT_TEST(set_caption_cmd)
     180        /* Check that new values of properties have persisted */
     181        caption = smenu_entry_get_caption(e);
     182        PCUT_ASSERT_STR_EQUALS("B", caption);
     183        cmd = smenu_entry_get_cmd(e);
     184        PCUT_ASSERT_STR_EQUALS("b", cmd);
     185
     186        tbarcfg_close(tbcfg);
     187        remove(fname);
     188}
     189
     190/** Create start menu entry */
     191PCUT_TEST(entry_create)
    127192{
    128193        errno_t rc;
     
    139204        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    140205
    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);
    146 
    147         caption = smenu_entry_get_caption(e);
    148         PCUT_ASSERT_STR_EQUALS("A", caption);
    149         cmd = smenu_entry_get_cmd(e);
    150         PCUT_ASSERT_STR_EQUALS("a", cmd);
    151 
    152         /* Set properties */
    153         rc = smenu_entry_set_caption(e, "B");
    154         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    155         rc = smenu_entry_set_cmd(e, "b");
    156         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    157 
    158         rc = smenu_entry_save(e);
    159         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    160 
    161         /* Check that properties have been set */
    162         caption = smenu_entry_get_caption(e);
    163         PCUT_ASSERT_STR_EQUALS("B", caption);
    164         cmd = smenu_entry_get_cmd(e);
    165         PCUT_ASSERT_STR_EQUALS("b", cmd);
    166 
    167         tbarcfg_close(tbcfg);
    168 
    169         /* Re-open repository */
    170 
    171         rc = tbarcfg_open(fname, &tbcfg);
    172         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    173 
    174         e = tbarcfg_smenu_first(tbcfg);
    175         PCUT_ASSERT_NOT_NULL(e);
    176 
    177         /* Check that new values of properties have persisted */
    178         caption = smenu_entry_get_caption(e);
    179         PCUT_ASSERT_STR_EQUALS("B", caption);
    180         cmd = smenu_entry_get_cmd(e);
    181         PCUT_ASSERT_STR_EQUALS("b", cmd);
    182 
    183         tbarcfg_close(tbcfg);
    184         remove(fname);
    185 }
    186 
    187 /** Create start menu entry */
    188 PCUT_TEST(entry_create)
    189 {
    190         errno_t rc;
    191         tbarcfg_t *tbcfg;
    192         char fname[L_tmpnam], *p;
    193         smenu_entry_t *e;
    194         const char *caption;
    195         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);
     206        rc = smenu_entry_create(tbcfg, "A", "a", &e);
     207        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    207208        PCUT_ASSERT_NOT_NULL(e);
    208209
     
    222223        tbarcfg_t *tbcfg;
    223224        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);
     225        smenu_entry_t *e, *f;
     226
     227        p = tmpnam(fname);
     228        PCUT_ASSERT_NOT_NULL(p);
     229
     230        rc = tbarcfg_create(fname, &tbcfg);
     231        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     232
     233        rc = smenu_entry_create(tbcfg, "A", "a", &e);
     234        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     235
     236        f = tbarcfg_smenu_first(tbcfg);
     237        PCUT_ASSERT_EQUALS(e, f);
    237238
    238239        rc = smenu_entry_destroy(e);
    239240        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    240241
    241         e = tbarcfg_smenu_first(tbcfg);
    242         PCUT_ASSERT_NULL(e);
     242        f = tbarcfg_smenu_first(tbcfg);
     243        PCUT_ASSERT_NULL(f);
    243244
    244245        tbarcfg_close(tbcfg);
Note: See TracChangeset for help on using the changeset viewer.