libsheepyCSmallIntTest.c (44548B)
1 #include <stdlib.h> 2 #include <stdio.h> 3 #include <check.h> 4 5 //START MEM TEST ANCHOR 6 7 #include "../libsheepy.h" 8 #include "../libsheepyObject.h" 9 10 #ifdef __GNUC__ 11 #define UNUSED __attribute__ ((unused)) 12 #else 13 #define UNUSED 14 #endif 15 16 // TODO redirect stderr 17 18 19 START_TEST(initiateSmallIntT) 20 21 smallIntt self; 22 23 initiateSmallInt(&self); 24 char *s = toStringO(&self); 25 ck_assert_ptr_eq(s, null); 26 27 END_TEST 28 29 30 START_TEST(initiateAllocateSmallIntT) 31 32 smallIntt *self; 33 34 initiateAllocateSmallInt(&self); 35 char *s = toStringO(self); 36 ck_assert_ptr_eq(s, null); 37 terminateO(self); 38 39 END_TEST 40 41 42 START_TEST(allocSmallIntT) 43 44 smallIntt* r; 45 46 r = allocSmallInt(1); 47 char *s = toStringO(r); 48 ck_assert_str_eq(s, "1"); 49 free(s); 50 terminateO(r); 51 52 END_TEST 53 54 55 START_TEST(freeSmallIntT) 56 57 smallIntt *self = allocSmallInt(1); 58 59 freeO(self); 60 char *s = toStringO(self); 61 ck_assert_ptr_eq(s, null); 62 terminateO(self); 63 64 END_TEST 65 66 67 START_TEST(terminateSmallIntT) 68 69 smallIntt *self = allocSmallInt(1); 70 71 terminateO(self); 72 ck_assert_ptr_eq(self, null); 73 74 END_TEST 75 76 77 START_TEST(toStringSmallIntT) 78 79 char* r; 80 smallIntt *self = allocSmallInt(1); 81 82 r = toStringO(self); 83 ck_assert_str_eq(r, "1"); 84 free(r); 85 // empty smallInt 86 freeO(self); 87 r = toStringO(self); 88 ck_assert_ptr_eq(r, null); 89 terminateO(self); 90 91 END_TEST 92 93 94 START_TEST(duplicateSmallIntT) 95 96 smallIntt* r; 97 smallIntt *self = allocSmallInt(1); 98 99 r = duplicateO(self); 100 ck_assert_ptr_ne(r, null); 101 char *s = toStringO(r); 102 ck_assert_str_eq(s, "1"); 103 free(s); 104 terminateO(r); 105 // empty smallInt 106 freeO(self); 107 r = duplicateO(self); 108 ck_assert_ptr_ne(r, null); 109 s = toStringO(r); 110 ck_assert_ptr_eq(s, null); 111 terminateO(r); 112 terminateO(self); 113 114 END_TEST 115 116 117 START_TEST(smashSmallIntT) 118 119 smallIntt *self = allocSmallInt(1); 120 121 freeO(self); 122 smashO(self); 123 ck_assert_ptr_eq(self, null); 124 125 END_TEST 126 127 128 START_TEST(finishSmallIntT) 129 130 smallIntt *self = allocSmallInt(1); 131 132 freeO(self); 133 finishO(self); 134 ck_assert_ptr_eq(self, null); 135 136 END_TEST 137 138 139 START_TEST(getSmallIntT) 140 141 int64_t r; 142 smallIntt *self = allocSmallInt(1); 143 144 r = getValO(self); 145 ck_assert(r == 1); 146 // empty smallInt 147 freeO(self); 148 r = getValO(self); 149 ck_assert(r == 0); 150 terminateO(self); 151 152 END_TEST 153 154 155 START_TEST(setSmallIntT) 156 157 smallIntt* r; 158 smallIntt *self = allocSmallInt(1); 159 160 r = setValO(self, 1); 161 ck_assert_ptr_ne(r, null); 162 char *s = toStringO(r); 163 ck_assert_str_eq(s, "1"); 164 free(s); 165 // empty smallInt 166 freeO(self); 167 r = setValO(self, 1); 168 ck_assert_ptr_ne(r, null); 169 s = toStringO(r); 170 ck_assert_str_eq(s, "1"); 171 free(s); 172 terminateO(self); 173 174 END_TEST 175 176 177 START_TEST(setBoolSmallIntT) 178 179 smallIntt* r; 180 smallIntt* self = allocSmallInt(0); 181 182 r = self->f->setBool(self, true); 183 ck_assert_ptr_ne(r, null); 184 char *s = toStringO(r); 185 ck_assert_str_eq(s, "1"); 186 free(s); 187 // empty smallInt 188 freeO(self); 189 r = self->f->setBool(self, true); 190 ck_assert_ptr_ne(r, null); 191 s = toStringO(r); 192 ck_assert_str_eq(s, "1"); 193 free(s); 194 terminateO(self); 195 196 END_TEST 197 198 199 START_TEST(setDoubleSmallIntT) 200 201 smallIntt* r; 202 smallIntt* self = allocSmallInt(1); 203 204 r = self->f->setDouble(self, 1.5); 205 ck_assert_ptr_ne(r, null); 206 char *s = toStringO(r); 207 ck_assert_str_eq(s, "1"); 208 free(s); 209 // empty smallInt 210 freeO(self); 211 r = self->f->setDouble(self, 1); 212 ck_assert_ptr_ne(r, null); 213 s = toStringO(r); 214 ck_assert_str_eq(s, "1"); 215 free(s); 216 terminateO(self); 217 218 END_TEST 219 220 221 START_TEST(setInt32SmallIntT) 222 223 smallIntt* r; 224 smallIntt* self = allocSmallInt(1); 225 226 r = self->f->setInt32(self, 2); 227 ck_assert_ptr_ne(r, null); 228 char *s = toStringO(r); 229 ck_assert_str_eq(s, "2"); 230 free(s); 231 // empty smallInt 232 freeO(self); 233 r = self->f->setInt32(self, 2); 234 ck_assert_ptr_ne(r, null); 235 s = toStringO(r); 236 ck_assert_str_eq(s, "2"); 237 free(s); 238 terminateO(self); 239 240 END_TEST 241 242 243 START_TEST(setUint32SmallIntT) 244 245 smallIntt* r; 246 smallIntt* self = allocSmallInt(1); 247 248 r = self->f->setUint32(self, 2); 249 ck_assert_ptr_ne(r, null); 250 char *s = toStringO(r); 251 ck_assert_str_eq(s, "2"); 252 free(s); 253 // empty smallInt 254 freeO(self); 255 r = self->f->setUint32(self, 2); 256 ck_assert_ptr_ne(r, null); 257 s = toStringO(r); 258 ck_assert_str_eq(s, "2"); 259 free(s); 260 terminateO(self); 261 262 END_TEST 263 264 265 START_TEST(setUint64SmallIntT) 266 267 smallIntt* r; 268 smallIntt* self = allocSmallInt(1); 269 270 r = self->f->setUint64(self, 2); 271 ck_assert_ptr_ne(r, null); 272 char *s = toStringO(r); 273 ck_assert_str_eq(s, "2"); 274 free(s); 275 // empty smallInt 276 freeO(self); 277 r = self->f->setUint64(self, 2); 278 ck_assert_ptr_ne(r, null); 279 s = toStringO(r); 280 ck_assert_str_eq(s, "2"); 281 free(s); 282 terminateO(self); 283 284 END_TEST 285 286 287 START_TEST(setSSmallIntT) 288 289 smallIntt* r; 290 smallIntt* self = allocSmallInt(1); 291 292 r = self->f->setS(self, "2"); 293 ck_assert_ptr_ne(r, null); 294 char *s = toStringO(r); 295 ck_assert_str_eq(s, "2"); 296 free(s); 297 r = self->f->setS(self, "3.5"); 298 ck_assert_ptr_ne(r, null); 299 s = toStringO(r); 300 ck_assert_str_eq(s, "3"); 301 free(s); 302 // empty smallInt 303 freeO(self); 304 r = self->f->setS(self, "5"); 305 ck_assert_ptr_ne(r, null); 306 s = toStringO(r); 307 ck_assert_str_eq(s, "5"); 308 free(s); 309 // NULL parameter 310 r = self->f->setS(self, null); 311 ck_assert_ptr_eq(r, null); 312 terminateO(self); 313 314 END_TEST 315 316 317 START_TEST(setSmallBoolSmallIntT) 318 319 smallIntt* r; 320 smallIntt* self = allocSmallInt(1); 321 smallBoolt* p2 = allocSmallBool(true); 322 323 r = self->f->setSmallBool(self, p2); 324 ck_assert_ptr_ne(r, null); 325 char *s = toStringO(r); 326 ck_assert_str_eq(s, "1"); 327 free(s); 328 // empty smallInt 329 freeO(self); 330 r = self->f->setSmallBool(self, p2); 331 terminateO(p2); 332 ck_assert_ptr_ne(r, null); 333 s = toStringO(r); 334 ck_assert_str_eq(s, "1"); 335 free(s); 336 // NULL parameter 337 r = self->f->setSmallBool(self, null); 338 ck_assert_ptr_eq(r, null); 339 terminateO(self); 340 341 END_TEST 342 343 344 START_TEST(setSmallDoubleSmallIntT) 345 346 smallIntt* r; 347 smallIntt* self = allocSmallInt(1); 348 smallDoublet* p2 = allocSmallDouble(2); 349 350 r = self->f->setSmallDouble(self, p2); 351 ck_assert_ptr_ne(r, null); 352 char *s = toStringO(r); 353 ck_assert_str_eq(s, "2"); 354 free(s); 355 // empty smallInt 356 freeO(self); 357 r = self->f->setSmallDouble(self, p2); 358 terminateO(p2); 359 ck_assert_ptr_ne(r, null); 360 s = toStringO(r); 361 ck_assert_str_eq(s, "2"); 362 free(s); 363 // NULL parameter 364 r = self->f->setSmallDouble(self, null); 365 ck_assert_ptr_eq(r, null); 366 terminateO(self); 367 368 END_TEST 369 370 371 START_TEST(setSmallIntSmallIntT) 372 373 smallIntt* r; 374 smallIntt* self = allocSmallInt(1); 375 smallIntt* p2 = allocSmallInt(2); 376 377 r = self->f->setSmallInt(self, p2); 378 ck_assert_ptr_ne(r, null); 379 char *s = toStringO(r); 380 ck_assert_str_eq(s, "2"); 381 free(s); 382 // empty smallInt 383 freeO(self); 384 r = self->f->setSmallInt(self, p2); 385 terminateO(p2); 386 ck_assert_ptr_ne(r, null); 387 s = toStringO(r); 388 ck_assert_str_eq(s, "2"); 389 free(s); 390 // NULL parameter 391 r = self->f->setSmallInt(self, null); 392 ck_assert_ptr_eq(r, null); 393 terminateO(self); 394 395 END_TEST 396 397 398 START_TEST(setSmallJsonSmallIntT) 399 400 smallIntt* r; 401 smallIntt* self = allocSmallInt(1); 402 smallJsont* p2 = allocSmallJson(); 403 404 // empty json >> error 405 r = self->f->setSmallJson(self, p2); 406 ck_assert_ptr_eq(r, null); 407 // json bool 408 setTopBoolO(p2, true); 409 r = self->f->setSmallJson(self, p2); 410 ck_assert_ptr_ne(r, null); 411 terminateO(p2); 412 char *s = toStringO(r); 413 ck_assert_str_eq(s, "1"); 414 free(s); 415 // json double 416 p2 = allocSmallJson(); 417 setTopDoubleO(p2, 2); 418 r = self->f->setSmallJson(self, p2); 419 ck_assert_ptr_ne(r, null); 420 terminateO(p2); 421 s = toStringO(r); 422 ck_assert_str_eq(s, "2"); 423 free(s); 424 // json int 425 p2 = allocSmallJson(); 426 setTopIntO(p2, 3); 427 r = self->f->setSmallJson(self, p2); 428 ck_assert_ptr_ne(r, null); 429 terminateO(p2); 430 s = toStringO(r); 431 ck_assert_str_eq(s, "3"); 432 free(s); 433 // json string 434 p2 = allocSmallJson(); 435 setTopSO(p2, "1.5"); 436 r = self->f->setSmallJson(self, p2); 437 ck_assert_ptr_ne(r, null); 438 terminateO(p2); 439 s = toStringO(r); 440 ck_assert_str_eq(s, "1"); 441 free(s); 442 // json dict 443 p2 = allocSmallJson(); 444 setTypeDictO(p2); 445 r = self->f->setSmallJson(self, p2); 446 ck_assert_ptr_eq(r, null); 447 terminateO(p2); 448 // NULL parameter 449 r = self->f->setSmallJson(self, null); 450 ck_assert_ptr_eq(r, null); 451 terminateO(self); 452 453 END_TEST 454 455 456 START_TEST(setSmallStringSmallIntT) 457 458 smallIntt* r; 459 smallIntt* self = allocSmallInt(1); 460 smallStringt* p2 = allocSmallString("1.5"); 461 462 r = self->f->setSmallString(self, p2); 463 ck_assert_ptr_ne(r, null); 464 char *s = toStringO(r); 465 ck_assert_str_eq(s, "1"); 466 free(s); 467 // empty smallInt 468 freeO(self); 469 r = self->f->setSmallString(self, p2); 470 terminateO(p2); 471 ck_assert_ptr_ne(r, null); 472 s = toStringO(r); 473 ck_assert_str_eq(s, "1"); 474 free(s); 475 // NULL parameter 476 r = self->f->setSmallString(self, null); 477 ck_assert_ptr_eq(r, null); 478 terminateO(self); 479 480 END_TEST 481 482 483 START_TEST(getPSmallIntT) 484 485 int64_t* r; 486 smallIntt *self = allocSmallInt(1); 487 488 r = self->f->getP(self); 489 ck_assert_ptr_ne(r, null); 490 ck_assert(*r == 1); 491 // empty smallInt 492 freeO(self); 493 r = self->f->getP(self); 494 ck_assert_ptr_eq(r, null); 495 terminateO(self); 496 497 END_TEST 498 499 500 START_TEST(equalSmallIntChaT) 501 502 bool r; 503 smallIntt* self = allocSmallInt(1); 504 char p2 = '1'; 505 506 // p2 is an int so it is false 507 r = self->f->equalCha(self, p2); 508 ck_assert(r); 509 r = self->f->equalCha(self, '2'); 510 ck_assert(!r); 511 // not a digit 512 r = self->f->equalCha(self, '!'); 513 ck_assert(!r); 514 // empty smallInt 515 freeO(self); 516 r = self->f->equalCha(self, p2); 517 ck_assert(!r); 518 terminateO(self); 519 520 END_TEST 521 522 523 START_TEST(equalSmallIntCharT) 524 525 bool r; 526 smallIntt* self = allocSmallInt(0); 527 528 r = self->f->equalChar(self, "0"); 529 ck_assert(r); 530 r = self->f->equalChar(self, "#"); 531 ck_assert(!r); 532 // NULL parameter 533 r = self->f->equalChar(self, null); 534 ck_assert(!r); 535 // empty smallInt 536 freeO(self); 537 r = self->f->equalChar(self, ""); 538 ck_assert(!r); 539 terminateO(self); 540 541 END_TEST 542 543 544 START_TEST(equalSmallIntBaseT) 545 546 bool r; 547 smallIntt* self = allocSmallInt(1); 548 baset* p2 = (baset*) allocSmallInt(1); 549 smallJsont* p3 = allocSmallJson(); 550 551 setTopBoolO(p3, false); 552 553 r = self->f->equalBase(self, p2); 554 terminateO(p2); 555 ck_assert(r); 556 p2 = (baset*) allocSmallInt(10); 557 r = self->f->equalBase(self, p2); 558 terminateO(p2); 559 ck_assert(!r); 560 p2 = (baset*) allocSmallDouble(1); 561 r = self->f->equalBase(self, p2); 562 terminateO(p2); 563 ck_assert(!r); 564 r = self->f->equalBase(self, (baset*)p3); 565 terminateO(p3); 566 ck_assert(!r); 567 p2 = (baset*) allocSmallString("qwe"); 568 r = self->f->equalBase(self, p2); 569 terminateO(p2); 570 ck_assert(!r); 571 // NULL parameter 572 r = self->f->equalBase(self, null); 573 ck_assert(!r); 574 // empty smallInt 575 freeO(self); 576 r = self->f->equalBase(self, p2); 577 ck_assert(!r); 578 terminateO(self); 579 580 END_TEST 581 582 583 START_TEST(equalSmallIntBoolT) 584 585 bool r; 586 smallIntt* self = allocSmallInt(0); 587 588 r = self->f->equalBool(self, true); 589 ck_assert(!r); 590 r = self->f->equalBool(self, false); 591 ck_assert(r); 592 // empty smallInt 593 freeO(self); 594 r = self->f->equalBool(self, false); 595 ck_assert(!r); 596 terminateO(self); 597 598 END_TEST 599 600 601 START_TEST(equalSmallIntDoubleT) 602 603 bool r; 604 smallIntt* self = allocSmallInt(1); 605 606 r = self->f->equalDouble(self, 1); 607 ck_assert(r); 608 r = self->f->equalDouble(self, 2); 609 ck_assert(!r); 610 // empty smallInt 611 freeO(self); 612 r = self->f->equalDouble(self, 1); 613 ck_assert(!r); 614 terminateO(self); 615 616 END_TEST 617 618 619 START_TEST(equalSmallIntInt64T) 620 621 bool r; 622 smallIntt* self = allocSmallInt(1); 623 624 r = self->f->equalInt64(self, 1); 625 ck_assert(r); 626 r = self->f->equalInt64(self, 0); 627 ck_assert(!r); 628 // empty smallInt 629 freeO(self); 630 r = self->f->equalInt64(self, 2); 631 ck_assert(!r); 632 terminateO(self); 633 634 END_TEST 635 636 637 START_TEST(equalSmallIntInt32T) 638 639 bool r; 640 smallIntt* self = allocSmallInt(1); 641 642 r = self->f->equalInt32(self, 1); 643 ck_assert(r); 644 r = self->f->equalInt32(self, 0); 645 ck_assert(!r); 646 // empty smallInt 647 freeO(self); 648 r = self->f->equalInt32(self, 2); 649 ck_assert(!r); 650 terminateO(self); 651 652 END_TEST 653 654 655 START_TEST(equalSmallIntUint32T) 656 657 bool r; 658 smallIntt* self = allocSmallInt(1); 659 660 r = self->f->equalUint32(self, 1); 661 ck_assert(r); 662 r = self->f->equalUint32(self, 0); 663 ck_assert(!r); 664 // empty smallInt 665 freeO(self); 666 r = self->f->equalUint32(self, 2); 667 ck_assert(!r); 668 terminateO(self); 669 670 END_TEST 671 672 673 START_TEST(equalSmallIntUint64T) 674 675 bool r; 676 smallIntt* self = allocSmallInt(1); 677 678 r = self->f->equalUint64(self, 1); 679 ck_assert(r); 680 r = self->f->equalUint64(self, 0); 681 ck_assert(!r); 682 // empty smallInt 683 freeO(self); 684 r = self->f->equalUint64(self, 2); 685 ck_assert(!r); 686 terminateO(self); 687 688 END_TEST 689 690 691 START_TEST(equalSmallIntSmallBoolT) 692 693 bool r; 694 smallIntt* self = allocSmallInt(1); 695 smallBoolt* p2 = allocSmallBool(true); 696 697 r = self->f->equalSmallBool(self, p2); 698 ck_assert(r); 699 setValO(p2, false); 700 r = self->f->equalSmallBool(self, p2); 701 ck_assert(!r); 702 // empty p2 703 freeO(p2); 704 r = self->f->equalSmallBool(self, p2); 705 ck_assert(!r); 706 // NULL parameter 707 r = self->f->equalSmallBool(self, null); 708 ck_assert(!r); 709 // empty smallInt 710 freeO(self); 711 r = self->f->equalSmallBool(self, p2); 712 ck_assert(!r); 713 terminateO(p2); 714 terminateO(self); 715 716 END_TEST 717 718 719 START_TEST(equalSmallIntSmallBytesT) 720 721 bool r; 722 smallIntt* self = allocSmallInt(1); 723 smallBytest* p2 = allocSmallBytes("1", sizeof("1")); 724 725 r = self->f->equalSmallBytes(self, p2); 726 ck_assert(r); 727 p2->f->set(p2, "false", sizeof("false")); 728 r = self->f->equalSmallBytes(self, p2); 729 ck_assert(!r); 730 p2->f->set(p2, "qwe", sizeof("qwe")); 731 r = self->f->equalSmallBytes(self, p2); 732 ck_assert(!r); 733 // without 0 at string end 734 p2->f->set(p2, "qwe", strlen("qwe")); 735 r = self->f->equalSmallBytes(self, p2); 736 ck_assert(!r); 737 // empty p2 738 freeO(p2); 739 r = self->f->equalSmallBytes(self, p2); 740 ck_assert(!r); 741 // NULL parameter 742 r = self->f->equalSmallBytes(self, null); 743 ck_assert(!r); 744 // empty smallInt 745 freeO(self); 746 r = self->f->equalSmallBytes(self, p2); 747 ck_assert(!r); 748 terminateO(p2); 749 terminateO(self); 750 751 END_TEST 752 753 754 START_TEST(equalSmallIntSmallDoubleT) 755 756 bool r; 757 smallIntt* self = allocSmallInt(1); 758 smallDoublet* p2 = allocSmallDouble(1); 759 760 r = self->f->equalSmallDouble(self, p2); 761 ck_assert(r); 762 setValO(p2, 1.5); 763 r = self->f->equalSmallDouble(self, p2); 764 ck_assert(!r); 765 // empty p2 766 freeO(p2); 767 r = self->f->equalSmallDouble(self, p2); 768 ck_assert(!r); 769 // NULL parameter 770 r = self->f->equalSmallDouble(self, null); 771 ck_assert(!r); 772 // empty smallInt 773 freeO(self); 774 r = self->f->equalSmallDouble(self, p2); 775 ck_assert(!r); 776 terminateO(p2); 777 terminateO(self); 778 779 END_TEST 780 781 782 START_TEST(equalSmallIntT) 783 784 bool r; 785 smallIntt* self = allocSmallInt(1); 786 smallIntt* p2 = allocSmallInt(1); 787 788 r = self->f->equal(self, p2); 789 ck_assert(r); 790 setValO(p2, 2); 791 r = self->f->equal(self, p2); 792 ck_assert(!r); 793 // empty p2 794 setValO(p2, 1); 795 freeO(p2); 796 r = self->f->equal(self, p2); 797 ck_assert(!r); 798 // NULL parameter 799 r = self->f->equal(self, null); 800 ck_assert(!r); 801 // empty smallInt 802 freeO(self); 803 r = self->f->equal(self, p2); 804 ck_assert(!r); 805 terminateO(p2); 806 terminateO(self); 807 808 END_TEST 809 810 811 START_TEST(equalSmallIntSmallJsonT) 812 813 bool r; 814 smallIntt* self = allocSmallInt(1); 815 smallJsont* p2 = allocSmallJson(); 816 817 r = self->f->equalSmallJson(self, p2); 818 ck_assert(!r); 819 // non json paramenter 820 terminateO(p2); 821 p2 = (smallJsont*) allocSmallBool(true); 822 r = self->f->equalSmallJson(self, p2); 823 terminateO(p2); 824 ck_assert(!r); 825 // NULL parameter 826 r = self->f->equalSmallJson(self, null); 827 ck_assert(!r); 828 terminateO(self); 829 830 END_TEST 831 832 833 START_TEST(equalSmallIntSmallStringT) 834 835 bool r; 836 smallIntt* self = allocSmallInt(1); 837 smallStringt* p2 = allocSmallString("1"); 838 839 r = self->f->equalSmallString(self, p2); 840 ck_assert(r); 841 setValO(p2, "qwe"); 842 r = self->f->equalSmallString(self, p2); 843 ck_assert(!r); 844 // empty p2 845 setValO(p2, "1"); 846 freeO(p2); 847 r = self->f->equalSmallString(self, p2); 848 ck_assert(!r); 849 // NULL parameter 850 r = self->f->equalSmallString(self, null); 851 ck_assert(!r); 852 // empty smallInt 853 freeO(self); 854 r = self->f->equalSmallString(self, p2); 855 ck_assert(!r); 856 terminateO(p2); 857 terminateO(self); 858 859 END_TEST 860 861 862 START_TEST(readFileSmallIntT) 863 864 smallIntt* r; 865 smallIntt *self = allocSmallInt(1); 866 const char *filePath = "smallInt.bin"; 867 868 writeFileO(self, filePath); 869 r = readFileO(self, filePath); 870 ck_assert_ptr_ne(r, null); 871 char *s = toStringO(r); 872 ck_assert_str_eq(s, "1"); 873 free(s); 874 // empty smallInt 875 freeO(self); 876 r = readFileO(self, filePath); 877 ck_assert_ptr_ne(r, null); 878 s = toStringO(r); 879 ck_assert_str_eq(s, "1"); 880 free(s); 881 rmAll(filePath); 882 // non existing file 883 r = readFileO(self, "nonexistingfile"); 884 ck_assert_ptr_eq(r, null); 885 // non double file 886 FILE *f = fopen("empty.file", "w"); 887 fclose(f); 888 r = readFileO(self, "empty.file"); 889 rmAll("empty.file"); 890 ck_assert_ptr_eq(r, null); 891 // blank file path 892 r = readFileO(self, " "); 893 ck_assert_ptr_eq(r, null); 894 terminateO(self); 895 896 END_TEST 897 898 899 START_TEST(readFileSmallJsonSmallIntT) 900 901 smallIntt* r; 902 smallIntt *self = allocSmallInt(1); 903 smallJsont *filePath = allocSmallJson(); 904 setTopSO(filePath, "smallInt.bin"); 905 906 writeFileO(self, sjGet(filePath)); 907 r = self->f->readFileSmallJson(self, filePath); 908 ck_assert_ptr_ne(r, null); 909 char *s = toStringO(r); 910 ck_assert_str_eq(s, "1"); 911 free(s); 912 // empty smallInt 913 freeO(self); 914 r = self->f->readFileSmallJson(self, filePath); 915 ck_assert_ptr_ne(r, null); 916 s = toStringO(r); 917 ck_assert_str_eq(s, "1"); 918 free(s); 919 rmAll(sjGet(filePath)); 920 // non existing file 921 freeO(filePath); 922 setTopSO(filePath, "nonexistingfile"); 923 r = self->f->readFileSmallJson(self, filePath); 924 ck_assert_ptr_eq(r, null); 925 // non bool file 926 FILE *f = fopen("empty.file", "w"); 927 fclose(f); 928 freeO(filePath); 929 setTopSO(filePath, "empty.file"); 930 r = self->f->readFileSmallJson(self, filePath); 931 rmAll("empty.file"); 932 ck_assert_ptr_eq(r, null); 933 // blank file path 934 freeO(filePath); 935 setTopSO(filePath, " "); 936 r = self->f->readFileSmallJson(self, filePath); 937 ck_assert_ptr_eq(r, null); 938 // non string json 939 freeO(filePath); 940 setTopIntO(filePath, 101); 941 r = self->f->readFileSmallJson(self, filePath); 942 ck_assert_ptr_eq(r, null); 943 terminateO(filePath); 944 // non smallJson object 945 filePath = (smallJsont*)allocSmallBool(true); 946 r = self->f->readFileSmallJson(self, filePath); 947 ck_assert_ptr_eq(r, null); 948 // NULL path 949 r = self->f->readFileSmallJson(self, null); 950 ck_assert_ptr_eq(r, null); 951 terminateO(filePath); 952 terminateO(self); 953 954 END_TEST 955 956 957 START_TEST(readFileSmallStringSmallIntT) 958 959 smallIntt* r; 960 smallIntt *self = allocSmallInt(1); 961 smallStringt *filePath = allocSmallString("smallInt.bin"); 962 963 writeFileO(self, ssGet(filePath)); 964 r = self->f->readFileSmallString(self, filePath); 965 ck_assert_ptr_ne(r, null); 966 char *s = toStringO(r); 967 ck_assert_str_eq(s, "1"); 968 free(s); 969 // empty smallInt 970 freeO(self); 971 r = self->f->readFileSmallString(self, filePath); 972 ck_assert_ptr_ne(r, null); 973 s = toStringO(r); 974 ck_assert_str_eq(s, "1"); 975 free(s); 976 rmAll(ssGet(filePath)); 977 // non existing file 978 setValO(filePath, "nonexistingfile"); 979 r = self->f->readFileSmallString(self, filePath); 980 ck_assert_ptr_eq(r, null); 981 // non bool file 982 FILE *f = fopen("empty.file", "w"); 983 fclose(f); 984 setValO(filePath, "empty.file"); 985 r = self->f->readFileSmallString(self, filePath); 986 rmAll("empty.file"); 987 ck_assert_ptr_eq(r, null); 988 // blank file path 989 setValO(filePath, " "); 990 r = self->f->readFileSmallString(self, filePath); 991 ck_assert_ptr_eq(r, null); 992 terminateO(filePath); 993 // non smallString object 994 filePath = (smallStringt*)allocSmallBool(true); 995 r = self->f->readFileSmallString(self, filePath); 996 ck_assert_ptr_eq(r, null); 997 // NULL path 998 r = self->f->readFileSmallString(self, null); 999 ck_assert_ptr_eq(r, null); 1000 terminateO(filePath); 1001 terminateO(self); 1002 1003 END_TEST 1004 1005 1006 START_TEST(readStreamSmallIntT) 1007 1008 smallIntt* r; 1009 smallIntt *self = allocSmallInt(1); 1010 FILE *fp; 1011 const char *filePath = "smallInt.bin"; 1012 1013 writeFileO(self, filePath); 1014 fp = fopen("smallInt.bin", "r"); 1015 r = readStreamO(self, fp); 1016 ck_assert_ptr_ne(r, null); 1017 fclose(fp); 1018 char *s = toStringO(r); 1019 ck_assert_str_eq(s, "1"); 1020 free(s); 1021 // empty smallInt 1022 freeO(self); 1023 fp = fopen("smallInt.bin", "r"); 1024 r = readStreamO(self, fp); 1025 ck_assert_ptr_ne(r, null); 1026 fclose(fp); 1027 s = toStringO(r); 1028 ck_assert_str_eq(s, "1"); 1029 free(s); 1030 rmAll(filePath); 1031 // non existing file 1032 r = readStreamO(self, null); 1033 ck_assert_ptr_eq(r, null); 1034 // non bool file 1035 FILE *f = fopen("empty.file", "w"); 1036 fclose(f); 1037 fp = fopen("empty.file", "r"); 1038 r = readStreamO(self, fp); 1039 rmAll("empty.file"); 1040 ck_assert_ptr_eq(r, null); 1041 fclose(fp); 1042 terminateO(self); 1043 1044 END_TEST 1045 1046 1047 START_TEST(writeFileSmallIntT) 1048 1049 int r; 1050 smallIntt *self = allocSmallInt(1); 1051 const char *filePath = "smallInt.bin"; 1052 1053 r = writeFileO(self, filePath); 1054 ck_assert_int_eq(r, 1); 1055 freeO(self); 1056 smallIntt *r2 = readFileO(self, filePath); 1057 ck_assert_ptr_ne(r2, null); 1058 char *s = toStringO(r2); 1059 ck_assert_str_eq(s, "1"); 1060 free(s); 1061 // non writable path 1062 r = writeFileO(self, "/nonexisting/readonly"); 1063 ck_assert_int_eq(r, 0); 1064 // blank path 1065 r = writeFileO(self, " "); 1066 ck_assert_int_eq(r, 0); 1067 // null path 1068 r = writeFileO(self, null); 1069 ck_assert_int_eq(r, 0); 1070 // empty smallInt 1071 freeO(self); 1072 r = writeFileO(self, filePath); 1073 ck_assert_int_eq(r, 0); 1074 terminateO(self); 1075 rmAll("smallInt.bin"); 1076 1077 END_TEST 1078 1079 1080 START_TEST(writeFileSmallJsonSmallIntT) 1081 1082 int r; 1083 smallIntt *self = allocSmallInt(1); 1084 smallJsont *filePath = allocSmallJson(); 1085 setTopSO(filePath, "smallInt.bin"); 1086 1087 r = self->f->writeFileSmallJson(self, filePath); 1088 ck_assert_int_eq(r, 1); 1089 freeO(self); 1090 smallIntt *r2 = readFileO(self, sjGet(filePath)); 1091 ck_assert_ptr_ne(r2, null); 1092 char *s = toStringO(r2); 1093 ck_assert_str_eq(s, "1"); 1094 free(s); 1095 // non writable path 1096 freeO(filePath); 1097 setTopSO(filePath, "/nonexistingfile/readonly"); 1098 r = self->f->writeFileSmallJson(self, filePath); 1099 ck_assert_int_eq(r, 0); 1100 // blank path 1101 freeO(filePath); 1102 setTopSO(filePath, " "); 1103 r = self->f->writeFileSmallJson(self, filePath); 1104 ck_assert_int_eq(r, 0); 1105 // null path 1106 r = self->f->writeFileSmallJson(self, null); 1107 ck_assert_int_eq(r, 0); 1108 // empty smallInt 1109 freeO(self); 1110 freeO(filePath); 1111 setTopSO(filePath, "smallInt.bin"); 1112 r = self->f->writeFileSmallJson(self, filePath); 1113 ck_assert_int_eq(r, 0); 1114 // non string json 1115 freeO(filePath); 1116 setTopIntO(filePath, 101); 1117 r = self->f->writeFileSmallJson(self, filePath); 1118 ck_assert_int_eq(r, 0); 1119 terminateO(filePath); 1120 // non smallJson object 1121 filePath = (smallJsont*)allocSmallBool(true); 1122 r = self->f->writeFileSmallJson(self, filePath); 1123 ck_assert_int_eq(r, 0); 1124 terminateO(filePath); 1125 terminateO(self); 1126 rmAll("smallInt.bin"); 1127 1128 END_TEST 1129 1130 1131 START_TEST(writeFileSmallStringSmallIntT) 1132 1133 int r; 1134 smallIntt *self = allocSmallInt(1); 1135 smallStringt *filePath = allocSmallString("smallInt.bin"); 1136 1137 r = self->f->writeFileSmallString(self, filePath); 1138 ck_assert_int_eq(r, 1); 1139 freeO(self); 1140 smallIntt *r2 = readFileO(self, ssGet(filePath)); 1141 ck_assert_ptr_ne(r2, null); 1142 char *s = toStringO(r2); 1143 ck_assert_str_eq(s, "1"); 1144 free(s); 1145 // non writable path 1146 setValO(filePath, "/nonexistingfile/readonly"); 1147 r = self->f->writeFileSmallString(self, filePath); 1148 ck_assert_int_eq(r, 0); 1149 // blank path 1150 setValO(filePath, " "); 1151 r = self->f->writeFileSmallString(self, filePath); 1152 ck_assert_int_eq(r, 0); 1153 // null path 1154 r = self->f->writeFileSmallString(self, null); 1155 ck_assert_int_eq(r, 0); 1156 // empty smallInt 1157 freeO(self); 1158 setValO(filePath, "smallInt.bin"); 1159 r = self->f->writeFileSmallString(self, filePath); 1160 ck_assert_int_eq(r, 0); 1161 terminateO(filePath); 1162 // non smallString object 1163 filePath = (smallStringt*)allocSmallBool(true); 1164 r = self->f->writeFileSmallString(self, filePath); 1165 ck_assert_int_eq(r, 0); 1166 terminateO(filePath); 1167 terminateO(self); 1168 rmAll("smallInt.bin"); 1169 1170 END_TEST 1171 1172 1173 START_TEST(writeStreamSmallIntT) 1174 1175 int r; 1176 smallIntt *self = allocSmallInt(1); 1177 FILE *fp; 1178 const char *filePath = "smallInt.bin"; 1179 1180 fp = fopen("smallInt.bin", "w"); 1181 r = writeStreamO(self, fp); 1182 ck_assert_int_eq(r, 1); 1183 fclose(fp); 1184 freeO(self); 1185 smallIntt *r2 = readFileO(self, filePath); 1186 ck_assert_ptr_ne(r2, null); 1187 char *s = toStringO(r2); 1188 ck_assert_str_eq(s, "1"); 1189 free(s); 1190 // null file 1191 r = writeStreamO(self, null); 1192 ck_assert_int_eq(r, 0); 1193 // empty smallInt 1194 freeO(self); 1195 fp = fopen("smallInt.bin", "w"); 1196 r = writeStreamO(self, fp); 1197 ck_assert_int_eq(r, 0); 1198 fclose(fp); 1199 terminateO(self); 1200 rmAll("smallInt.bin"); 1201 1202 END_TEST 1203 1204 1205 START_TEST(appendFileSmallIntT) 1206 1207 int r; 1208 smallIntt *self = allocSmallInt(1); 1209 const char *filePath = "smallInt.bin"; 1210 1211 FILE *f = fopen(filePath, "w"); 1212 fclose(f); 1213 r = appendFileO(self, filePath); 1214 ck_assert_int_eq(r, 1); 1215 freeO(self); 1216 smallIntt *r2 = readFileO(self, filePath); 1217 ck_assert_ptr_ne(r2, null); 1218 char *s = toStringO(r2); 1219 ck_assert_str_eq(s, "1"); 1220 free(s); 1221 // non existing file 1222 r = appendFileO(self, "/nonexisting/readonly"); 1223 ck_assert_int_eq(r, 0); 1224 // blank path 1225 r = appendFileO(self, " "); 1226 ck_assert_int_eq(r, 0); 1227 // null path 1228 r = appendFileO(self, null); 1229 ck_assert_int_eq(r, 0); 1230 // empty smallInt 1231 freeO(self); 1232 r = appendFileO(self, filePath); 1233 ck_assert_int_eq(r, 0); 1234 terminateO(self); 1235 rmAll("smallInt.bin"); 1236 1237 END_TEST 1238 1239 1240 START_TEST(appendFileSmallStringSmallIntT) 1241 1242 int r; 1243 smallIntt *self = allocSmallInt(1); 1244 smallStringt *filePath = allocSmallString("smallInt.bin"); 1245 1246 FILE *f = fopen(ssGet(filePath), "w"); 1247 fclose(f); 1248 r = appendFileSmallStringO(self, filePath); 1249 ck_assert_int_eq(r, 1); 1250 freeO(self); 1251 smallIntt *r2 = readFileO(self, ssGet(filePath)); 1252 ck_assert_ptr_ne(r2, null); 1253 char *s = toStringO(r2); 1254 ck_assert_str_eq(s, "1"); 1255 free(s); 1256 // non existing file 1257 setValO(filePath, "/nonexisting/readonly"); 1258 r = appendFileSmallStringO(self, filePath); 1259 ck_assert_int_eq(r, 0); 1260 // blank path 1261 setValO(filePath, " "); 1262 r = appendFileSmallStringO(self, filePath); 1263 ck_assert_int_eq(r, 0); 1264 // null path 1265 r = appendFileSmallStringO(self, null); 1266 ck_assert_int_eq(r, 0); 1267 // empty smallInt 1268 freeO(self); 1269 setValO(filePath, "smallInt.bin"); 1270 r = appendFileSmallStringO(self, filePath); 1271 ck_assert_int_eq(r, 0); 1272 terminateO(filePath); 1273 terminateO(self); 1274 rmAll("smallInt.bin"); 1275 1276 END_TEST 1277 1278 1279 START_TEST(duplicateSmallIntGT) 1280 1281 smallIntt* r; 1282 smallIntt *self = allocSmallInt(1); 1283 1284 r = duplicateSmallIntG(self); 1285 char *s = toStringO(r); 1286 ck_assert_str_eq(s, "1"); 1287 free(s); 1288 terminateO(r); 1289 terminateO(self); 1290 1291 END_TEST 1292 1293 1294 START_TEST(freeSmallIntGT) 1295 1296 smallIntt *self = allocSmallInt(1); 1297 1298 freeSmallIntG(self); 1299 char *s = toStringO(self); 1300 ck_assert_ptr_eq(s, null); 1301 terminateO(self); 1302 1303 END_TEST 1304 1305 1306 START_TEST(getIntSmallIntGT) 1307 1308 int64_t r; 1309 smallIntt *self = allocSmallInt(1); 1310 1311 r = getIntSmallIntG(self, 0, 0); 1312 ck_assert_int_eq(r, 1); 1313 terminateO(self); 1314 1315 END_TEST 1316 1317 1318 START_TEST(getIntPSmallIntGT) 1319 1320 int64_t* r; 1321 smallIntt *self = allocSmallInt(1); 1322 1323 r = getIntPSmallIntG(self, null, 0); 1324 ck_assert_ptr_ne(r, null); 1325 ck_assert_int_eq(*r, 1); 1326 terminateO(self); 1327 1328 END_TEST 1329 1330 1331 START_TEST(getInt32SmallIntGT) 1332 1333 int32_t r; 1334 smallIntt *self = allocSmallInt(1); 1335 1336 r = getInt32SmallIntG(self, 0, 0); 1337 ck_assert_int_eq(r, 1); 1338 terminateO(self); 1339 1340 END_TEST 1341 1342 1343 START_TEST(getInt32PSmallIntGT) 1344 1345 int32_t* r; 1346 smallIntt *self = allocSmallInt(1); 1347 1348 r = getInt32PSmallIntG(self, null, 0); 1349 ck_assert_ptr_ne(r, null); 1350 ck_assert_int_eq(*r, 1); 1351 terminateO(self); 1352 1353 END_TEST 1354 1355 1356 START_TEST(getUintSmallIntGT) 1357 1358 uint64_t r; 1359 smallIntt *self = allocSmallInt(1); 1360 1361 r = getUintSmallIntG(self, 0, 0); 1362 ck_assert_int_eq(r, 1); 1363 terminateO(self); 1364 1365 END_TEST 1366 1367 1368 START_TEST(getUintPSmallIntGT) 1369 1370 uint64_t* r; 1371 smallIntt *self = allocSmallInt(1); 1372 1373 r = getUintPSmallIntG(self, null, 0); 1374 ck_assert_ptr_ne(r, null); 1375 ck_assert_int_eq(*r, 1); 1376 terminateO(self); 1377 1378 END_TEST 1379 1380 1381 START_TEST(getUint32SmallIntGT) 1382 1383 uint32_t r; 1384 smallIntt *self = allocSmallInt(1); 1385 1386 r = getUint32SmallIntG(self, 0, 0); 1387 ck_assert_int_eq(r, 1); 1388 terminateO(self); 1389 1390 END_TEST 1391 1392 1393 START_TEST(getUint32PSmallIntGT) 1394 1395 uint32_t* r; 1396 smallIntt *self = allocSmallInt(1); 1397 1398 r = getUint32PSmallIntG(self, null, 0); 1399 ck_assert_ptr_ne(r, null); 1400 ck_assert_int_eq(*r, 1); 1401 terminateO(self); 1402 1403 END_TEST 1404 1405 1406 START_TEST(setBoolSmallIntGT) 1407 1408 smallIntt* r; 1409 smallIntt* self = allocSmallInt(0); 1410 1411 r = setBoolSmallIntG(self, true); 1412 ck_assert_ptr_ne(r, null); 1413 int64_t r2 = getIntSmallIntG(self, 0, 0); 1414 ck_assert_int_eq(r2, 1); 1415 terminateO(self); 1416 1417 END_TEST 1418 1419 1420 START_TEST(setDoubleSmallIntGT) 1421 1422 smallIntt* r; 1423 smallIntt* self = allocSmallInt(1); 1424 1425 r = setDoubleSmallIntG(self, 1.5); 1426 ck_assert_ptr_ne(r, null); 1427 int64_t r2 = getIntSmallIntG(self, 0, 0); 1428 ck_assert_int_eq(r2, 1); 1429 terminateO(self); 1430 1431 END_TEST 1432 1433 1434 START_TEST(setInt32SmallIntGT) 1435 1436 smallIntt* r; 1437 smallIntt* self = allocSmallInt(1); 1438 1439 r = setInt32SmallIntG(self, 2); 1440 ck_assert_ptr_ne(r, null); 1441 int64_t r2 = getIntSmallIntG(self, 0, 0); 1442 ck_assert_int_eq(r2, 2); 1443 terminateO(self); 1444 1445 END_TEST 1446 1447 1448 START_TEST(setUint32SmallIntGT) 1449 1450 smallIntt* r; 1451 smallIntt* self = allocSmallInt(1); 1452 1453 r = setUint32SmallIntG(self, 2); 1454 ck_assert_ptr_ne(r, null); 1455 int64_t r2 = getIntSmallIntG(self, 0, 0); 1456 ck_assert_int_eq(r2, 2); 1457 terminateO(self); 1458 1459 END_TEST 1460 1461 1462 START_TEST(setUint64SmallIntGT) 1463 1464 smallIntt* r; 1465 smallIntt* self = allocSmallInt(1); 1466 1467 r = setUint64SmallIntG(self, 2); 1468 ck_assert_ptr_ne(r, null); 1469 int64_t r2 = getIntSmallIntG(self, 0, 0); 1470 ck_assert_int_eq(r2, 2); 1471 terminateO(self); 1472 1473 END_TEST 1474 1475 1476 START_TEST(setSSmallIntGT) 1477 1478 smallIntt* r; 1479 smallIntt* self = allocSmallInt(1); 1480 1481 r = setSSmallIntG(self, "2"); 1482 ck_assert_ptr_ne(r, null); 1483 int64_t r2 = getIntSmallIntG(self, 0, 0); 1484 ck_assert_int_eq(r2, 2); 1485 terminateO(self); 1486 1487 END_TEST 1488 1489 1490 START_TEST(setSmallBoolSmallIntGT) 1491 1492 smallIntt* r; 1493 smallIntt* self = allocSmallInt(0); 1494 smallBoolt* p2 = allocSmallBool(true); 1495 1496 r = setSmallBoolSmallIntG(self, p2); 1497 ck_assert_ptr_ne(r, null); 1498 terminateO(p2); 1499 int64_t r2 = getIntSmallIntG(self, 0, 0); 1500 ck_assert_int_eq(r2, 1); 1501 terminateO(self); 1502 1503 END_TEST 1504 1505 1506 START_TEST(setSmallDoubleSmallIntGT) 1507 1508 smallIntt* r; 1509 smallIntt* self = allocSmallInt(1); 1510 smallDoublet* p2 = allocSmallDouble(2.5); 1511 1512 r = setSmallDoubleSmallIntG(self, p2); 1513 ck_assert_ptr_ne(r, null); 1514 terminateO(p2); 1515 int64_t r2 = getIntSmallIntG(self, 0, 0); 1516 ck_assert_int_eq(r2, 2); 1517 terminateO(self); 1518 1519 END_TEST 1520 1521 1522 START_TEST(setSmallIntSmallIntGT) 1523 1524 smallIntt* r; 1525 smallIntt* self = allocSmallInt(1); 1526 smallIntt* p2 = allocSmallInt(2); 1527 1528 r = setSmallIntSmallIntG(self, p2); 1529 ck_assert_ptr_ne(r, null); 1530 terminateO(p2); 1531 double r2 = getIntSmallIntG(self, 0, 0); 1532 ck_assert_int_eq(r2, 2); 1533 terminateO(self); 1534 1535 END_TEST 1536 1537 1538 START_TEST(setSmallJsonSmallIntGT) 1539 1540 smallIntt* r; 1541 smallIntt* self = allocSmallInt(1); 1542 smallJsont* p2 = allocSmallJson(); 1543 setTopIntO(p2, 2); 1544 1545 r = setSmallJsonSmallIntG(self, p2); 1546 ck_assert_ptr_ne(r, null); 1547 terminateO(p2); 1548 int64_t r2 = getIntSmallIntG(self, 0, 0); 1549 ck_assert_int_eq(r2, 2); 1550 terminateO(self); 1551 1552 END_TEST 1553 1554 1555 START_TEST(setSmallStringSmallIntGT) 1556 1557 smallIntt* r; 1558 smallIntt* self = allocSmallInt(1); 1559 smallStringt* p2 = allocSmallString("2.5"); 1560 1561 r = setSmallStringSmallIntG(self, p2); 1562 ck_assert_ptr_ne(r, null); 1563 terminateO(p2); 1564 double r2 = getIntSmallIntG(self, 0, 0); 1565 ck_assert_int_eq(r2, 2); 1566 terminateO(self); 1567 1568 END_TEST 1569 1570 1571 START_TEST(equalSmallIntChaGT) 1572 1573 bool r; 1574 smallIntt* self = allocSmallInt(1); 1575 1576 r = equalSmallIntChaG(self, '1'); 1577 ck_assert(r); 1578 terminateO(self); 1579 1580 END_TEST 1581 1582 1583 START_TEST(equalSmallIntCharGT) 1584 1585 bool r; 1586 smallIntt* self = allocSmallInt(1); 1587 1588 r = equalSmallIntCharG(self, "1"); 1589 ck_assert(r); 1590 terminateO(self); 1591 1592 END_TEST 1593 1594 1595 START_TEST(equalSmallIntBaseGT) 1596 1597 bool r; 1598 smallIntt* self = allocSmallInt(1); 1599 baset* p2 = (baset*) allocSmallInt(1); 1600 1601 r = equalSmallIntBaseG(self, p2); 1602 ck_assert(r); 1603 terminateO(p2); 1604 terminateO(self); 1605 1606 END_TEST 1607 1608 1609 START_TEST(equalSmallIntBoolGT) 1610 1611 bool r; 1612 smallIntt* self = allocSmallInt(1); 1613 1614 r = equalSmallIntBoolG(self, true); 1615 ck_assert(r); 1616 terminateO(self); 1617 1618 END_TEST 1619 1620 1621 START_TEST(equalSmallIntDoubleGT) 1622 1623 bool r; 1624 smallIntt* self = allocSmallInt(1); 1625 1626 r = equalSmallIntDoubleG(self, 1); 1627 ck_assert(r); 1628 terminateO(self); 1629 1630 END_TEST 1631 1632 1633 START_TEST(equalSmallIntInt64GT) 1634 1635 bool r; 1636 smallIntt* self = allocSmallInt(1); 1637 1638 r = equalSmallIntInt64G(self, 1); 1639 ck_assert(r); 1640 terminateO(self); 1641 1642 END_TEST 1643 1644 1645 START_TEST(equalSmallIntInt32GT) 1646 1647 bool r; 1648 smallIntt* self = allocSmallInt(1); 1649 1650 r = equalSmallIntInt32G(self, 1); 1651 ck_assert(r); 1652 terminateO(self); 1653 1654 END_TEST 1655 1656 1657 START_TEST(equalSmallIntUint32GT) 1658 1659 bool r; 1660 smallIntt* self = allocSmallInt(1); 1661 1662 r = equalSmallIntUint32G(self, 1); 1663 ck_assert(r); 1664 terminateO(self); 1665 1666 END_TEST 1667 1668 1669 START_TEST(equalSmallIntUint64GT) 1670 1671 bool r; 1672 smallIntt* self = allocSmallInt(1); 1673 1674 r = equalSmallIntUint64G(self, 1); 1675 ck_assert(r); 1676 terminateO(self); 1677 1678 END_TEST 1679 1680 1681 START_TEST(equalSmallIntSmallBoolGT) 1682 1683 bool r; 1684 smallIntt* self = allocSmallInt(1); 1685 smallBoolt* p2 = allocSmallBool(true); 1686 1687 r = equalSmallIntSmallBoolG(self, p2); 1688 ck_assert(r); 1689 terminateO(p2); 1690 terminateO(self); 1691 1692 END_TEST 1693 1694 1695 START_TEST(equalSmallIntSmallBytesGT) 1696 1697 bool r; 1698 smallIntt* self = allocSmallInt(1); 1699 smallBytest* p2 = allocSmallBytes("1", sizeof("1")); 1700 1701 r = equalSmallIntSmallBytesG(self, p2); 1702 ck_assert(r); 1703 terminateO(p2); 1704 terminateO(self); 1705 1706 END_TEST 1707 1708 1709 START_TEST(equalSmallIntSmallDoubleGT) 1710 1711 bool r; 1712 smallIntt* self = allocSmallInt(1); 1713 smallDoublet* p2 = allocSmallDouble(1); 1714 1715 r = equalSmallIntSmallDoubleG(self, p2); 1716 ck_assert(r); 1717 terminateO(p2); 1718 terminateO(self); 1719 1720 END_TEST 1721 1722 1723 START_TEST(equalSmallIntFGT) 1724 1725 bool r; 1726 smallIntt* self = allocSmallInt(1); 1727 smallIntt* p2 = allocSmallInt(1); 1728 1729 r = equalSmallIntFG(self, p2); 1730 ck_assert(r); 1731 terminateO(p2); 1732 terminateO(self); 1733 1734 END_TEST 1735 1736 1737 START_TEST(equalSmallIntSmallJsonGT) 1738 1739 bool r; 1740 smallIntt* self = allocSmallInt(1); 1741 smallJsont* p2 = allocSmallJson(); 1742 setTopIntO(p2, 1); 1743 1744 r = equalSmallIntSmallJsonG(self, p2); 1745 ck_assert(r); 1746 terminateO(p2); 1747 terminateO(self); 1748 1749 END_TEST 1750 1751 1752 START_TEST(equalSmallIntSmallStringGT) 1753 1754 bool r; 1755 smallIntt* self = allocSmallInt(1); 1756 smallStringt* p2 = allocSmallString("1"); 1757 1758 r = equalSmallIntSmallStringG(self, p2); 1759 ck_assert(r); 1760 terminateO(p2); 1761 terminateO(self); 1762 1763 END_TEST 1764 1765 1766 START_TEST(readFileSmallIntGT) 1767 1768 smallIntt* r; 1769 smallIntt *self = allocSmallInt(1); 1770 const char *filePath = "smallInt.bin"; 1771 1772 writeFileO(self, filePath); 1773 r = readFileSmallIntG(self, filePath); 1774 ck_assert_ptr_ne(r, null); 1775 char *s = toStringO(r); 1776 ck_assert_str_eq(s, "1"); 1777 free(s); 1778 rmAll(filePath); 1779 terminateO(self); 1780 1781 END_TEST 1782 1783 1784 START_TEST(readFileSmallJsonSmallIntGT) 1785 1786 smallIntt* r; 1787 smallIntt *self = allocSmallInt(1); 1788 smallJsont *filePath = allocSmallJson(); 1789 setTopSO(filePath, "smallInt.bin"); 1790 1791 writeFileO(self, sjGet(filePath)); 1792 r = readFileSmallJsonSmallIntG(self, filePath); 1793 ck_assert_ptr_ne(r, null); 1794 char *s = toStringO(r); 1795 ck_assert_str_eq(s, "1"); 1796 free(s); 1797 rmAll(sjGet(filePath)); 1798 terminateO(filePath); 1799 terminateO(self); 1800 1801 END_TEST 1802 1803 1804 START_TEST(readFileSmallStringSmallIntGT) 1805 1806 smallIntt* r; 1807 smallIntt *self = allocSmallInt(1); 1808 smallStringt *filePath = allocSmallString("smallInt.bin"); 1809 1810 writeFileO(self, ssGet(filePath)); 1811 r = readFileSmallStringSmallIntG(self, filePath); 1812 ck_assert_ptr_ne(r, null); 1813 char *s = toStringO(r); 1814 ck_assert_str_eq(s, "1"); 1815 free(s); 1816 rmAll(ssGet(filePath)); 1817 terminateO(filePath); 1818 terminateO(self); 1819 1820 END_TEST 1821 1822 1823 START_TEST(readStreamSmallIntGT) 1824 1825 smallIntt* r; 1826 smallIntt *self = allocSmallInt(1); 1827 FILE *fp; 1828 const char *filePath = "smallInt.bin"; 1829 1830 writeFileO(self, filePath); 1831 fp = fopen(filePath, "r"); 1832 r = readStreamSmallIntG(self, fp); 1833 ck_assert_ptr_ne(r, null); 1834 fclose(fp); 1835 char *s = toStringO(r); 1836 ck_assert_str_eq(s, "1"); 1837 free(s); 1838 rmAll(filePath); 1839 terminateO(self); 1840 1841 END_TEST 1842 1843 1844 START_TEST(writeFileSmallIntGT) 1845 1846 int r; 1847 smallIntt *self = allocSmallInt(1); 1848 const char *filePath = "smallInt.bin"; 1849 1850 r = writeFileSmallIntG(self, filePath); 1851 ck_assert_int_eq(r, 1); 1852 freeO(self); 1853 smallIntt *r2 = readFileO(self, filePath); 1854 ck_assert_ptr_ne(r2, null); 1855 char *s = toStringO(r2); 1856 ck_assert_str_eq(s, "1"); 1857 free(s); 1858 rmAll(filePath); 1859 terminateO(self); 1860 1861 END_TEST 1862 1863 1864 START_TEST(writeFileSmallJsonSmallIntGT) 1865 1866 int r; 1867 smallIntt *self = allocSmallInt(1); 1868 smallJsont *filePath = allocSmallJson(); 1869 setTopSO(filePath, "smallInt.bin"); 1870 1871 r = writeFileSmallJsonSmallIntG(self, filePath); 1872 ck_assert_int_eq(r, 1); 1873 freeO(self); 1874 smallIntt *r2 = readFileO(self, sjGet(filePath)); 1875 ck_assert_ptr_ne(r2, null); 1876 char *s = toStringO(r2); 1877 ck_assert_str_eq(s, "1"); 1878 free(s); 1879 terminateO(filePath); 1880 terminateO(self); 1881 rmAll("smallInt.bin"); 1882 1883 END_TEST 1884 1885 1886 START_TEST(writeFileSmallStringSmallIntGT) 1887 1888 int r; 1889 smallIntt *self = allocSmallInt(1); 1890 smallStringt *filePath = allocSmallString("smallInt.bin"); 1891 1892 r = writeFileSmallStringSmallIntG(self, filePath); 1893 ck_assert_int_eq(r, 1); 1894 freeO(self); 1895 smallIntt *r2 = readFileO(self, ssGet(filePath)); 1896 ck_assert_ptr_ne(r2, null); 1897 char *s = toStringO(r2); 1898 ck_assert_str_eq(s, "1"); 1899 free(s); 1900 terminateO(filePath); 1901 terminateO(self); 1902 rmAll("smallInt.bin"); 1903 1904 END_TEST 1905 1906 1907 START_TEST(writeStreamSmallIntGT) 1908 1909 int r; 1910 smallIntt *self = allocSmallInt(1); 1911 FILE *fp; 1912 const char *filePath = "smallInt.bin"; 1913 1914 fp = fopen(filePath, "w"); 1915 r = writeStreamSmallIntG(self, fp); 1916 ck_assert_int_eq(r, 1); 1917 fclose(fp); 1918 freeO(self); 1919 smallIntt *r2 = readFileO(self, filePath); 1920 ck_assert_ptr_ne(r2, null); 1921 char *s = toStringO(r2); 1922 ck_assert_str_eq(s, "1"); 1923 free(s); 1924 terminateO(self); 1925 rmAll(filePath); 1926 1927 END_TEST 1928 1929 1930 START_TEST(appendFileSmallIntFGT) 1931 1932 int r; 1933 smallIntt *self = allocSmallInt(1); 1934 const char *filePath = "smallInt.bin"; 1935 1936 FILE *f = fopen(filePath, "w"); 1937 fclose(f); 1938 r = appendFileSmallIntFG(self, filePath); 1939 ck_assert_int_eq(r, 1); 1940 freeO(self); 1941 smallIntt *r2 = readFileO(self, filePath); 1942 ck_assert_ptr_ne(r2, null); 1943 char *s = toStringO(r2); 1944 ck_assert_str_eq(s, "1"); 1945 free(s); 1946 terminateO(self); 1947 rmAll("smallInt.bin"); 1948 1949 END_TEST 1950 1951 1952 START_TEST(appendFileSmallStringSmallIntGT) 1953 1954 int r; 1955 smallIntt *self = allocSmallInt(1); 1956 smallStringt *filePath = allocSmallString("smallInt.bin"); 1957 1958 FILE *f = fopen(ssGet(filePath), "w"); 1959 fclose(f); 1960 r = appendFileSmallStringSmallIntG(self, filePath); 1961 ck_assert_int_eq(r, 1); 1962 freeO(self); 1963 smallIntt *r2 = readFileO(self, ssGet(filePath)); 1964 ck_assert_ptr_ne(r2, null); 1965 char *s = toStringO(r2); 1966 ck_assert_str_eq(s, "1"); 1967 free(s); 1968 terminateO(filePath); 1969 terminateO(self); 1970 rmAll("smallInt.bin"); 1971 1972 END_TEST 1973 1974 1975 1976 1977 1978 Suite * libsheepySuite(void) { 1979 Suite *s; 1980 TCase *tc_core; 1981 1982 s = suite_create("libsheepy"); 1983 1984 /* Core test case */ 1985 tc_core = tcase_create("Object"); 1986 1987 setLogMode(LOG_VERBOSE); 1988 1989 // disable btrace to make the test run faster 1990 btraceDisable(); 1991 1992 tcase_add_test(tc_core, initiateSmallIntT); 1993 tcase_add_test(tc_core, initiateAllocateSmallIntT); 1994 tcase_add_test(tc_core, allocSmallIntT); 1995 tcase_add_test(tc_core, freeSmallIntT); 1996 tcase_add_test(tc_core, terminateSmallIntT); 1997 tcase_add_test(tc_core, toStringSmallIntT); 1998 tcase_add_test(tc_core, duplicateSmallIntT); 1999 tcase_add_test(tc_core, smashSmallIntT); 2000 tcase_add_test(tc_core, finishSmallIntT); 2001 tcase_add_test(tc_core, getSmallIntT); 2002 tcase_add_test(tc_core, setSmallIntT); 2003 tcase_add_test(tc_core, setBoolSmallIntT); 2004 tcase_add_test(tc_core, setDoubleSmallIntT); 2005 tcase_add_test(tc_core, setInt32SmallIntT); 2006 tcase_add_test(tc_core, setUint32SmallIntT); 2007 tcase_add_test(tc_core, setUint64SmallIntT); 2008 tcase_add_test(tc_core, setSSmallIntT); 2009 tcase_add_test(tc_core, setSmallBoolSmallIntT); 2010 tcase_add_test(tc_core, setSmallDoubleSmallIntT); 2011 tcase_add_test(tc_core, setSmallIntSmallIntT); 2012 tcase_add_test(tc_core, setSmallJsonSmallIntT); 2013 tcase_add_test(tc_core, setSmallStringSmallIntT); 2014 tcase_add_test(tc_core, getPSmallIntT); 2015 tcase_add_test(tc_core, equalSmallIntChaT); 2016 tcase_add_test(tc_core, equalSmallIntCharT); 2017 tcase_add_test(tc_core, equalSmallIntBaseT); 2018 tcase_add_test(tc_core, equalSmallIntBoolT); 2019 tcase_add_test(tc_core, equalSmallIntDoubleT); 2020 tcase_add_test(tc_core, equalSmallIntInt64T); 2021 tcase_add_test(tc_core, equalSmallIntInt32T); 2022 tcase_add_test(tc_core, equalSmallIntUint32T); 2023 tcase_add_test(tc_core, equalSmallIntUint64T); 2024 tcase_add_test(tc_core, equalSmallIntSmallBoolT); 2025 tcase_add_test(tc_core, equalSmallIntSmallBytesT); 2026 tcase_add_test(tc_core, equalSmallIntSmallDoubleT); 2027 tcase_add_test(tc_core, equalSmallIntT); 2028 tcase_add_test(tc_core, equalSmallIntSmallJsonT); 2029 tcase_add_test(tc_core, equalSmallIntSmallStringT); 2030 tcase_add_test(tc_core, readFileSmallIntT); 2031 tcase_add_test(tc_core, readFileSmallJsonSmallIntT); 2032 tcase_add_test(tc_core, readFileSmallStringSmallIntT); 2033 tcase_add_test(tc_core, readStreamSmallIntT); 2034 tcase_add_test(tc_core, writeFileSmallIntT); 2035 tcase_add_test(tc_core, writeFileSmallJsonSmallIntT); 2036 tcase_add_test(tc_core, writeFileSmallStringSmallIntT); 2037 tcase_add_test(tc_core, writeStreamSmallIntT); 2038 tcase_add_test(tc_core, appendFileSmallIntT); 2039 tcase_add_test(tc_core, appendFileSmallStringSmallIntT); 2040 tcase_add_test(tc_core, duplicateSmallIntGT); 2041 tcase_add_test(tc_core, freeSmallIntGT); 2042 tcase_add_test(tc_core, getIntSmallIntGT); 2043 tcase_add_test(tc_core, getIntPSmallIntGT); 2044 tcase_add_test(tc_core, getInt32SmallIntGT); 2045 tcase_add_test(tc_core, getInt32PSmallIntGT); 2046 tcase_add_test(tc_core, getUintSmallIntGT); 2047 tcase_add_test(tc_core, getUintPSmallIntGT); 2048 tcase_add_test(tc_core, getUint32SmallIntGT); 2049 tcase_add_test(tc_core, getUint32PSmallIntGT); 2050 tcase_add_test(tc_core, setBoolSmallIntGT); 2051 tcase_add_test(tc_core, setDoubleSmallIntGT); 2052 tcase_add_test(tc_core, setInt32SmallIntGT); 2053 tcase_add_test(tc_core, setUint32SmallIntGT); 2054 tcase_add_test(tc_core, setUint64SmallIntGT); 2055 tcase_add_test(tc_core, setSSmallIntGT); 2056 tcase_add_test(tc_core, setSmallBoolSmallIntGT); 2057 tcase_add_test(tc_core, setSmallDoubleSmallIntGT); 2058 tcase_add_test(tc_core, setSmallIntSmallIntGT); 2059 tcase_add_test(tc_core, setSmallJsonSmallIntGT); 2060 tcase_add_test(tc_core, setSmallStringSmallIntGT); 2061 tcase_add_test(tc_core, equalSmallIntChaGT); 2062 tcase_add_test(tc_core, equalSmallIntCharGT); 2063 tcase_add_test(tc_core, equalSmallIntBaseGT); 2064 tcase_add_test(tc_core, equalSmallIntBoolGT); 2065 tcase_add_test(tc_core, equalSmallIntDoubleGT); 2066 tcase_add_test(tc_core, equalSmallIntInt64GT); 2067 tcase_add_test(tc_core, equalSmallIntInt32GT); 2068 tcase_add_test(tc_core, equalSmallIntUint32GT); 2069 tcase_add_test(tc_core, equalSmallIntUint64GT); 2070 tcase_add_test(tc_core, equalSmallIntSmallBoolGT); 2071 tcase_add_test(tc_core, equalSmallIntSmallBytesGT); 2072 tcase_add_test(tc_core, equalSmallIntSmallDoubleGT); 2073 tcase_add_test(tc_core, equalSmallIntFGT); 2074 tcase_add_test(tc_core, equalSmallIntSmallJsonGT); 2075 tcase_add_test(tc_core, equalSmallIntSmallStringGT); 2076 tcase_add_test(tc_core, readFileSmallIntGT); 2077 tcase_add_test(tc_core, readFileSmallJsonSmallIntGT); 2078 tcase_add_test(tc_core, readFileSmallStringSmallIntGT); 2079 tcase_add_test(tc_core, readStreamSmallIntGT); 2080 tcase_add_test(tc_core, writeFileSmallIntGT); 2081 tcase_add_test(tc_core, writeFileSmallJsonSmallIntGT); 2082 tcase_add_test(tc_core, writeFileSmallStringSmallIntGT); 2083 tcase_add_test(tc_core, writeStreamSmallIntGT); 2084 tcase_add_test(tc_core, appendFileSmallIntFGT); 2085 tcase_add_test(tc_core, appendFileSmallStringSmallIntGT); 2086 2087 suite_add_tcase(s, tc_core); 2088 2089 return s; 2090 } 2091 2092 int main(int ARGC UNUSED, char** ARGV UNUSED) { 2093 int number_failed; 2094 Suite *s; 2095 SRunner *sr; 2096 2097 s = libsheepySuite(); 2098 sr = srunner_create(s); 2099 2100 srunner_run_all(sr, CK_NORMAL); 2101 number_failed = srunner_ntests_failed(sr); 2102 srunner_free(sr); 2103 2104 exit((number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE); 2105 } 2106 // vim: set expandtab ts=2 sw=2: