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

libsheepyObjectCuTest.c (64725B)


      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 void cSmallDictT(CuTest *tc UNUSED) {
     30 
     31   // local object
     32   createSmallDict(obj);
     33   ck_assert_str_eq(obj.type, "smallDict");
     34   // object
     35   createAllocateSmallDict(obj2);
     36   ck_assert_str_eq(obj2->type, "smallDict");
     37   // toString
     38   char *s = obj2->f->toString(obj2);
     39   ck_assert_str_eq(s, "{}");
     40   free(s);
     41   // duplicate
     42   smallDictt *o;
     43   createAllocateSmallBool(oBool2);
     44   oBool2->f->set(oBool2, true);
     45   obj2->f->set(obj2, "lib", (baset *)oBool2);
     46   finishO(oBool2);
     47   o = obj2->f->duplicate(obj2);
     48   smallBoolt *oBool3;
     49   oBool3 = (smallBoolt *)o->f->get(o, "lib");
     50   ck_assert_ptr_ne(oBool3, NULL);
     51   ck_assert(oBool3->value->value == true);
     52   finishO(oBool3);
     53   terminateO(o);
     54   // toString
     55   createAllocateUndefined(oU);
     56   obj2->f->set(obj2, "u", (baset *)oU);
     57   finishO(oU);
     58   createAllocateSmallString(oStr);
     59   oStr->f->set(oStr, "sheepy");
     60   obj2->f->set(obj2, "str", (baset *)oStr);
     61   finishO(oStr);
     62   s = obj2->f->toString(obj2);
     63   ck_assert_str_eq(s, "{\"lib\":true,\"u\":null,\"str\":\"sheepy\"}");
     64   free(s);
     65   // dispose
     66   o                = obj2->f->duplicate(obj2);
     67   undefinedt *u    = (undefinedt *) o->f->get(o, "u");
     68   smallStringt *st = (smallStringt *) o->f->get(o, "str");
     69   oBool2           = (smallBoolt *) o->f->get(o, "lib");
     70   smallt *data     = sDictGetTiny(o->d, "u");
     71   sFree(data);
     72   data  = sDictGetTiny(o->d, "str");
     73   sFree(data);
     74   data  = sDictGetTiny(o->d, "lib");
     75   sFree(data);
     76   o->f->dispose(o);
     77   ck_assert_uint_eq(o->f->len(o), 0);
     78   terminateO(u);
     79   smashO(st);
     80   smashO(oBool2);
     81   terminateO(o);
     82   // smash
     83   o      = obj2->f->duplicate(obj2);
     84   u      = (undefinedt *) o->f->get(o, "u");
     85   st     = (smallStringt *) o->f->get(o, "str");
     86   oBool2 = (smallBoolt *) o->f->get(o, "lib");
     87   data  = sDictGetTiny(o->d, "u");
     88   sFree(data);
     89   data  = sDictGetTiny(o->d, "str");
     90   sFree(data);
     91   data  = sDictGetTiny(o->d, "lib");
     92   sFree(data);
     93   o->f->smash(&o);
     94   terminateO(u);
     95   smashO(st);
     96   smashO(oBool2);
     97   ck_assert_ptr_eq(o, NULL);
     98   // set NULL (not possible)
     99   obj2->f->set(obj2, NULL, NULL);
    100   obj2->f->set(obj2, "no", NULL);
    101   ck_assert_uint_eq(obj2->f->len(obj2), 3);
    102   // get non existing element
    103   oBool3 = (smallBoolt *)obj2->f->get(obj2, "non existing");
    104   ck_assert_ptr_eq(oBool3, NULL);
    105   ck_assert_ptr_eq(obj2->f->get(obj2, NULL), NULL);
    106   // delete element
    107   obj2->f->del(obj2, "lib");
    108   oBool3 = (smallBoolt *)obj2->f->get(obj2, "lib");
    109   ck_assert_ptr_eq(oBool3, NULL);
    110   // delete non existing element
    111   obj2->f->del(obj2, NULL);
    112   obj2->f->del(obj2, "non existing");
    113   // has
    114   ck_assert(!obj2->f->has(obj2, "qwe"));
    115   ck_assert(!obj2->f->has(obj2, NULL));
    116   ck_assert(obj2->f->has(obj2, "u"));
    117   // keys
    118   char **keys = obj2->f->keys(obj2);
    119   size_t len  = listLengthS(keys);
    120   ck_assert_uint_eq(len, 2);
    121   ck_assert_str_eq(keys[0], "u");
    122   ck_assert_str_eq(keys[1], "str");
    123   listFreeS(keys);
    124     // empty dict
    125   initiateAllocateSmallDict(&o);
    126   keys = o->f->keys(o);
    127   ck_assert_ptr_eq(keys, NULL);
    128   terminateO(o);
    129   // values
    130   smallArrayt *values = obj2->f->values(obj2);
    131   s  = toStringO(values);
    132   ck_assert_str_eq(s, "[null,\"sheepy\"]");
    133   free(s);
    134   values->f->smash(&values);
    135     // empty dict
    136   initiateAllocateSmallDict(&o);
    137   values = o->f->values(o);
    138   ck_assert_ptr_eq(values, NULL);
    139   terminateO(o);
    140   // merge
    141   smallDictt *oM;
    142   o = obj2->f->duplicate(obj2);
    143   initiateAllocateSmallDict(&oM);
    144   initiateAllocateSmallString(&st);
    145   st->f->set(st, "SHEEPY MERGED");
    146   oM->f->set(oM, "str", (baset *) st);
    147   finishO(st);
    148   s = toStringO(o);
    149   ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}");
    150   free(s);
    151   o->f->merge(o, oM);
    152   s = toStringO(o);
    153   ck_assert_str_eq(s, "{\"u\":null,\"str\":\"SHEEPY MERGED\"}");
    154   free(s);
    155   oM->f->smash(&oM);
    156   terminateO(o);
    157     // empty dict
    158   o = obj2->f->duplicate(obj2);
    159   initiateAllocateSmallDict(&oM);
    160   s = toStringO(o);
    161   ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}");
    162   free(s);
    163   o->f->merge(o, oM);
    164   s = toStringO(o);
    165   ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}");
    166   free(s);
    167   oM->f->smash(&oM);
    168   terminateO(o);
    169     // NULL dict
    170   o = obj2->f->duplicate(obj2);
    171   s = toStringO(o);
    172   ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}");
    173   free(s);
    174   o->f->merge(o, NULL);
    175   s = toStringO(o);
    176   ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}");
    177   free(s);
    178   terminateO(o);
    179   // append
    180   o = obj2->f->duplicate(obj2);
    181   initiateAllocateSmallDict(&oM);
    182   initiateAllocateSmallString(&st);
    183   initiateAllocateUndefined(&oU);
    184   st->f->set(st, "SHEEPY MERGED");
    185   oM->f->set(oM, "str", (baset *) st);
    186   finishO(st);
    187   oM->f->set(oM, "u2", (baset *) oU);
    188   finishO(oU);
    189   s = toStringO(o);
    190   ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}");
    191   free(s);
    192   o->f->append(o, oM);
    193   s = toStringO(o);
    194   ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\",\"u2\":null}");
    195   free(s);
    196   data  = sDictGetTiny(oM->d, "str");
    197   sFree(data);
    198   oM->f->smash(&oM);
    199   terminateO(o);
    200     // empty dict
    201   o = obj2->f->duplicate(obj2);
    202   initiateAllocateSmallDict(&oM);
    203   s = toStringO(o);
    204   ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}");
    205   free(s);
    206   o->f->append(o, oM);
    207   s = toStringO(o);
    208   ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}");
    209   free(s);
    210   oM->f->smash(&oM);
    211   terminateO(o);
    212     // NULL dict
    213   o = obj2->f->duplicate(obj2);
    214   s = toStringO(o);
    215   ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}");
    216   free(s);
    217   o->f->append(o, NULL);
    218   s = toStringO(o);
    219   ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}");
    220   free(s);
    221   terminateO(o);
    222   // len
    223   ck_assert_uint_eq(obj2->f->len(obj2), 2);
    224     // empty dict
    225   initiateAllocateSmallDict(&o);
    226   ck_assert_uint_eq(o->f->len(o), 0);
    227   terminateO(o);
    228   // empty
    229   o = obj2->f->duplicate(obj2);
    230   o->f->empty(o);
    231   ck_assert_uint_eq(o->f->len(o), 0);
    232   terminateO(o);
    233   // typeString type typeStrings
    234   initiateAllocateSmallDict(&oM);
    235   o = allocSmallDict();
    236   oU = allocUndefined();
    237   o->f->set(o, "u", (baset *)oU);
    238   finishO(oU);
    239   st = allocSmallString("sheepy");
    240   o->f->set(o, "str", (baset *) st);
    241   finishO(st);
    242   oBool2 = allocSmallBool(true);
    243   o->f->set(o, "b", (baset *)oBool2);
    244   finishO(oBool2);
    245   oBool2 = allocSmallBool(true);
    246   o->f->set(o, "B", (baset *)oBool2);
    247   finishO(oBool2);
    248   o->f->del(o, "B");
    249     // typeString
    250   s = (char *)o->f->typeString(o, "b");
    251   ck_assert_str_eq(s, "bool");
    252       // non existing key
    253   ck_assert_ptr_eq(o->f->typeString(o, "B"), NULL);
    254       // empty object
    255   ck_assert_ptr_eq(oM->f->typeString(oM, "B"), NULL);
    256     // type
    257   char c;
    258   c = o->f->type(o, "str");
    259   ck_assert_uint_eq(c, STRING);
    260       // non existing key
    261   ck_assert(!o->f->type(o, "B"));
    262       // empty object
    263   ck_assert(!oM->f->type(oM, "B"));
    264     // typeStrings
    265   smallDictt *oT = o->f->typeStrings(o);
    266   s = toStringO(oT);
    267   ck_assert_str_eq(s, "{\"u\":\"undefined\",\"str\":\"string\",\"b\":\"bool\"}");
    268   free(s);
    269   terminateO(oT);
    270     // empty object
    271   oT = oM->f->typeStrings(oM);
    272   ck_assert_ptr_eq(oT, NULL);
    273   terminateO(o);
    274   terminateO(oM);
    275   // free local object
    276   obj.f->free(&obj);
    277   ck_assert_str_eq(obj.type, "smallDict");
    278   // free object
    279   obj2->f->terminate(&obj2);
    280   ck_assert_ptr_eq(obj2, NULL);
    281 
    282 }
    283 
    284 
    285 void cSmallJsonT(CuTest *tc UNUSED) {
    286 
    287   // local object
    288   createSmallJson(obj);
    289   ck_assert_str_eq(obj.type, "smallJson");
    290   // object
    291   createAllocateSmallJson(obj2);
    292   ck_assert_str_eq(obj2->type, "smallJson");
    293   // toString
    294   char *s = obj2->f->toString(obj2);
    295   ck_assert_str_eq(s, "{}");
    296   free(s);
    297   createAllocateSmallInt(oInt);
    298   oInt->f->set(oInt, 123);
    299   obj2->f->set(obj2, "int", (baset *) oInt);
    300   finishO(oInt);
    301   initiateAllocateSmallInt(&oInt);
    302   oInt->f->set(oInt, 123);
    303   obj2->f->set(obj2, "int2", (baset *) oInt);
    304   finishO(oInt);
    305     // no effect - no push to dictionary
    306   initiateAllocateSmallInt(&oInt);
    307   obj2->f->push(obj2, (baset *) oInt);
    308   finishO(oInt);
    309   s = obj2->f->toString(obj2);
    310   ck_assert_str_eq(s, "{\"int\":123,\"int2\":123}");
    311   free(s);
    312   terminateO(obj2);
    313   initiateAllocateSmallJson(&obj2);
    314   createAllocateSmallInt(oInt2);
    315   oInt2->f->set(oInt2, 123);
    316   obj2->f->push(obj2, (baset *) oInt2);
    317   finishO(oInt2);
    318   initiateAllocateSmallInt(&oInt2);
    319   oInt2->f->set(oInt2, 123);
    320   obj2->f->push(obj2, (baset *) oInt2);
    321   finishO(oInt2);
    322     // no effect - no set with key to array
    323   initiateAllocateSmallInt(&oInt2);
    324   obj2->f->set(obj2, "noEffect", (baset *) oInt2);
    325   finishO(oInt2);
    326   s = obj2->f->toString(obj2);
    327   ck_assert_str_eq(s, "[123,123]");
    328   free(s);
    329   // duplicate
    330   smallJsont *o;
    331   o = obj2->f->duplicate(obj2);
    332   s = toStringO(o);
    333   ck_assert_str_eq(s, "[123,123]");
    334   free(s);
    335   terminateO(o);
    336   terminateO(obj2);
    337   initiateAllocateSmallJson(&obj2);
    338   createAllocateSmallInt(oInt3);
    339   oInt3->f->set(oInt3, 123);
    340   obj2->f->set(obj2, "int", (baset *) oInt3);
    341   finishO(oInt3);
    342   o = obj2->f->duplicate(obj2);
    343   s = toStringO(o);
    344   ck_assert_str_eq(s, "{\"int\":123}");
    345   free(s);
    346   terminateO(o);
    347   // dispose
    348     // array
    349   initiateAllocateSmallJson(&o);
    350   initiateAllocateSmallInt(&oInt);
    351   oInt->f->set(oInt, 123);
    352   o->f->push(o, (baset*)oInt);
    353   finishO(oInt);
    354   ck_assert_uint_eq(o->topA->count, 1);
    355   smallt *i = sArrayGetTiny(o->topA, 0);
    356   o->f->dispose(o);
    357   ck_assert_ptr_eq(o->topA, NULL);
    358   sFree(i);
    359   terminateO(o);
    360     // dictionary
    361   initiateAllocateSmallJson(&o);
    362   initiateAllocateSmallInt(&oInt);
    363   oInt->f->set(oInt, 123);
    364   o->f->set(o, "in", (baset*)oInt);
    365   finishO(oInt);
    366   ck_assert_uint_eq(o->top->count, 1);
    367   smallt *data = o->top->elements.data;
    368   sFree(data);
    369   o->f->dispose(o);
    370   ck_assert_ptr_eq(o->top, NULL);
    371   terminateO(o);
    372   // smash
    373   initiateAllocateSmallJson(&o);
    374     // array
    375   initiateAllocateSmallInt(&oInt);
    376   oInt->f->set(oInt, 123);
    377   o->f->push(o, (baset*)oInt);
    378   finishO(oInt);
    379   ck_assert_uint_eq(o->topA->count, 1);
    380   i = sArrayGetTiny(o->topA, 0);
    381   o->f->smash(&o);
    382   ck_assert_ptr_eq(o, NULL);
    383   sFree(i);
    384     // dict
    385   initiateAllocateSmallJson(&o);
    386   initiateAllocateSmallInt(&oInt);
    387   oInt->f->set(oInt, 123);
    388   o->f->set(o, "in", (baset*)oInt);
    389   finishO(oInt);
    390   ck_assert_uint_eq(o->top->count, 1);
    391   data = o->top->elements.data;
    392   sFree(data);
    393   o->f->smash(&o);
    394   ck_assert_ptr_eq(o, NULL);
    395   // setType*
    396   initiateAllocateSmallJson(&o);
    397   o->f->setTypeUndefined(o);
    398   ck_assert_str_eq(o->f->getTopType(o), "undefined");
    399   o->f->setTypeBool(o);
    400   ck_assert_str_eq(o->f->getTopType(o), "bool");
    401   o->f->setTypeDouble(o);
    402   ck_assert_str_eq(o->f->getTopType(o), "double");
    403   o->f->setTypeInt(o);
    404   ck_assert_str_eq(o->f->getTopType(o), "int");
    405   o->f->setTypeString(o);
    406   ck_assert_str_eq(o->f->getTopType(o), "string");
    407   o->f->setTypeDict(o);
    408   ck_assert_str_eq(o->f->getTopType(o), "dict");
    409   o->f->setTypeArray(o);
    410   ck_assert_str_eq(o->f->getTopType(o), "array");
    411   terminateO(o);
    412   // getTopTypeJson setTopJson getTopJson - undefined bool double int string
    413   baset *b;
    414   smallJsont *o2;
    415   initiateAllocateSmallJson(&o);
    416   ck_assert_ptr_eq(o->f->getTopType(o), NULL);
    417     // non json object
    418   createAllocateSmallContainer(jcontainer);
    419       // setTop
    420   o->f->setTop(o, (baset *)jcontainer);
    421   terminateO(jcontainer);
    422   ck_assert_ptr_eq(o->f->getTopType(o), NULL);
    423       // getTop
    424   b = o->f->getTop(o);
    425   ck_assert_ptr_eq(b, NULL);
    426     // undefined
    427   createAllocateUndefined(jUndef);
    428       // setTop
    429   o->f->setTop(o, (baset *)jUndef);
    430   finishO(jUndef);
    431       // getTopType
    432   ck_assert_str_eq(o->f->getTopType(o), "undefined");
    433       // getTop
    434   b = o->f->getTop(o);
    435   ck_assert_str_eq(b->type, "undefined");
    436   finishO(b);
    437       // duplicateO
    438   o2 = duplicateO(o);
    439       // toStringO
    440   s  = toStringO(o2);
    441   ck_assert_str_eq(s, "null");
    442   free(s);
    443       // stringify
    444   s = o->f->stringify(o,2);
    445   ck_assert_str_eq(s, "null");
    446   free(s);
    447       // toYML
    448   s = o->f->toYML(o,2);
    449   ck_assert_str_eq(s, "---\n  null");
    450   free(s);
    451       // smash
    452   o2->f->smash(&o2);
    453       // freeO
    454   freeO(o);
    455   ck_assert_ptr_eq(o->f->getTopType(o), NULL);
    456   terminateO(o);
    457     // cBool
    458   initiateAllocateSmallJson(&o);
    459   createAllocateSmallBool(jBool);
    460       // setTop
    461   o->f->setTop(o, (baset *)jBool);
    462   finishO(jBool);
    463       // getTopType
    464   ck_assert_str_eq(o->f->getTopType(o), "bool");
    465       // getTop
    466   b = o->f->getTop(o);
    467   ck_assert_str_eq(b->type, "smallBool");
    468   finishO(b);
    469       // duplicateO
    470   o2 = duplicateO(o);
    471       // toStringO
    472   s  = toStringO(o2);
    473   ck_assert_str_eq(s, "false");
    474   free(s);
    475       // stringify
    476   s = o->f->stringify(o,2);
    477   ck_assert_str_eq(s, "false");
    478   free(s);
    479       // toYML
    480   s = o->f->toYML(o,2);
    481   ck_assert_str_eq(s, "---\n  false");
    482   free(s);
    483       // smash
    484   o2->f->smash(&o2);
    485       // freeO
    486   freeO(o);
    487   ck_assert_ptr_eq(o->f->getTopType(o), NULL);
    488   terminateO(o);
    489     // cDouble
    490   initiateAllocateSmallJson(&o);
    491   createAllocateSmallDouble(jDouble);
    492       // setTop
    493   o->f->setTop(o, (baset *)jDouble);
    494   finishO(jDouble);
    495       // getTopType
    496   ck_assert_str_eq(o->f->getTopType(o), "double");
    497       // getTop
    498   b = o->f->getTop(o);
    499   ck_assert_str_eq(b->type, "smallDouble");
    500   finishO(b);
    501       // duplicateO
    502   o2 = duplicateO(o);
    503       // toStringO
    504   s  = toStringO(o2);
    505   ck_assert_str_eq(s, "0.000000e+00");
    506   free(s);
    507       // stringify
    508   s = o->f->stringify(o,2);
    509   ck_assert_str_eq(s, "0.000000e+00");
    510   free(s);
    511       // toYML
    512   s = o->f->toYML(o,2);
    513   ck_assert_str_eq(s, "---\n  0.000000e+00");
    514   free(s);
    515       // smash
    516   o2->f->smash(&o2);
    517       // freeO
    518   freeO(o);
    519   ck_assert_ptr_eq(o->f->getTopType(o), NULL);
    520   terminateO(o);
    521     // cInt
    522   initiateAllocateSmallJson(&o);
    523   createAllocateSmallInt(jInt);
    524       // setTop
    525   o->f->setTop(o, (baset *)jInt);
    526   finishO(jInt);
    527       // getTopType
    528   ck_assert_str_eq(o->f->getTopType(o), "int");
    529       // getTop
    530   b = o->f->getTop(o);
    531   ck_assert_str_eq(b->type, "smallInt");
    532   finishO(b);
    533       // duplicateO
    534   o2 = duplicateO(o);
    535       // toStringO
    536   s  = toStringO(o2);
    537   ck_assert_str_eq(s, "0");
    538   free(s);
    539       // stringify
    540   s = o->f->stringify(o,2);
    541   ck_assert_str_eq(s, "0");
    542   free(s);
    543       // toYML
    544   s = o->f->toYML(o,2);
    545   ck_assert_str_eq(s, "---\n  0");
    546   free(s);
    547       // smash
    548   o2->f->smash(&o2);
    549       // freeO
    550   freeO(o);
    551   ck_assert_ptr_eq(o->f->getTopType(o), NULL);
    552   terminateO(o);
    553     // string
    554   initiateAllocateSmallJson(&o);
    555   createAllocateSmallString(jString);
    556   jString->f->set(jString, "sheepy");
    557       // setTop
    558   o->f->setTop(o, (baset *)jString);
    559   finishO(jString);
    560       // getTopType
    561   ck_assert_str_eq(o->f->getTopType(o), "string");
    562       // getTop
    563   b = o->f->getTop(o);
    564   ck_assert_str_eq(b->type, "smallString");
    565   finishO(b);
    566       // duplicateO
    567   o2 = duplicateO(o);
    568       // toStringO
    569   s  = toStringO(o2);
    570   ck_assert_str_eq(s, "sheepy");
    571   free(s);
    572       // stringify
    573   s = o->f->stringify(o,2);
    574   ck_assert_str_eq(s, "\"sheepy\"");
    575   free(s);
    576       // toYML
    577   s = o->f->toYML(o,2);
    578   ck_assert_str_eq(s, "---\n  \"sheepy\"");
    579   free(s);
    580       // smash
    581   o2->f->smash(&o2);
    582       // freeO
    583   freeO(o);
    584   ck_assert_ptr_eq(o->f->getTopType(o), NULL);
    585   terminateO(o);
    586     // dict
    587   initiateAllocateSmallJson(&o);
    588   createAllocateSmallDict(jdict);
    589       // setTop
    590   o->f->setTop(o, (baset *)jdict);
    591   finishO(jdict);
    592       // getTopType
    593   ck_assert_str_eq(o->f->getTopType(o), "dict");
    594       // getTop
    595   b = o->f->getTop(o);
    596   ck_assert_str_eq(b->type, "smallDict");
    597   finishO(b);
    598       // duplicateO
    599   o2 = duplicateO(o);
    600       // toStringO
    601   s  = toStringO(o2);
    602   ck_assert_str_eq(s, "{}");
    603   free(s);
    604       // stringify
    605   s = o->f->stringify(o,2);
    606   ck_assert_str_eq(s, "{}\n");
    607   free(s);
    608       // toYML
    609   s = o->f->toYML(o,2);
    610   ck_assert_str_eq(s, "---\n  {}\n");
    611   free(s);
    612       // smash
    613   o2->f->smash(&o2);
    614       // freeO
    615   freeO(o);
    616   ck_assert_ptr_eq(o->f->getTopType(o), NULL);
    617   terminateO(o);
    618     // array
    619   initiateAllocateSmallJson(&o);
    620   createAllocateSmallArray(jArray);
    621       // setTop
    622   o->f->setTop(o, (baset *)jArray);
    623   finishO(jArray);
    624       // getTopType
    625   ck_assert_str_eq(o->f->getTopType(o), "array");
    626       // getTop
    627   b = o->f->getTop(o);
    628   ck_assert_str_eq(b->type, "smallArray");
    629   finishO(b);
    630       // duplicateO
    631   o2 = duplicateO(o);
    632       // toStringO
    633   s  = toStringO(o2);
    634   ck_assert_str_eq(s, "[]");
    635   free(s);
    636       // stringify
    637   s = o->f->stringify(o,2);
    638   ck_assert_str_eq(s, "[]\n");
    639   free(s);
    640       // toYML
    641   s = o->f->toYML(o,2);
    642   ck_assert_str_eq(s, "---\n  []\n");
    643   free(s);
    644       // smash
    645   o2->f->smash(&o2);
    646       // freeO
    647   freeO(o);
    648   ck_assert_ptr_eq(o->f->getTopType(o), NULL);
    649   terminateO(o);
    650   // get
    651   smallIntt *in = (smallIntt *) obj2->f->get(obj2, "int");
    652   ck_assert(in->value->value == 123);
    653   createAllocateSmallDict(oD2);
    654   smallIntt *in2 = duplicateO(in);
    655   oD2->f->set(oD2, "int", (baset *)in2);
    656   finishO(in2);
    657   in2 = duplicateO(in);
    658   oD2->f->set(oD2, "int2", (baset *)in2);
    659   finishO(in2);
    660   obj2->f->set(obj2, "dict", (baset *)oD2);
    661   finishO(oD2);
    662   createAllocateSmallArray(oTA2);
    663   in2 = duplicateO(in);
    664   oTA2->f->push(oTA2, (baset *)in2);
    665   finishO(in2);
    666   in2 = duplicateO(in);
    667   oTA2->f->push(oTA2, (baset *)in2);
    668   finishO(in2);
    669   smashO(in);
    670   obj2->f->set(obj2, "array", (baset *)oTA2);
    671   finishO(oTA2);
    672     // get dict element
    673   in = (smallIntt *) obj2->f->get(obj2, "\"dict\".\"int2\"");
    674   ck_assert(in->value->value == 123);
    675   smashO(in);
    676     // non existing element
    677   in = (smallIntt *) obj2->f->get(obj2, "\"dict\".\"void\"");
    678   ck_assert_ptr_eq(in, NULL);
    679     // missing " at the end
    680   in = (smallIntt *) obj2->f->get(obj2, "\"dict\".\"int2");
    681   ck_assert_ptr_eq(in, NULL);
    682     // get array element
    683   in = (smallIntt *) obj2->f->get(obj2, "\"array\"[0]");
    684   ck_assert(in->value->value == 123);
    685   smashO(in);
    686     // missing ] at the end
    687   in = (smallIntt *) obj2->f->get(obj2, "\"array\"[0");
    688   ck_assert_ptr_eq(in, NULL);
    689     // json array
    690   createAllocateSmallJson(json);
    691   createAllocateSmallInt(oInt4);
    692   oInt4->f->set(oInt4, 345);
    693   json->f->push(json, (baset *) oInt4);
    694   finishO(oInt4);
    695   in = (smallIntt *) json->f->get(json, "[0]");
    696   ck_assert(in->value->value == 345);
    697   smashO(in);
    698   // set get json path
    699   createSmallJson(jpath);
    700     // dict is top
    701   jpath.f->parse(&jpath, "{ \"a\": {\"a\": true}, \"b\": 234, \"c\": [\"qwe\",32]}");
    702       // get non existing element in 'c' array
    703   b = jpath.f->get(&jpath,"\"c\"[3]");
    704   ck_assert_ptr_eq(b, NULL);
    705   finishO(b);
    706       // dictionary keys should not be unescaped
    707   createSmallBool(ba);
    708   jpath.f->set(&jpath, "b\\\\", cBa(&ba));
    709   jBool = (smallBoolt*)jpath.f->get(&jpath,"b\\\\");
    710   ck_assert(jBool->value->value == false);
    711   finishO(jBool);
    712       // keys in json paths should be unescaped
    713   createSmallBool(bb);
    714   bb.f->set(&bb, true);
    715   jpath.f->set(&jpath, "\"b\\\\\"", (baset*)&bb);
    716   jBool = (smallBoolt*)jpath.f->get(&jpath,"\"b\\\\\"");
    717   ck_assert(jBool->value->value == true);
    718   finishO(jBool);
    719   freeO(&jpath);
    720     // array is top
    721     // get dict in dict
    722   jpath.f->parse(&jpath, "[1,{\"a\": {\"a\": true}, \"b\": 234, \"c\": [\"qwe\",32]}, [[11],22,33]]");
    723   b = jpath.f->get(&jpath,"[1].\"a\"");
    724   ck_assert_str_eq(b->type, "smallDict");
    725   finishO(b);
    726     // get bool in dict
    727   jBool = (smallBoolt*)jpath.f->get(&jpath,"[1]\"a\"\"a\"");
    728   ck_assert(jBool->value->value == true);
    729   finishO(jBool);
    730     // get array in array
    731   jArray = (smallArrayt*)jpath.f->get(&jpath,"[2][0]");
    732   ck_assert_str_eq(jArray->type, "smallArray");
    733   ck_assert_uint_eq(lenO(jArray), 1);
    734   finishG(jArray);
    735     // get element in array
    736   in = (smallIntt*)(jpath.f->get(&jpath,"[2][0][0]"));
    737   ck_assert_uint_eq(in->value->value, 11);
    738   finishG(in);
    739     // set element in array with negative index
    740   createSmallBool(be);
    741   jpath.f->set(&jpath, "[-1][0][0]", (baset*)&be);
    742     // get element in array with negative index
    743   jBool = (smallBoolt*)jpath.f->get(&jpath,"[-1][0][0]");
    744   ck_assert(jBool->value->value == false);
    745   finishG(jBool);
    746     // set new element in dict
    747   createSmallBool(b2);
    748   o2 = jpath.f->set(&jpath, "[1]\"a\"\"b\\\"\"", (baset*)&b2);
    749   ck_assert_ptr_ne(o2, NULL);
    750   jBool = (smallBoolt*)jpath.f->get(&jpath,"[1]\"a\"\"b\\\"\"");
    751   ck_assert(jBool->value->value == false);
    752   finishG(jBool);
    753   createSmallBool(b3);
    754   o2 = jpath.f->set(&jpath, "[1]\"a\"\"b\\\\\"", (baset*)&b3);
    755   ck_assert_ptr_ne(o2, NULL);
    756   jBool = (smallBoolt*)jpath.f->get(&jpath,"[1]\"a\"\"b\\\\\"");
    757   ck_assert(jBool->value->value == false);
    758   finishG(jBool);
    759     // escape key in json path
    760     // \\\""
    761   char *ks = jpath.f->makeKey(&jpath, "\\\\\\\"\"");
    762   ck_assert_str_eq(ks, "\"\\\\\\\\\\\\\\\"\\\"\"");
    763   createSmallBool(b4);
    764   pErrorNULL(iPrependS(&ks, "[1]"));
    765   o2 = jpath.f->set(&jpath, ks, (baset*)&b4);
    766   ck_assert_ptr_ne(o2, NULL);
    767   jBool = (smallBoolt*)jpath.f->get(&jpath,ks);
    768   ck_assert(jBool->value->value == false);
    769   finishG(jBool);
    770   free(ks);
    771     // wrong path
    772   b = jpath.f->get(&jpath,"[3][0][0]");
    773   ck_assert_ptr_eq(b, NULL);
    774   finishG(b);
    775     // missing index
    776   b = jpath.f->get(&jpath,"[][0][0]");
    777   ck_assert_ptr_eq(b, NULL);
    778   finishG(b);
    779     // try to assign dictionary key to array, wrong
    780   createSmallBool(b0);
    781   o2 = jpath.f->set(&jpath, "[2][0]\"sdf\\\"", (baset*)&b0);
    782   ck_assert_ptr_eq(o2, NULL);
    783   freeO(&jpath);
    784   // len
    785   initiateAllocateSmallJson(&o);
    786   ck_assert_uint_eq(o->f->len(o), 0);
    787   o->f->setTypeUndefined(o);
    788   ck_assert_uint_eq(o->f->len(o), 1);
    789   o->f->setTypeBool(o);
    790   ck_assert_uint_eq(o->f->len(o), 1);
    791   o->f->setTypeDouble(o);
    792   ck_assert_uint_eq(o->f->len(o), 1);
    793   o->f->setTypeInt(o);
    794   ck_assert_uint_eq(o->f->len(o), 1);
    795   o->f->setTypeString(o);
    796   ck_assert_uint_eq(o->f->len(o), 0);
    797   o->f->setTypeDict(o);
    798   ck_assert_uint_eq(o->f->len(o), 0);
    799   o->f->setTypeArray(o);
    800   ck_assert_uint_eq(o->f->len(o), 0);
    801   terminateO(o);
    802   // empty
    803   initiateAllocateSmallJson(&o);
    804     // empty empty
    805   o->f->empty(o);
    806   o->f->setTypeString(o);
    807   sFree((smallt *)o->topS);
    808   o->topS = allocSStringTiny("er");
    809   o->f->empty(o);
    810   ck_assert_uint_eq(o->f->len(o), 0);
    811   o->f->setTypeDict(o);
    812   initiateAllocateSmallInt(&in);
    813   o->f->set(o, "wer", (baset *)in);
    814   finishO(in);
    815   o->f->empty(o);
    816   ck_assert_uint_eq(o->f->len(o), 0);
    817   o->f->setTypeArray(o);
    818   initiateAllocateSmallInt(&in);
    819   o->f->push(o, (baset *)in);
    820   finishO(in);
    821   o->f->empty(o);
    822   ck_assert_uint_eq(o->f->len(o), 0);
    823   terminateO(o);
    824   // stringify
    825     // array
    826   initiateAllocateSmallString(&jString);
    827   jString->f->set(jString, "sheepy");
    828   json->f->push(json, (baset *) jString);
    829   finishO(jString);
    830   initiateAllocateSmallDict(&jdict);
    831   json->f->push(json, (baset *) jdict);
    832   finishO(jdict);
    833   initiateAllocateSmallArray(&jArray);
    834   json->f->push(json, (baset *) jArray);
    835   finishO(jArray);
    836   initiateAllocateSmallDict(&jdict);
    837   initiateAllocateSmallString(&jString);
    838   jString->f->set(jString, "sheepy");
    839   jdict->f->set(jdict, "string", (baset *) jString);
    840   finishO(jString);
    841   initiateAllocateSmallContainer(&jcontainer);
    842   jdict->f->set(jdict, "container", (baset *) jcontainer);
    843   finishO(jcontainer);
    844   json->f->push(json, (baset *) jdict);
    845   finishO(jdict);
    846   initiateAllocateSmallArray(&jArray);
    847   initiateAllocateSmallString(&jString);
    848   jString->f->set(jString, "sheepy");
    849   jArray->f->push(jArray, (baset *) jString);
    850   finishO(jString);
    851   initiateAllocateSmallContainer(&jcontainer);
    852   jArray->f->push(jArray, (baset *) jcontainer);
    853   finishO(jcontainer);
    854   json->f->push(json, (baset *) jArray);
    855   finishO(jArray);
    856 
    857   s = json->f->stringify(json, 2);
    858   ck_assert_str_eq(s, "[\n  345,\n  \"sheepy\",\n  {},\n  [],\n  {\n    \"string\": \"sheepy\",\n    \"container\": \"<data container>\"\n  },\n  [\n    \"sheepy\",\n    \"<data container>\"\n  ]\n]\n");
    859   free(s);
    860     // empty
    861   createAllocateSmallJson(json2);
    862   s = json2->f->stringify(json2, 2);
    863   ck_assert_str_eq(s, "{}");
    864   free(s);
    865     // dict
    866   initiateAllocateSmallString(&jString);
    867   jString->f->set(jString, "sheepy");
    868   json2->f->set(json2, "s", (baset *) jString);
    869   finishO(jString);
    870   initiateAllocateSmallDict(&jdict);
    871   json2->f->set(json2, "d",(baset *) jdict);
    872   finishO(jdict);
    873   initiateAllocateSmallArray(&jArray);
    874   json2->f->set(json2, "a", (baset *) jArray);
    875   finishO(jArray);
    876   initiateAllocateSmallDict(&jdict);
    877   initiateAllocateSmallString(&jString);
    878   jString->f->set(jString, "sheepy");
    879   jdict->f->set(jdict, "string", (baset *) jString);
    880   finishO(jString);
    881   initiateAllocateSmallContainer(&jcontainer);
    882   jdict->f->set(jdict, "container", (baset *) jcontainer);
    883   finishO(jcontainer);
    884   json2->f->set(json2, "d2",(baset *) jdict);
    885   finishO(jdict);
    886   initiateAllocateSmallArray(&jArray);
    887   initiateAllocateSmallString(&jString);
    888   jString->f->set(jString, "sheepy");
    889   jArray->f->push(jArray, (baset *) jString);
    890   finishO(jString);
    891   initiateAllocateSmallContainer(&jcontainer);
    892   jArray->f->push(jArray, (baset *) jcontainer);
    893   finishO(jcontainer);
    894   json2->f->set(json2, "a2", (baset *) jArray);
    895   finishO(jArray);
    896   initiateAllocateSmallInt(&oInt4);
    897   oInt4->f->set(oInt4, 345);
    898   json2->f->set(json2, "int", (baset *) oInt4);
    899   finishO(oInt4);
    900   s = json2->f->stringify(json2, 2);
    901   ck_assert_str_eq(s, "{\n  \"s\": \"sheepy\",\n  \"d\": {},\n  \"a\": [],\n  \"d2\": {\n    \"string\": \"sheepy\",\n    \"container\": \"<data container>\"\n  },\n  \"a2\": [\n    \"sheepy\",\n    \"<data container>\"\n  ],\n  \"int\": 345\n}\n");
    902   free(s);
    903   // toYML
    904     // array
    905   s = json->f->toYML(json, 2);
    906   ck_assert_str_eq(s, "---\n  - 345\n  - sheepy\n  - {}\n  - []\n  - string: sheepy\n    container: \"<data container>\"\n  - - sheepy\n    - \"<data container>\"\n");
    907   free(s);
    908     // empty
    909   createAllocateSmallJson(json3);
    910   s = json3->f->toYML(json3, 2);
    911   ck_assert_str_eq(s, "---\n");
    912   free(s);
    913   terminateO(json3);
    914     // dict
    915   s = json2->f->toYML(json2, 2);
    916   ck_assert_str_eq(s, "---\n  s: sheepy\n  d:\n    {}\n  a:\n    []\n  d2:\n    string: sheepy\n    container: \"<data container>\"\n  a2:\n    - sheepy\n    - \"<data container>\"\n  int: 345\n");
    917   free(s);
    918   terminateO(json2);
    919   terminateO(json);
    920   // parse
    921     // top null - undefined
    922   initiateAllocateSmallJson(&json);
    923   json->f->parse(json, "null");
    924   ck_assert_str_eq(json->f->getTopType(json), "undefined");
    925   terminateO(json);
    926     // top bool
    927   initiateAllocateSmallJson(&json);
    928   json->f->parse(json, "true");
    929   ck_assert_str_eq(json->f->getTopType(json), "bool");
    930   terminateO(json);
    931     // top double
    932   initiateAllocateSmallJson(&json);
    933   json->f->parse(json, "0.01");
    934   ck_assert_str_eq(json->f->getTopType(json), "double");
    935   terminateO(json);
    936     // top int
    937   initiateAllocateSmallJson(&json);
    938   json->f->parse(json, "10");
    939   ck_assert_str_eq(json->f->getTopType(json), "int");
    940   terminateO(json);
    941     // top string
    942   initiateAllocateSmallJson(&json);
    943   json->f->parse(json, "\"wef\"");
    944   ck_assert_str_eq(json->f->getTopType(json), "string");
    945   terminateO(json);
    946     // from file dictionary
    947   char **file = readText("file.json");
    948   char *jsonText = join(file, "\n");
    949   createAllocateSmallJson(jsOfromF);
    950   jsOfromF->f->parse(jsOfromF, jsonText);
    951   s = toStringO(jsOfromF);
    952   //printf("JSON FILE: %s\n", s);
    953   ck_assert_str_eq(s, "{\"dasd\":\"asd\",\"asd\":234,\"dict\":{\"array\":[1,1],\"asd\":true,\"float\":3.434000e+01},\"bool\":false,\"zzz\":null}");
    954   free(s);
    955   free(jsonText);
    956   listFreeS(file);
    957   terminateO(jsOfromF);
    958     // json array top
    959   file = readText("fileA.json");
    960   jsonText = join(file, "\n");
    961   initiateAllocateSmallJson(&jsOfromF);
    962   jsOfromF->f->parse(jsOfromF, jsonText);
    963   s = toStringO(jsOfromF);
    964   ck_assert_str_eq(s, "[\"asd\",234,{\"array\":[1,1],\"asd\":true,\"float\":3.434000e+01}]");
    965   free(s);
    966   free(jsonText);
    967   listFreeS(file);
    968   terminateO(jsOfromF);
    969     // wrong json incomplete dict
    970   initiateAllocateSmallJson(&json);
    971   json->f->parse(json, "{\"wef\": {");
    972   s = toStringO(json);
    973   ck_assert_str_eq(s, "{}");
    974   free(s);
    975   terminateO(json);
    976     // wrong json incomplete array
    977   initiateAllocateSmallJson(&json);
    978   json->f->parse(json, "{\"wef\": [");
    979   s = toStringO(json);
    980   ck_assert_str_eq(s, "{}");
    981   free(s);
    982   terminateO(json);
    983     // wrong json incomplete string
    984   initiateAllocateSmallJson(&json);
    985   json->f->parse(json, "{\"wef\": \"wer");
    986   s = toStringO(json);
    987   ck_assert_str_eq(s, "{}");
    988   free(s);
    989   terminateO(json);
    990     // wrong json incomplete top dict
    991   initiateAllocateSmallJson(&json);
    992   json->f->parse(json, "{ \"wef");
    993   s = toStringO(json);
    994   ck_assert_str_eq(s, "{}");
    995   free(s);
    996   terminateO(json);
    997     // wrong json incomplete top array
    998   initiateAllocateSmallJson(&json);
    999   json->f->parse(json, "[\"wef");
   1000   s = toStringO(json);
   1001   ck_assert_str_eq(s, "{}");
   1002   free(s);
   1003   terminateO(json);
   1004     // wrong json incomplete top string
   1005   initiateAllocateSmallJson(&json);
   1006   json->f->parse(json, "\"wef");
   1007   s = toStringO(json);
   1008   ck_assert_str_eq(s, "{}");
   1009   free(s);
   1010   terminateO(json);
   1011   // parseYML
   1012     // yml only top dict or array - NO: top null undefined top bool top double top int top string
   1013     // from file dictionary
   1014   file = readText("file.yml");
   1015   jsonText = join(file, "\n");
   1016   initiateAllocateSmallJson(&jsOfromF);
   1017   jsOfromF->f->parseYML(jsOfromF, jsonText);
   1018   s = toStringO(jsOfromF);
   1019   ck_assert_str_eq(s, "{\"dict\":{\"array\":[1,1],\"float\":3.434000e+01,\"asd\":true},\"dasd\":\"asd\",\"asd\":234,\"bool\":false,\"zzz\":null}");
   1020   free(s);
   1021   free(jsonText);
   1022   listFreeS(file);
   1023   terminateO(jsOfromF);
   1024     // json array top
   1025   file = readText("fileA.yml");
   1026   jsonText = join(file, "\n");
   1027   initiateAllocateSmallJson(&jsOfromF);
   1028   jsOfromF->f->parseYML(jsOfromF, jsonText);
   1029   s = toStringO(jsOfromF);
   1030   //printf("JSON FILE: %s\n", toStringO(jsOfromF));
   1031   ck_assert_str_eq(s, "[{\"dict\":\"hello\",\"array\":[1,1],\"float\":3.434000e+01,\"asd\":true},\"asd\",234]");
   1032   free(s);
   1033   free(jsonText);
   1034   listFreeS(file);
   1035   terminateO(jsOfromF);
   1036   // serial deserial
   1037   smallBytest *B;
   1038   initiateAllocateSmallJson(&o);
   1039   ck_assert_ptr_eq(o->f->serial(o), NULL);
   1040     // non json object
   1041   initiateAllocateSmallContainer(&jcontainer);
   1042   o->f->setTop(o, (baset *)jcontainer);
   1043   ck_assert_ptr_eq(o->f->serial(o), NULL);
   1044   terminateO(jcontainer);
   1045     // undefined
   1046   undefinedt *oU = allocUndefined();
   1047   o->f->setTop(o, (baset *)oU);
   1048   finishO(oU);
   1049   B = o->f->serial(o);
   1050   s = sToString((smallt *) B->B);
   1051   ck_assert_str_eq(s, "[0x01]");
   1052   free(s);
   1053   freeO(o);
   1054   o->f->deserial(o, B);
   1055   s = toStringO(o);
   1056   ck_assert_str_eq(s, "null");
   1057   free(s);
   1058   terminateO(B);
   1059   terminateO(o);
   1060     // Bool
   1061   initiateAllocateSmallJson(&o);
   1062   smallBoolt *oBool = allocSmallBool(true);
   1063   o->f->setTop(o, (baset *)oBool);
   1064   finishO(oBool);
   1065   B = o->f->serial(o);
   1066   s = sToString((smallt *) B->B);
   1067   ck_assert_str_eq(s, "[0x02,0x01]");
   1068   free(s);
   1069   o->f->deserial(o, B);
   1070   s = toStringO(o);
   1071   ck_assert_str_eq(s, "true");
   1072   free(s);
   1073   terminateO(B);
   1074   terminateO(o);
   1075     // Double
   1076   initiateAllocateSmallJson(&o);
   1077   smallDoublet *od = allocSmallDouble(10);
   1078   o->f->setTop(o, (baset *)od);
   1079   finishO(od);
   1080   B = o->f->serial(o);
   1081   s = sToString((smallt *) B->B);
   1082   ck_assert_str_eq(s, "[0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x24,0x40]");
   1083   free(s);
   1084   o->f->deserial(o, B);
   1085   s = toStringO(o);
   1086   ck_assert_str_eq(s, "1.000000e+01");
   1087   free(s);
   1088   terminateO(B);
   1089   terminateO(o);
   1090     // Int
   1091   initiateAllocateSmallJson(&o);
   1092   oInt = allocSmallInt(85);
   1093   o->f->setTop(o, (baset *)oInt);
   1094   finishO(oInt);
   1095   B = o->f->serial(o);
   1096   s = sToString((smallt *) B->B);
   1097   ck_assert_str_eq(s, "[0x07,0x55,0x00,0x00,0x00,0x00,0x00,0x00,0x00]");
   1098   free(s);
   1099   o->f->deserial(o, B);
   1100   s = toStringO(o);
   1101   ck_assert_str_eq(s, "85");
   1102   free(s);
   1103   terminateO(B);
   1104   terminateO(o);
   1105     // string
   1106   initiateAllocateSmallJson(&o);
   1107   smallStringt *st = allocSmallString("sheepy");
   1108   o->f->setTop(o, (baset *)st);
   1109   finishO(st);
   1110   B = o->f->serial(o);
   1111   s = sToString((smallt *) B->B);
   1112   ck_assert_str_eq(s, "[0x08,0x73,0x68,0x65,0x65,0x70,0x79,0x00]");
   1113   free(s);
   1114   o->f->deserial(o, B);
   1115   s = toStringO(o);
   1116   ck_assert_str_eq(s, "sheepy");
   1117   free(s);
   1118   terminateO(B);
   1119   terminateO(o);
   1120     // dict
   1121   initiateAllocateSmallJson(&o);
   1122   smallDictt *sDD = allocSmallDict();
   1123   o->f->setTop(o, (baset *)sDD);
   1124   finishO(sDD);
   1125   B = o->f->serial(o);
   1126   s = sToString((smallt *) B->B);
   1127   ck_assert_str_eq(s, "[0x04,0x00,0x00,0x00,0x00]");
   1128   free(s);
   1129   o->f->deserial(o, B);
   1130   s = toStringO(o);
   1131   ck_assert_str_eq(s, "{}");
   1132   free(s);
   1133   terminateO(B);
   1134   terminateO(o);
   1135     // array
   1136   initiateAllocateSmallJson(&o);
   1137   smallArrayt *sAA = allocSmallArray();
   1138   o->f->setTop(o, (baset *)sAA);
   1139   finishO(sAA);
   1140   B = o->f->serial(o);
   1141   s = sToString((smallt *) B->B);
   1142   ck_assert_str_eq(s, "[0x0a,0x00,0x00,0x00,0x00]");
   1143   free(s);
   1144   o->f->deserial(o, B);
   1145   s = toStringO(o);
   1146   ck_assert_str_eq(s, "[]");
   1147   free(s);
   1148   terminateO(B);
   1149   terminateO(o);
   1150     // deserial non json object
   1151   initiateAllocateSmallJson(&o);
   1152   initiateAllocateSmallBytes(&B);
   1153   sContainert *c = allocSContainer(NULL);
   1154   B->B = sSerial((smallt *) c);
   1155   sFree((smallt *) c);
   1156   o->f->deserial(o, B);
   1157   ck_assert_uint_eq(o->topIsA, 0/*=JSON_IS_EMPTY*/);
   1158   terminateO(B);
   1159   terminateO(o);
   1160     // deserial empty sBytest
   1161   initiateAllocateSmallJson(&o);
   1162   initiateAllocateSmallBytes(&B);
   1163   o->f->deserial(o, B);
   1164   ck_assert_uint_eq(o->topIsA, 0/*=JSON_IS_EMPTY*/);
   1165   terminateO(B);
   1166   terminateO(o);
   1167     // NULL object
   1168   initiateAllocateSmallJson(&o);
   1169   o->f->setTypeUndefined(o);
   1170   sFree((smallt *) o->topU);
   1171   o->topU = NULL;
   1172   ck_assert_ptr_eq(o->f->serial(o),NULL);
   1173   o->f->deserial(o, NULL);
   1174   terminateO(o);
   1175   // free local object
   1176   obj.f->free(&obj);
   1177   ck_assert_str_eq(obj.type, "smallJson");
   1178   // free object
   1179   obj2->f->terminate(&obj2);
   1180   ck_assert_ptr_eq(obj2, NULL);
   1181   initiateAllocateSmallJson(&o);
   1182   terminateO(o);
   1183   ck_assert_ptr_eq(o, NULL);
   1184     // undefined
   1185   initiateAllocateSmallJson(&o);
   1186   o->f->setTypeUndefined(o);
   1187   terminateO(o);
   1188   ck_assert_ptr_eq(o, NULL);
   1189     // bool
   1190   initiateAllocateSmallJson(&o);
   1191   o->f->setTypeBool(o);
   1192   terminateO(o);
   1193   ck_assert_ptr_eq(o, NULL);
   1194     // double
   1195   initiateAllocateSmallJson(&o);
   1196   o->f->setTypeDouble(o);
   1197   terminateO(o);
   1198   ck_assert_ptr_eq(o, NULL);
   1199     // int
   1200   initiateAllocateSmallJson(&o);
   1201   o->f->setTypeInt(o);
   1202   terminateO(o);
   1203   ck_assert_ptr_eq(o, NULL);
   1204     // string
   1205   initiateAllocateSmallJson(&o);
   1206   o->f->setTypeString(o);
   1207   terminateO(o);
   1208   ck_assert_ptr_eq(o, NULL);
   1209     // dict
   1210   initiateAllocateSmallJson(&o);
   1211   o->f->setTypeDict(o);
   1212   terminateO(o);
   1213   ck_assert_ptr_eq(o, NULL);
   1214     // array
   1215   initiateAllocateSmallJson(&o);
   1216   o->f->setTypeArray(o);
   1217   terminateO(o);
   1218   ck_assert_ptr_eq(o, NULL);
   1219 
   1220 }
   1221 
   1222 
   1223 void cSmallArrayT(CuTest *tc UNUSED) {
   1224 
   1225   // local object
   1226   createSmallArray(obj);
   1227   ck_assert_str_eq(obj.type, "smallArray");
   1228   // object
   1229   createAllocateSmallArray(obj2);
   1230   ck_assert_str_eq(obj2->type, "smallArray");
   1231   // toString
   1232   char *s = obj2->f->toString(obj2);
   1233   ck_assert_str_eq(s, "[]");
   1234   free(s);
   1235   createAllocateUndefined(oU);
   1236   obj2->f->push(obj2, (baset *)oU);
   1237   finishO(oU);
   1238   createAllocateSmallInt(oInt);
   1239   oInt->f->set(oInt, 123);
   1240   obj2->f->push(obj2, (baset *)oInt);
   1241   finishO(oInt);
   1242   createAllocateSmallString(oStr);
   1243   oStr->f->set(oStr, "sheepy");
   1244   obj2->f->push(obj2, (baset *)oStr);
   1245   finishO(oStr);
   1246   s = obj2->f->toString(obj2);
   1247   ck_assert_str_eq(s, "[null,123,\"sheepy\"]");
   1248   free(s);
   1249     // delete an element
   1250   smallArrayt *o2;
   1251   o2 = obj2->f->duplicate(obj2);
   1252   o2->f->delElem(o2, 0);
   1253   s = o2->f->toString(o2);
   1254   ck_assert_str_eq(s, "[123,\"sheepy\"]");
   1255   free(s);
   1256   terminateO(o2);
   1257   // duplicate
   1258   smallArrayt *o;
   1259   o = obj2->f->duplicate(obj2);
   1260   undefinedt *u;
   1261   u = (undefinedt *) o->f->getAt(o, 0);
   1262   ck_assert(isOType(u, "undefined"));
   1263   terminateO(u);
   1264   smallIntt *in;
   1265   in = (smallIntt *) o->f->getAt(o, 1);
   1266   ck_assert(in->value->value == 123);
   1267   smashO(in);
   1268   smallStringt *st;
   1269   st = (smallStringt *) o->f->getAt(o, 2);
   1270   bool r = strEq(st->f->get(st), "sheepy");
   1271   ck_assert(r);
   1272   smashO(st);
   1273   terminateO(o);
   1274     // delete an element
   1275   o2 = obj2->f->duplicate(obj2);
   1276   o2->f->delElem(o2, 0);
   1277   o = o2->f->duplicate(o2);
   1278   in = (smallIntt *) o->f->getAt(o, 0);
   1279   ck_assert(in->value->value == 123);
   1280   smashO(in);
   1281   st = (smallStringt *) o->f->getAt(o, 1);
   1282   r = strEq(st->f->get(st), "sheepy");
   1283   ck_assert(r);
   1284   smashO(st);
   1285   terminateO(o);
   1286   terminateO(o2);
   1287   // fromArray
   1288   initiateAllocateSmallArray(&o);
   1289   char *array[] = {"1", "22", "333"};
   1290   char *arrayNULL[] = {"1", NULL, "333"};
   1291     // copy array to list
   1292   o->f->fromArray(o, (void *)array, 3);
   1293   ck_assert_uint_eq(o->f->len(o),3);
   1294   smallStringt *strFrom;
   1295   strFrom = (smallStringt*) o->f->getAt(o,0);
   1296   ck_assert_str_eq(strFrom->f->get(strFrom), "1");
   1297   smashO(strFrom);
   1298   strFrom = (smallStringt*) o->f->getAt(o,1);
   1299   ck_assert_str_eq(strFrom->f->get(strFrom), "22");
   1300   smashO(strFrom);
   1301   strFrom = (smallStringt*) o->f->getAt(o,2);
   1302   ck_assert_str_eq(strFrom->f->get(strFrom), "333");
   1303   smashO(strFrom);
   1304     // array with NULL inside
   1305   o->f->fromArray(o, (void *)arrayNULL, 3);
   1306   ck_assert_uint_eq(o->f->len(o),3);
   1307   strFrom = (smallStringt*) o->f->getAt(o,0);
   1308   ck_assert_str_eq(strFrom->f->get(strFrom), "1");
   1309   smashO(strFrom);
   1310   strFrom = (smallStringt*) o->f->getAt(o,1);
   1311   ck_assert_ptr_eq(strFrom, NULL);
   1312   strFrom = (smallStringt*) o->f->getAt(o,2);
   1313   ck_assert_str_eq(strFrom->f->get(strFrom), "333");
   1314   smashO(strFrom);
   1315     // char** list
   1316   char **shpList = listCreateS("lib", "sheepy");
   1317   o->f->fromArray(o, shpList, 0);
   1318   ck_assert_uint_eq(o->f->len(o),2);
   1319   listFreeS(shpList);
   1320     // NULL pointer to list - list not changed
   1321   o->f->fromArray(o, (void *)arrayNULL, 3);
   1322   o->f->fromArray(o, NULL, 3);
   1323   ck_assert_uint_eq(o->f->len(o),3);
   1324   strFrom = (smallStringt*) o->f->getAt(o,0);
   1325   ck_assert_str_eq(strFrom->f->get(strFrom), "1");
   1326   smashO(strFrom);
   1327   strFrom = (smallStringt*) o->f->getAt(o,1);
   1328   ck_assert_ptr_eq(strFrom, NULL);
   1329   strFrom = (smallStringt*) o->f->getAt(o,2);
   1330   ck_assert_str_eq(strFrom->f->get(strFrom), "333");
   1331   smashO(strFrom);
   1332   terminateO(o);
   1333   // push
   1334   o = obj2->f->duplicate(obj2);
   1335   initiateAllocateSmallInt(&in);
   1336   in->f->set(in, 654);
   1337   o->f->push(o, (baset *)in);
   1338   finishO(in);
   1339   in = (smallIntt *) o->f->getAt(o, 3);
   1340   ck_assert_uint_eq(o->f->len(o), 4);
   1341   ck_assert_uint_eq(in->value->value, 654);
   1342   smashO(in);
   1343     // NULL
   1344   o->f->push(o, NULL);
   1345   ck_assert_uint_eq(o->f->len(o), 4);
   1346   terminateO(o);
   1347   // pop
   1348   o = obj2->f->duplicate(obj2);
   1349   ck_assert_uint_eq(o->f->len(o), 3);
   1350   st = (smallStringt *) o->f->pop(o);
   1351   ck_assert_uint_eq(o->f->len(o), 2);
   1352   ck_assert_str_eq(st->f->get(st), "sheepy");
   1353   terminateO(st);
   1354   in = (smallIntt *) o->f->pop(o);
   1355   ck_assert_uint_eq(in->value->value, 123);
   1356   terminateO(in);
   1357   u = (undefinedt *) o->f->pop(o);
   1358   ck_assert(isOType(u, "undefined"));
   1359   terminateO(u);
   1360     // empty list
   1361   u = (undefinedt *) o->f->pop(o);
   1362   ck_assert_ptr_eq(u,NULL);
   1363     // after initialize
   1364   o->f->free(o);
   1365   ck_assert_uint_eq(o->f->len(o), 0);
   1366   u = (undefinedt *) o->f->pop(o);
   1367   ck_assert_uint_eq(o->f->len(o), 0);
   1368   ck_assert_ptr_eq(u,NULL);
   1369   terminateO(o);
   1370   // append
   1371   o  = obj2->f->duplicate(obj2);
   1372   o2 = obj2->f->duplicate(obj2);
   1373   in = (smallIntt *) o2->f->getAt(o2, 1);
   1374   in->value->value = 789;
   1375   o2->f->setAt(o2, 1, (baset *)in);
   1376   finishO(in);
   1377   o->f->append(o, o2);
   1378   s = toStringO(o);
   1379   ck_assert_str_eq(s, "[null,123,\"sheepy\",null,789,\"sheepy\"]");
   1380   free(s);
   1381     // same list
   1382   o->f->append(o, o);
   1383   s = toStringO(o);
   1384   ck_assert_str_eq(s, "[null,123,\"sheepy\",null,789,\"sheepy\"]");
   1385   free(s);
   1386   o->f->free(o);
   1387   o2->f->smash(&o2);
   1388     // empty list + list
   1389   o2 = obj2->f->duplicate(obj2);
   1390   in = (smallIntt *) o2->f->getAt(o2, 1);
   1391   in->value->value = 789;
   1392   o2->f->setAt(o2, 1, (baset *)in);
   1393   finishO(in);
   1394   o->f->append(o, o2);
   1395   s = toStringO(o);
   1396   ck_assert_str_eq(s, "[null,789,\"sheepy\"]");
   1397   free(s);
   1398     // list + empty list
   1399   o2->f->dispose(o2);
   1400   o->f->append(o, o2);
   1401   s = toStringO(o);
   1402   ck_assert_str_eq(s, "[null,789,\"sheepy\"]");
   1403   free(s);
   1404     // empty list + empty list
   1405   o->f->free(o);
   1406   o->f->append(o, o2);
   1407   s = toStringO(o);
   1408   ck_assert_str_eq(s, "[]");
   1409   free(s);
   1410   terminateO(o2);
   1411     // NULL list
   1412   o->f->append(o, NULL);
   1413   s = toStringO(o);
   1414   ck_assert_str_eq(s, "[]");
   1415   free(s);
   1416   terminateO(o);
   1417   // slice
   1418   o  = obj2->f->duplicate(obj2);
   1419   initiateAllocateSmallInt(&in);
   1420   in->f->set(in, 5345);
   1421   o->f->push(o, (baset *) in);
   1422   finishO(in);
   1423   o->f->slice(o,1,-1);
   1424   s = toStringO(o);
   1425   ck_assert_str_eq(s, "[123,\"sheepy\"]");
   1426   free(s);
   1427   terminateO(o);
   1428     // start outside
   1429   o  = obj2->f->duplicate(obj2);
   1430   initiateAllocateSmallInt(&in);
   1431   in->f->set(in, 5345);
   1432   o->f->push(o, (baset *) in);
   1433   finishO(in);
   1434   o->f->slice(o,20,-1);
   1435   s = toStringO(o);
   1436   ck_assert_str_eq(s, "[]");
   1437   free(s);
   1438   terminateO(o);
   1439     // start negative and outside
   1440   o  = obj2->f->duplicate(obj2);
   1441   initiateAllocateSmallInt(&in);
   1442   in->f->set(in, 5345);
   1443   o->f->push(o, (baset *) in);
   1444   finishO(in);
   1445   o->f->slice(o,-20,1);
   1446   s = toStringO(o);
   1447   ck_assert_str_eq(s, "[null]");
   1448   free(s);
   1449   terminateO(o);
   1450     // end outside
   1451   o  = obj2->f->duplicate(obj2);
   1452   initiateAllocateSmallInt(&in);
   1453   in->f->set(in, 5345);
   1454   o->f->push(o, (baset *) in);
   1455   finishO(in);
   1456   o->f->slice(o,2,40);
   1457   s = toStringO(o);
   1458   ck_assert_str_eq(s, "[\"sheepy\",5345]");
   1459   free(s);
   1460   terminateO(o);
   1461     // end negative and outside
   1462   o  = obj2->f->duplicate(obj2);
   1463   initiateAllocateSmallInt(&in);
   1464   in->f->set(in, 5345);
   1465   o->f->push(o, (baset *) in);
   1466   finishO(in);
   1467   o->f->slice(o,2,-40);
   1468   s = toStringO(o);
   1469   ck_assert_str_eq(s, "[]");
   1470   free(s);
   1471   terminateO(o);
   1472     // end before start
   1473   o  = obj2->f->duplicate(obj2);
   1474   initiateAllocateSmallInt(&in);
   1475   in->f->set(in, 5345);
   1476   o->f->push(o, (baset *) in);
   1477   finishO(in);
   1478   o->f->slice(o,3,2);
   1479   s = toStringO(o);
   1480   ck_assert_str_eq(s, "[]");
   1481   free(s);
   1482   terminateO(o);
   1483     // negative start last element
   1484   o  = obj2->f->duplicate(obj2);
   1485   initiateAllocateSmallInt(&in);
   1486   in->f->set(in, 5345);
   1487   o->f->push(o, (baset *) in);
   1488   finishO(in);
   1489   o->f->slice(o,-1,0);
   1490   s = toStringO(o);
   1491   ck_assert_str_eq(s, "[5345]");
   1492   free(s);
   1493   terminateO(o);
   1494     // start = end
   1495   o  = obj2->f->duplicate(obj2);
   1496   initiateAllocateSmallInt(&in);
   1497   in->f->set(in, 5345);
   1498   o->f->push(o, (baset *) in);
   1499   finishO(in);
   1500   o->f->slice(o,1,1);
   1501   s = toStringO(o);
   1502   ck_assert_str_eq(s, "[]");
   1503   free(s);
   1504   terminateO(o);
   1505     // empty list
   1506   initiateAllocateSmallArray(&o);
   1507   o->f->slice(o,0,0);
   1508   s = toStringO(o);
   1509   ck_assert_str_eq(s, "[]");
   1510   free(s);
   1511   terminateO(o);
   1512   // insert
   1513   o  = obj2->f->duplicate(obj2);
   1514   o2 = obj2->f->duplicate(obj2);
   1515   in = (smallIntt *) o2->f->getAt(o2, 1);
   1516   in->value->value = 789;
   1517   o2->f->setAt(o2, 1, (baset *)in);
   1518   finishO(in);
   1519   o->f->insert(o, 0, o2);
   1520   s = toStringO(o);
   1521   ck_assert_str_eq(s, "[null,789,\"sheepy\",null,123,\"sheepy\"]");
   1522   free(s);
   1523   terminateO(o);
   1524   o2->f->smash(&o2);
   1525     // negative index
   1526   o  = obj2->f->duplicate(obj2);
   1527   o2 = obj2->f->duplicate(obj2);
   1528   in = (smallIntt *) o2->f->getAt(o2, 1);
   1529   in->value->value = 789;
   1530   o2->f->setAt(o2, 1, (baset *)in);
   1531   finishO(in);
   1532   o->f->insert(o, -1, o2);
   1533   s = toStringO(o);
   1534   ck_assert_str_eq(s, "[null,123,\"sheepy\",null,789,\"sheepy\"]");
   1535   free(s);
   1536   terminateO(o);
   1537   o2->f->smash(&o2);
   1538     // edge
   1539   o  = obj2->f->duplicate(obj2);
   1540   o2 = obj2->f->duplicate(obj2);
   1541   in = (smallIntt *) o2->f->getAt(o2, 1);
   1542   in->value->value = 789;
   1543   o2->f->setAt(o2, 1, (baset *)in);
   1544   finishO(in);
   1545   o->f->insert(o, 3, o2);
   1546   s = toStringO(o);
   1547   ck_assert_str_eq(s, "[null,123,\"sheepy\",null,789,\"sheepy\"]");
   1548   free(s);
   1549   terminateO(o);
   1550   o2->f->smash(&o2);
   1551     // outside
   1552   o  = obj2->f->duplicate(obj2);
   1553   o2 = obj2->f->duplicate(obj2);
   1554   in = (smallIntt *) o2->f->getAt(o2, 1);
   1555   in->value->value = 789;
   1556   o2->f->setAt(o2, 1, (baset *)in);
   1557   finishO(in);
   1558   o->f->insert(o, 4, o2);
   1559   s = toStringO(o);
   1560   ck_assert_str_eq(s, "[null,123,\"sheepy\"]");
   1561   free(s);
   1562   o->f->insert(o, -5, o2);
   1563   s = toStringO(o);
   1564   ck_assert_str_eq(s, "[null,123,\"sheepy\"]");
   1565   free(s);
   1566   terminateO(o);
   1567   terminateO(o2);
   1568     // negative index in a one element list
   1569   o  = obj2->f->duplicate(obj2);
   1570   o2 = obj2->f->duplicate(obj2);
   1571   in = (smallIntt *) o2->f->getAt(o2, 1);
   1572   in->value->value = 789;
   1573   o2->f->setAt(o2, 1, (baset *)in);
   1574   finishO(in);
   1575   o->f->delElem(o, 1);
   1576   o->f->delElem(o, 2);
   1577   o->f->trim(o);
   1578   o->f->insert(o, -1, o2);
   1579   s = toStringO(o);
   1580   ck_assert_str_eq(s, "[null,null,789,\"sheepy\"]");
   1581   free(s);
   1582   terminateO(o);
   1583   o2->f->smash(&o2);
   1584     // empty list
   1585   initiateAllocateSmallArray(&o);
   1586   o2 = obj2->f->duplicate(obj2);
   1587   in = (smallIntt *) o2->f->getAt(o2, 1);
   1588   in->value->value = 789;
   1589   o2->f->setAt(o2, 1, (baset *)in);
   1590   finishO(in);
   1591   o->f->insert(o, 0, o2);
   1592   s = toStringO(o);
   1593   ck_assert_str_eq(s, "[null,789,\"sheepy\"]");
   1594   free(s);
   1595   terminateO(o);
   1596   o2->f->dispose(o2);
   1597     // empty insert list
   1598   o  = obj2->f->duplicate(obj2);
   1599   o->f->insert(o, 0, o2);
   1600   s = toStringO(o);
   1601   ck_assert_str_eq(s, "[null,123,\"sheepy\"]");
   1602   free(s);
   1603   terminateO(o);
   1604   o2->f->smash(&o2);
   1605     //NULL insert
   1606   o  = obj2->f->duplicate(obj2);
   1607   o->f->insert(o, 0, NULL);
   1608   s = toStringO(o);
   1609   ck_assert_str_eq(s, "[null,123,\"sheepy\"]");
   1610   free(s);
   1611   terminateO(o);
   1612   // del
   1613   o  = obj2->f->duplicate(obj2);
   1614   initiateAllocateSmallInt(&in);
   1615   in->f->set(in, 5345);
   1616   o->f->push(o, (baset *) in);
   1617   finishO(in);
   1618   o->f->del(o,1,-1);
   1619   s = toStringO(o);
   1620   ck_assert_str_eq(s, "[null,5345]");
   1621   free(s);
   1622   terminateO(o);
   1623     // start outside
   1624   o  = obj2->f->duplicate(obj2);
   1625   initiateAllocateSmallInt(&in);
   1626   in->f->set(in, 5345);
   1627   o->f->push(o, (baset *) in);
   1628   finishO(in);
   1629   o->f->del(o,20,-1);
   1630   s = toStringO(o);
   1631   ck_assert_str_eq(s, "[null,123,\"sheepy\",5345]");
   1632   free(s);
   1633   terminateO(o);
   1634     // start negative and outside
   1635   o  = obj2->f->duplicate(obj2);
   1636   initiateAllocateSmallInt(&in);
   1637   in->f->set(in, 5345);
   1638   o->f->push(o, (baset *) in);
   1639   finishO(in);
   1640   o->f->del(o,-20,1);
   1641   s = toStringO(o);
   1642   ck_assert_str_eq(s, "[123,\"sheepy\",5345]");
   1643   free(s);
   1644   terminateO(o);
   1645     // end outside
   1646   o  = obj2->f->duplicate(obj2);
   1647   initiateAllocateSmallInt(&in);
   1648   in->f->set(in, 5345);
   1649   o->f->push(o, (baset *) in);
   1650   finishO(in);
   1651   o->f->del(o,2,40);
   1652   s = toStringO(o);
   1653   ck_assert_str_eq(s, "[null,123]");
   1654   free(s);
   1655   terminateO(o);
   1656     // end negative and outside
   1657   o  = obj2->f->duplicate(obj2);
   1658   initiateAllocateSmallInt(&in);
   1659   in->f->set(in, 5345);
   1660   o->f->push(o, (baset *) in);
   1661   finishO(in);
   1662   o->f->del(o,2,-40);
   1663   s = toStringO(o);
   1664   ck_assert_str_eq(s, "[null,123,\"sheepy\",5345]");
   1665   free(s);
   1666   terminateO(o);
   1667     // end before start
   1668   o  = obj2->f->duplicate(obj2);
   1669   initiateAllocateSmallInt(&in);
   1670   in->f->set(in, 5345);
   1671   o->f->push(o, (baset *) in);
   1672   finishO(in);
   1673   o->f->del(o,3,2);
   1674   s = toStringO(o);
   1675   ck_assert_str_eq(s, "[null,123,\"sheepy\",5345]");
   1676   free(s);
   1677   terminateO(o);
   1678     // negative start last element
   1679   o  = obj2->f->duplicate(obj2);
   1680   initiateAllocateSmallInt(&in);
   1681   in->f->set(in, 5345);
   1682   o->f->push(o, (baset *) in);
   1683   finishO(in);
   1684   o->f->del(o,-1,0);
   1685   s = toStringO(o);
   1686   ck_assert_str_eq(s, "[null,123,\"sheepy\"]");
   1687   free(s);
   1688   terminateO(o);
   1689     // start = end
   1690   o  = obj2->f->duplicate(obj2);
   1691   initiateAllocateSmallInt(&in);
   1692   in->f->set(in, 5345);
   1693   o->f->push(o, (baset *) in);
   1694   finishO(in);
   1695   o->f->del(o,1,1);
   1696   s = toStringO(o);
   1697   ck_assert_str_eq(s, "[null,123,\"sheepy\",5345]");
   1698   free(s);
   1699   terminateO(o);
   1700     // empty list
   1701   initiateAllocateSmallArray(&o);
   1702   o->f->del(o,0,0);
   1703   s = toStringO(o);
   1704   ck_assert_str_eq(s, "[]");
   1705   free(s);
   1706   terminateO(o);
   1707   // len
   1708   ck_assert_uint_eq(obj2->f->len(obj2), 3);
   1709   // trim
   1710   o = obj2->f->duplicate(obj2);
   1711   ck_assert_uint_eq(o->f->len(o), 3);
   1712   st = (smallStringt *) o->f->pop(o);
   1713   terminateO(st);
   1714   o->f->delElem(o, 0);
   1715   o->f->trim(o);
   1716   ck_assert_uint_eq(o->f->len(o), 1);
   1717   s = toStringO(o);
   1718   ck_assert_str_eq(s, "[123]");
   1719   free(s);
   1720   terminateO(o);
   1721   // getAt
   1722   o = obj2->f->duplicate(obj2);
   1723   u = (undefinedt *) o->f->getAt(o, 0);
   1724   ck_assert_str_eq(u->type, "undefined");
   1725   terminateO(u);
   1726   st = (smallStringt *) o->f->getAt(o, -1);
   1727   ck_assert_str_eq(st->type, "smallString");
   1728   smashO(st);
   1729     // outside
   1730   u = (undefinedt *) o->f->getAt(o, 4);
   1731   ck_assert_ptr_eq(u, NULL);
   1732   u = (undefinedt *) o->f->getAt(o, -4);
   1733   ck_assert_ptr_eq(u, NULL);
   1734   terminateO(o);
   1735     // empty
   1736   initiateAllocateSmallArray(&o);
   1737   u = (undefinedt *) o->f->getAt(o, 0);
   1738   ck_assert_ptr_eq(u, NULL);
   1739   terminateO(o);
   1740   // setAt
   1741   o = obj2->f->duplicate(obj2);
   1742   initiateAllocateSmallInt(&in);
   1743   o->f->setAt(o, 0, (baset *) in);
   1744   finishO(in);
   1745   s = toStringO(o);
   1746   ck_assert_str_eq(s, "[0,123,\"sheepy\"]");
   1747   free(s);
   1748   initiateAllocateSmallInt(&in);
   1749   o->f->setAt(o, -1, (baset *) in);
   1750   finishO(in);
   1751   s = toStringO(o);
   1752   ck_assert_str_eq(s, "[0,123,0]");
   1753   free(s);
   1754     // outside
   1755   o->f->setAt(o, 4, (baset *) in);
   1756   s = toStringO(o);
   1757   ck_assert_str_eq(s, "[0,123,0]");
   1758   free(s);
   1759   o->f->setAt(o, -4, (baset *) in);
   1760   s = toStringO(o);
   1761   ck_assert_str_eq(s, "[0,123,0]");
   1762   free(s);
   1763   terminateO(o);
   1764   // empty
   1765   o = obj2->f->duplicate(obj2);
   1766   o->f->empty(o);
   1767   ck_assert(o->f->isEmpty(o));
   1768   terminateO(o);
   1769   // isEmpty
   1770   o = obj2->f->duplicate(obj2);
   1771   ck_assert(!o->f->isEmpty(o));
   1772   terminateO(o);
   1773   initiateAllocateSmallArray(&o);
   1774   ck_assert(o->f->isEmpty(o));
   1775   terminateO(o);
   1776   // typeString type typeStrings types
   1777   initiateAllocateSmallArray(&o2);
   1778   o  = allocSmallArray();
   1779   oU = allocUndefined();
   1780   o->f->push(o, (baset *)oU);
   1781   finishO(oU);
   1782   oInt = allocSmallInt(123);
   1783   o->f->push(o, (baset *)oInt);
   1784   finishO(oInt);
   1785   oStr = allocSmallString("sheepy");
   1786   o->f->push(o, (baset *)oStr);
   1787   finishO(oStr);
   1788   o->f->push(o, NULL);
   1789     // typeString
   1790   s = (char *)o->f->typeString(o, 0);
   1791   ck_assert_str_eq(s, "undefined");
   1792     // type
   1793   char c = o->f->type(o, 2);
   1794   ck_assert_uint_eq(c, STRING);
   1795       // negative index
   1796   c = o->f->type(o, -2);
   1797   ck_assert_uint_eq(c, INT);
   1798       // outside
   1799   ck_assert(!o->f->type(o, 10));
   1800   ck_assert(!o->f->type(o, -14));
   1801       // NULL element
   1802   c = o->f->type(o, 0);
   1803   ck_assert_uint_eq(c, UNDEFINED);
   1804       // empty object
   1805   ck_assert(!o2->f->type(o2, 0));
   1806     // typeStrings
   1807   const char **l = o->f->typeStrings(o);
   1808   s = joinCS(l, ",");
   1809   ck_assert_str_eq(s, "undefined,int,string");
   1810   free(s);
   1811   free(l);
   1812       // empty object
   1813   ck_assert_ptr_eq(o2->f->typeStrings(o2), NULL);
   1814     // types
   1815   smallBytest *B = o->f->types(o);
   1816   s = sToStringTiny((smallt *)B->B);
   1817   ck_assert_str_eq(s, "[0x01,0x07,0x08]");
   1818   free(s);
   1819       // empty object
   1820   ck_assert_ptr_eq(o2->f->types(o2), NULL);
   1821   terminateO(B);
   1822   terminateO(o);
   1823   terminateO(o2);
   1824   // free local object
   1825   obj.f->free(&obj);
   1826   ck_assert_str_eq(obj.type, "smallArray");
   1827   // free object
   1828   obj2->f->terminate(&obj2);
   1829   ck_assert_ptr_eq(obj2, NULL);
   1830   // init NULL
   1831   initiateAllocateSmallArray(NULL);
   1832 
   1833 }
   1834 
   1835 
   1836 void cUndefinedT(CuTest *tc UNUSED) {
   1837 
   1838   // local object
   1839   createUndefined(obj);
   1840   ck_assert_str_eq(obj.type, "undefined");
   1841   // object
   1842   createAllocateUndefined(obj2);
   1843   ck_assert_str_eq(obj2->type, "undefined");
   1844   // toString
   1845   char *s = obj2->f->toString(obj2);
   1846   ck_assert_str_eq(s, "null");
   1847   free(s);
   1848   // duplicate
   1849   undefinedt *o;
   1850   o = obj2->f->duplicate(obj2);
   1851   terminateO(o);
   1852   // free local object
   1853   obj.f->free(&obj);
   1854   ck_assert_str_eq(obj.type, "undefined");
   1855   // free object
   1856   obj2->f->terminate(&obj2);
   1857   ck_assert_ptr_eq(obj2, NULL);
   1858 
   1859 }
   1860 
   1861 
   1862 
   1863 void cSmallBytesT(CuTest *tc UNUSED) {
   1864 
   1865   // local object
   1866   createSmallBytes(obj);
   1867   ck_assert_str_eq(obj.type, "smallBytes");
   1868   // object
   1869   createAllocateSmallBytes(obj2);
   1870   ck_assert_str_eq(obj2->type, "smallBytes");
   1871   // alloc - pushBuffer
   1872   smallBytest *obj3 = allocSmallBytes(NULL, 0);
   1873   terminateO(obj3);
   1874   // toString
   1875   char *s = obj2->f->toString(obj2);
   1876   ck_assert_str_eq(s, "[]");
   1877   free(s);
   1878   // duplicate
   1879   obj2->B = allocSBytes();
   1880   sBytesPush(&(obj2->B), 2);
   1881   obj3 = duplicateO(obj2);
   1882   ck_assert_uint_eq(obj3->B->data, 2);
   1883   terminateO(obj3);
   1884   // get
   1885   obj3 = duplicateO(obj2);
   1886   char *r = obj3->f->get(obj3);
   1887   ck_assert_uint_eq(*r, 2);
   1888   terminateO(obj3);
   1889   // push
   1890   obj3 = duplicateO(obj2);
   1891   obj3->f->push(obj3, 4);
   1892   r = obj3->f->get(obj3);
   1893   ck_assert_uint_eq(r[1], 4);
   1894   terminateO(obj3);
   1895   // getAt
   1896   obj3 = duplicateO(obj2);
   1897   char c = obj3->f->getAt(obj3,0);
   1898   ck_assert_uint_eq(c, 2);
   1899   c = obj3->f->getAt(obj3,1);
   1900   ck_assert_uint_eq(c, 0);
   1901   terminateO(obj3);
   1902     // NULL
   1903   initiateAllocateSmallBytes(&obj3);
   1904   c = obj3->f->getAt(obj3,0);
   1905   ck_assert_uint_eq(c, 0);
   1906   terminateO(obj3);
   1907   // free local object
   1908   obj.f->free(&obj);
   1909   ck_assert_str_eq(obj.type, "smallBytes");
   1910   // free object
   1911   obj2->f->terminate(&obj2);
   1912   ck_assert_ptr_eq(obj2, NULL);
   1913 
   1914 }
   1915 
   1916 
   1917 void putsOT(CuTest *tc UNUSED) {
   1918 
   1919   createAllocateSmallArray(l);
   1920 
   1921   // object
   1922   putsO(l);
   1923   // NULL
   1924   putsO(NULL);
   1925 
   1926   terminateO(l);
   1927 
   1928 }
   1929 
   1930 
   1931 void execOT(CuTest *tc UNUSED) {
   1932 
   1933   createAllocateSmallArray(l);
   1934 
   1935   // command
   1936   execO("ls libsheepyObjectTest.c", l, NULL);
   1937   ck_assert_uint_eq(l->f->len(l),1);
   1938   ck_assert_str_eq(l->f->getAtS(l, 0), "libsheepyObjectTest.c");
   1939   freeO(l);
   1940 
   1941   // invalid command
   1942   execO("randomComand", l, NULL);
   1943   ck_assert_uint_eq(l->f->len(l),0);
   1944   terminateO(l);
   1945   // NULL command
   1946   ck_assert_int_eq(execO(NULL, NULL, NULL), 0);
   1947 
   1948 }
   1949 
   1950 
   1951 void walkDirOT(CuTest *tc UNUSED) {
   1952 
   1953   smallArrayt *l;
   1954 
   1955   // existing directory
   1956   l = walkDirO("../dirTest.null");
   1957   ck_assert_uint_eq(l->f->len(l),3);
   1958   ck_assert_str_eq(l->f->getAtS(l, 0), "../dirTest.null/one");
   1959   ck_assert_str_eq(l->f->getAtS(l, 1), "../dirTest.null/two/four");
   1960   ck_assert_str_eq(l->f->getAtS(l, 2), "../dirTest.null/two/three");
   1961   terminateO(l);
   1962   // empty path
   1963   ck_assert_ptr_eq(walkDirO(""), NULL);
   1964   // non existing directory
   1965   l = walkDirO("nonExisting.null");
   1966   ck_assert(l->f->isEmpty(l));
   1967   terminateO(l);
   1968   // NULL path
   1969   ck_assert_ptr_eq(walkDirO(NULL), NULL);
   1970 
   1971 }
   1972 
   1973 
   1974 void expandHomeOT(CuTest *tc UNUSED) {
   1975 
   1976   // no ~/
   1977   createAllocateSmallString(v);
   1978   v->f->set(v, "sheepy");
   1979   expandHomeO(v);
   1980   ck_assert(v->f->equalS(v, "sheepy"));
   1981   terminateO(v);
   1982   // NULL var
   1983   expandHomeO(NULL);
   1984 
   1985 }
   1986 
   1987 
   1988 void chDirOT(CuTest *tc UNUSED) {
   1989 
   1990   // change directory
   1991   smallStringt *c;
   1992   c = getCwdO();
   1993   createAllocateSmallString(v);
   1994   v->f->set(v, "../dirTest.null");
   1995   ck_assert(chDirO(v));
   1996   char *s = getCwd();
   1997   bool r = (size_t)findS(s, "dirTest.null");
   1998   ck_assert(r);
   1999   chDirO(c);
   2000   free(s);
   2001   terminateO(c);
   2002   // non existing dir
   2003   createAllocateSmallString(n);
   2004   n->f->set(n, "RandomNonExistingDir");
   2005   ck_assert(!chDirO(n));
   2006   // NULL path
   2007   ck_assert(!chDirO(NULL));
   2008   terminateO(v);
   2009   terminateO(n);
   2010 
   2011 }
   2012 
   2013 
   2014 void fileExistsOT(CuTest *tc UNUSED) {
   2015 
   2016   createAllocateSmallArray(sA);
   2017   char **l = listCreateS("../libsheepyTest.c", "wefwepfk34.c", "../../src", "");
   2018   sA->f->fromArrayNFree(sA, l, 0);
   2019   // detect existing file
   2020   smallStringt *S = sA->f->getAtSmallString(sA, 0);
   2021   ck_assert(fileExistsO(S));
   2022   finishO(S);
   2023   // non existing file
   2024   S = sA->f->getAtSmallString(sA, 1);
   2025   ck_assert(!fileExistsO(S));
   2026   finishO(S);
   2027   // folder
   2028   S = sA->f->getAtSmallString(sA, 2);
   2029   ck_assert(fileExistsO(S));
   2030   finishO(S);
   2031   // empty path
   2032   S = sA->f->getAtSmallString(sA, 3);
   2033   ck_assert(!fileExistsO(S));
   2034   finishO(S);
   2035   // NULL path
   2036   ck_assert(!fileExistsO(NULL));
   2037   terminateO(sA);
   2038 
   2039 }
   2040 
   2041 
   2042 void fileChmodOT(CuTest *tc UNUSED) {
   2043 
   2044   // existing file
   2045   createAllocateSmallString(v);
   2046   v->f->set(v, "../chmodTest.null");
   2047   ck_assert(fileChmodO(v, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH));
   2048   ck_assert(fileChmodO(v, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH));
   2049   // non existing file
   2050   createAllocateSmallString(n);
   2051   n->f->set(n, "qweqwe_null");
   2052   ck_assert(!fileChmodO(n, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH));
   2053   // empty path
   2054   createAllocateSmallString(e);
   2055   e->f->set(e, "");
   2056   ck_assert(!fileChmodO(e,0));
   2057   // NULL path
   2058   ck_assert(!fileChmodO(NULL,0));
   2059   terminateO(v);
   2060   terminateO(n);
   2061   terminateO(e);
   2062 
   2063 }
   2064 
   2065 
   2066 void fileSizeOT(CuTest *tc UNUSED) {
   2067 
   2068   // existing file
   2069   createAllocateSmallString(s);
   2070   s->f->set(s, "../sizeTest.null");
   2071   ck_assert_uint_eq(fileSizeO(s), 743);
   2072   // empty file
   2073   createAllocateSmallString(v);
   2074   v->f->set(v, "../chmodTest.null");
   2075   ck_assert_uint_eq(fileSizeO(v), 0);
   2076   // non existing file
   2077   createAllocateSmallString(n);
   2078   n->f->set(n, "qweqwe_null");
   2079   ck_assert_int_eq(fileSizeO(n), -1);
   2080   // empty path
   2081   createAllocateSmallString(e);
   2082   e->f->set(e, "");
   2083   ck_assert_int_eq(fileSizeO(e), -1);
   2084   // NULL path
   2085   ck_assert_int_eq(fileSizeO(NULL), -1);
   2086   terminateO(s);
   2087   terminateO(v);
   2088   terminateO(n);
   2089   terminateO(e);
   2090 
   2091 }
   2092 
   2093 
   2094 void mkdirParentsOT(CuTest *tc UNUSED) {
   2095 
   2096   // directory
   2097   pError0(rmAll("mkdirTest.null/null"));
   2098   createAllocateSmallString(s);
   2099   s->f->set(s, "mkdirTest.null/null");
   2100   ck_assert_int_eq(mkdirParentsO(s),1);
   2101   // not allowed
   2102   createAllocateSmallString(v);
   2103   v->f->set(v, "/usr/null");
   2104   ck_assert_int_eq(mkdirParentsO(v),0);
   2105   // empty path
   2106   createAllocateSmallString(e);
   2107   e->f->set(e, "");
   2108   ck_assert_int_eq(mkdirParentsO(e),0);
   2109   // NULL path
   2110   ck_assert_int_eq(mkdirParentsO(NULL),0);
   2111   terminateO(s);
   2112   terminateO(e);
   2113   terminateO(v);
   2114 
   2115 }
   2116 
   2117 
   2118 void rmAllOT(CuTest *tc UNUSED) {
   2119 
   2120   // directory
   2121   createAllocateSmallString(s);
   2122   s->f->set(s, "rmAllTest.null/null");
   2123   pError0(mkdirParents("rmAllTest.null/null"));
   2124   ck_assert_int_eq(rmAllO(s),1);
   2125   // empty path
   2126   createAllocateSmallString(e);
   2127   e->f->set(e,"");
   2128   ck_assert_int_eq(rmAllO(e),0);
   2129   // too little permissions
   2130   createAllocateSmallString(v);
   2131   v->f->set(v,"/var/lock");
   2132   ck_assert_int_eq(rmAllO(v),0);
   2133   // NULL path
   2134   ck_assert_int_eq(rmAllO(NULL),0);
   2135   terminateO(s);
   2136   terminateO(e);
   2137   terminateO(v);
   2138 
   2139 
   2140 }
   2141 
   2142 
   2143 void copyOT(CuTest *tc UNUSED) {
   2144 
   2145   // file
   2146   createAllocateSmallString(s);
   2147   createAllocateSmallString(d);
   2148   s->f->set(s, "../chmodTest.null");
   2149   d->f->set(d, "../copyTest.null");
   2150   ck_assert_int_eq(copyO(s, d),1);
   2151   bool r = fileExists("../copyTest.null");
   2152   ck_assert(r);
   2153   // too little permissions
   2154   pError0(fileChmod("../copyTest.null", 1));
   2155   ck_assert_int_eq(copyO(d, d),0);
   2156   pError0(fileChmod("../copyTest.null", 777));
   2157   pError0(rmAll("../copyTest.null"));
   2158   // empty path
   2159   createAllocateSmallString(e);
   2160   e->f->set(e, "");
   2161   ck_assert_int_eq(copyO(e, d),0);
   2162   ck_assert(!fileExists("copyTest.null"));
   2163   ck_assert_int_eq(copyO(s, e),0);
   2164   ck_assert(!fileExists("copyTest.null"));
   2165   // NULL path
   2166   ck_assert_int_eq(copyO(NULL, d),0);
   2167   ck_assert_int_eq(copyO(s, NULL),0);
   2168   ck_assert_int_eq(copyO(NULL, NULL),0);
   2169   terminateO(s);
   2170   terminateO(d);
   2171   terminateO(e);
   2172 
   2173 }
   2174 
   2175 
   2176 void randomSOT(CuTest *tc UNUSED) {
   2177 
   2178   // get random string
   2179   smallStringt *s = randomSO(10);
   2180   ck_assert_ptr_ne(s, NULL);
   2181   terminateO(s);
   2182   // invalid length (0)
   2183   ck_assert_ptr_eq(randomSO(0), NULL);
   2184 
   2185   randomUrandomClose();
   2186 
   2187 }
   2188 
   2189 
   2190 void randomAlphaNumSOT(CuTest *tc UNUSED) {
   2191 
   2192   // get random string
   2193   smallStringt *s = randomAlphaNumSO(10);
   2194   ck_assert_ptr_ne(s, NULL);
   2195   terminateO(s);
   2196   // invalid length (0)
   2197   ck_assert_ptr_eq(randomAlphaNumSO(0), NULL);
   2198 
   2199   randomUrandomClose();
   2200 
   2201 }
   2202 
   2203 
   2204 void readLineOT(CuTest *tc UNUSED) {
   2205 
   2206   FILE *fp;
   2207   smallStringt *s;
   2208 
   2209   // file with data
   2210   fp = fopen("../textTest.null", "r");
   2211   s = readLineO(fp);
   2212   fclose(fp);
   2213   ck_assert_str_eq(s->f->get(s), "LINE 1");
   2214   terminateO(s);
   2215   // empty file or end of stream
   2216   fp = fopen("../chmodTest.null", "r");
   2217   s = readLineO(fp);
   2218   fclose(fp);
   2219   ck_assert_str_eq(ssGet(s), "");
   2220   terminateO(s);
   2221   // NULL stream
   2222   ck_assert_ptr_eq(readLineO(NULL), NULL);
   2223 
   2224 
   2225 }
   2226 
   2227 
   2228 void toSmalltT(CuTest *tc UNUSED) {
   2229 
   2230   smallStringt *s;
   2231   smallIntt *i;
   2232 
   2233   // undefined
   2234   createAllocateUndefined(u);
   2235   sUndefinedt *su = (sUndefinedt *) toSmallt((baset *)u);
   2236   finishO(u);
   2237   ck_assert(isSType(su, UNDEFINED));
   2238   sFree((smallt *) su);
   2239   // smallArray
   2240   createAllocateSmallArray(a);
   2241   initiateAllocateSmallString(&s);
   2242   s->f->set(s, "sheepy");
   2243   a->f->push(a, (baset *) s);
   2244   finishO(s);
   2245   initiateAllocateSmallInt(&i);
   2246   i->f->set(i, 20);
   2247   a->f->push(a, (baset *) i);
   2248   finishO(i);
   2249   sArrayt *sa = (sArrayt *) toSmallt((baset *)a);
   2250   finishO(a);
   2251   ck_assert_uint_eq(sa->count, 2);
   2252   char *S = sToString((smallt *) sa);
   2253   ck_assert_str_eq(S, "[\"sheepy\",20]");
   2254   free(S);
   2255   sFree((smallt *) sa);
   2256   // smallDict
   2257   createAllocateSmallDict(d);
   2258   initiateAllocateSmallString(&s);
   2259   s->f->set(s, "sheepy");
   2260   d->f->set(d, "s", (baset *) s);
   2261   finishO(s);
   2262   initiateAllocateSmallInt(&i);
   2263   i->f->set(i, 20);
   2264   d->f->set(d, "i", (baset *) i);
   2265   finishO(i);
   2266   sDictt *sd = (sDictt *) toSmallt((baset *)d);
   2267   finishO(d);
   2268   ck_assert_uint_eq(sd->count, 2);
   2269   S = sToString((smallt *) sd);
   2270   ck_assert_str_eq(S, "{\"s\":\"sheepy\",\"i\":20}");
   2271   free(S);
   2272   sFree((smallt *) sd);
   2273   // smallJson
   2274   createAllocateSmallJson(j);
   2275   smallt *so = toSmallt((baset *)j);
   2276   ck_assert_ptr_ne(so, NULL);
   2277   ck_assert_int_eq(so->type, CONTAINER);
   2278   ck_assert_ptr_eq(((sContainert*)so)->data, j);
   2279   sFree(so); // sFree does terminateO(j); because smallJson is stored in a container
   2280   // NULL
   2281   ck_assert_ptr_eq(toSmallt(NULL), NULL);
   2282 
   2283 }
   2284 
   2285 
   2286 void toBasetT(CuTest *tc UNUSED) {
   2287 
   2288   // bool
   2289   sBoolt *sb    = allocSBool(true);
   2290   smallBoolt *b = (smallBoolt *) toBaset((smallt *)sb);
   2291   ck_assert(b->value->value);
   2292   terminateO(b);
   2293   // container
   2294   sContainert *sc = allocSContainer(strdup("sheepy"));
   2295   smallContainert *c = (smallContainert *) toBaset((smallt *)sc);
   2296   ck_assert_str_eq(c->data->data, "sheepy");
   2297   free(c->data->data);
   2298   terminateO(c);
   2299   // double
   2300   sDoublet     *sD = allocSDouble(10);
   2301   smallDoublet *D  = (smallDoublet *) toBaset((smallt *)sD);
   2302   ck_assert_uint_eq((uint)D->value->value, 10);
   2303   terminateO(D);
   2304   // int
   2305   sIntt     *si = allocSInt(10);
   2306   smallIntt  *i = (smallIntt *) toBaset((smallt *)si);
   2307   ck_assert_uint_eq(i->value->value, 10);
   2308   terminateO(i);
   2309   // string
   2310   sStringt      *ss = allocSStringTiny("sheepy");
   2311   smallStringt   *s = (smallStringt *) toBaset((smallt *)ss);
   2312   char           *r = ssGet(s);
   2313   ck_assert_str_eq(r, "sheepy");
   2314   terminateO(s);
   2315   // undefined
   2316   sUndefinedt *su = allocSUndefined();
   2317   undefinedt   *u = (undefinedt *) toBaset((smallt *)su);
   2318   ck_assert(isOType(u, "undefined"));
   2319   sFree((smallt *) su);
   2320   terminateO(u);
   2321   // smallArray
   2322   sArrayt *sa    = allocSArray();
   2323   ss             = allocSStringTiny("sheepy");
   2324   sArrayPushTiny(&sa, (smallt *) ss);
   2325   si             = allocSInt(20);
   2326   sArrayPushTiny(&sa, (smallt *) si);
   2327   smallArrayt *a = (smallArrayt *) toBaset((smallt *)sa);
   2328   ck_assert_uint_eq(a->a->count, 2);
   2329   char *S = toStringO(a);
   2330   ck_assert_str_eq(S, "[\"sheepy\",20]");
   2331   free(S);
   2332   terminateO(a);
   2333   // smallDict
   2334   sDictt *sd    = allocSDict();
   2335   ss            = allocSStringTiny("sheepy");
   2336   sDictPushTiny(&sd, "s", (smallt *) ss);
   2337   si            = allocSInt(20);
   2338   sDictPushTiny(&sd, "i", (smallt *) si);
   2339   smallDictt *d = (smallDictt *) toBaset((smallt *)sd);
   2340   ck_assert_uint_eq(d->d->count, 2);
   2341   S = toStringO(d);
   2342   ck_assert_str_eq(S, "{\"s\":\"sheepy\",\"i\":20}");
   2343   free(S);
   2344   terminateO(d);
   2345   // NULL
   2346   ck_assert_ptr_eq(toBaset(NULL), NULL);
   2347 
   2348 }
   2349 
   2350 
   2351 
   2352 
   2353 
   2354 
   2355 int main(int n UNUSED, char**v UNUSED) {
   2356   // disable btrace to make the test run faster
   2357   btraceDisable();
   2358   CuString *output = CuStringNew();
   2359   CuSuite *suite = CuSuiteNew();
   2360 
   2361   SUITE_ADD_TEST(suite, cSmallDictT);
   2362   SUITE_ADD_TEST(suite, cSmallJsonT);
   2363   SUITE_ADD_TEST(suite, cSmallArrayT);
   2364   SUITE_ADD_TEST(suite, cUndefinedT);
   2365   SUITE_ADD_TEST(suite, cSmallBytesT);
   2366   SUITE_ADD_TEST(suite, putsOT);
   2367   SUITE_ADD_TEST(suite, execOT);
   2368   SUITE_ADD_TEST(suite, walkDirOT);
   2369   SUITE_ADD_TEST(suite, expandHomeOT);
   2370   SUITE_ADD_TEST(suite, chDirOT);
   2371   SUITE_ADD_TEST(suite, fileExistsOT);
   2372   SUITE_ADD_TEST(suite, fileChmodOT);
   2373   SUITE_ADD_TEST(suite, fileSizeOT);
   2374   SUITE_ADD_TEST(suite, mkdirParentsOT);
   2375   SUITE_ADD_TEST(suite, rmAllOT);
   2376   SUITE_ADD_TEST(suite, copyOT);
   2377   SUITE_ADD_TEST(suite, randomSOT);
   2378   SUITE_ADD_TEST(suite, randomAlphaNumSOT);
   2379   SUITE_ADD_TEST(suite, readLineOT);
   2380   SUITE_ADD_TEST(suite, toSmalltT);
   2381   SUITE_ADD_TEST(suite, toBasetT);
   2382 
   2383 
   2384   CuSuiteRun(suite);
   2385   CuSuiteDetails(suite, output);
   2386   printf ("%s\n", output->buffer);
   2387   return suite->failCount;
   2388 }