Changeset 28ca31ed in mainline for uspace/lib/tbarcfg/test/tbarcfg.c
- Timestamp:
- 2024-02-13T20:13:48Z (9 months ago)
- Branches:
- master
- Children:
- 10657856
- Parents:
- 242e3c3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/tbarcfg/test/tbarcfg.c
r242e3c3 r28ca31ed 101 101 } 102 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 103 137 /** Getting menu entry properties */ 104 138 PCUT_TEST(get_caption_cmd_term) … … 274 308 } 275 309 310 /** Move start menu entry up */ 311 PCUT_TEST(entry_move_up) 312 { 313 errno_t rc; 314 tbarcfg_t *tbcfg; 315 char fname[L_tmpnam], *p; 316 smenu_entry_t *e1, *e2, *e3; 317 smenu_entry_t *f; 318 const char *caption; 319 const char *cmd; 320 321 p = tmpnam(fname); 322 PCUT_ASSERT_NOT_NULL(p); 323 324 rc = tbarcfg_create(fname, &tbcfg); 325 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 326 327 rc = smenu_entry_create(tbcfg, "A", "a", false, &e1); 328 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 329 330 rc = smenu_entry_create(tbcfg, "B", "b", false, &e2); 331 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 332 333 rc = smenu_entry_create(tbcfg, "C", "c", false, &e3); 334 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 335 336 f = tbarcfg_smenu_first(tbcfg); 337 PCUT_ASSERT_EQUALS(e1, f); 338 339 /* Moving the first entry up should have no effect */ 340 341 rc = smenu_entry_move_up(e1); 342 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 343 344 f = tbarcfg_smenu_first(tbcfg); 345 PCUT_ASSERT_EQUALS(e1, f); 346 347 /* Moving the second entry up should move it to first position */ 348 349 rc = smenu_entry_move_up(e2); 350 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 351 352 f = tbarcfg_smenu_first(tbcfg); 353 PCUT_ASSERT_EQUALS(e2, f); 354 355 /* Moving the last entry up should move it to second position */ 356 357 rc = smenu_entry_move_up(e3); 358 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 359 360 f = tbarcfg_smenu_first(tbcfg); 361 PCUT_ASSERT_EQUALS(e2, f); 362 363 f = tbarcfg_smenu_next(f); 364 PCUT_ASSERT_EQUALS(e3, f); 365 366 f = tbarcfg_smenu_next(f); 367 PCUT_ASSERT_EQUALS(e1, f); 368 369 tbarcfg_close(tbcfg); 370 371 /* Re-open repository */ 372 373 rc = tbarcfg_open(fname, &tbcfg); 374 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 375 376 /* Check that new order of entries persisted */ 377 378 f = tbarcfg_smenu_first(tbcfg); 379 PCUT_ASSERT_NOT_NULL(f); 380 381 caption = smenu_entry_get_caption(f); 382 PCUT_ASSERT_STR_EQUALS("B", caption); 383 cmd = smenu_entry_get_cmd(f); 384 PCUT_ASSERT_STR_EQUALS("b", cmd); 385 386 f = tbarcfg_smenu_next(f); 387 PCUT_ASSERT_NOT_NULL(f); 388 389 caption = smenu_entry_get_caption(f); 390 PCUT_ASSERT_STR_EQUALS("C", caption); 391 cmd = smenu_entry_get_cmd(f); 392 PCUT_ASSERT_STR_EQUALS("c", cmd); 393 394 f = tbarcfg_smenu_next(f); 395 PCUT_ASSERT_NOT_NULL(f); 396 397 caption = smenu_entry_get_caption(f); 398 PCUT_ASSERT_STR_EQUALS("A", caption); 399 cmd = smenu_entry_get_cmd(f); 400 PCUT_ASSERT_STR_EQUALS("a", cmd); 401 402 tbarcfg_close(tbcfg); 403 remove(fname); 404 } 405 406 /** Move start menu entry down */ 407 PCUT_TEST(entry_move_down) 408 { 409 errno_t rc; 410 tbarcfg_t *tbcfg; 411 char fname[L_tmpnam], *p; 412 smenu_entry_t *e1, *e2, *e3; 413 smenu_entry_t *f; 414 const char *caption; 415 const char *cmd; 416 417 p = tmpnam(fname); 418 PCUT_ASSERT_NOT_NULL(p); 419 420 rc = tbarcfg_create(fname, &tbcfg); 421 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 422 423 rc = smenu_entry_create(tbcfg, "A", "a", false, &e1); 424 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 425 426 rc = smenu_entry_create(tbcfg, "B", "b", false, &e2); 427 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 428 429 rc = smenu_entry_create(tbcfg, "C", "c", false, &e3); 430 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 431 432 f = tbarcfg_smenu_last(tbcfg); 433 PCUT_ASSERT_EQUALS(e3, f); 434 435 /* Moving the last entry down should have no effect */ 436 437 rc = smenu_entry_move_down(e3); 438 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 439 440 f = tbarcfg_smenu_last(tbcfg); 441 PCUT_ASSERT_EQUALS(e3, f); 442 443 /* Moving the second entry down should move it to last position */ 444 445 rc = smenu_entry_move_down(e2); 446 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 447 448 f = tbarcfg_smenu_last(tbcfg); 449 PCUT_ASSERT_EQUALS(e2, f); 450 451 /* Moving the first entry down should move it to second position */ 452 453 rc = smenu_entry_move_down(e1); 454 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 455 456 f = tbarcfg_smenu_last(tbcfg); 457 PCUT_ASSERT_EQUALS(e2, f); 458 459 f = tbarcfg_smenu_prev(f); 460 PCUT_ASSERT_EQUALS(e1, f); 461 462 f = tbarcfg_smenu_prev(f); 463 PCUT_ASSERT_EQUALS(e3, f); 464 465 tbarcfg_close(tbcfg); 466 467 /* Re-open repository */ 468 469 rc = tbarcfg_open(fname, &tbcfg); 470 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 471 472 /* Check that new order of entries persisted */ 473 474 f = tbarcfg_smenu_first(tbcfg); 475 PCUT_ASSERT_NOT_NULL(f); 476 477 caption = smenu_entry_get_caption(f); 478 PCUT_ASSERT_STR_EQUALS("C", caption); 479 cmd = smenu_entry_get_cmd(f); 480 PCUT_ASSERT_STR_EQUALS("c", cmd); 481 482 f = tbarcfg_smenu_next(f); 483 PCUT_ASSERT_NOT_NULL(f); 484 485 caption = smenu_entry_get_caption(f); 486 PCUT_ASSERT_STR_EQUALS("A", caption); 487 cmd = smenu_entry_get_cmd(f); 488 PCUT_ASSERT_STR_EQUALS("a", cmd); 489 490 f = tbarcfg_smenu_next(f); 491 PCUT_ASSERT_NOT_NULL(f); 492 493 caption = smenu_entry_get_caption(f); 494 PCUT_ASSERT_STR_EQUALS("B", caption); 495 cmd = smenu_entry_get_cmd(f); 496 PCUT_ASSERT_STR_EQUALS("b", cmd); 497 498 tbarcfg_close(tbcfg); 499 remove(fname); 500 } 501 276 502 PCUT_EXPORT(tbarcfg);
Note:
See TracChangeset
for help on using the changeset viewer.