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