[7d78e466] | 1 | /*
|
---|
[806d761] | 2 | * Copyright (c) 2024 Jiri Svoboda
|
---|
[7d78e466] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | #include <errno.h>
|
---|
| 30 | #include <pcut/pcut.h>
|
---|
[b279899] | 31 | #include <tbarcfg/tbarcfg.h>
|
---|
[ee3b28a9] | 32 | #include <stdbool.h>
|
---|
[7d78e466] | 33 | #include <stdio.h>
|
---|
| 34 |
|
---|
| 35 | PCUT_INIT;
|
---|
| 36 |
|
---|
[b279899] | 37 | PCUT_TEST_SUITE(tbarcfg);
|
---|
[7d78e466] | 38 |
|
---|
[ee3b28a9] | 39 | typedef struct {
|
---|
| 40 | bool notified;
|
---|
| 41 | } tbarcfg_test_resp_t;
|
---|
| 42 |
|
---|
| 43 | static void test_cb(void *);
|
---|
| 44 |
|
---|
[84d29a2] | 45 | /** Creating, opening and closing taskbar configuration */
|
---|
| 46 | PCUT_TEST(create_open_close)
|
---|
[7d78e466] | 47 | {
|
---|
| 48 | errno_t rc;
|
---|
[b279899] | 49 | tbarcfg_t *tbcfg;
|
---|
[84d29a2] | 50 | char fname[L_tmpnam], *p;
|
---|
[7d78e466] | 51 |
|
---|
[84d29a2] | 52 | p = tmpnam(fname);
|
---|
| 53 | PCUT_ASSERT_NOT_NULL(p);
|
---|
[7d78e466] | 54 |
|
---|
[84d29a2] | 55 | /* Create new repository */
|
---|
| 56 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
| 57 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 58 |
|
---|
[bff8619] | 59 | tbarcfg_sync(tbcfg);
|
---|
[84d29a2] | 60 | tbarcfg_close(tbcfg);
|
---|
[7d78e466] | 61 |
|
---|
[84d29a2] | 62 | /* Re-open the repository */
|
---|
[7d78e466] | 63 |
|
---|
[84d29a2] | 64 | rc = tbarcfg_open(fname, &tbcfg);
|
---|
[7d78e466] | 65 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 66 |
|
---|
[b279899] | 67 | tbarcfg_close(tbcfg);
|
---|
[84d29a2] | 68 | remove(fname);
|
---|
[7d78e466] | 69 | }
|
---|
| 70 |
|
---|
| 71 | /** Iterating over start menu entries */
|
---|
| 72 | PCUT_TEST(first_next)
|
---|
| 73 | {
|
---|
| 74 | errno_t rc;
|
---|
[b279899] | 75 | tbarcfg_t *tbcfg;
|
---|
[84d29a2] | 76 | char fname[L_tmpnam], *p;
|
---|
[550ed86] | 77 | smenu_entry_t *e1 = NULL, *e2 = NULL;
|
---|
[b279899] | 78 | smenu_entry_t *e;
|
---|
[7d78e466] | 79 |
|
---|
[84d29a2] | 80 | p = tmpnam(fname);
|
---|
| 81 | PCUT_ASSERT_NOT_NULL(p);
|
---|
[7d78e466] | 82 |
|
---|
[84d29a2] | 83 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
| 84 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
[7d78e466] | 85 |
|
---|
[806d761] | 86 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
|
---|
[84d29a2] | 87 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
[550ed86] | 88 | PCUT_ASSERT_NOT_NULL(e1);
|
---|
[7d78e466] | 89 |
|
---|
[806d761] | 90 | rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
|
---|
[550ed86] | 91 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 92 | PCUT_ASSERT_NOT_NULL(e2);
|
---|
| 93 |
|
---|
| 94 | /* Create entry without getting a pointer to it */
|
---|
[806d761] | 95 | rc = smenu_entry_create(tbcfg, "C", "c", false, NULL);
|
---|
[7d78e466] | 96 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 97 |
|
---|
[b279899] | 98 | e = tbarcfg_smenu_first(tbcfg);
|
---|
[550ed86] | 99 | PCUT_ASSERT_EQUALS(e1, e);
|
---|
| 100 | e = tbarcfg_smenu_next(e);
|
---|
| 101 | PCUT_ASSERT_EQUALS(e2, e);
|
---|
[b279899] | 102 | e = tbarcfg_smenu_next(e);
|
---|
[7d78e466] | 103 | PCUT_ASSERT_NOT_NULL(e);
|
---|
[b279899] | 104 | e = tbarcfg_smenu_next(e);
|
---|
[7d78e466] | 105 | PCUT_ASSERT_NULL(e);
|
---|
| 106 |
|
---|
[b279899] | 107 | tbarcfg_close(tbcfg);
|
---|
[84d29a2] | 108 | remove(fname);
|
---|
[7d78e466] | 109 | }
|
---|
| 110 |
|
---|
[28ca31ed] | 111 | /** Iterating over start menu entries backwards */
|
---|
| 112 | PCUT_TEST(last_prev)
|
---|
| 113 | {
|
---|
| 114 | errno_t rc;
|
---|
| 115 | tbarcfg_t *tbcfg;
|
---|
| 116 | char fname[L_tmpnam], *p;
|
---|
| 117 | smenu_entry_t *e1 = NULL, *e2 = NULL;
|
---|
| 118 | smenu_entry_t *e;
|
---|
| 119 |
|
---|
| 120 | p = tmpnam(fname);
|
---|
| 121 | PCUT_ASSERT_NOT_NULL(p);
|
---|
| 122 |
|
---|
| 123 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
| 124 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 125 |
|
---|
| 126 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
|
---|
| 127 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 128 | PCUT_ASSERT_NOT_NULL(e1);
|
---|
| 129 |
|
---|
| 130 | rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
|
---|
| 131 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 132 | PCUT_ASSERT_NOT_NULL(e2);
|
---|
| 133 |
|
---|
| 134 | e = tbarcfg_smenu_last(tbcfg);
|
---|
| 135 | PCUT_ASSERT_EQUALS(e2, e);
|
---|
| 136 | e = tbarcfg_smenu_prev(e);
|
---|
| 137 | PCUT_ASSERT_EQUALS(e1, e);
|
---|
| 138 | e = tbarcfg_smenu_prev(e);
|
---|
| 139 | PCUT_ASSERT_NULL(e);
|
---|
| 140 |
|
---|
| 141 | tbarcfg_close(tbcfg);
|
---|
| 142 | remove(fname);
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[e63e74a] | 145 | /** Separator entry */
|
---|
| 146 | PCUT_TEST(separator)
|
---|
| 147 | {
|
---|
| 148 | errno_t rc;
|
---|
| 149 | tbarcfg_t *tbcfg;
|
---|
| 150 | char fname[L_tmpnam], *p;
|
---|
| 151 | const char *caption;
|
---|
| 152 | const char *cmd;
|
---|
| 153 | smenu_entry_t *e1 = NULL, *e2 = NULL;
|
---|
| 154 | smenu_entry_t *e;
|
---|
| 155 |
|
---|
| 156 | p = tmpnam(fname);
|
---|
| 157 | PCUT_ASSERT_NOT_NULL(p);
|
---|
| 158 |
|
---|
| 159 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
| 160 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 161 |
|
---|
| 162 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
|
---|
| 163 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 164 | PCUT_ASSERT_NOT_NULL(e1);
|
---|
| 165 |
|
---|
| 166 | rc = smenu_entry_sep_create(tbcfg, &e2);
|
---|
| 167 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 168 | PCUT_ASSERT_NOT_NULL(e2);
|
---|
| 169 |
|
---|
| 170 | PCUT_ASSERT_FALSE(smenu_entry_get_separator(e1));
|
---|
| 171 | PCUT_ASSERT_TRUE(smenu_entry_get_separator(e2));
|
---|
| 172 |
|
---|
[bff8619] | 173 | tbarcfg_sync(tbcfg);
|
---|
[e63e74a] | 174 | tbarcfg_close(tbcfg);
|
---|
| 175 |
|
---|
| 176 | /* Re-open repository */
|
---|
| 177 |
|
---|
| 178 | rc = tbarcfg_open(fname, &tbcfg);
|
---|
| 179 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 180 |
|
---|
| 181 | e = tbarcfg_smenu_first(tbcfg);
|
---|
| 182 | PCUT_ASSERT_NOT_NULL(e);
|
---|
| 183 |
|
---|
| 184 | /* Check that new values of properties have persisted */
|
---|
| 185 | PCUT_ASSERT_FALSE(smenu_entry_get_separator(e));
|
---|
| 186 | caption = smenu_entry_get_caption(e);
|
---|
| 187 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
| 188 | cmd = smenu_entry_get_cmd(e);
|
---|
| 189 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
| 190 |
|
---|
| 191 | e = tbarcfg_smenu_next(e);
|
---|
| 192 |
|
---|
| 193 | /* Check that entry is still a separator */
|
---|
| 194 | PCUT_ASSERT_TRUE(smenu_entry_get_separator(e));
|
---|
| 195 |
|
---|
| 196 | tbarcfg_close(tbcfg);
|
---|
| 197 | remove(fname);
|
---|
| 198 | }
|
---|
| 199 |
|
---|
[7d78e466] | 200 | /** Getting menu entry properties */
|
---|
[806d761] | 201 | PCUT_TEST(get_caption_cmd_term)
|
---|
[7d78e466] | 202 | {
|
---|
| 203 | errno_t rc;
|
---|
[b279899] | 204 | tbarcfg_t *tbcfg;
|
---|
[84d29a2] | 205 | char fname[L_tmpnam], *p;
|
---|
[b279899] | 206 | smenu_entry_t *e;
|
---|
[7d78e466] | 207 | const char *caption;
|
---|
| 208 | const char *cmd;
|
---|
[806d761] | 209 | bool terminal;
|
---|
[7d78e466] | 210 |
|
---|
[84d29a2] | 211 | p = tmpnam(fname);
|
---|
| 212 | PCUT_ASSERT_NOT_NULL(p);
|
---|
| 213 |
|
---|
| 214 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
| 215 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 216 |
|
---|
[806d761] | 217 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
|
---|
[84d29a2] | 218 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 219 |
|
---|
| 220 | caption = smenu_entry_get_caption(e);
|
---|
| 221 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
| 222 | cmd = smenu_entry_get_cmd(e);
|
---|
| 223 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
[806d761] | 224 | terminal = smenu_entry_get_terminal(e);
|
---|
| 225 | PCUT_ASSERT_FALSE(terminal);
|
---|
[84d29a2] | 226 |
|
---|
| 227 | tbarcfg_close(tbcfg);
|
---|
| 228 | remove(fname);
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | /** Setting menu entry properties */
|
---|
[806d761] | 232 | PCUT_TEST(set_caption_cmd_term)
|
---|
[84d29a2] | 233 | {
|
---|
| 234 | errno_t rc;
|
---|
| 235 | tbarcfg_t *tbcfg;
|
---|
| 236 | char fname[L_tmpnam], *p;
|
---|
| 237 | smenu_entry_t *e;
|
---|
| 238 | const char *caption;
|
---|
| 239 | const char *cmd;
|
---|
[806d761] | 240 | bool terminal;
|
---|
[84d29a2] | 241 |
|
---|
| 242 | p = tmpnam(fname);
|
---|
| 243 | PCUT_ASSERT_NOT_NULL(p);
|
---|
| 244 |
|
---|
| 245 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
| 246 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 247 |
|
---|
[806d761] | 248 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
|
---|
[84d29a2] | 249 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 250 |
|
---|
| 251 | caption = smenu_entry_get_caption(e);
|
---|
| 252 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
| 253 | cmd = smenu_entry_get_cmd(e);
|
---|
| 254 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
[806d761] | 255 | terminal = smenu_entry_get_terminal(e);
|
---|
| 256 | PCUT_ASSERT_FALSE(terminal);
|
---|
[84d29a2] | 257 |
|
---|
| 258 | /* Set properties */
|
---|
| 259 | rc = smenu_entry_set_caption(e, "B");
|
---|
| 260 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 261 | rc = smenu_entry_set_cmd(e, "b");
|
---|
| 262 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
[806d761] | 263 | smenu_entry_set_terminal(e, true);
|
---|
[84d29a2] | 264 |
|
---|
[bff8619] | 265 | rc = tbarcfg_sync(tbcfg);
|
---|
[84d29a2] | 266 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
[7d78e466] | 267 |
|
---|
[84d29a2] | 268 | /* Check that properties have been set */
|
---|
| 269 | caption = smenu_entry_get_caption(e);
|
---|
| 270 | PCUT_ASSERT_STR_EQUALS("B", caption);
|
---|
| 271 | cmd = smenu_entry_get_cmd(e);
|
---|
| 272 | PCUT_ASSERT_STR_EQUALS("b", cmd);
|
---|
[806d761] | 273 | terminal = smenu_entry_get_terminal(e);
|
---|
| 274 | PCUT_ASSERT_TRUE(terminal);
|
---|
[84d29a2] | 275 |
|
---|
[bff8619] | 276 | tbarcfg_sync(tbcfg);
|
---|
[84d29a2] | 277 | tbarcfg_close(tbcfg);
|
---|
[7d78e466] | 278 |
|
---|
[84d29a2] | 279 | /* Re-open repository */
|
---|
| 280 |
|
---|
| 281 | rc = tbarcfg_open(fname, &tbcfg);
|
---|
| 282 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 283 |
|
---|
| 284 | e = tbarcfg_smenu_first(tbcfg);
|
---|
| 285 | PCUT_ASSERT_NOT_NULL(e);
|
---|
| 286 |
|
---|
| 287 | /* Check that new values of properties have persisted */
|
---|
| 288 | caption = smenu_entry_get_caption(e);
|
---|
| 289 | PCUT_ASSERT_STR_EQUALS("B", caption);
|
---|
| 290 | cmd = smenu_entry_get_cmd(e);
|
---|
| 291 | PCUT_ASSERT_STR_EQUALS("b", cmd);
|
---|
| 292 |
|
---|
| 293 | tbarcfg_close(tbcfg);
|
---|
| 294 | remove(fname);
|
---|
| 295 | }
|
---|
| 296 |
|
---|
| 297 | /** Create start menu entry */
|
---|
| 298 | PCUT_TEST(entry_create)
|
---|
| 299 | {
|
---|
| 300 | errno_t rc;
|
---|
| 301 | tbarcfg_t *tbcfg;
|
---|
| 302 | char fname[L_tmpnam], *p;
|
---|
| 303 | smenu_entry_t *e;
|
---|
| 304 | const char *caption;
|
---|
| 305 | const char *cmd;
|
---|
[806d761] | 306 | bool terminal;
|
---|
[84d29a2] | 307 |
|
---|
| 308 | p = tmpnam(fname);
|
---|
| 309 | PCUT_ASSERT_NOT_NULL(p);
|
---|
| 310 |
|
---|
| 311 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
| 312 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
[7d78e466] | 313 |
|
---|
[806d761] | 314 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
|
---|
[7d78e466] | 315 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 316 | PCUT_ASSERT_NOT_NULL(e);
|
---|
| 317 |
|
---|
[b279899] | 318 | caption = smenu_entry_get_caption(e);
|
---|
[7d78e466] | 319 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
[b279899] | 320 | cmd = smenu_entry_get_cmd(e);
|
---|
[7d78e466] | 321 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
[806d761] | 322 | terminal = smenu_entry_get_terminal(e);
|
---|
| 323 | PCUT_ASSERT_FALSE(terminal);
|
---|
| 324 |
|
---|
| 325 | smenu_entry_destroy(e);
|
---|
| 326 |
|
---|
| 327 | rc = smenu_entry_create(tbcfg, "B", "b", true, &e);
|
---|
| 328 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 329 | PCUT_ASSERT_NOT_NULL(e);
|
---|
| 330 |
|
---|
| 331 | caption = smenu_entry_get_caption(e);
|
---|
| 332 | PCUT_ASSERT_STR_EQUALS("B", caption);
|
---|
| 333 | cmd = smenu_entry_get_cmd(e);
|
---|
| 334 | PCUT_ASSERT_STR_EQUALS("b", cmd);
|
---|
| 335 | terminal = smenu_entry_get_terminal(e);
|
---|
| 336 | PCUT_ASSERT_TRUE(terminal);
|
---|
| 337 |
|
---|
| 338 | smenu_entry_destroy(e);
|
---|
[7d78e466] | 339 |
|
---|
[b279899] | 340 | tbarcfg_close(tbcfg);
|
---|
[84d29a2] | 341 | remove(fname);
|
---|
[7d78e466] | 342 | }
|
---|
| 343 |
|
---|
[2b4e02b] | 344 | /** Destroy start menu entry */
|
---|
| 345 | PCUT_TEST(entry_destroy)
|
---|
| 346 | {
|
---|
| 347 | errno_t rc;
|
---|
| 348 | tbarcfg_t *tbcfg;
|
---|
| 349 | char fname[L_tmpnam], *p;
|
---|
[550ed86] | 350 | smenu_entry_t *e, *f;
|
---|
[2b4e02b] | 351 |
|
---|
| 352 | p = tmpnam(fname);
|
---|
| 353 | PCUT_ASSERT_NOT_NULL(p);
|
---|
| 354 |
|
---|
| 355 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
| 356 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 357 |
|
---|
[806d761] | 358 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
|
---|
[2b4e02b] | 359 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 360 |
|
---|
[550ed86] | 361 | f = tbarcfg_smenu_first(tbcfg);
|
---|
| 362 | PCUT_ASSERT_EQUALS(e, f);
|
---|
[2b4e02b] | 363 |
|
---|
[bff8619] | 364 | smenu_entry_destroy(e);
|
---|
[2b4e02b] | 365 |
|
---|
[550ed86] | 366 | f = tbarcfg_smenu_first(tbcfg);
|
---|
| 367 | PCUT_ASSERT_NULL(f);
|
---|
[2b4e02b] | 368 |
|
---|
| 369 | tbarcfg_close(tbcfg);
|
---|
| 370 | remove(fname);
|
---|
| 371 | }
|
---|
| 372 |
|
---|
[28ca31ed] | 373 | /** Move start menu entry up */
|
---|
| 374 | PCUT_TEST(entry_move_up)
|
---|
| 375 | {
|
---|
| 376 | errno_t rc;
|
---|
| 377 | tbarcfg_t *tbcfg;
|
---|
| 378 | char fname[L_tmpnam], *p;
|
---|
| 379 | smenu_entry_t *e1, *e2, *e3;
|
---|
| 380 | smenu_entry_t *f;
|
---|
| 381 | const char *caption;
|
---|
| 382 | const char *cmd;
|
---|
| 383 |
|
---|
| 384 | p = tmpnam(fname);
|
---|
| 385 | PCUT_ASSERT_NOT_NULL(p);
|
---|
| 386 |
|
---|
| 387 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
| 388 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 389 |
|
---|
| 390 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
|
---|
| 391 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 392 |
|
---|
| 393 | rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
|
---|
| 394 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 395 |
|
---|
| 396 | rc = smenu_entry_create(tbcfg, "C", "c", false, &e3);
|
---|
| 397 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 398 |
|
---|
| 399 | f = tbarcfg_smenu_first(tbcfg);
|
---|
| 400 | PCUT_ASSERT_EQUALS(e1, f);
|
---|
| 401 |
|
---|
| 402 | /* Moving the first entry up should have no effect */
|
---|
| 403 |
|
---|
[bff8619] | 404 | smenu_entry_move_up(e1);
|
---|
[28ca31ed] | 405 |
|
---|
| 406 | f = tbarcfg_smenu_first(tbcfg);
|
---|
| 407 | PCUT_ASSERT_EQUALS(e1, f);
|
---|
| 408 |
|
---|
| 409 | /* Moving the second entry up should move it to first position */
|
---|
| 410 |
|
---|
[bff8619] | 411 | smenu_entry_move_up(e2);
|
---|
[28ca31ed] | 412 |
|
---|
| 413 | f = tbarcfg_smenu_first(tbcfg);
|
---|
| 414 | PCUT_ASSERT_EQUALS(e2, f);
|
---|
| 415 |
|
---|
| 416 | /* Moving the last entry up should move it to second position */
|
---|
| 417 |
|
---|
[bff8619] | 418 | smenu_entry_move_up(e3);
|
---|
[28ca31ed] | 419 |
|
---|
| 420 | f = tbarcfg_smenu_first(tbcfg);
|
---|
| 421 | PCUT_ASSERT_EQUALS(e2, f);
|
---|
| 422 |
|
---|
| 423 | f = tbarcfg_smenu_next(f);
|
---|
| 424 | PCUT_ASSERT_EQUALS(e3, f);
|
---|
| 425 |
|
---|
| 426 | f = tbarcfg_smenu_next(f);
|
---|
| 427 | PCUT_ASSERT_EQUALS(e1, f);
|
---|
| 428 |
|
---|
[bff8619] | 429 | tbarcfg_sync(tbcfg);
|
---|
[28ca31ed] | 430 | tbarcfg_close(tbcfg);
|
---|
| 431 |
|
---|
| 432 | /* Re-open repository */
|
---|
| 433 |
|
---|
| 434 | rc = tbarcfg_open(fname, &tbcfg);
|
---|
| 435 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 436 |
|
---|
| 437 | /* Check that new order of entries persisted */
|
---|
| 438 |
|
---|
| 439 | f = tbarcfg_smenu_first(tbcfg);
|
---|
| 440 | PCUT_ASSERT_NOT_NULL(f);
|
---|
| 441 |
|
---|
| 442 | caption = smenu_entry_get_caption(f);
|
---|
| 443 | PCUT_ASSERT_STR_EQUALS("B", caption);
|
---|
| 444 | cmd = smenu_entry_get_cmd(f);
|
---|
| 445 | PCUT_ASSERT_STR_EQUALS("b", cmd);
|
---|
| 446 |
|
---|
| 447 | f = tbarcfg_smenu_next(f);
|
---|
| 448 | PCUT_ASSERT_NOT_NULL(f);
|
---|
| 449 |
|
---|
| 450 | caption = smenu_entry_get_caption(f);
|
---|
| 451 | PCUT_ASSERT_STR_EQUALS("C", caption);
|
---|
| 452 | cmd = smenu_entry_get_cmd(f);
|
---|
| 453 | PCUT_ASSERT_STR_EQUALS("c", cmd);
|
---|
| 454 |
|
---|
| 455 | f = tbarcfg_smenu_next(f);
|
---|
| 456 | PCUT_ASSERT_NOT_NULL(f);
|
---|
| 457 |
|
---|
| 458 | caption = smenu_entry_get_caption(f);
|
---|
| 459 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
| 460 | cmd = smenu_entry_get_cmd(f);
|
---|
| 461 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
| 462 |
|
---|
| 463 | tbarcfg_close(tbcfg);
|
---|
| 464 | remove(fname);
|
---|
| 465 | }
|
---|
| 466 |
|
---|
| 467 | /** Move start menu entry down */
|
---|
| 468 | PCUT_TEST(entry_move_down)
|
---|
| 469 | {
|
---|
| 470 | errno_t rc;
|
---|
| 471 | tbarcfg_t *tbcfg;
|
---|
| 472 | char fname[L_tmpnam], *p;
|
---|
| 473 | smenu_entry_t *e1, *e2, *e3;
|
---|
| 474 | smenu_entry_t *f;
|
---|
| 475 | const char *caption;
|
---|
| 476 | const char *cmd;
|
---|
| 477 |
|
---|
| 478 | p = tmpnam(fname);
|
---|
| 479 | PCUT_ASSERT_NOT_NULL(p);
|
---|
| 480 |
|
---|
| 481 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
| 482 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 483 |
|
---|
| 484 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
|
---|
| 485 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 486 |
|
---|
| 487 | rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
|
---|
| 488 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 489 |
|
---|
| 490 | rc = smenu_entry_create(tbcfg, "C", "c", false, &e3);
|
---|
| 491 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 492 |
|
---|
| 493 | f = tbarcfg_smenu_last(tbcfg);
|
---|
| 494 | PCUT_ASSERT_EQUALS(e3, f);
|
---|
| 495 |
|
---|
| 496 | /* Moving the last entry down should have no effect */
|
---|
| 497 |
|
---|
[bff8619] | 498 | smenu_entry_move_down(e3);
|
---|
[28ca31ed] | 499 |
|
---|
| 500 | f = tbarcfg_smenu_last(tbcfg);
|
---|
| 501 | PCUT_ASSERT_EQUALS(e3, f);
|
---|
| 502 |
|
---|
| 503 | /* Moving the second entry down should move it to last position */
|
---|
| 504 |
|
---|
[bff8619] | 505 | smenu_entry_move_down(e2);
|
---|
[28ca31ed] | 506 |
|
---|
| 507 | f = tbarcfg_smenu_last(tbcfg);
|
---|
| 508 | PCUT_ASSERT_EQUALS(e2, f);
|
---|
| 509 |
|
---|
| 510 | /* Moving the first entry down should move it to second position */
|
---|
| 511 |
|
---|
[bff8619] | 512 | smenu_entry_move_down(e1);
|
---|
[28ca31ed] | 513 |
|
---|
| 514 | f = tbarcfg_smenu_last(tbcfg);
|
---|
| 515 | PCUT_ASSERT_EQUALS(e2, f);
|
---|
| 516 |
|
---|
| 517 | f = tbarcfg_smenu_prev(f);
|
---|
| 518 | PCUT_ASSERT_EQUALS(e1, f);
|
---|
| 519 |
|
---|
| 520 | f = tbarcfg_smenu_prev(f);
|
---|
| 521 | PCUT_ASSERT_EQUALS(e3, f);
|
---|
| 522 |
|
---|
[bff8619] | 523 | tbarcfg_sync(tbcfg);
|
---|
[28ca31ed] | 524 | tbarcfg_close(tbcfg);
|
---|
| 525 |
|
---|
| 526 | /* Re-open repository */
|
---|
| 527 |
|
---|
| 528 | rc = tbarcfg_open(fname, &tbcfg);
|
---|
| 529 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 530 |
|
---|
| 531 | /* Check that new order of entries persisted */
|
---|
| 532 |
|
---|
| 533 | f = tbarcfg_smenu_first(tbcfg);
|
---|
| 534 | PCUT_ASSERT_NOT_NULL(f);
|
---|
| 535 |
|
---|
| 536 | caption = smenu_entry_get_caption(f);
|
---|
| 537 | PCUT_ASSERT_STR_EQUALS("C", caption);
|
---|
| 538 | cmd = smenu_entry_get_cmd(f);
|
---|
| 539 | PCUT_ASSERT_STR_EQUALS("c", cmd);
|
---|
| 540 |
|
---|
| 541 | f = tbarcfg_smenu_next(f);
|
---|
| 542 | PCUT_ASSERT_NOT_NULL(f);
|
---|
| 543 |
|
---|
| 544 | caption = smenu_entry_get_caption(f);
|
---|
| 545 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
| 546 | cmd = smenu_entry_get_cmd(f);
|
---|
| 547 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
| 548 |
|
---|
| 549 | f = tbarcfg_smenu_next(f);
|
---|
| 550 | PCUT_ASSERT_NOT_NULL(f);
|
---|
| 551 |
|
---|
| 552 | caption = smenu_entry_get_caption(f);
|
---|
| 553 | PCUT_ASSERT_STR_EQUALS("B", caption);
|
---|
| 554 | cmd = smenu_entry_get_cmd(f);
|
---|
| 555 | PCUT_ASSERT_STR_EQUALS("b", cmd);
|
---|
| 556 |
|
---|
| 557 | tbarcfg_close(tbcfg);
|
---|
| 558 | remove(fname);
|
---|
| 559 | }
|
---|
| 560 |
|
---|
[ee3b28a9] | 561 | /** Notifications can be delivered from tbarcfg_notify() to a listener. */
|
---|
| 562 | PCUT_TEST(notify)
|
---|
| 563 | {
|
---|
| 564 | errno_t rc;
|
---|
| 565 | tbarcfg_listener_t *lst;
|
---|
| 566 | tbarcfg_test_resp_t test_resp;
|
---|
| 567 |
|
---|
| 568 | test_resp.notified = false;
|
---|
| 569 |
|
---|
| 570 | printf("create listener resp=%p\n", (void *)&test_resp);
|
---|
| 571 | rc = tbarcfg_listener_create(TBARCFG_NOTIFY_DEFAULT,
|
---|
| 572 | test_cb, &test_resp, &lst);
|
---|
| 573 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 574 |
|
---|
| 575 | rc = tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT);
|
---|
| 576 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 577 |
|
---|
| 578 | PCUT_ASSERT_TRUE(test_resp.notified);
|
---|
| 579 | tbarcfg_listener_destroy(lst);
|
---|
| 580 | }
|
---|
| 581 |
|
---|
| 582 | static void test_cb(void *arg)
|
---|
| 583 | {
|
---|
| 584 | tbarcfg_test_resp_t *resp = (tbarcfg_test_resp_t *)arg;
|
---|
| 585 |
|
---|
| 586 | printf("test_cb: executing resp=%p\n", (void *)resp);
|
---|
| 587 | resp->notified = true;
|
---|
| 588 | }
|
---|
| 589 |
|
---|
[b279899] | 590 | PCUT_EXPORT(tbarcfg);
|
---|