libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

libsheepyCSmallBytesCuTest.c (40323B)


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