libsheepyCSmallBytesTestMem.c (37649B)
1 #include <stdlib.h> 2 #include <stdio.h> 3 #include <string.h> 4 5 #define ck_assert_str_eq(a,b) a;b; 6 #define ck_assert_str_ne(a,b) a;b; 7 #define ck_assert_ptr_eq(a,b) a;b; 8 #define ck_assert_ptr_ne(a,b) a;b; 9 #define ck_assert_uint_eq(a,b) a;b; 10 #define ck_assert_uint_ne(a,b) a;b; 11 #define ck_assert_int_eq(a,b) a;b; 12 #define ck_assert_int_ne(a,b) a;b; 13 #define ck_assert(a) a; 14 15 16 #include "../libsheepy.h" 17 #include "../libsheepyObject.h" 18 19 #ifdef __GNUC__ 20 #define UNUSED __attribute__ ((unused)) 21 #else 22 #define UNUSED 23 #endif 24 25 // TODO redirect stderr 26 27 28 void initiateSmallBytesT(void) { 29 30 smallBytest self; 31 32 initiateSmallBytes(&self); 33 char *s = toStringO(&self); 34 ck_assert_str_eq(s, "[]"); 35 free(s); 36 37 } 38 39 40 void initiateAllocateSmallBytesT(void) { 41 42 smallBytest *self; 43 44 initiateAllocateSmallBytes(&self); 45 char *s = toStringO(self); 46 ck_assert_str_eq(s, "[]"); 47 free(s); 48 terminateO(self); 49 50 } 51 52 53 void allocSmallBytesT(void) { 54 55 smallBytest* r; 56 57 r = allocSmallBytes("qwe", sizeof("qwe")); 58 char *s = toStringO(r); 59 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 60 free(s); 61 terminateO(r); 62 63 } 64 65 66 void freeSmallBytesT(void) { 67 68 createAllocateSmallBytes(self); 69 70 self->f->set(self, "qwe", sizeof("qwe")); 71 freeO(self); 72 char *s = toStringO(self); 73 ck_assert_str_eq(s, "[]"); 74 free(s); 75 terminateO(self); 76 77 } 78 79 80 void terminateSmallBytesT(void) { 81 82 createAllocateSmallBytes(self); 83 84 terminateO(self); 85 ck_assert_ptr_eq(self, null); 86 87 } 88 89 90 void finishSmallBytesT(void) { 91 92 createAllocateSmallBytes(self); 93 94 finishO(self); 95 ck_assert_ptr_eq(self, null); 96 97 } 98 99 100 void toStringSmallBytesT(void) { 101 102 char* r; 103 createAllocateSmallBytes(self); 104 105 r = toStringO(self); 106 ck_assert_str_eq(r, "[]"); 107 free(r); 108 self->f->set(self, "qwe", sizeof("qwe")); 109 r = toStringO(self); 110 ck_assert_str_eq(r, "[0x71,0x77,0x65,0x00]"); 111 free(r); 112 terminateO(self); 113 114 } 115 116 117 void duplicateSmallBytesT(void) { 118 119 smallBytest* r; 120 createAllocateSmallBytes(self); 121 122 self->f->set(self, "qwe", sizeof("qwe")); 123 r = duplicateO(self); 124 ck_assert_ptr_ne(r, null); 125 char *s = toStringO(r); 126 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 127 free(s); 128 terminateO(r); 129 terminateO(self); 130 131 } 132 133 134 void getSmallBytesT(void) { 135 136 void* r; 137 createAllocateSmallBytes(self); 138 139 self->f->set(self, "qwe", sizeof("qwe")); 140 r = getValO(self); 141 ck_assert_ptr_ne(r, null); 142 char *s = r; 143 ck_assert_str_eq(s, "qwe"); 144 terminateO(self); 145 146 } 147 148 149 void setSmallBytesT(void) { 150 151 smallBytest* r; 152 createAllocateSmallBytes(self); 153 154 r = self->f->set(self, "123", sizeof("123")); 155 ck_assert_ptr_ne(r, null); 156 r = self->f->set(self, "qwe", sizeof("qwe")); 157 ck_assert_ptr_ne(r, null); 158 char *s = toStringO(r); 159 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 160 free(s); 161 terminateO(self); 162 163 } 164 165 166 void pushSmallBytesT(void) { 167 168 smallBytest* r; 169 createAllocateSmallBytes(self); 170 171 r = pushO(self, 'a'); 172 ck_assert_ptr_ne(r, null); 173 char *s = toStringO(r); 174 ck_assert_str_eq(s, "[0x61]"); 175 free(s); 176 terminateO(self); 177 178 } 179 180 181 void pushBufferSmallBytesT(void) { 182 183 smallBytest* r; 184 createAllocateSmallBytes(self); 185 186 r = self->f->set(self, "123", sizeof("123")); 187 ck_assert_ptr_ne(r, null); 188 r = pushBufferO(self, "qwe", sizeof("qwe")); 189 ck_assert_ptr_ne(r, null); 190 char *s = toStringO(r); 191 ck_assert_str_eq(s, "[0x31,0x32,0x33,0x00,0x71,0x77,0x65,0x00]"); 192 free(s); 193 terminateO(self); 194 195 } 196 197 198 void getAtSmallBytesT(void) { 199 200 char r; 201 createAllocateSmallBytes(self); 202 203 // empty smallBytes 204 r = getAtO(self, 0); 205 ck_assert_int_eq(r, 0); 206 // get byte 207 self->f->set(self, "qwe", sizeof("qwe")); 208 r = getAtO(self, 0); 209 ck_assert_int_eq(r, 0x71); 210 // negative index 211 r = getAtO(self, -2); 212 ck_assert_int_eq(r, 0x65); 213 // outside buffer 214 r = getAtO(self, -5); 215 ck_assert_int_eq(r, 0); 216 terminateO(self); 217 218 } 219 220 221 void lenSmallBytesT(void) { 222 223 size_t r; 224 createAllocateSmallBytes(self); 225 226 // empty smallBytes 227 r = lenO(self); 228 ck_assert_int_eq(r, 0); 229 // length 230 self->f->set(self, "qwe", sizeof("qwe")); 231 r = lenO(self); 232 ck_assert_int_eq(r, 4); 233 terminateO(self); 234 235 } 236 237 238 void isEmptySmallBytesT(void) { 239 240 bool r; 241 createAllocateSmallBytes(self); 242 243 r = isEmptyO(self); 244 ck_assert(r); 245 // non empty 246 self->f->set(self, "qwe", sizeof("qwe")); 247 r = isEmptyO(self); 248 ck_assert(!r); 249 terminateO(self); 250 251 } 252 253 254 void readFileSmallBytesT(void) { 255 256 smallBytest* r; 257 createAllocateSmallBytes(self); 258 const char *filePath = "smallBytes.bin"; 259 260 self->f->set(self, "qwe", sizeof("qwe")); 261 writeFileO(self, filePath); 262 freeO(self); 263 r = readFileO(self, filePath); 264 ck_assert_ptr_ne(r, null); 265 char *s = toStringO(r); 266 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 267 free(s); 268 rmAll(filePath); 269 // empty file 270 FILE *f = fopen("empty.file", "w"); 271 fclose(f); 272 r = readFileO(self, "empty.file"); 273 rmAll("empty.file"); 274 ck_assert_ptr_ne(r, null); 275 s = toStringO(r); 276 ck_assert_str_eq(s, "[]"); 277 free(s); 278 // non existing file 279 r = readFileO(self, "nonexistingfile"); 280 ck_assert_ptr_eq(r, null); 281 // blank path 282 r = readFileO(self, " "); 283 ck_assert_ptr_eq(r, null); 284 // null path 285 r = readFileO(self, null); 286 ck_assert_ptr_eq(r, null); 287 terminateO(self); 288 289 } 290 291 292 void readFileSmallJsonSmallBytesT(void) { 293 294 smallBytest* r; 295 createAllocateSmallBytes(self); 296 smallJsont *filePath = allocSmallJson(); 297 setTopSO(filePath, "smallBytes.bin"); 298 299 self->f->set(self, "qwe", sizeof("qwe")); 300 writeFileO(self, sjGet(filePath)); 301 r = pushBufferO(self, "qwe", sizeof("qwe")); 302 ck_assert_ptr_ne(r, null); 303 r = self->f->readFileSmallJson(self, filePath); 304 ck_assert_ptr_ne(r, null); 305 char *s = toStringO(r); 306 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 307 free(s); 308 rmAll(sjGet(filePath)); 309 // empty file 310 FILE *f = fopen("empty.file", "w"); 311 fclose(f); 312 freeO(filePath); 313 setTopSO(filePath, "empty.file"); 314 r = self->f->readFileSmallJson(self, filePath); 315 rmAll("empty.file"); 316 s = toStringO(r); 317 ck_assert_str_eq(s, "[]"); 318 free(s); 319 // non existing file 320 freeO(filePath); 321 setTopSO(filePath, "nonexistingfile"); 322 r = self->f->readFileSmallJson(self, filePath); 323 ck_assert_ptr_eq(r, null); 324 // blank path 325 freeO(filePath); 326 setTopSO(filePath, " "); 327 r = self->f->readFileSmallJson(self, filePath); 328 ck_assert_ptr_eq(r, null); 329 // null path 330 r = self->f->readFileSmallJson(self, null); 331 ck_assert_ptr_eq(r, null); 332 // non string json 333 freeO(filePath); 334 setTopIntO(filePath, 101); 335 r = self->f->readFileSmallJson(self, filePath); 336 ck_assert_ptr_eq(r, null); 337 terminateO(filePath); 338 // non smallJson object 339 filePath = (smallJsont*)allocSmallBool(true); 340 r = self->f->readFileSmallJson(self, filePath); 341 ck_assert_ptr_eq(r, null); 342 terminateO(filePath); 343 terminateO(self); 344 345 } 346 347 348 void readFileSmallStringSmallBytesT(void) { 349 350 smallBytest* r; 351 createAllocateSmallBytes(self); 352 smallStringt *filePath = allocSmallString("smallBytes.bin"); 353 354 self->f->set(self, "qwe", sizeof("qwe")); 355 writeFileO(self, ssGet(filePath)); 356 r = pushBufferO(self, "qwe", sizeof("qwe")); 357 ck_assert_ptr_ne(r, null); 358 r = self->f->readFileSmallString(self, filePath); 359 ck_assert_ptr_ne(r, null); 360 char *s = toStringO(r); 361 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 362 free(s); 363 rmAll(ssGet(filePath)); 364 // empty file 365 FILE *f = fopen("empty.file", "w"); 366 fclose(f); 367 setValO(filePath, "empty.file"); 368 r = self->f->readFileSmallString(self, filePath); 369 rmAll("empty.file"); 370 s = toStringO(r); 371 ck_assert_str_eq(s, "[]"); 372 free(s); 373 // non existing file 374 freeO(filePath); 375 setValO(filePath, "nonexistingfile"); 376 r = self->f->readFileSmallString(self, filePath); 377 ck_assert_ptr_eq(r, null); 378 // blank path 379 freeO(filePath); 380 setValO(filePath, " "); 381 r = self->f->readFileSmallString(self, filePath); 382 ck_assert_ptr_eq(r, null); 383 terminateO(filePath); 384 // null path 385 r = self->f->readFileSmallString(self, null); 386 ck_assert_ptr_eq(r, null); 387 // non smallString object 388 filePath = (smallStringt*)allocSmallBool(true); 389 r = self->f->readFileSmallString(self, filePath); 390 ck_assert_ptr_eq(r, null); 391 terminateO(filePath); 392 terminateO(self); 393 394 } 395 396 397 void readStreamSmallBytesT(void) { 398 399 smallBytest* r; 400 createAllocateSmallBytes(self); 401 FILE *fp; 402 const char *filePath = "smallBool.bin"; 403 404 self->f->set(self, "qwe", sizeof("qwe")); 405 writeFileO(self, filePath); 406 r = pushBufferO(self, "qwe", sizeof("qwe")); 407 ck_assert_ptr_ne(r, null); 408 fp = fopen("smallBool.bin", "r"); 409 r = readStreamO(self, fp); 410 ck_assert_ptr_ne(r, null); 411 fclose(fp); 412 char *s = toStringO(r); 413 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 414 free(s); 415 // empty smallBytes 416 freeO(self); 417 fp = fopen("smallBool.bin", "r"); 418 r = readStreamO(self, fp); 419 ck_assert_ptr_ne(r, null); 420 fclose(fp); 421 s = toStringO(r); 422 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 423 free(s); 424 rmAll(filePath); 425 // non existing file 426 r = readStreamO(self, null); 427 ck_assert_ptr_eq(r, null); 428 // empty file 429 FILE *f = fopen("empty.file", "w"); 430 fclose(f); 431 fp = fopen("empty.file", "r"); 432 r = readStreamO(self, fp); 433 rmAll("empty.file"); 434 ck_assert_ptr_ne(r, null); 435 s = toStringO(r); 436 ck_assert_str_eq(s, "[]"); 437 free(s); 438 fclose(fp); 439 terminateO(self); 440 441 } 442 443 444 void writeFileSmallBytesT(void) { 445 446 int r; 447 createAllocateSmallBytes(self); 448 const char *filePath = "smallBool.bin"; 449 450 self->f->set(self, "qwe", sizeof("qwe")); 451 r = writeFileO(self, filePath); 452 ck_assert_int_eq(r, 1); 453 freeO(self); 454 smallBytest *r2 = readFileO(self, filePath); 455 ck_assert_ptr_ne(r2, null); 456 char *s = toStringO(r2); 457 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 458 free(s); 459 // non writable path 460 r = writeFileO(self, "/nonexisting/readonly"); 461 ck_assert_int_eq(r, 0); 462 // blank path 463 r = writeFileO(self, " "); 464 ck_assert_int_eq(r, 0); 465 // null path 466 r = writeFileO(self, null); 467 ck_assert_int_eq(r, 0); 468 // empty smallBytes 469 freeO(self); 470 r = writeFileO(self, filePath); 471 ck_assert_int_eq(r, 0); 472 terminateO(self); 473 rmAll("smallBool.bin"); 474 475 } 476 477 478 void writeFileSmallJsonSmallBytesT(void) { 479 480 int r; 481 createAllocateSmallBytes(self); 482 smallJsont *filePath = allocSmallJson(); 483 setTopSO(filePath, "smallBool.bin"); 484 485 self->f->set(self, "qwe", sizeof("qwe")); 486 r = self->f->writeFileSmallJson(self, filePath); 487 ck_assert_int_eq(r, 1); 488 freeO(self); 489 smallBytest *r2 = readFileO(self, sjGet(filePath)); 490 ck_assert_ptr_ne(r2, null); 491 char *s = toStringO(r2); 492 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 493 free(s); 494 // non writable path 495 freeO(filePath); 496 setTopSO(filePath, "/nonexistingfile/readonly"); 497 r = self->f->writeFileSmallJson(self, filePath); 498 ck_assert_int_eq(r, 0); 499 // blank path 500 freeO(filePath); 501 setTopSO(filePath, " "); 502 r = self->f->writeFileSmallJson(self, filePath); 503 ck_assert_int_eq(r, 0); 504 // null path 505 r = self->f->writeFileSmallJson(self, null); 506 ck_assert_int_eq(r, 0); 507 // empty smallBool 508 freeO(self); 509 freeO(filePath); 510 setTopSO(filePath, "smallBool.bin"); 511 r = self->f->writeFileSmallJson(self, filePath); 512 ck_assert_int_eq(r, 0); 513 // non string json 514 freeO(filePath); 515 setTopIntO(filePath, 101); 516 r = self->f->writeFileSmallJson(self, filePath); 517 ck_assert_int_eq(r, 0); 518 terminateO(filePath); 519 // non smallJson object 520 filePath = (smallJsont*)allocSmallBool(true); 521 r = self->f->writeFileSmallJson(self, filePath); 522 ck_assert_int_eq(r, 0); 523 terminateO(filePath); 524 terminateO(self); 525 rmAll("smallBool.bin"); 526 527 } 528 529 530 void writeFileSmallStringSmallBytesT(void) { 531 532 int r; 533 createAllocateSmallBytes(self); 534 smallStringt *filePath = allocSmallString("smallBool.bin"); 535 536 self->f->set(self, "qwe", sizeof("qwe")); 537 r = self->f->writeFileSmallString(self, filePath); 538 ck_assert_int_eq(r, 1); 539 freeO(self); 540 smallBytest *r2 = readFileO(self, ssGet(filePath)); 541 ck_assert_ptr_ne(r2, null); 542 char *s = toStringO(r2); 543 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 544 free(s); 545 // non writable path 546 setValO(filePath, "/nonexistingfile/readonly"); 547 r = self->f->writeFileSmallString(self, filePath); 548 ck_assert_int_eq(r, 0); 549 // blank path 550 setValO(filePath, " "); 551 r = self->f->writeFileSmallString(self, filePath); 552 ck_assert_int_eq(r, 0); 553 // null path 554 r = self->f->writeFileSmallString(self, null); 555 ck_assert_int_eq(r, 0); 556 // empty smallBytes 557 freeO(self); 558 setValO(filePath, "smallBool.bin"); 559 r = self->f->writeFileSmallString(self, filePath); 560 ck_assert_int_eq(r, 0); 561 terminateO(filePath); 562 // non smallString object 563 filePath = (smallStringt*)allocSmallBool(true); 564 r = self->f->writeFileSmallString(self, filePath); 565 ck_assert_int_eq(r, 0); 566 terminateO(filePath); 567 terminateO(self); 568 rmAll("smallBool.bin"); 569 terminateO(self); 570 571 } 572 573 574 void writeStreamSmallBytesT(void) { 575 576 int r; 577 createAllocateSmallBytes(self); 578 FILE *fp; 579 const char *filePath = "smallBool.bin"; 580 581 self->f->set(self, "qwe", sizeof("qwe")); 582 fp = fopen(filePath, "w"); 583 r = writeStreamO(self, fp); 584 ck_assert_int_eq(r, 1); 585 fclose(fp); 586 freeO(self); 587 smallBytest *r2 = readFileO(self, filePath); 588 ck_assert_ptr_ne(r2, null); 589 char *s = toStringO(r2); 590 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 591 free(s); 592 // null file 593 r = writeStreamO(self, null); 594 ck_assert_int_eq(r, 0); 595 // empty smallBytes 596 freeO(self); 597 fp = fopen(filePath, "w"); 598 r = writeStreamO(self, fp); 599 ck_assert_int_eq(r, 0); 600 fclose(fp); 601 terminateO(self); 602 rmAll(filePath); 603 604 } 605 606 607 void appendFileSmallBytesT(void) { 608 609 int r; 610 createAllocateSmallBytes(self); 611 const char *filePath = "smallBool.bin"; 612 613 // append to empty file 614 self->f->set(self, "qwe", sizeof("qwe")); 615 FILE *f = fopen(filePath, "w"); 616 fclose(f); 617 r = appendFileO(self, filePath); 618 ck_assert_int_eq(r, 1); 619 freeO(self); 620 smallBytest *r2 = readFileO(self, filePath); 621 ck_assert_ptr_ne(r2, null); 622 char *s = toStringO(r2); 623 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 624 free(s); 625 // append 626 self->f->set(self, "123", sizeof("123")); 627 r = appendFileO(self, filePath); 628 ck_assert_int_eq(r, 1); 629 r2 = readFileO(self, filePath); 630 ck_assert_ptr_ne(r2, null); 631 s = toStringO(r2); 632 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00,0x31,0x32,0x33,0x00]"); 633 free(s); 634 // non existing file 635 r = appendFileO(self, "/nonexisting/readonly"); 636 ck_assert_int_eq(r, 0); 637 // blank path 638 r = appendFileO(self, " "); 639 ck_assert_int_eq(r, 0); 640 // null path 641 r = appendFileO(self, null); 642 ck_assert_int_eq(r, 0); 643 // empty smallBytes 644 freeO(self); 645 r = appendFileO(self, filePath); 646 ck_assert_int_eq(r, 0); 647 terminateO(self); 648 rmAll("smallBool.bin"); 649 650 } 651 652 653 void appendFileSmallStringSmallBytesT(void) { 654 655 int r; 656 createAllocateSmallBytes(self); 657 smallStringt *filePath = allocSmallString("smallBool.bin"); 658 659 self->f->set(self, "qwe", sizeof("qwe")); 660 FILE *f = fopen(ssGet(filePath), "w"); 661 fclose(f); 662 r = appendFileSmallStringO(self, filePath); 663 ck_assert_int_eq(r, 1); 664 freeO(self); 665 smallBytest *r2 = readFileO(self, ssGet(filePath)); 666 ck_assert_ptr_ne(r2, null); 667 char *s = toStringO(r2); 668 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 669 free(s); 670 // non existing file 671 setValO(filePath, "/nonexisting/readonly"); 672 r = appendFileSmallStringO(self, filePath); 673 ck_assert_int_eq(r, 0); 674 // blank path 675 setValO(filePath, " "); 676 r = appendFileSmallStringO(self, filePath); 677 ck_assert_int_eq(r, 0); 678 // null path 679 r = appendFileSmallStringO(self, null); 680 ck_assert_int_eq(r, 0); 681 // empty smallBytes 682 freeO(self); 683 setValO(filePath, "smallBool.bin"); 684 r = appendFileSmallStringO(self, filePath); 685 ck_assert_int_eq(r, 0); 686 terminateO(filePath); 687 terminateO(self); 688 rmAll("smallBool.bin"); 689 690 } 691 692 693 void equalSmallBytesT(void) { 694 695 bool r; 696 createAllocateSmallBytes(self); 697 smallBytest *value = allocSmallBytes("qwe", sizeof("qwe")); 698 699 // equal 700 self->f->set(self, "qwe", sizeof("qwe")); 701 r = equalO(self, value); 702 ck_assert(r); 703 // non equal 704 self->f->set(self, "Qwe", sizeof("qwe")); 705 r = equalO(self, value); 706 ck_assert(!r); 707 // different size 708 self->f->set(self, "qwe", sizeof("qwe")); 709 pushO(value, '?'); 710 r = equalO(self, value); 711 ck_assert(!r); 712 // empty smallBytes 713 freeO(value); 714 r = equalO(self, value); 715 ck_assert(!r); 716 // empty self 717 value->f->set(value, "qwe", sizeof("qwe")); 718 freeO(self); 719 r = equalO(self, value); 720 ck_assert(!r); 721 // null value 722 self->f->set(self, "qwe", sizeof("qwe")); 723 r = equalO(self, null); 724 ck_assert(!r); 725 terminateO(value); 726 terminateO(self); 727 728 } 729 730 731 void equalSmallBytesBoolT(void) { 732 733 bool r; 734 createAllocateSmallBytes(self); 735 bool value = true; 736 737 // equal 738 self->f->set(self, "true", sizeof("true")); 739 r = self->f->equalBool(self, value); 740 ck_assert(r); 741 self->f->set(self, "FALSE", sizeof("FALSE")); 742 value = false; 743 r = self->f->equalBool(self, value); 744 ck_assert(r); 745 // non equal 746 self->f->set(self, "True", sizeof("True")); 747 value = true; 748 r = self->f->equalBool(self, value); 749 ck_assert(!r); 750 value = false; 751 r = self->f->equalBool(self, value); 752 ck_assert(!r); 753 // different size 754 self->f->set(self, "qwe", sizeof("qwe")); 755 r = self->f->equalBool(self, value); 756 ck_assert(!r); 757 // empty self 758 freeO(self); 759 r = self->f->equalBool(self, value); 760 ck_assert(!r); 761 terminateO(self); 762 763 } 764 765 766 void equalSmallBytesDoubleT(void) { 767 768 bool r; 769 createAllocateSmallBytes(self); 770 double value = 1.5; 771 772 self->f->set(self, "1.500000", sizeof("1.500000")); 773 pushO(self, '!'); 774 r = self->f->equalDouble(self, value); 775 ck_assert(r); 776 // non equal 777 self->f->set(self, "1.500000", strlen("1.500000")); 778 r = self->f->equalDouble(self, value); 779 ck_assert(!r); 780 // not a double 781 self->f->set(self, "1", sizeof("1")); 782 r = self->f->equalDouble(self, value); 783 ck_assert(!r); 784 // empty self 785 freeO(self); 786 r = self->f->equalDouble(self, value); 787 ck_assert(!r); 788 terminateO(self); 789 790 } 791 792 793 void equalSmallBytesInt64T(void) { 794 795 bool r; 796 createAllocateSmallBytes(self); 797 int64_t value = 2; 798 799 self->f->set(self, "2", sizeof("2")); 800 pushO(self, '!'); 801 r = self->f->equalInt64(self, value); 802 ck_assert(r); 803 // non equal 804 self->f->set(self, "1", sizeof("1")); 805 r = self->f->equalInt64(self, value); 806 ck_assert(!r); 807 // not an int 808 self->f->set(self, "1.500000", sizeof("1.500000")); 809 r = self->f->equalInt64(self, value); 810 ck_assert(!r); 811 self->f->set(self, "1.500000", strlen("1.500000")); 812 r = self->f->equalInt64(self, value); 813 ck_assert(!r); 814 // empty self 815 freeO(self); 816 r = self->f->equalInt64(self, value); 817 ck_assert(!r); 818 terminateO(self); 819 820 } 821 822 823 void equalSmallBytesInt32T(void) { 824 825 bool r; 826 createAllocateSmallBytes(self); 827 int32_t value = 2; 828 829 self->f->set(self, "2", sizeof("2")); 830 pushO(self, '!'); 831 r = self->f->equalInt32(self, value); 832 ck_assert(r); 833 // non equal 834 self->f->set(self, "1", sizeof("1")); 835 r = self->f->equalInt32(self, value); 836 ck_assert(!r); 837 // not an int 838 self->f->set(self, "1.500000", sizeof("1.500000")); 839 r = self->f->equalInt32(self, value); 840 ck_assert(!r); 841 self->f->set(self, "1.500000", strlen("1.500000")); 842 r = self->f->equalInt32(self, value); 843 ck_assert(!r); 844 // empty self 845 freeO(self); 846 r = self->f->equalInt32(self, value); 847 ck_assert(!r); 848 terminateO(self); 849 850 } 851 852 853 void equalSmallBytesUint32T(void) { 854 855 bool r; 856 createAllocateSmallBytes(self); 857 uint32_t value = 2; 858 859 self->f->set(self, "2", sizeof("2")); 860 pushO(self, '!'); 861 r = self->f->equalUint32(self, value); 862 ck_assert(r); 863 // non equal 864 self->f->set(self, "1", sizeof("1")); 865 r = self->f->equalUint32(self, value); 866 ck_assert(!r); 867 // not an int 868 self->f->set(self, "1.500000", sizeof("1.500000")); 869 r = self->f->equalUint32(self, value); 870 ck_assert(!r); 871 self->f->set(self, "1.500000", strlen("1.500000")); 872 r = self->f->equalUint32(self, value); 873 ck_assert(!r); 874 // empty self 875 freeO(self); 876 r = self->f->equalUint32(self, value); 877 ck_assert(!r); 878 terminateO(self); 879 880 } 881 882 883 void equalSmallBytesUint64T(void) { 884 885 bool r; 886 createAllocateSmallBytes(self); 887 uint64_t value = 2; 888 889 self->f->set(self, "2", sizeof("2")); 890 pushO(self, '!'); 891 r = self->f->equalUint64(self, value); 892 ck_assert(r); 893 // non equal 894 self->f->set(self, "1", sizeof("1")); 895 r = self->f->equalUint64(self, value); 896 ck_assert(!r); 897 // not an int 898 self->f->set(self, "1.500000", sizeof("1.500000")); 899 r = self->f->equalUint64(self, value); 900 ck_assert(!r); 901 self->f->set(self, "1.500000", strlen("1.500000")); 902 r = self->f->equalUint64(self, value); 903 ck_assert(!r); 904 // empty self 905 freeO(self); 906 r = self->f->equalUint64(self, value); 907 ck_assert(!r); 908 terminateO(self); 909 910 } 911 912 913 void equalSmallBytesSmallBoolT(void) { 914 915 bool r; 916 createAllocateSmallBytes(self); 917 smallBoolt *value = allocSmallBool(true); 918 919 self->f->set(self, "true", sizeof("true")); 920 r = self->f->equalSmallBool(self, value); 921 ck_assert(r); 922 // empty value 923 freeO(value); 924 r = self->f->equalSmallBool(self, value); 925 ck_assert(!r); 926 // null value 927 r = self->f->equalSmallBool(self, null); 928 ck_assert(!r); 929 // empty self 930 setValO(value, true); 931 freeO(self); 932 r = self->f->equalSmallBool(self, value); 933 ck_assert(!r); 934 terminateO(value); 935 terminateO(self); 936 937 } 938 939 940 void equalSmallBytesSmallDoubleT(void) { 941 942 bool r; 943 createAllocateSmallBytes(self); 944 smallDoublet *value = allocSmallDouble(1.5); 945 946 self->f->set(self, "1.500000", sizeof("1.500000")); 947 r = self->f->equalSmallDouble(self, value); 948 ck_assert(r); 949 // empty value 950 freeO(value); 951 r = self->f->equalSmallDouble(self, value); 952 ck_assert(!r); 953 // null value 954 r = self->f->equalSmallDouble(self, null); 955 ck_assert(!r); 956 // empty self 957 setValO(value, 1); 958 freeO(self); 959 r = self->f->equalSmallDouble(self, value); 960 ck_assert(!r); 961 terminateO(value); 962 terminateO(self); 963 964 } 965 966 967 void equalSmallBytesSmallIntT(void) { 968 969 bool r; 970 createAllocateSmallBytes(self); 971 smallIntt *value = allocSmallInt(2); 972 973 self->f->set(self, "2", sizeof("2")); 974 r = self->f->equalSmallInt(self, value); 975 ck_assert(r); 976 // empty value 977 freeO(value); 978 r = self->f->equalSmallInt(self, value); 979 ck_assert(!r); 980 // null value 981 r = self->f->equalSmallInt(self, null); 982 ck_assert(!r); 983 // empty self 984 setValO(value, 1); 985 freeO(self); 986 r = self->f->equalSmallInt(self, value); 987 ck_assert(!r); 988 terminateO(value); 989 terminateO(self); 990 991 } 992 993 994 void equalSmallBytesCharT(void) { 995 996 bool r; 997 createAllocateSmallBytes(self); 998 const char *value = "qwe"; 999 1000 // equal 1001 self->f->set(self, "qwe", sizeof("qwe")); 1002 r = self->f->equalS(self, value); 1003 ck_assert(r); 1004 // different size 1005 r = self->f->equalS(self, "qweq"); 1006 ck_assert(!r); 1007 // null value 1008 r = self->f->equalS(self, null); 1009 ck_assert(!r); 1010 // empty self 1011 freeO(self); 1012 r = self->f->equalS(self, "qweq"); 1013 ck_assert(!r); 1014 terminateO(self); 1015 1016 } 1017 1018 1019 void equalSmallBytesSmallStringT(void) { 1020 1021 bool r; 1022 createAllocateSmallBytes(self); 1023 smallStringt *value = allocSmallString("qwe"); 1024 1025 // equal 1026 self->f->set(self, "qwe", sizeof("qwe")); 1027 r = self->f->equalSmallString(self, value); 1028 ck_assert(r); 1029 // different size 1030 setValO(value, "q"); 1031 r = self->f->equalSmallString(self, value); 1032 ck_assert(!r); 1033 // empty value 1034 freeO(value); 1035 r = self->f->equalSmallString(self, value); 1036 ck_assert(!r); 1037 // null value 1038 r = self->f->equalSmallString(self, null); 1039 ck_assert(!r); 1040 // empty self 1041 setValO(value, "q"); 1042 freeO(self); 1043 r = self->f->equalSmallString(self, value); 1044 ck_assert(!r); 1045 terminateO(value); 1046 terminateO(self); 1047 1048 } 1049 1050 1051 void equalSmallBytesBaseT(void) { 1052 1053 bool r; 1054 createAllocateSmallBytes(self); 1055 baset *value = (baset*)allocSmallBytes("qwe", sizeof("qwe")); 1056 1057 // equal smallBytes 1058 self->f->set(self, "qwe", sizeof("qwe")); 1059 r = self->f->equalBase(self, value); 1060 ck_assert(r); 1061 terminateO(value); 1062 // equal smallString 1063 value = (baset*)allocSmallString("qwe"); 1064 r = self->f->equalBase(self, value); 1065 ck_assert(r); 1066 // unsupport base object 1067 terminateO(value); 1068 value = (baset*)allocSmallInt(1); 1069 r = self->f->equalBase(self, value); 1070 ck_assert(!r); 1071 // null parameter 1072 r = self->f->equalBase(self, null); 1073 ck_assert(!r); 1074 // empty self 1075 freeO(self); 1076 r = self->f->equalBase(self, value); 1077 ck_assert(!r); 1078 terminateO(value); 1079 terminateO(self); 1080 1081 } 1082 1083 1084 void duplicateSmallBytesGT(void) { 1085 1086 smallBytest* r; 1087 createAllocateSmallBytes(self); 1088 1089 self->f->set(self, "qwe", sizeof("qwe")); 1090 r = duplicateSmallBytesG(self); 1091 char *s = toStringO(r); 1092 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 1093 free(s); 1094 terminateO(r); 1095 terminateO(self); 1096 1097 } 1098 1099 1100 void freeSmallBytesGT(void) { 1101 1102 createAllocateSmallBytes(self); 1103 1104 self->f->set(self, "qwe", sizeof("qwe")); 1105 freeSmallBytesG(self); 1106 char *s = toStringO(self); 1107 ck_assert_str_eq(s, "[]"); 1108 free(s); 1109 terminateO(self); 1110 1111 } 1112 1113 1114 void getAtSmallBytesGT(void) { 1115 1116 char r; 1117 createAllocateSmallBytes(self); 1118 1119 self->f->set(self, "qwe", sizeof("qwe")); 1120 r = getAtSmallBytesG(self, 'x', 0); 1121 ck_assert_int_eq(r, 'q'); 1122 terminateO(self); 1123 1124 } 1125 1126 1127 void pushSmallBytesGT(void) { 1128 1129 smallBytest* r; 1130 createAllocateSmallBytes(self); 1131 1132 self->f->set(self, "qwe", sizeof("qwe")); 1133 r = pushSmallBytesG(self, '='); 1134 char *s = toStringO(r); 1135 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00,0x3d]"); 1136 free(s); 1137 terminateO(self); 1138 1139 } 1140 1141 1142 void lenSmallBytesGT(void) { 1143 1144 size_t r; 1145 createAllocateSmallBytes(self); 1146 1147 self->f->set(self, "qwe", sizeof("qwe")); 1148 r = lenSmallBytesG(self); 1149 ck_assert_int_eq(r, 4); 1150 terminateO(self); 1151 1152 } 1153 1154 1155 void isEmptySmallBytesGT(void) { 1156 1157 bool r; 1158 createAllocateSmallBytes(self); 1159 1160 r = isEmptySmallBytesG(self); 1161 ck_assert(r); 1162 terminateO(self); 1163 1164 } 1165 1166 1167 void readFileSmallBytesGT(void) { 1168 1169 smallBytest* r; 1170 createAllocateSmallBytes(self); 1171 const char *filePath = "smallBytes.bin"; 1172 1173 self->f->set(self, "qwe", sizeof("qwe")); 1174 writeFileO(self, filePath); 1175 freeO(self); 1176 r = readFileSmallBytesG(self, filePath); 1177 ck_assert_ptr_ne(r, null); 1178 char *s = toStringO(r); 1179 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 1180 free(s); 1181 rmAll(filePath); 1182 terminateO(self); 1183 1184 } 1185 1186 1187 void readFileSmallJsonSmallBytesGT(void) { 1188 1189 smallBytest* r; 1190 createAllocateSmallBytes(self); 1191 smallJsont *filePath = allocSmallJson(); 1192 1193 setTopSO(filePath, "smallBytes.bin"); 1194 1195 self->f->set(self, "qwe", sizeof("qwe")); 1196 writeFileO(self, sjGet(filePath)); 1197 r = pushBufferO(self, "qwe", sizeof("qwe")); 1198 ck_assert_ptr_ne(r, null); 1199 r = readFileSmallJsonSmallBytesG(self, filePath); 1200 ck_assert_ptr_ne(r, null); 1201 char *s = toStringO(r); 1202 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 1203 free(s); 1204 rmAll(sjGet(filePath)); 1205 terminateO(filePath); 1206 terminateO(self); 1207 1208 } 1209 1210 1211 void readFileSmallStringSmallBytesGT(void) { 1212 1213 smallBytest* r; 1214 createAllocateSmallBytes(self); 1215 smallStringt *filePath = allocSmallString("smallBytes.bin"); 1216 1217 self->f->set(self, "qwe", sizeof("qwe")); 1218 writeFileO(self, ssGet(filePath)); 1219 r = pushBufferO(self, "qwe", sizeof("qwe")); 1220 ck_assert_ptr_ne(r, null); 1221 r = readFileSmallStringSmallBytesG(self, filePath); 1222 ck_assert_ptr_ne(r, null); 1223 char *s = toStringO(r); 1224 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 1225 free(s); 1226 rmAll(ssGet(filePath)); 1227 terminateO(filePath); 1228 terminateO(self); 1229 1230 } 1231 1232 1233 void readStreamSmallBytesGT(void) { 1234 1235 smallBytest* r; 1236 createAllocateSmallBytes(self); 1237 FILE *fp; 1238 const char *filePath = "smallBool.bin"; 1239 1240 self->f->set(self, "qwe", sizeof("qwe")); 1241 writeFileO(self, filePath); 1242 r = pushBufferO(self, "qwe", sizeof("qwe")); 1243 ck_assert_ptr_ne(r, null); 1244 fp = fopen("smallBool.bin", "r"); 1245 r = readStreamSmallBytesG(self, fp); 1246 ck_assert_ptr_ne(r, null); 1247 fclose(fp); 1248 char *s = toStringO(r); 1249 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 1250 free(s); 1251 rmAll(filePath); 1252 terminateO(self); 1253 1254 } 1255 1256 1257 void writeFileSmallBytesGT(void) { 1258 1259 int r; 1260 createAllocateSmallBytes(self); 1261 const char *filePath = "smallBool.bin"; 1262 1263 self->f->set(self, "qwe", sizeof("qwe")); 1264 r = writeFileSmallBytesG(self, filePath); 1265 ck_assert_int_eq(r, 1); 1266 freeO(self); 1267 smallBytest *r2 = readFileO(self, filePath); 1268 ck_assert_ptr_ne(r2, null); 1269 char *s = toStringO(r2); 1270 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 1271 free(s); 1272 rmAll(filePath); 1273 terminateO(self); 1274 1275 } 1276 1277 1278 void writeFileSmallJsonSmallBytesGT(void) { 1279 1280 int r; 1281 createAllocateSmallBytes(self); 1282 smallJsont *filePath = allocSmallJson(); 1283 setTopSO(filePath, "smallBool.bin"); 1284 1285 self->f->set(self, "qwe", sizeof("qwe")); 1286 r = writeFileSmallJsonSmallBytesG(self, filePath); 1287 ck_assert_int_eq(r, 1); 1288 freeO(self); 1289 smallBytest *r2 = readFileO(self, sjGet(filePath)); 1290 ck_assert_ptr_ne(r2, null); 1291 char *s = toStringO(r2); 1292 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 1293 free(s); 1294 terminateO(filePath); 1295 terminateO(self); 1296 rmAll("smallBool.bin"); 1297 1298 } 1299 1300 1301 void writeFileSmallStringSmallBytesGT(void) { 1302 1303 int r; 1304 createAllocateSmallBytes(self); 1305 smallStringt *filePath = allocSmallString("smallBool.bin"); 1306 1307 self->f->set(self, "qwe", sizeof("qwe")); 1308 r = writeFileSmallStringSmallBytesG(self, filePath); 1309 ck_assert_int_eq(r, 1); 1310 freeO(self); 1311 smallBytest *r2 = readFileO(self, ssGet(filePath)); 1312 ck_assert_ptr_ne(r2, null); 1313 char *s = toStringO(r2); 1314 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 1315 free(s); 1316 terminateO(filePath); 1317 terminateO(self); 1318 rmAll("smallBool.bin"); 1319 1320 } 1321 1322 1323 void writeStreamSmallBytesGT(void) { 1324 1325 int r; 1326 createAllocateSmallBytes(self); 1327 FILE *fp; 1328 const char *filePath = "smallBool.bin"; 1329 1330 self->f->set(self, "qwe", sizeof("qwe")); 1331 fp = fopen(filePath, "w"); 1332 r = writeStreamSmallBytesG(self, fp); 1333 ck_assert_int_eq(r, 1); 1334 fclose(fp); 1335 freeO(self); 1336 smallBytest *r2 = readFileO(self, filePath); 1337 ck_assert_ptr_ne(r2, null); 1338 char *s = toStringO(r2); 1339 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 1340 free(s); 1341 terminateO(self); 1342 rmAll(filePath); 1343 1344 } 1345 1346 1347 void appendFileSmallBytesGT(void) { 1348 1349 int r; 1350 createAllocateSmallBytes(self); 1351 const char *filePath = "smallBool.bin"; 1352 1353 // append to empty file 1354 self->f->set(self, "qwe", sizeof("qwe")); 1355 FILE *f = fopen(filePath, "w"); 1356 fclose(f); 1357 r = appendFileSmallBytesG(self, filePath); 1358 ck_assert_int_eq(r, 1); 1359 freeO(self); 1360 smallBytest *r2 = readFileO(self, filePath); 1361 ck_assert_ptr_ne(r2, null); 1362 char *s = toStringO(r2); 1363 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 1364 free(s); 1365 terminateO(self); 1366 rmAll(filePath); 1367 1368 } 1369 1370 1371 void appendFileSmallStringSmallBytesGT(void) { 1372 1373 int r; 1374 createAllocateSmallBytes(self); 1375 smallStringt *filePath = allocSmallString("smallBool.bin"); 1376 1377 self->f->set(self, "qwe", sizeof("qwe")); 1378 FILE *f = fopen(ssGet(filePath), "w"); 1379 fclose(f); 1380 r = appendFileSmallStringSmallBytesG(self, filePath); 1381 ck_assert_int_eq(r, 1); 1382 freeO(self); 1383 smallBytest *r2 = readFileO(self, ssGet(filePath)); 1384 ck_assert_ptr_ne(r2, null); 1385 char *s = toStringO(r2); 1386 ck_assert_str_eq(s, "[0x71,0x77,0x65,0x00]"); 1387 free(s); 1388 terminateO(filePath); 1389 terminateO(self); 1390 rmAll("smallBool.bin"); 1391 1392 } 1393 1394 1395 void equalSmallBytesGT(void) { 1396 1397 bool r; 1398 createAllocateSmallBytes(self); 1399 smallBytest *value = allocSmallBytes("qwe", sizeof("qwe")); 1400 1401 // equal 1402 self->f->set(self, "qwe", sizeof("qwe")); 1403 r = equalSmallBytesG(self, value); 1404 ck_assert(r); 1405 terminateO(value); 1406 terminateO(self); 1407 1408 } 1409 1410 1411 void equalSmallBytesBoolGT(void) { 1412 1413 bool r; 1414 createAllocateSmallBytes(self); 1415 bool value = true; 1416 1417 // equal 1418 self->f->set(self, "true", sizeof("true")); 1419 r = equalSmallBytesBoolG(self, value); 1420 ck_assert(r); 1421 terminateO(self); 1422 1423 } 1424 1425 1426 void equalSmallBytesDoubleGT(void) { 1427 1428 bool r; 1429 createAllocateSmallBytes(self); 1430 double value = 1.5; 1431 1432 self->f->set(self, "1.500000", sizeof("1.500000")); 1433 pushO(self, '!'); 1434 r = equalSmallBytesDoubleG(self, value); 1435 ck_assert(r); 1436 terminateO(self); 1437 1438 } 1439 1440 1441 void equalSmallBytesInt64GT(void) { 1442 1443 bool r; 1444 createAllocateSmallBytes(self); 1445 int64_t value = 2; 1446 1447 self->f->set(self, "2", sizeof("2")); 1448 pushO(self, '!'); 1449 r = equalSmallBytesInt64G(self, value); 1450 ck_assert(r); 1451 terminateO(self); 1452 1453 } 1454 1455 1456 void equalSmallBytesInt32GT(void) { 1457 1458 bool r; 1459 createAllocateSmallBytes(self); 1460 int32_t value = 2; 1461 1462 self->f->set(self, "2", sizeof("2")); 1463 pushO(self, '!'); 1464 r = equalSmallBytesInt32G(self, value); 1465 ck_assert(r); 1466 terminateO(self); 1467 1468 } 1469 1470 1471 void equalSmallBytesUint32GT(void) { 1472 1473 bool r; 1474 createAllocateSmallBytes(self); 1475 uint32_t value = 2; 1476 1477 self->f->set(self, "2", sizeof("2")); 1478 pushO(self, '!'); 1479 r = equalSmallBytesUint32G(self, value); 1480 ck_assert(r); 1481 terminateO(self); 1482 1483 } 1484 1485 1486 void equalSmallBytesUint64GT(void) { 1487 1488 bool r; 1489 createAllocateSmallBytes(self); 1490 uint64_t value = 2; 1491 1492 self->f->set(self, "2", sizeof("2")); 1493 pushO(self, '!'); 1494 r = equalSmallBytesUint64G(self, value); 1495 ck_assert(r); 1496 terminateO(self); 1497 1498 } 1499 1500 1501 void equalSmallBytesSmallBoolGT(void) { 1502 1503 bool r; 1504 createAllocateSmallBytes(self); 1505 smallBoolt *value = allocSmallBool(true); 1506 1507 self->f->set(self, "true", sizeof("true")); 1508 r = equalSmallBytesSmallBoolG(self, value); 1509 ck_assert(r); 1510 terminateO(value); 1511 terminateO(self); 1512 1513 } 1514 1515 1516 void equalSmallBytesSmallDoubleGT(void) { 1517 1518 bool r; 1519 createAllocateSmallBytes(self); 1520 smallDoublet *value = allocSmallDouble(1.5); 1521 1522 self->f->set(self, "1.500000", sizeof("1.500000")); 1523 r = equalSmallBytesSmallDoubleG(self, value); 1524 ck_assert(r); 1525 terminateO(value); 1526 terminateO(self); 1527 1528 } 1529 1530 1531 void equalSmallBytesSmallIntGT(void) { 1532 1533 bool r; 1534 createAllocateSmallBytes(self); 1535 smallIntt *value = allocSmallInt(2); 1536 1537 self->f->set(self, "2", sizeof("2")); 1538 r = equalSmallBytesSmallIntG(self, value); 1539 ck_assert(r); 1540 terminateO(value); 1541 terminateO(self); 1542 1543 } 1544 1545 1546 void equalSmallBytesCharGT(void) { 1547 1548 bool r; 1549 createAllocateSmallBytes(self); 1550 const char *value = "qwe"; 1551 1552 // equal 1553 self->f->set(self, "qwe", sizeof("qwe")); 1554 r = equalSmallBytesCharG(self, value); 1555 ck_assert(r); 1556 terminateO(self); 1557 1558 } 1559 1560 1561 void equalSmallBytesSmallStringGT(void) { 1562 1563 bool r; 1564 createAllocateSmallBytes(self); 1565 smallStringt *value = allocSmallString("qwe"); 1566 1567 // equal 1568 self->f->set(self, "qwe", sizeof("qwe")); 1569 r = equalSmallBytesSmallStringG(self, value); 1570 ck_assert(r); 1571 terminateO(value); 1572 terminateO(self); 1573 1574 } 1575 1576 1577 void equalSmallBytesBaseGT(void) { 1578 1579 bool r; 1580 createAllocateSmallBytes(self); 1581 baset *value = (baset*)allocSmallBytes("qwe", sizeof("qwe")); 1582 1583 // equal smallBytes 1584 self->f->set(self, "qwe", sizeof("qwe")); 1585 r = equalSmallBytesBaseG(self, value); 1586 ck_assert(r); 1587 terminateO(value); 1588 terminateO(self); 1589 1590 } 1591 1592 1593 void cSmallBytesT(void) { 1594 1595 // local object 1596 createSmallBytes(obj); 1597 ck_assert_str_eq(obj.type, "smallBytes"); 1598 // object 1599 createAllocateSmallBytes(obj2); 1600 ck_assert_str_eq(obj2->type, "smallBytes"); 1601 // alloc - pushBuffer 1602 smallBytest *obj3 = allocSmallBytes(NULL, 0); 1603 terminateO(obj3); 1604 // toString 1605 char *s = obj2->f->toString(obj2); 1606 ck_assert_str_eq(s, "[]"); 1607 free(s); 1608 // duplicate 1609 obj2->B = allocSBytes(); 1610 sBytesPush(&(obj2->B), 2); 1611 obj3 = duplicateO(obj2); 1612 ck_assert_uint_eq(obj3->B->data, 2); 1613 terminateO(obj3); 1614 // get 1615 obj3 = duplicateO(obj2); 1616 char *r = obj3->f->get(obj3); 1617 ck_assert_uint_eq(*r, 2); 1618 terminateO(obj3); 1619 // push 1620 obj3 = duplicateO(obj2); 1621 obj3->f->push(obj3, 4); 1622 r = obj3->f->get(obj3); 1623 ck_assert_uint_eq(r[1], 4); 1624 terminateO(obj3); 1625 // getAt 1626 obj3 = duplicateO(obj2); 1627 char c = obj3->f->getAt(obj3,0); 1628 ck_assert_uint_eq(c, 2); 1629 c = obj3->f->getAt(obj3,1); 1630 ck_assert_uint_eq(c, 0); 1631 terminateO(obj3); 1632 // NULL 1633 initiateAllocateSmallBytes(&obj3); 1634 c = obj3->f->getAt(obj3,0); 1635 ck_assert_uint_eq(c, 0); 1636 terminateO(obj3); 1637 // free local object 1638 obj.f->free(&obj); 1639 ck_assert_str_eq(obj.type, "smallBytes"); 1640 // free object 1641 obj2->f->terminate(&obj2); 1642 ck_assert_ptr_eq(obj2, NULL); 1643 1644 } 1645 1646 1647 1648 1649 int main(int n UNUSED, char**v UNUSED) { 1650 // disable btrace to make the test run faster 1651 btraceDisable(); 1652 initiateSmallBytesT(); 1653 initiateAllocateSmallBytesT(); 1654 allocSmallBytesT(); 1655 freeSmallBytesT(); 1656 terminateSmallBytesT(); 1657 finishSmallBytesT(); 1658 toStringSmallBytesT(); 1659 duplicateSmallBytesT(); 1660 getSmallBytesT(); 1661 setSmallBytesT(); 1662 pushSmallBytesT(); 1663 pushBufferSmallBytesT(); 1664 getAtSmallBytesT(); 1665 lenSmallBytesT(); 1666 isEmptySmallBytesT(); 1667 readFileSmallBytesT(); 1668 readFileSmallJsonSmallBytesT(); 1669 readFileSmallStringSmallBytesT(); 1670 readStreamSmallBytesT(); 1671 writeFileSmallBytesT(); 1672 writeFileSmallJsonSmallBytesT(); 1673 writeFileSmallStringSmallBytesT(); 1674 writeStreamSmallBytesT(); 1675 appendFileSmallBytesT(); 1676 appendFileSmallStringSmallBytesT(); 1677 equalSmallBytesT(); 1678 equalSmallBytesBoolT(); 1679 equalSmallBytesDoubleT(); 1680 equalSmallBytesInt64T(); 1681 equalSmallBytesInt32T(); 1682 equalSmallBytesUint32T(); 1683 equalSmallBytesUint64T(); 1684 equalSmallBytesSmallBoolT(); 1685 equalSmallBytesSmallDoubleT(); 1686 equalSmallBytesSmallIntT(); 1687 equalSmallBytesCharT(); 1688 equalSmallBytesSmallStringT(); 1689 equalSmallBytesBaseT(); 1690 duplicateSmallBytesGT(); 1691 freeSmallBytesGT(); 1692 getAtSmallBytesGT(); 1693 pushSmallBytesGT(); 1694 lenSmallBytesGT(); 1695 isEmptySmallBytesGT(); 1696 readFileSmallBytesGT(); 1697 readFileSmallJsonSmallBytesGT(); 1698 readFileSmallStringSmallBytesGT(); 1699 readStreamSmallBytesGT(); 1700 writeFileSmallBytesGT(); 1701 writeFileSmallJsonSmallBytesGT(); 1702 writeFileSmallStringSmallBytesGT(); 1703 writeStreamSmallBytesGT(); 1704 appendFileSmallBytesGT(); 1705 appendFileSmallStringSmallBytesGT(); 1706 equalSmallBytesGT(); 1707 equalSmallBytesBoolGT(); 1708 equalSmallBytesDoubleGT(); 1709 equalSmallBytesInt64GT(); 1710 equalSmallBytesInt32GT(); 1711 equalSmallBytesUint32GT(); 1712 equalSmallBytesUint64GT(); 1713 equalSmallBytesSmallBoolGT(); 1714 equalSmallBytesSmallDoubleGT(); 1715 equalSmallBytesSmallIntGT(); 1716 equalSmallBytesCharGT(); 1717 equalSmallBytesSmallStringGT(); 1718 equalSmallBytesBaseGT(); 1719 cSmallBytesT(); 1720 1721 finalizeSmallDict(); 1722 finalizeSmallArray(); 1723 finalizeSmallJson(); 1724 finalizeUndefined(); 1725 finalizeSmallBytes(); 1726 finalizeSmallBool(); 1727 finalizeSmallContainer(); 1728 finalizeSmallDouble(); 1729 finalizeSmallInt(); 1730 finalizeSmallString(); 1731 }