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