Changes in uspace/lib/tbarcfg/test/tbarcfg.c [2b4e02b:e63e74a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/tbarcfg/test/tbarcfg.c
r2b4e02b re63e74a 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 67 67 tbarcfg_t *tbcfg; 68 68 char fname[L_tmpnam], *p; 69 smenu_entry_t *e1 = NULL, *e2 = NULL; 69 70 smenu_entry_t *e; 70 71 … … 75 76 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 76 77 77 rc = smenu_entry_create(tbcfg, "A", "a"); 78 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 79 80 rc = smenu_entry_create(tbcfg, "B", "b"); 78 rc = smenu_entry_create(tbcfg, "A", "a", false, &e1); 79 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 80 PCUT_ASSERT_NOT_NULL(e1); 81 82 rc = smenu_entry_create(tbcfg, "B", "b", false, &e2); 83 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 84 PCUT_ASSERT_NOT_NULL(e2); 85 86 /* Create entry without getting a pointer to it */ 87 rc = smenu_entry_create(tbcfg, "C", "c", false, NULL); 81 88 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 82 89 83 90 e = tbarcfg_smenu_first(tbcfg); 84 PCUT_ASSERT_NOT_NULL(e); 91 PCUT_ASSERT_EQUALS(e1, e); 92 e = tbarcfg_smenu_next(e); 93 PCUT_ASSERT_EQUALS(e2, e); 85 94 e = tbarcfg_smenu_next(e); 86 95 PCUT_ASSERT_NOT_NULL(e); … … 92 101 } 93 102 103 /** Iterating over start menu entries backwards */ 104 PCUT_TEST(last_prev) 105 { 106 errno_t rc; 107 tbarcfg_t *tbcfg; 108 char fname[L_tmpnam], *p; 109 smenu_entry_t *e1 = NULL, *e2 = NULL; 110 smenu_entry_t *e; 111 112 p = tmpnam(fname); 113 PCUT_ASSERT_NOT_NULL(p); 114 115 rc = tbarcfg_create(fname, &tbcfg); 116 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 117 118 rc = smenu_entry_create(tbcfg, "A", "a", false, &e1); 119 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 120 PCUT_ASSERT_NOT_NULL(e1); 121 122 rc = smenu_entry_create(tbcfg, "B", "b", false, &e2); 123 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 124 PCUT_ASSERT_NOT_NULL(e2); 125 126 e = tbarcfg_smenu_last(tbcfg); 127 PCUT_ASSERT_EQUALS(e2, e); 128 e = tbarcfg_smenu_prev(e); 129 PCUT_ASSERT_EQUALS(e1, e); 130 e = tbarcfg_smenu_prev(e); 131 PCUT_ASSERT_NULL(e); 132 133 tbarcfg_close(tbcfg); 134 remove(fname); 135 } 136 137 /** Separator entry */ 138 PCUT_TEST(separator) 139 { 140 errno_t rc; 141 tbarcfg_t *tbcfg; 142 char fname[L_tmpnam], *p; 143 const char *caption; 144 const char *cmd; 145 smenu_entry_t *e1 = NULL, *e2 = NULL; 146 smenu_entry_t *e; 147 148 p = tmpnam(fname); 149 PCUT_ASSERT_NOT_NULL(p); 150 151 rc = tbarcfg_create(fname, &tbcfg); 152 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 153 154 rc = smenu_entry_create(tbcfg, "A", "a", false, &e1); 155 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 156 PCUT_ASSERT_NOT_NULL(e1); 157 158 rc = smenu_entry_sep_create(tbcfg, &e2); 159 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 160 PCUT_ASSERT_NOT_NULL(e2); 161 162 PCUT_ASSERT_FALSE(smenu_entry_get_separator(e1)); 163 PCUT_ASSERT_TRUE(smenu_entry_get_separator(e2)); 164 165 tbarcfg_close(tbcfg); 166 167 /* Re-open repository */ 168 169 rc = tbarcfg_open(fname, &tbcfg); 170 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 171 172 e = tbarcfg_smenu_first(tbcfg); 173 PCUT_ASSERT_NOT_NULL(e); 174 175 /* Check that new values of properties have persisted */ 176 PCUT_ASSERT_FALSE(smenu_entry_get_separator(e)); 177 caption = smenu_entry_get_caption(e); 178 PCUT_ASSERT_STR_EQUALS("A", caption); 179 cmd = smenu_entry_get_cmd(e); 180 PCUT_ASSERT_STR_EQUALS("a", cmd); 181 182 e = tbarcfg_smenu_next(e); 183 184 /* Check that entry is still a separator */ 185 PCUT_ASSERT_TRUE(smenu_entry_get_separator(e)); 186 187 tbarcfg_close(tbcfg); 188 remove(fname); 189 } 190 94 191 /** Getting menu entry properties */ 95 PCUT_TEST(get_caption_cmd )192 PCUT_TEST(get_caption_cmd_term) 96 193 { 97 194 errno_t rc; … … 101 198 const char *caption; 102 199 const char *cmd; 103 104 p = tmpnam(fname); 105 PCUT_ASSERT_NOT_NULL(p); 106 107 rc = tbarcfg_create(fname, &tbcfg); 108 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 109 110 rc = smenu_entry_create(tbcfg, "A", "a"); 111 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 112 113 e = tbarcfg_smenu_first(tbcfg); 114 PCUT_ASSERT_NOT_NULL(e); 200 bool terminal; 201 202 p = tmpnam(fname); 203 PCUT_ASSERT_NOT_NULL(p); 204 205 rc = tbarcfg_create(fname, &tbcfg); 206 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 207 208 rc = smenu_entry_create(tbcfg, "A", "a", false, &e); 209 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 115 210 116 211 caption = smenu_entry_get_caption(e); … … 118 213 cmd = smenu_entry_get_cmd(e); 119 214 PCUT_ASSERT_STR_EQUALS("a", cmd); 215 terminal = smenu_entry_get_terminal(e); 216 PCUT_ASSERT_FALSE(terminal); 120 217 121 218 tbarcfg_close(tbcfg); … … 124 221 125 222 /** Setting menu entry properties */ 126 PCUT_TEST(set_caption_cmd )223 PCUT_TEST(set_caption_cmd_term) 127 224 { 128 225 errno_t rc; … … 132 229 const char *caption; 133 230 const char *cmd; 134 135 p = tmpnam(fname); 136 PCUT_ASSERT_NOT_NULL(p); 137 138 rc = tbarcfg_create(fname, &tbcfg); 139 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 140 141 rc = smenu_entry_create(tbcfg, "A", "a"); 142 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 143 144 e = tbarcfg_smenu_first(tbcfg); 145 PCUT_ASSERT_NOT_NULL(e); 231 bool terminal; 232 233 p = tmpnam(fname); 234 PCUT_ASSERT_NOT_NULL(p); 235 236 rc = tbarcfg_create(fname, &tbcfg); 237 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 238 239 rc = smenu_entry_create(tbcfg, "A", "a", false, &e); 240 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 146 241 147 242 caption = smenu_entry_get_caption(e); … … 149 244 cmd = smenu_entry_get_cmd(e); 150 245 PCUT_ASSERT_STR_EQUALS("a", cmd); 246 terminal = smenu_entry_get_terminal(e); 247 PCUT_ASSERT_FALSE(terminal); 151 248 152 249 /* Set properties */ … … 155 252 rc = smenu_entry_set_cmd(e, "b"); 156 253 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 254 smenu_entry_set_terminal(e, true); 157 255 158 256 rc = smenu_entry_save(e); … … 164 262 cmd = smenu_entry_get_cmd(e); 165 263 PCUT_ASSERT_STR_EQUALS("b", cmd); 264 terminal = smenu_entry_get_terminal(e); 265 PCUT_ASSERT_TRUE(terminal); 166 266 167 267 tbarcfg_close(tbcfg); … … 194 294 const char *caption; 195 295 const char *cmd; 196 197 p = tmpnam(fname); 198 PCUT_ASSERT_NOT_NULL(p); 199 200 rc = tbarcfg_create(fname, &tbcfg); 201 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 202 203 rc = smenu_entry_create(tbcfg, "A", "a"); 204 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 205 206 e = tbarcfg_smenu_first(tbcfg); 296 bool terminal; 297 298 p = tmpnam(fname); 299 PCUT_ASSERT_NOT_NULL(p); 300 301 rc = tbarcfg_create(fname, &tbcfg); 302 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 303 304 rc = smenu_entry_create(tbcfg, "A", "a", false, &e); 305 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 207 306 PCUT_ASSERT_NOT_NULL(e); 208 307 … … 211 310 cmd = smenu_entry_get_cmd(e); 212 311 PCUT_ASSERT_STR_EQUALS("a", cmd); 312 terminal = smenu_entry_get_terminal(e); 313 PCUT_ASSERT_FALSE(terminal); 314 315 smenu_entry_destroy(e); 316 317 rc = smenu_entry_create(tbcfg, "B", "b", true, &e); 318 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 319 PCUT_ASSERT_NOT_NULL(e); 320 321 caption = smenu_entry_get_caption(e); 322 PCUT_ASSERT_STR_EQUALS("B", caption); 323 cmd = smenu_entry_get_cmd(e); 324 PCUT_ASSERT_STR_EQUALS("b", cmd); 325 terminal = smenu_entry_get_terminal(e); 326 PCUT_ASSERT_TRUE(terminal); 327 328 smenu_entry_destroy(e); 213 329 214 330 tbarcfg_close(tbcfg); … … 222 338 tbarcfg_t *tbcfg; 223 339 char fname[L_tmpnam], *p; 224 smenu_entry_t *e ;225 226 p = tmpnam(fname); 227 PCUT_ASSERT_NOT_NULL(p); 228 229 rc = tbarcfg_create(fname, &tbcfg); 230 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 231 232 rc = smenu_entry_create(tbcfg, "A", "a" );233 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 234 235 e= tbarcfg_smenu_first(tbcfg);236 PCUT_ASSERT_ NOT_NULL(e);340 smenu_entry_t *e, *f; 341 342 p = tmpnam(fname); 343 PCUT_ASSERT_NOT_NULL(p); 344 345 rc = tbarcfg_create(fname, &tbcfg); 346 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 347 348 rc = smenu_entry_create(tbcfg, "A", "a", false, &e); 349 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 350 351 f = tbarcfg_smenu_first(tbcfg); 352 PCUT_ASSERT_EQUALS(e, f); 237 353 238 354 rc = smenu_entry_destroy(e); 239 355 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 240 356 241 e = tbarcfg_smenu_first(tbcfg); 242 PCUT_ASSERT_NULL(e); 357 f = tbarcfg_smenu_first(tbcfg); 358 PCUT_ASSERT_NULL(f); 359 360 tbarcfg_close(tbcfg); 361 remove(fname); 362 } 363 364 /** Move start menu entry up */ 365 PCUT_TEST(entry_move_up) 366 { 367 errno_t rc; 368 tbarcfg_t *tbcfg; 369 char fname[L_tmpnam], *p; 370 smenu_entry_t *e1, *e2, *e3; 371 smenu_entry_t *f; 372 const char *caption; 373 const char *cmd; 374 375 p = tmpnam(fname); 376 PCUT_ASSERT_NOT_NULL(p); 377 378 rc = tbarcfg_create(fname, &tbcfg); 379 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 380 381 rc = smenu_entry_create(tbcfg, "A", "a", false, &e1); 382 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 383 384 rc = smenu_entry_create(tbcfg, "B", "b", false, &e2); 385 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 386 387 rc = smenu_entry_create(tbcfg, "C", "c", false, &e3); 388 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 389 390 f = tbarcfg_smenu_first(tbcfg); 391 PCUT_ASSERT_EQUALS(e1, f); 392 393 /* Moving the first entry up should have no effect */ 394 395 rc = smenu_entry_move_up(e1); 396 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 397 398 f = tbarcfg_smenu_first(tbcfg); 399 PCUT_ASSERT_EQUALS(e1, f); 400 401 /* Moving the second entry up should move it to first position */ 402 403 rc = smenu_entry_move_up(e2); 404 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 405 406 f = tbarcfg_smenu_first(tbcfg); 407 PCUT_ASSERT_EQUALS(e2, f); 408 409 /* Moving the last entry up should move it to second position */ 410 411 rc = smenu_entry_move_up(e3); 412 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 413 414 f = tbarcfg_smenu_first(tbcfg); 415 PCUT_ASSERT_EQUALS(e2, f); 416 417 f = tbarcfg_smenu_next(f); 418 PCUT_ASSERT_EQUALS(e3, f); 419 420 f = tbarcfg_smenu_next(f); 421 PCUT_ASSERT_EQUALS(e1, f); 422 423 tbarcfg_close(tbcfg); 424 425 /* Re-open repository */ 426 427 rc = tbarcfg_open(fname, &tbcfg); 428 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 429 430 /* Check that new order of entries persisted */ 431 432 f = tbarcfg_smenu_first(tbcfg); 433 PCUT_ASSERT_NOT_NULL(f); 434 435 caption = smenu_entry_get_caption(f); 436 PCUT_ASSERT_STR_EQUALS("B", caption); 437 cmd = smenu_entry_get_cmd(f); 438 PCUT_ASSERT_STR_EQUALS("b", cmd); 439 440 f = tbarcfg_smenu_next(f); 441 PCUT_ASSERT_NOT_NULL(f); 442 443 caption = smenu_entry_get_caption(f); 444 PCUT_ASSERT_STR_EQUALS("C", caption); 445 cmd = smenu_entry_get_cmd(f); 446 PCUT_ASSERT_STR_EQUALS("c", cmd); 447 448 f = tbarcfg_smenu_next(f); 449 PCUT_ASSERT_NOT_NULL(f); 450 451 caption = smenu_entry_get_caption(f); 452 PCUT_ASSERT_STR_EQUALS("A", caption); 453 cmd = smenu_entry_get_cmd(f); 454 PCUT_ASSERT_STR_EQUALS("a", cmd); 455 456 tbarcfg_close(tbcfg); 457 remove(fname); 458 } 459 460 /** Move start menu entry down */ 461 PCUT_TEST(entry_move_down) 462 { 463 errno_t rc; 464 tbarcfg_t *tbcfg; 465 char fname[L_tmpnam], *p; 466 smenu_entry_t *e1, *e2, *e3; 467 smenu_entry_t *f; 468 const char *caption; 469 const char *cmd; 470 471 p = tmpnam(fname); 472 PCUT_ASSERT_NOT_NULL(p); 473 474 rc = tbarcfg_create(fname, &tbcfg); 475 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 476 477 rc = smenu_entry_create(tbcfg, "A", "a", false, &e1); 478 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 479 480 rc = smenu_entry_create(tbcfg, "B", "b", false, &e2); 481 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 482 483 rc = smenu_entry_create(tbcfg, "C", "c", false, &e3); 484 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 485 486 f = tbarcfg_smenu_last(tbcfg); 487 PCUT_ASSERT_EQUALS(e3, f); 488 489 /* Moving the last entry down should have no effect */ 490 491 rc = smenu_entry_move_down(e3); 492 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 493 494 f = tbarcfg_smenu_last(tbcfg); 495 PCUT_ASSERT_EQUALS(e3, f); 496 497 /* Moving the second entry down should move it to last position */ 498 499 rc = smenu_entry_move_down(e2); 500 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 501 502 f = tbarcfg_smenu_last(tbcfg); 503 PCUT_ASSERT_EQUALS(e2, f); 504 505 /* Moving the first entry down should move it to second position */ 506 507 rc = smenu_entry_move_down(e1); 508 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 509 510 f = tbarcfg_smenu_last(tbcfg); 511 PCUT_ASSERT_EQUALS(e2, f); 512 513 f = tbarcfg_smenu_prev(f); 514 PCUT_ASSERT_EQUALS(e1, f); 515 516 f = tbarcfg_smenu_prev(f); 517 PCUT_ASSERT_EQUALS(e3, f); 518 519 tbarcfg_close(tbcfg); 520 521 /* Re-open repository */ 522 523 rc = tbarcfg_open(fname, &tbcfg); 524 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 525 526 /* Check that new order of entries persisted */ 527 528 f = tbarcfg_smenu_first(tbcfg); 529 PCUT_ASSERT_NOT_NULL(f); 530 531 caption = smenu_entry_get_caption(f); 532 PCUT_ASSERT_STR_EQUALS("C", caption); 533 cmd = smenu_entry_get_cmd(f); 534 PCUT_ASSERT_STR_EQUALS("c", cmd); 535 536 f = tbarcfg_smenu_next(f); 537 PCUT_ASSERT_NOT_NULL(f); 538 539 caption = smenu_entry_get_caption(f); 540 PCUT_ASSERT_STR_EQUALS("A", caption); 541 cmd = smenu_entry_get_cmd(f); 542 PCUT_ASSERT_STR_EQUALS("a", cmd); 543 544 f = tbarcfg_smenu_next(f); 545 PCUT_ASSERT_NOT_NULL(f); 546 547 caption = smenu_entry_get_caption(f); 548 PCUT_ASSERT_STR_EQUALS("B", caption); 549 cmd = smenu_entry_get_cmd(f); 550 PCUT_ASSERT_STR_EQUALS("b", cmd); 243 551 244 552 tbarcfg_close(tbcfg);
Note:
See TracChangeset
for help on using the changeset viewer.