Changes in uspace/lib/tbarcfg/test/tbarcfg.c [e63e74a:2b4e02b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/tbarcfg/test/tbarcfg.c
re63e74a r2b4e02b 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2023 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; 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", 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); 88 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 89 90 e = tbarcfg_smenu_first(tbcfg); 91 PCUT_ASSERT_EQUALS(e1, e); 92 e = tbarcfg_smenu_next(e); 93 PCUT_ASSERT_EQUALS(e2, e); 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"); 81 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 82 83 e = tbarcfg_smenu_first(tbcfg); 84 PCUT_ASSERT_NOT_NULL(e); 94 85 e = tbarcfg_smenu_next(e); 95 86 PCUT_ASSERT_NOT_NULL(e); … … 101 92 } 102 93 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; 94 /** Getting menu entry properties */ 95 PCUT_TEST(get_caption_cmd) 96 { 97 errno_t rc; 98 tbarcfg_t *tbcfg; 99 char fname[L_tmpnam], *p; 100 smenu_entry_t *e; 143 101 const char *caption; 144 102 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)); 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); 115 177 116 caption = smenu_entry_get_caption(e); 178 117 PCUT_ASSERT_STR_EQUALS("A", caption); … … 180 119 PCUT_ASSERT_STR_EQUALS("a", cmd); 181 120 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 191 /** Getting menu entry properties */ 192 PCUT_TEST(get_caption_cmd_term) 121 tbarcfg_close(tbcfg); 122 remove(fname); 123 } 124 125 /** Setting menu entry properties */ 126 PCUT_TEST(set_caption_cmd) 193 127 { 194 128 errno_t rc; … … 198 132 const char *caption; 199 133 const char *cmd; 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); 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); 210 146 211 147 caption = smenu_entry_get_caption(e); … … 213 149 cmd = smenu_entry_get_cmd(e); 214 150 PCUT_ASSERT_STR_EQUALS("a", cmd); 215 terminal = smenu_entry_get_terminal(e); 216 PCUT_ASSERT_FALSE(terminal); 217 218 tbarcfg_close(tbcfg); 219 remove(fname); 220 } 221 222 /** Setting menu entry properties */ 223 PCUT_TEST(set_caption_cmd_term) 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) 224 189 { 225 190 errno_t rc; … … 229 194 const char *caption; 230 195 const char *cmd; 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); 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); 207 PCUT_ASSERT_NOT_NULL(e); 241 208 242 209 caption = smenu_entry_get_caption(e); … … 244 211 cmd = smenu_entry_get_cmd(e); 245 212 PCUT_ASSERT_STR_EQUALS("a", cmd); 246 terminal = smenu_entry_get_terminal(e);247 PCUT_ASSERT_FALSE(terminal);248 249 /* Set properties */250 rc = smenu_entry_set_caption(e, "B");251 PCUT_ASSERT_ERRNO_VAL(EOK, rc);252 rc = smenu_entry_set_cmd(e, "b");253 PCUT_ASSERT_ERRNO_VAL(EOK, rc);254 smenu_entry_set_terminal(e, true);255 256 rc = smenu_entry_save(e);257 PCUT_ASSERT_ERRNO_VAL(EOK, rc);258 259 /* Check that properties have been set */260 caption = smenu_entry_get_caption(e);261 PCUT_ASSERT_STR_EQUALS("B", caption);262 cmd = smenu_entry_get_cmd(e);263 PCUT_ASSERT_STR_EQUALS("b", cmd);264 terminal = smenu_entry_get_terminal(e);265 PCUT_ASSERT_TRUE(terminal);266 267 tbarcfg_close(tbcfg);268 269 /* Re-open repository */270 271 rc = tbarcfg_open(fname, &tbcfg);272 PCUT_ASSERT_ERRNO_VAL(EOK, rc);273 274 e = tbarcfg_smenu_first(tbcfg);275 PCUT_ASSERT_NOT_NULL(e);276 277 /* Check that new values of properties have persisted */278 caption = smenu_entry_get_caption(e);279 PCUT_ASSERT_STR_EQUALS("B", caption);280 cmd = smenu_entry_get_cmd(e);281 PCUT_ASSERT_STR_EQUALS("b", cmd);282 283 tbarcfg_close(tbcfg);284 remove(fname);285 }286 287 /** Create start menu entry */288 PCUT_TEST(entry_create)289 {290 errno_t rc;291 tbarcfg_t *tbcfg;292 char fname[L_tmpnam], *p;293 smenu_entry_t *e;294 const char *caption;295 const char *cmd;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);306 PCUT_ASSERT_NOT_NULL(e);307 308 caption = smenu_entry_get_caption(e);309 PCUT_ASSERT_STR_EQUALS("A", caption);310 cmd = smenu_entry_get_cmd(e);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);329 213 330 214 tbarcfg_close(tbcfg); … … 338 222 tbarcfg_t *tbcfg; 339 223 char fname[L_tmpnam], *p; 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);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); 353 237 354 238 rc = smenu_entry_destroy(e); 355 239 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 356 240 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); 241 e = tbarcfg_smenu_first(tbcfg); 242 PCUT_ASSERT_NULL(e); 551 243 552 244 tbarcfg_close(tbcfg);
Note:
See TracChangeset
for help on using the changeset viewer.