Changeset 7b87e1d in mainline for uspace/lib/sif/test/sif.c
- Timestamp:
- 2018-08-02T11:39:22Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 233a3a06
- Parents:
- 1c398db2
- git-author:
- Jiri Svoboda <jiri@…> (2018-08-01 17:38:51)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-08-02 11:39:22)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/sif/test/sif.c
r1c398db2 r7b87e1d 30 30 #include <pcut/pcut.h> 31 31 #include <stdio.h> 32 #include <str.h> 32 33 #include "../include/sif.h" 33 34 … … 53 54 rc = sif_create(fname, &sess); 54 55 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 56 57 rc = sif_close(sess); 58 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 59 60 rv = remove(fname); 61 PCUT_ASSERT_INT_EQUALS(0, rv); 62 } 63 64 /** Test sif_open. */ 65 PCUT_TEST(sif_open) 66 { 67 sif_sess_t *sess; 68 errno_t rc; 69 int rv; 70 char *fname; 71 char *p; 72 73 fname = calloc(L_tmpnam, 1); 74 PCUT_ASSERT_NOT_NULL(fname); 75 76 p = tmpnam(fname); 77 PCUT_ASSERT_TRUE(p == fname); 78 79 rc = sif_create(fname, &sess); 80 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 81 82 rc = sif_close(sess); 83 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 84 85 rc = sif_open(fname, &sess); 86 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 87 88 rc = sif_close(sess); 89 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 90 91 rv = remove(fname); 92 PCUT_ASSERT_INT_EQUALS(0, rv); 93 } 94 95 /** Test sif_get_root. */ 96 PCUT_TEST(sif_get_root) 97 { 98 sif_sess_t *sess; 99 sif_node_t *root; 100 errno_t rc; 101 int rv; 102 char *fname; 103 char *p; 104 105 fname = calloc(L_tmpnam, 1); 106 PCUT_ASSERT_NOT_NULL(fname); 107 108 p = tmpnam(fname); 109 PCUT_ASSERT_TRUE(p == fname); 110 111 rc = sif_create(fname, &sess); 112 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 113 114 root = sif_get_root(sess); 115 PCUT_ASSERT_NOT_NULL(root); 116 PCUT_ASSERT_INT_EQUALS(0, str_cmp(sif_node_get_type(root), "sif")); 55 117 56 118 rc = sif_close(sess); … … 297 359 } 298 360 361 /** Test sif_node_destroy. */ 362 PCUT_TEST(sif_node_destroy) 363 { 364 sif_sess_t *sess; 365 sif_node_t *root; 366 sif_node_t *ca; 367 sif_node_t *cb; 368 sif_node_t *cc; 369 sif_node_t *c1; 370 sif_node_t *c2; 371 sif_node_t *c3; 372 sif_trans_t *trans; 373 errno_t rc; 374 int rv; 375 char *fname; 376 char *p; 377 378 fname = calloc(L_tmpnam, 1); 379 PCUT_ASSERT_NOT_NULL(fname); 380 381 p = tmpnam(fname); 382 PCUT_ASSERT_TRUE(p == fname); 383 384 rc = sif_create(fname, &sess); 385 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 386 387 root = sif_get_root(sess); 388 389 rc = sif_trans_begin(sess, &trans); 390 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 391 392 rc = sif_node_append_child(trans, root, "a", &ca); 393 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 394 395 rc = sif_node_append_child(trans, root, "b", &cb); 396 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 397 398 rc = sif_node_append_child(trans, root, "c", &cc); 399 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 400 401 rc = sif_trans_end(trans); 402 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 403 404 rc = sif_trans_begin(sess, &trans); 405 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 406 407 sif_node_destroy(trans, cb); 408 409 rc = sif_trans_end(trans); 410 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 411 412 c1 = sif_node_first_child(root); 413 PCUT_ASSERT_TRUE(c1 == ca); 414 415 c2 = sif_node_next_child(c1); 416 PCUT_ASSERT_TRUE(c2 == cc); 417 418 c3 = sif_node_next_child(c2); 419 PCUT_ASSERT_TRUE(c3 == NULL); 420 421 rc = sif_close(sess); 422 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 423 424 rv = remove(fname); 425 PCUT_ASSERT_INT_EQUALS(0, rv); 426 } 427 428 /** Test sif_node_set_attr. */ 429 PCUT_TEST(sif_node_set_attr) 430 { 431 sif_sess_t *sess; 432 sif_node_t *root; 433 sif_node_t *node; 434 sif_trans_t *trans; 435 errno_t rc; 436 int rv; 437 char *fname; 438 char *p; 439 const char *aval; 440 441 fname = calloc(L_tmpnam, 1); 442 PCUT_ASSERT_NOT_NULL(fname); 443 444 p = tmpnam(fname); 445 PCUT_ASSERT_TRUE(p == fname); 446 447 rc = sif_create(fname, &sess); 448 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 449 450 root = sif_get_root(sess); 451 452 rc = sif_trans_begin(sess, &trans); 453 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 454 455 rc = sif_node_append_child(trans, root, "node", &node); 456 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 457 458 rc = sif_node_set_attr(trans, node, "a", "?"); 459 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 460 461 rc = sif_node_set_attr(trans, node, "a", "X"); 462 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 463 464 rc = sif_node_set_attr(trans, node, "b", "Y"); 465 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 466 467 rc = sif_trans_end(trans); 468 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 469 470 aval = sif_node_get_attr(node, "a"); 471 PCUT_ASSERT_INT_EQUALS(0, str_cmp(aval, "X")); 472 473 aval = sif_node_get_attr(node, "b"); 474 PCUT_ASSERT_INT_EQUALS(0, str_cmp(aval, "Y")); 475 476 aval = sif_node_get_attr(node, "c"); 477 PCUT_ASSERT_NULL((void *) aval); // XXX PCUT_ASSERT_NULL does not accept const pointer 478 479 rc = sif_close(sess); 480 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 481 482 rv = remove(fname); 483 PCUT_ASSERT_INT_EQUALS(0, rv); 484 } 485 486 /** Test sif_node_unset_attr. */ 487 PCUT_TEST(sif_node_unset_attr) 488 { 489 sif_sess_t *sess; 490 sif_node_t *root; 491 sif_node_t *node; 492 sif_trans_t *trans; 493 errno_t rc; 494 int rv; 495 char *fname; 496 char *p; 497 const char *aval; 498 499 fname = calloc(L_tmpnam, 1); 500 PCUT_ASSERT_NOT_NULL(fname); 501 502 p = tmpnam(fname); 503 PCUT_ASSERT_TRUE(p == fname); 504 505 rc = sif_create(fname, &sess); 506 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 507 508 root = sif_get_root(sess); 509 510 rc = sif_trans_begin(sess, &trans); 511 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 512 513 rc = sif_node_append_child(trans, root, "node", &node); 514 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 515 516 rc = sif_node_set_attr(trans, node, "a", "X"); 517 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 518 519 rc = sif_trans_end(trans); 520 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 521 522 aval = sif_node_get_attr(node, "a"); 523 PCUT_ASSERT_INT_EQUALS(0, str_cmp(aval, "X")); 524 525 rc = sif_trans_begin(sess, &trans); 526 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 527 528 sif_node_unset_attr(trans, node, "a"); 529 sif_node_unset_attr(trans, node, "b"); 530 531 rc = sif_trans_end(trans); 532 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 533 534 aval = sif_node_get_attr(node, "a"); 535 PCUT_ASSERT_NULL((void *) aval); // XXX PCUT_ASSERT_NULL does not accept const pointer 536 537 rc = sif_close(sess); 538 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 539 540 rv = remove(fname); 541 PCUT_ASSERT_INT_EQUALS(0, rv); 542 } 543 544 /** Test persistence of nodes and attributes. */ 545 PCUT_TEST(sif_persist) 546 { 547 sif_sess_t *sess; 548 sif_node_t *root; 549 sif_node_t *node; 550 sif_trans_t *trans; 551 errno_t rc; 552 int rv; 553 char *fname; 554 char *p; 555 const char *aval; 556 557 fname = calloc(L_tmpnam, 1); 558 PCUT_ASSERT_NOT_NULL(fname); 559 560 p = tmpnam(fname); 561 PCUT_ASSERT_TRUE(p == fname); 562 563 rc = sif_create(fname, &sess); 564 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 565 566 root = sif_get_root(sess); 567 568 rc = sif_trans_begin(sess, &trans); 569 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 570 571 rc = sif_node_append_child(trans, root, "node", &node); 572 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 573 574 rc = sif_node_set_attr(trans, node, "a", "X"); 575 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 576 577 rc = sif_trans_end(trans); 578 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 579 580 rc = sif_close(sess); 581 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 582 583 /* Now reopen the repository */ 584 585 rc = sif_open(fname, &sess); 586 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 587 588 root = sif_get_root(sess); 589 590 node = sif_node_first_child(root); 591 PCUT_ASSERT_NOT_NULL(node); 592 PCUT_ASSERT_INT_EQUALS(0, str_cmp(sif_node_get_type(node), "node")); 593 594 aval = sif_node_get_attr(node, "a"); 595 PCUT_ASSERT_INT_EQUALS(0, str_cmp(aval, "X")); 596 597 rc = sif_close(sess); 598 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 599 600 rv = remove(fname); 601 PCUT_ASSERT_INT_EQUALS(0, rv); 602 } 603 604 299 605 PCUT_EXPORT(sif);
Note:
See TracChangeset
for help on using the changeset viewer.