netSerial

serializer producing compact bitstreams
git clone https://noulin.net/git/netSerial.git
Log | Files | Refs | README | LICENSE

testNetSerial.c (50221B)


      1 #! /usr/bin/env sheepy
      2 /* or direct path to sheepy: #! /usr/local/bin/sheepy */
      3 
      4 /** \file
      5  * Each test must be independent and self contained
      6  */
      7 
      8 #include <check.h>
      9 
     10 //START MEM TEST ANCHOR
     11 
     12 #include "libsheepyObject.h"
     13 #include "netSerial.h"
     14 
     15 int argc; char **argv;
     16 
     17 /* enable/disable logging */
     18 /* #undef pLog */
     19 /* #define pLog(...) */
     20 
     21 
     22 START_TEST(topT)
     23 
     24   // STEPS
     25   // init
     26   // init allocate
     27   // terminate
     28   // allocate
     29   // string
     30   // duplicate
     31 
     32   createNetSerial(n);
     33   createNetSerial(ds);
     34   char *s;
     35   smallBytest *B;
     36   createSmallDict(d);
     37   createSmallArray(a);
     38 
     39   // empty smallBytes
     40   initiateG(&B);
     41   pushBufferG(B, NULL, 1);
     42   // store garbage data in empty smallBytes
     43   B->B->data = 0;
     44   ck_assert_ptr_eq(getTopTypeG(&ds), NULL);
     45   deserialG(&ds, B);
     46   // nothing should deserialized
     47   ck_assert_ptr_eq(getTopTypeG(&ds), NULL);
     48   terminateG(B);
     49 
     50   // undefined
     51   undefinedt *oU = allocUndefined();
     52   setTopNFreeG(&n, (baset *)oU);
     53   B = serialG(&n);
     54   s = sToString((smallt *) B->B);
     55   ck_assert_str_eq(s, "[0x00]");
     56   free(s);
     57   deserialG(&ds, B);
     58   s = toStringG(&ds);
     59   ck_assert_str_eq(s, "null");
     60   free(s);
     61   terminateG(B);
     62   freeManyG(&n, &ds);
     63 
     64   // bool
     65   setTopG(&n, TRUE);
     66   B = serialG(&n);
     67   s = sToString((smallt *) B->B);
     68   ck_assert_str_eq(s, "[0x11]");
     69   free(s);
     70   deserialG(&ds, B);
     71   s = toStringG(&ds);
     72   ck_assert_str_eq(s, "true");
     73   free(s);
     74   terminateG(B);
     75   freeManyG(&n, &ds);
     76 
     77   // double
     78   setTopG(&n, 1.2);
     79   B = serialG(&n);
     80   logI("len %u", lenG(B));
     81   logSI("%s", toHexSepS(getValG(B), lenG(B), " "));
     82   s = sToString((smallt *) B->B);
     83   ck_assert_str_eq(s, "[0x03,0x33,0x33,0x33,0x33,0x33,0x33,0xf3,0x3f]");
     84   free(s);
     85   deserialG(&ds, B);
     86   s = toStringG(&ds);
     87   ck_assert_str_eq(s, "1.200000e+00");
     88   free(s);
     89   terminateG(B);
     90   freeManyG(&n, &ds);
     91 
     92   // TODO test with 0x8000000000000000 and 0x7FFFFFFFFFFFFFFF
     93   // 64 bit int test with bit 63 set
     94   setTopG(&n, -8030967404224553996);
     95   B = serialG(&n);
     96   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
     97   s = sToString((smallt *) B->B);
     98   ck_assert_str_eq(s, "[0xf4,0x82,0xd2,0x8b,0xc7,0xb7,0xd2,0xbb,0xee,0x1b]");
     99   free(s);
    100   deserialG(&ds, B);
    101   s = toStringG(&ds);
    102   logVarG(s);
    103   ck_assert_str_eq(s, "-8030967404224553996");
    104   free(s);
    105   terminateG(B);
    106   freeManyG(&n, &ds);
    107 
    108   // 64 bit int test large positive value
    109   setTopG(&n, 12000000000UL);
    110   B = serialG(&n);
    111   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    112   s = sToString((smallt *) B->B);
    113   ck_assert_str_eq(s, "[0x84,0x80,0xbc,0xc1,0x96,0x0b]");
    114   free(s);
    115   deserialG(&ds, B);
    116   s = toStringG(&ds);
    117   logVarG(s);
    118   ck_assert_str_eq(s, "12000000000");
    119   free(s);
    120   terminateG(B);
    121   freeManyG(&n, &ds);
    122 
    123   // int
    124   setTopG(&n, 120);
    125   B = serialG(&n);
    126   logI("len %u", lenG(B));
    127   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    128   s = sToString((smallt *) B->B);
    129   ck_assert_str_eq(s, "[0x84,0x1e]");
    130   free(s);
    131   deserialG(&ds, B);
    132   s = toStringG(&ds);
    133   ck_assert_str_eq(s, "120");
    134   free(s);
    135   terminateG(B);
    136   freeManyG(&n, &ds);
    137 
    138   // string
    139   setTopG(&n, "string");
    140   B = serialG(&n);
    141   logI("len %u", lenG(B));
    142   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    143   s = sToString((smallt *) B->B);
    144   ck_assert_str_eq(s, "[0x05,0x73,0x74,0x72,0x69,0x6e,0x67,0x00]");
    145   free(s);
    146   deserialG(&ds, B);
    147   s = toStringG(&ds);
    148   ck_assert_str_eq(s, "string");
    149   free(s);
    150   terminateG(B);
    151   freeManyG(&n, &ds);
    152 
    153   // dict
    154   setG(&d, "k", 4);
    155   setTopG(&n, &d);
    156   B = serialG(&n);
    157   logI("len %u", lenG(B));
    158   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    159   s = sToString((smallt *) B->B);
    160   ck_assert_str_eq(s, "[0x4e,0x01,0x6b,0x00,0x08]");
    161   free(s);
    162   deserialG(&ds, B);
    163   s = toStringG(&ds);
    164   ck_assert_str_eq(s, "{\"k\":4}");
    165   free(s);
    166   terminateG(B);
    167   freeManyG(&n, &ds);
    168 
    169   // array
    170   pushG(&a, "k");
    171   pushG(&a, 4);
    172   setTopG(&n, &a);
    173   B = serialG(&n);
    174   logI("len %u", lenG(B));
    175   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    176   s = sToString((smallt *) B->B);
    177   ck_assert_str_eq(s, "[0x26,0x45,0x6b,0x00,0x08]");
    178   free(s);
    179   deserialG(&ds, B);
    180   s = toStringG(&ds);
    181   ck_assert_str_eq(s, "[\"k\",4]");
    182   free(s);
    183   terminateG(B);
    184   freeManyG(&n, &ds);
    185 
    186 END_TEST
    187 
    188 
    189 
    190 START_TEST(uniformDictT)
    191 
    192   // STEPS
    193   // init
    194   // init allocate
    195   // terminate
    196   // allocate
    197   // string
    198   // duplicate
    199 
    200   createNetSerial(n);
    201   createNetSerial(ds);
    202   char *s;
    203   smallBytest *B;
    204   createSmallDict(d);
    205   createSmallDict(dd);
    206   createSmallArray(a);
    207 
    208   // undefined
    209   undefinedt *oU = allocUndefined();
    210   setG(&d, "0", oU);
    211   setG(&d, "1", oU);
    212   setG(&d, "2", oU);
    213   setG(&d, "3", oU);
    214   setG(&d, "4", oU);
    215   setNFreeG(&d, "5", oU);
    216   setTopG(&n, &d);
    217   B = serialG(&n);
    218   logI("len %u", lenG(B));
    219   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    220   s = sToString((smallt *) B->B);
    221   ck_assert_str_eq(s, "[0x0e,0x06,0x30,0x00,0x31,0x00,0x32,0x00,0x33,0x00,0x34,0x00,0x35,0x00]");
    222   free(s);
    223   deserialG(&ds, B);
    224   s = toStringG(&ds);
    225   ck_assert_str_eq(s, "{\"0\":null,\"1\":null,\"2\":null,\"3\":null,\"4\":null,\"5\":null}");
    226   free(s);
    227   terminateG(B);
    228   freeManyG(&n, &ds);
    229 
    230   // empty dict
    231   initiateG(&d);
    232   setTopG(&n, &d);
    233   B = serialG(&n);
    234   logI("len %u", lenG(B));
    235   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    236   s = sToString((smallt *) B->B);
    237   ck_assert_str_eq(s, "[0x0e,0x00]");
    238   free(s);
    239   deserialG(&ds, B);
    240   s = toStringG(&ds);
    241   ck_assert_str_eq(s, "{}");
    242   free(s);
    243   terminateG(B);
    244   freeManyG(&n, &ds);
    245 
    246   // bool
    247   initiateG(&d);
    248   setG(&d, "0", TRUE);
    249   setG(&d, "1", TRUE);
    250   setG(&d, "2", TRUE);
    251   setG(&d, "3", TRUE);
    252   setTopG(&n, &d);
    253   B = serialG(&n);
    254   logI("len %u", lenG(B));
    255   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    256   s = sToString((smallt *) B->B);
    257   ck_assert_str_eq(s, "[0x1e,0x04,0x30,0x00,0x0f,0x31,0x00,0x32,0x00,0x33,0x00]");
    258   free(s);
    259   deserialG(&ds, B);
    260   s = toStringG(&ds);
    261   ck_assert_str_eq(s, "{\"0\":true,\"1\":true,\"2\":true,\"3\":true}");
    262   free(s);
    263   terminateG(B);
    264   freeManyG(&n, &ds);
    265 
    266   // 9 bools
    267   initiateG(&d);
    268   setG(&d, "0", TRUE);
    269   setG(&d, "1", TRUE);
    270   setG(&d, "2", TRUE);
    271   setG(&d, "3", TRUE);
    272   setG(&d, "4", TRUE);
    273   setG(&d, "5", TRUE);
    274   setG(&d, "6", TRUE);
    275   setG(&d, "7", TRUE);
    276   setG(&d, "8", TRUE);
    277   setTopG(&n, &d);
    278   B = serialG(&n);
    279   logI("len %u", lenG(B));
    280   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    281   s = sToString((smallt *) B->B);
    282   ck_assert_str_eq(s, "[0x1e,0x09,0x30,0x00,0xff,0x31,0x00,0x32,0x00,0x33,0x00,0x34,0x00,0x35,0x00,0x36,0x00,0x37,0x00,0x38,0x00,0x01]");
    283   free(s);
    284   deserialG(&ds, B);
    285   s = toStringG(&ds);
    286   ck_assert_str_eq(s, "{\"0\":true,\"1\":true,\"2\":true,\"3\":true,\"4\":true,\"5\":true,\"6\":true,\"7\":true,\"8\":true}");
    287   free(s);
    288   terminateG(B);
    289   freeManyG(&n, &ds);
    290 
    291 
    292   // double
    293   initiateG(&d);
    294   setG(&d, "0", 1.1);
    295   setG(&d, "1", 2.2);
    296   setG(&d, "2", 3.3);
    297   setTopG(&n, &d);
    298   B = serialG(&n);
    299   logI("len %u", lenG(B));
    300   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    301   s = sToString((smallt *) B->B);
    302   ck_assert_str_eq(s, "[0x3e,0x03,0x30,0x00,0x9a,0x99,0x99,0x99,0x99,0x99,0xf1,0x3f,0x31,0x00,0x9a,0x99,0x99,0x99,0x99,0x99,0x01,0x40,0x32,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x0a,0x40]");
    303   free(s);
    304   deserialG(&ds, B);
    305   s = toStringG(&ds);
    306   ck_assert_str_eq(s, "{\"0\":1.100000e+00,\"1\":2.200000e+00,\"2\":3.300000e+00}");
    307   free(s);
    308   terminateG(B);
    309   freeManyG(&n, &ds);
    310 
    311   // int
    312   initiateG(&d);
    313   setG(&d, "0", 1);
    314   setG(&d, "1", 2);
    315   setTopG(&n, &d);
    316   B = serialG(&n);
    317   logI("len %u", lenG(B));
    318   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    319   s = sToString((smallt *) B->B);
    320   ck_assert_str_eq(s, "[0x4e,0x02,0x30,0x00,0x02,0x31,0x00,0x04]");
    321   free(s);
    322   deserialG(&ds, B);
    323   s = toStringG(&ds);
    324   ck_assert_str_eq(s, "{\"0\":1,\"1\":2}");
    325   free(s);
    326   terminateG(B);
    327   freeManyG(&n, &ds);
    328 
    329   // string
    330   initiateG(&d);
    331   setG(&d, "0", "a");
    332   setG(&d, "1", "A");
    333   setG(&d, "2", "z");
    334   setTopG(&n, &d);
    335   B = serialG(&n);
    336   logI("len %u", lenG(B));
    337   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    338   s = sToString((smallt *) B->B);
    339   ck_assert_str_eq(s, "[0x5e,0x03,0x30,0x00,0x61,0x00,0x31,0x00,0x41,0x00,0x32,0x00,0x7a,0x00]");
    340   free(s);
    341   deserialG(&ds, B);
    342   s = toStringG(&ds);
    343   ck_assert_str_eq(s, "{\"0\":\"a\",\"1\":\"A\",\"2\":\"z\"}");
    344   free(s);
    345   terminateG(B);
    346   freeManyG(&n, &ds);
    347 
    348   // dict
    349   initiateG(&d);
    350   setG(&dd, "9", "z");
    351   setG(&dd, "1", 1);
    352   setG(&d, "0", &dd);
    353   initiateG(&dd);
    354   setG(&dd, "Z", "-");
    355   setG(&dd, "A", 234);
    356   setG(&d, "1", &dd);
    357   setTopG(&n, &d);
    358   logVarG(&n);
    359   B = serialG(&n);
    360   logI("len %u", lenG(B));
    361   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    362   s = sToString((smallt *) B->B);
    363   ck_assert_str_eq(s, "[0x2e,0x02,0x30,0x00,0x02,0x39,0x00,0x45,0x7a,0x00,0x31,0x00,0x02,0x31,0x00,0x02,0x5a,0x00,0x45,0x2d,0x00,0x41,0x00,0xd4,0x03]");
    364   free(s);
    365   deserialG(&ds, B);
    366   s = toStringG(&ds);
    367   ck_assert_str_eq(s, "{\"0\":{\"9\":\"z\",\"1\":1},\"1\":{\"Z\":\"-\",\"A\":234}}");
    368   free(s);
    369   terminateG(B);
    370   freeManyG(&n, &ds);
    371 
    372   // uniform dict
    373   initiateG(&dd);
    374   initiateG(&d);
    375   setG(&dd, "9", 1);
    376   setG(&dd, "1", 2);
    377   setG(&d, "0", &dd);
    378   initiateG(&dd);
    379   setG(&dd, "Z", "-");
    380   setG(&dd, "A", "+");
    381   setG(&d, "1", &dd);
    382   setTopG(&n, &d);
    383   logVarG(&n);
    384   B = serialG(&n);
    385   logI("len %u", lenG(B));
    386   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    387   s = sToString((smallt *) B->B);
    388   ck_assert_str_eq(s, "[0xee,0x02,0x30,0x00,0x24,0x39,0x00,0x02,0x31,0x00,0x04,0x31,0x00,0x25,0x5a,0x00,0x2d,0x00,0x41,0x00,0x2b,0x00]");
    389   free(s);
    390   deserialG(&ds, B);
    391   s = toStringG(&ds);
    392   ck_assert_str_eq(s, "{\"0\":{\"9\":1,\"1\":2},\"1\":{\"Z\":\"-\",\"A\":\"+\"}}");
    393   free(s);
    394   terminateG(B);
    395   freeManyG(&n, &ds);
    396 
    397   // array
    398   initiateG(&d);
    399   pushG(&a, "k");
    400   pushG(&a, 4);
    401   setG(&d, "0", &a);
    402   setTopG(&n, &d);
    403   B = serialG(&n);
    404   logI("len %u", lenG(B));
    405   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    406   s = sToString((smallt *) B->B);
    407   ck_assert_str_eq(s, "[0x6e,0x01,0x30,0x00,0x02,0x45,0x6b,0x00,0x08]");
    408   free(s);
    409   deserialG(&ds, B);
    410   s = toStringG(&ds);
    411   ck_assert_str_eq(s, "{\"0\":[\"k\",4]}");
    412   free(s);
    413   terminateG(B);
    414   freeManyG(&n, &ds);
    415 
    416   // uniform array
    417   initiateG(&d);
    418   initiateG(&a);
    419   pushG(&a, 1);
    420   pushG(&a, 2);
    421   pushG(&a, 3);
    422   pushG(&a, 4);
    423   setG(&d, "0", &a);
    424   setTopG(&n, &d);
    425   B = serialG(&n);
    426   logI("len %u", lenG(B));
    427   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    428   s = sToString((smallt *) B->B);
    429   ck_assert_str_eq(s, "[0xfe,0x01,0x30,0x00,0x44,0x02,0x04,0x06,0x08]");
    430   free(s);
    431   deserialG(&ds, B);
    432   s = toStringG(&ds);
    433   ck_assert_str_eq(s, "{\"0\":[1,2,3,4]}");
    434   free(s);
    435   terminateG(B);
    436   freeManyG(&n, &ds);
    437 
    438   // smallBytes
    439   initiateG(&d);
    440   createSmallBytes(b);
    441   createSmallBytes(b1);
    442   pushG(&b, 1);
    443   pushG(&b, 2);
    444   pushG(&b, 3);
    445   pushG(&b, 4);
    446   pushG(&b1, 5);
    447   pushG(&b1, 6);
    448   pushG(&b1, 7);
    449   setG(&d, "0", &b);
    450   setG(&d, "1", &b1);
    451   setTopG(&n, &d);
    452   B = serialG(&n);
    453   logI("len %u", lenG(B));
    454   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    455   s = sToString((smallt *) B->B);
    456   ck_assert_str_eq(s, "[0x7e,0x02,0x30,0x00,0x04,0x01,0x02,0x03,0x04,0x31,0x00,0x03,0x05,0x06,0x07]");
    457   free(s);
    458   deserialG(&ds, B);
    459   s = toStringG(&ds);
    460   ck_assert_str_eq(s, "{"_"0"_":[0x01,0x02,0x03,0x04],"_"1"_":[0x05,0x06,0x07]}");
    461   free(s);
    462   terminateG(B);
    463   freeManyG(&n, &ds);
    464 
    465 END_TEST
    466 
    467 
    468 // uniformArray
    469 START_TEST(uniformArrayT)
    470 
    471   // STEPS
    472   // init
    473   // init allocate
    474   // terminate
    475   // allocate
    476   // string
    477   // duplicate
    478 
    479   createNetSerial(n);
    480   createNetSerial(ds);
    481   char *s;
    482   smallBytest *B;
    483   createSmallArray(A);
    484   createSmallDict(dd);
    485   createSmallArray(a);
    486 
    487   // undefined
    488   undefinedt *oU = allocUndefined();
    489   pushG(&A, oU);
    490   pushG(&A, oU);
    491   pushG(&A, oU);
    492   pushG(&A, oU);
    493   pushG(&A, oU);
    494   pushNFreeG(&A, oU);
    495   setTopG(&n, &A);
    496   B = serialG(&n);
    497   logI("len %u", lenG(B));
    498   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    499   s = sToString((smallt *) B->B);
    500   ck_assert_str_eq(s, "[0x0f,0x06]");
    501   free(s);
    502   deserialG(&ds, B);
    503   s = toStringG(&ds);
    504   ck_assert_str_eq(s, "[null,null,null,null,null,null]");
    505   free(s);
    506   terminateG(B);
    507   freeManyG(&n, &ds);
    508 
    509   // empty dict
    510   initiateG(&A);
    511   setTopG(&n, &A);
    512   B = serialG(&n);
    513   logI("len %u", lenG(B));
    514   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    515   s = sToString((smallt *) B->B);
    516   ck_assert_str_eq(s, "[0x0f,0x00]");
    517   free(s);
    518   deserialG(&ds, B);
    519   s = toStringG(&ds);
    520   ck_assert_str_eq(s, "[]");
    521   free(s);
    522   terminateG(B);
    523   freeManyG(&n, &ds);
    524 
    525   // bool
    526   initiateG(&A);
    527   pushG(&A, TRUE);
    528   pushG(&A, TRUE);
    529   pushG(&A, TRUE);
    530   pushG(&A, TRUE);
    531   setTopG(&n, &A);
    532   B = serialG(&n);
    533   logI("len %u", lenG(B));
    534   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    535   s = sToString((smallt *) B->B);
    536   ck_assert_str_eq(s, "[0x1f,0x04,0x0f]");
    537   free(s);
    538   deserialG(&ds, B);
    539   s = toStringG(&ds);
    540   ck_assert_str_eq(s, "[true,true,true,true]");
    541   free(s);
    542   terminateG(B);
    543   freeManyG(&n, &ds);
    544 
    545   // double
    546   initiateG(&A);
    547   pushG(&A, 1.1);
    548   pushG(&A, 2.2);
    549   pushG(&A, 3.3);
    550   setTopG(&n, &A);
    551   B = serialG(&n);
    552   logI("len %u", lenG(B));
    553   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    554   s = sToString((smallt *) B->B);
    555   ck_assert_str_eq(s, "[0x3f,0x03,0x9a,0x99,0x99,0x99,0x99,0x99,0xf1,0x3f,0x9a,0x99,0x99,0x99,0x99,0x99,0x01,0x40,0x66,0x66,0x66,0x66,0x66,0x66,0x0a,0x40]");
    556   free(s);
    557   deserialG(&ds, B);
    558   s = toStringG(&ds);
    559   ck_assert_str_eq(s, "[1.100000e+00,2.200000e+00,3.300000e+00]");
    560   free(s);
    561   terminateG(B);
    562   freeManyG(&n, &ds);
    563 
    564   // int
    565   initiateG(&A);
    566   pushG(&A, 1);
    567   pushG(&A, 2);
    568   setTopG(&n, &A);
    569   B = serialG(&n);
    570   logI("len %u", lenG(B));
    571   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    572   s = sToString((smallt *) B->B);
    573   ck_assert_str_eq(s, "[0x4f,0x02,0x02,0x04]");
    574   free(s);
    575   deserialG(&ds, B);
    576   s = toStringG(&ds);
    577   ck_assert_str_eq(s, "[1,2]");
    578   free(s);
    579   terminateG(B);
    580   freeManyG(&n, &ds);
    581 
    582   // string
    583   initiateG(&A);
    584   pushG(&A, "a");
    585   pushG(&A, "A");
    586   pushG(&A, "z");
    587   setTopG(&n, &A);
    588   B = serialG(&n);
    589   logI("len %u", lenG(B));
    590   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    591   s = sToString((smallt *) B->B);
    592   ck_assert_str_eq(s, "[0x5f,0x03,0x61,0x00,0x41,0x00,0x7a,0x00]");
    593   free(s);
    594   deserialG(&ds, B);
    595   s = toStringG(&ds);
    596   ck_assert_str_eq(s, "[\"a\",\"A\",\"z\"]");
    597   free(s);
    598   terminateG(B);
    599   freeManyG(&n, &ds);
    600 
    601   // dict
    602   initiateG(&A);
    603   setG(&dd, "9", "z");
    604   setG(&dd, "1", 1);
    605   pushG(&A, &dd);
    606   initiateG(&dd);
    607   setG(&dd, "Z", "-");
    608   setG(&dd, "A", 234);
    609   pushG(&A, &dd);
    610   setTopG(&n, &A);
    611   logVarG(&n);
    612   B = serialG(&n);
    613   logI("len %u", lenG(B));
    614   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    615   s = sToString((smallt *) B->B);
    616   ck_assert_str_eq(s, "[0x2f,0x02,0x02,0x39,0x00,0x45,0x7a,0x00,0x31,0x00,0x02,0x02,0x5a,0x00,0x45,0x2d,0x00,0x41,0x00,0xd4,0x03]");
    617   free(s);
    618   deserialG(&ds, B);
    619   s = toStringG(&ds);
    620   ck_assert_str_eq(s, "[{\"9\":\"z\",\"1\":1},{\"Z\":\"-\",\"A\":234}]");
    621   free(s);
    622   terminateG(B);
    623   freeManyG(&n, &ds);
    624 
    625   // uniform dict
    626   initiateG(&dd);
    627   initiateG(&A);
    628   setG(&dd, "9", 1);
    629   setG(&dd, "1", 2);
    630   pushG(&A, &dd);
    631   initiateG(&dd);
    632   setG(&dd, "Z", "-");
    633   setG(&dd, "A", "+");
    634   pushG(&A, &dd);
    635   setTopG(&n, &A);
    636   logVarG(&n);
    637   B = serialG(&n);
    638   logI("len %u", lenG(B));
    639   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    640   s = sToString((smallt *) B->B);
    641   ck_assert_str_eq(s, "[0xef,0x02,0x24,0x39,0x00,0x02,0x31,0x00,0x04,0x25,0x5a,0x00,0x2d,0x00,0x41,0x00,0x2b,0x00]");
    642   free(s);
    643   deserialG(&ds, B);
    644   s = toStringG(&ds);
    645   ck_assert_str_eq(s, "[{\"9\":1,\"1\":2},{\"Z\":\"-\",\"A\":\"+\"}]");
    646   free(s);
    647   terminateG(B);
    648   freeManyG(&n, &ds);
    649 
    650   // array
    651   initiateG(&A);
    652   pushG(&a, "k");
    653   pushG(&a, 4);
    654   pushG(&A, &a);
    655   setTopG(&n, &A);
    656   B = serialG(&n);
    657   logI("len %u", lenG(B));
    658   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    659   s = sToString((smallt *) B->B);
    660   ck_assert_str_eq(s, "[0x6f,0x01,0x02,0x45,0x6b,0x00,0x08]");
    661   free(s);
    662   deserialG(&ds, B);
    663   s = toStringG(&ds);
    664   ck_assert_str_eq(s, "[[\"k\",4]]");
    665   free(s);
    666   terminateG(B);
    667   freeManyG(&n, &ds);
    668 
    669   initiateG(&A);
    670   initiateG(&a);
    671   pushG(&a, 1);
    672   pushG(&a, 2);
    673   pushG(&a, 3);
    674   pushG(&a, 4);
    675   pushG(&A, &a);
    676   setTopG(&n, &A);
    677   B = serialG(&n);
    678   logI("len %u", lenG(B));
    679   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    680   s = sToString((smallt *) B->B);
    681   ck_assert_str_eq(s, "[0xff,0x01,0x44,0x02,0x04,0x06,0x08]");
    682   free(s);
    683   deserialG(&ds, B);
    684   s = toStringG(&ds);
    685   ck_assert_str_eq(s, "[[1,2,3,4]]");
    686   free(s);
    687   terminateG(B);
    688   freeManyG(&n, &ds);
    689 
    690   // many bools in uniform array
    691   parseG(&n, "[true,true,true,true,true,true,true,true,false,true]");
    692   logVarG(&n);
    693   B = serialG(&n);
    694   logI("len %u", lenG(B));
    695   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    696   s = sToString((smallt *) B->B);
    697   ck_assert_str_eq(s, "[0x1f,0x0a,0xff,0x02]");
    698   free(s);
    699   deserialG(&ds, B);
    700   s = toStringG(&ds);
    701   ck_assert_str_eq(s, "[true,true,true,true,true,true,true,true,false,true]");
    702   free(s);
    703   terminateG(B);
    704   freeManyG(&n, &ds);
    705 
    706   // smallBytes
    707   initiateG(&A);
    708   createSmallBytes(b);
    709   pushG(&b, 1);
    710   pushG(&b, 2);
    711   pushG(&b, 3);
    712   pushG(&b, 4);
    713   pushG(&b, 5);
    714   pushG(&b, 6);
    715   pushG(&A, &b);
    716   initiateG(&b);
    717   pushG(&b, 7);
    718   pushG(&b, 8);
    719   pushG(&b, 9);
    720   pushG(&b, 10);
    721   pushG(&b, 11);
    722   pushG(&b, 12);
    723   pushG(&A, &b);
    724   setTopG(&n, &A);
    725   logVarG(&n);
    726   B = serialG(&n);
    727   logI("len %u", lenG(B));
    728   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    729   s = sToString((smallt *) B->B);
    730   ck_assert_str_eq(s, "[0x7f,0x02,0x06,0x01,0x02,0x03,0x04,0x05,0x06,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c]");
    731   free(s);
    732   deserialG(&ds, B);
    733   s = toStringG(&ds);
    734   ck_assert_str_eq(s, "[[0x01,0x02,0x03,0x04,0x05,0x06],[0x07,0x08,0x09,0x0a,0x0b,0x0c]]");
    735   free(s);
    736   terminateG(B);
    737   freeManyG(&n, &ds);
    738 
    739 END_TEST
    740 
    741 
    742 // dict with values, dict, array, uniforms, packed test high/low nibbles
    743 START_TEST(dictT)
    744 
    745   // STEPS
    746   // init
    747   // init allocate
    748   // terminate
    749   // allocate
    750   // string
    751   // duplicate
    752 
    753   createNetSerial(n);
    754   createNetSerial(ds);
    755   char *s;
    756   smallBytest *B;
    757   createSmallDict(d);
    758   createSmallDict(dd);
    759   createSmallArray(a);
    760 
    761   // dict with a deleted element (empty with dict->count == 1)
    762   initiateG(&d);
    763   setG(&d, "0", NULL);
    764   delElemG(&d, "0");
    765   setTopG(&n, &d);
    766   logVarG(&n);
    767   B = serialG(&n);
    768   logI("len %u", lenG(B));
    769   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    770   s = sToString((smallt *) B->B);
    771   ck_assert_str_eq(s, "[0x0e,0x00]");
    772   free(s);
    773   deserialG(&ds, B);
    774   s = toStringG(&ds);
    775   ck_assert_str_eq(s, "{}");
    776   free(s);
    777   terminateG(B);
    778   freeManyG(&n, &ds);
    779 
    780   // null and uniform dict
    781   initiateG(&d);
    782   setG(&d, "0", NULL);
    783   initiateG(&dd);
    784   setG(&dd, "Z", "-");
    785   setG(&dd, "A", "+");
    786   setG(&d, "1", &dd);
    787   setTopG(&n, &d);
    788   logVarG(&n);
    789   B = serialG(&n);
    790   logI("len %u", lenG(B));
    791   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    792   s = sToString((smallt *) B->B);
    793   ck_assert_str_eq(s, "[0x22,0x30,0x00,0xe0,0x31,0x00,0x25,0x5a,0x00,0x2d,0x00,0x41,0x00,0x2b,0x00]");
    794   free(s);
    795   deserialG(&ds, B);
    796   s = toStringG(&ds);
    797   ck_assert_str_eq(s, "{\"0\":null,\"1\":{\"Z\":\"-\",\"A\":\"+\"}}");
    798   free(s);
    799   terminateG(B);
    800   freeManyG(&n, &ds);
    801 
    802   // null and dict
    803   initiateG(&d);
    804   setG(&d, "0", NULL);
    805   initiateG(&dd);
    806   setG(&dd, "Z", "-");
    807   setG(&dd, "A", 1);
    808   setG(&d, "1", &dd);
    809   setTopG(&n, &d);
    810   logVarG(&n);
    811   B = serialG(&n);
    812   logI("len %u", lenG(B));
    813   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    814   s = sToString((smallt *) B->B);
    815   ck_assert_str_eq(s, "[0x22,0x30,0x00,0x20,0x31,0x00,0x02,0x5a,0x00,0x45,0x2d,0x00,0x41,0x00,0x02]");
    816   free(s);
    817   deserialG(&ds, B);
    818   s = toStringG(&ds);
    819   ck_assert_str_eq(s, "{\"0\":null,\"1\":{\"Z\":\"-\",\"A\":1}}");
    820   free(s);
    821   terminateG(B);
    822   freeManyG(&n, &ds);
    823 
    824   // bool and uniform dict
    825   initiateG(&d);
    826   setG(&d, "0", TRUE);
    827   initiateG(&dd);
    828   setG(&dd, "Z", "-");
    829   setG(&dd, "A", "+");
    830   setG(&d, "1", &dd);
    831   setTopG(&n, &d);
    832   logVarG(&n);
    833   B = serialG(&n);
    834   logI("len %u", lenG(B));
    835   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    836   s = sToString((smallt *) B->B);
    837   ck_assert_str_eq(s, "[0x22,0x30,0x00,0x11,0x31,0x00,0x5e,0x02,0x5a,0x00,0x2d,0x00,0x41,0x00,0x2b,0x00]");
    838   free(s);
    839   deserialG(&ds, B);
    840   s = toStringG(&ds);
    841   ck_assert_str_eq(s, "{\"0\":true,\"1\":{\"Z\":\"-\",\"A\":\"+\"}}");
    842   free(s);
    843   terminateG(B);
    844   freeManyG(&n, &ds);
    845 
    846   // null element and uniform array
    847   initiateG(&d);
    848   setG(&d, "1", NULL);
    849   initiateG(&a);
    850   pushG(&a, 1);
    851   pushG(&a, 2);
    852   pushG(&a, 3);
    853   pushG(&a, 4);
    854   setG(&d, "0", &a);
    855   setTopG(&n, &d);
    856   logVarG(&n);
    857   B = serialG(&n);
    858   logI("len %u", lenG(B));
    859   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    860   s = sToString((smallt *) B->B);
    861   ck_assert_str_eq(s, "[0x22,0x31,0x00,0xf0,0x30,0x00,0x44,0x02,0x04,0x06,0x08]");
    862   free(s);
    863   deserialG(&ds, B);
    864   s = toStringG(&ds);
    865   ck_assert_str_eq(s, "{\"1\":null,\"0\":[1,2,3,4]}");
    866   free(s);
    867   terminateG(B);
    868   freeManyG(&n, &ds);
    869 
    870   // uniform array high nibble
    871   initiateG(&d);
    872   setG(&d, "1", TRUE);
    873   initiateG(&a);
    874   pushG(&a, 1);
    875   pushG(&a, 2);
    876   pushG(&a, 3);
    877   pushG(&a, 4);
    878   setG(&d, "0", &a);
    879   setTopG(&n, &d);
    880   logVarG(&n);
    881   B = serialG(&n);
    882   logI("len %u", lenG(B));
    883   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    884   s = sToString((smallt *) B->B);
    885   ck_assert_str_eq(s, "[0x22,0x31,0x00,0x11,0x30,0x00,0x4f,0x04,0x02,0x04,0x06,0x08]");
    886   free(s);
    887   deserialG(&ds, B);
    888   s = toStringG(&ds);
    889   ck_assert_str_eq(s, "{\"1\":true,\"0\":[1,2,3,4]}");
    890   free(s);
    891   terminateG(B);
    892   freeManyG(&n, &ds);
    893 
    894   // uniform array in high nibble
    895   initiateG(&d);
    896   setG(&d, "1", "1");
    897   initiateG(&a);
    898   pushG(&a, 1);
    899   pushG(&a, 2);
    900   pushG(&a, 3);
    901   pushG(&a, 4);
    902   setG(&d, "0", &a);
    903   setTopG(&n, &d);
    904   logVarG(&n);
    905   B = serialG(&n);
    906   logI("len %u", lenG(B));
    907   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    908   s = sToString((smallt *) B->B);
    909   ck_assert_str_eq(s, "[0x22,0x31,0x00,0xf5,0x31,0x00,0x30,0x00,0x44,0x02,0x04,0x06,0x08]");
    910   free(s);
    911   deserialG(&ds, B);
    912   s = toStringG(&ds);
    913   ck_assert_str_eq(s, "{\"1\":\"1\",\"0\":[1,2,3,4]}");
    914   free(s);
    915   terminateG(B);
    916   freeManyG(&n, &ds);
    917 
    918   // low and high nibble undefined
    919   parseG(&n, "{"_"0"_":null,"_"1"_":null, "_"2"_":1}");
    920   logVarG(&n);
    921   B = serialG(&n);
    922   logI("len %u", lenG(B));
    923   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    924   s = sToString((smallt *) B->B);
    925   ck_assert_str_eq(s, "[0x32,0x30,0x00,0x00,0x31,0x00,0x32,0x00,0x24]");
    926   free(s);
    927   deserialG(&ds, B);
    928   s = toStringG(&ds);
    929   ck_assert_str_eq(s, "{\"0\":null,\"1\":null,\"2\":1}");
    930   free(s);
    931   terminateG(B);
    932   freeManyG(&n, &ds);
    933 
    934   // low and high nibble bool
    935   parseG(&n, "{"_"z"_":null,"_"0"_":true,"_"1"_":true, "_"2"_":true, "_"3"_":true"_"4"_":true"_"5"_":true, "_"6"_":true, "_"7"_":true, "_"8"_":true, "_"9"_":true, "_"a"_":true, "_"b"_":true, "_"c"_":true, "_"d"_":true}");
    936   logVarG(&n);
    937   B = serialG(&n);
    938   logI("len %u", lenG(B));
    939   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    940   s = sToString((smallt *) B->B);
    941   ck_assert_str_eq(s, "[0xf2,0x01,0x7a,0x00,0x10,0x30,0x00,0xff,0x31,0x00,0x11,0x32,0x00,0x33,0x00,0x11,0x34,0x00,0x35,0x00,0x11,0x36,0x00,0x37,0x00,0x11,0x38,0x00,0x3f,0x39,0x00,0x11,0x61,0x00,0x62,0x00,0x11,0x63,0x00,0x64,0x00,0x01]");
    942   free(s);
    943   deserialG(&ds, B);
    944   s = toStringG(&ds);
    945   ck_assert_str_eq(s, "{\"z\":null,\"0\":true,\"1\":true,\"2\":true,\"3\":true,\"4\":true,\"5\":true,\"6\":true,\"7\":true,\"8\":true,\"9\":true,\"a\":true,\"b\":true,\"c\":true,\"d\":true}");
    946   free(s);
    947   terminateG(B);
    948   freeManyG(&n, &ds);
    949 
    950   // low and high nibble bool - deserialDict ctx->nibble == lowNbl and ctx->boolShift == 8
    951   parseG(&n, "{"_"z"_":null,"_"0"_":true,"_"1"_":true, "_"2"_":true, "_"3"_":true, "_"4"_":true, "_"5"_":true, "_"6"_":true, "_"7"_":true, \"Z\": null, "_"8"_":true, "_"9"_":true, "_"a"_":true, "_"b"_":true, "_"c"_":true, "_"d"_":true}");
    952   logVarG(&n);
    953   B = serialG(&n);
    954   logI("len %u", lenG(B));
    955   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    956   s = sToString((smallt *) B->B);
    957   ck_assert_str_eq(s, "[0x82,0x02,0x7a,0x00,0x10,0x30,0x00,0xff,0x31,0x00,0x11,0x32,0x00,0x33,0x00,0x11,0x34,0x00,0x35,0x00,0x11,0x36,0x00,0x37,0x00,0x01,0x5a,0x00,0x38,0x00,0xf1,0x39,0x00,0x11,0x61,0x00,0x62,0x00,0x11,0x63,0x00,0x03,0x64,0x00,0x01]");
    958   free(s);
    959   deserialG(&ds, B);
    960   s = toStringG(&ds);
    961   ck_assert_str_eq(s, "{\"z\":null,\"0\":true,\"1\":true,\"2\":true,\"3\":true,\"4\":true,\"5\":true,\"6\":true,\"7\":true,\"Z\":null,\"8\":true,\"9\":true,\"a\":true,\"b\":true,\"c\":true,\"d\":true}");
    962   free(s);
    963   terminateG(B);
    964   freeManyG(&n, &ds);
    965 
    966   // dict in dict
    967   parseG(&n, "{"_"0"_":{\"0\":true}, "_"2"_":{\"0\":false},\"z\":null}");
    968   logVarG(&n);
    969   B = serialG(&n);
    970   logI("len %u", lenG(B));
    971   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    972   s = sToString((smallt *) B->B);
    973   ck_assert_str_eq(s, "[0x32,0x30,0x00,0x1e,0x01,0x30,0x00,0x01,0x32,0x00,0x1e,0x01,0x30,0x00,0x7a,0x00,0x00]");
    974   free(s);
    975   deserialG(&ds, B);
    976   s = toStringG(&ds);
    977   ck_assert_str_eq(s, "{\"0\":{\"0\":true},\"2\":{\"0\":false},\"z\":null}");
    978   free(s);
    979   terminateG(B);
    980   freeManyG(&n, &ds);
    981 
    982 
    983   // low and high nibble double
    984   parseG(&n, "{"_"0"_":0.0, "_"2"_":2.0,\"z\":null}");
    985   logVarG(&n);
    986   B = serialG(&n);
    987   logI("len %u", lenG(B));
    988   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    989   s = sToString((smallt *) B->B);
    990   ck_assert_str_eq(s, "[0x32,0x30,0x00,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x7a,0x00,0x00]");
    991   free(s);
    992   deserialG(&ds, B);
    993   s = toStringG(&ds);
    994   ck_assert_str_eq(s, "{\"0\":0.000000e+00,\"2\":2.000000e+00,\"z\":null}");
    995   free(s);
    996   terminateG(B);
    997   freeManyG(&n, &ds);
    998 
    999   // high nibble string
   1000   parseG(&n, "{"_"0"_":null, "_"2"_":\"2.0\",\"z\":null}");
   1001   logVarG(&n);
   1002   B = serialG(&n);
   1003   logI("len %u", lenG(B));
   1004   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1005   s = sToString((smallt *) B->B);
   1006   ck_assert_str_eq(s, "[0x32,0x30,0x00,0x50,0x32,0x00,0x32,0x2e,0x30,0x00,0x7a,0x00,0x00]");
   1007   free(s);
   1008   deserialG(&ds, B);
   1009   s = toStringG(&ds);
   1010   ck_assert_str_eq(s, "{\"0\":null,\"2\":\"2.0\",\"z\":null}");
   1011   free(s);
   1012   terminateG(B);
   1013   freeManyG(&n, &ds);
   1014 
   1015   // array in dict
   1016   parseG(&n, "{"_"0"_":null, "_"2"_":[1,2],\"z\":[true,3]}");
   1017   logVarG(&n);
   1018   B = serialG(&n);
   1019   logI("len %u", lenG(B));
   1020   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1021   s = sToString((smallt *) B->B);
   1022   ck_assert_str_eq(s, "[0x32,0x30,0x00,0xf0,0x32,0x00,0x24,0x02,0x04,0x7a,0x00,0x26,0x11,0x64]");
   1023   free(s);
   1024   deserialG(&ds, B);
   1025   s = toStringG(&ds);
   1026   ck_assert_str_eq(s, "{\"0\":null,\"2\":[1,2],\"z\":[true,3]}");
   1027   free(s);
   1028   terminateG(B);
   1029   freeManyG(&n, &ds);
   1030 
   1031 
   1032 
   1033   // packed dicts
   1034   parseG(&n, "{"_"0"_":{},"_"1"_":{}, "_"2"_":{}, "_"3"_":{}, "_"4"_":{}, "_"5"_": 1}");
   1035   logVarG(&n);
   1036   B = serialG(&n);
   1037   logI("len %u", lenG(B));
   1038   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1039   s = sToString((smallt *) B->B);
   1040   ck_assert_str_eq(s, "[0x62,0x30,0x00,0x58,0x00,0x31,0x00,0x00,0x32,0x00,0x00,0x33,0x00,0x00,0x34,0x00,0x00,0x35,0x00,0x24]");
   1041   free(s);
   1042   deserialG(&ds, B);
   1043   s = toStringG(&ds);
   1044   ck_assert_str_eq(s, "{\"0\":{},\"1\":{},\"2\":{},\"3\":{},\"4\":{},\"5\":1}");
   1045   free(s);
   1046   terminateG(B);
   1047   freeManyG(&n, &ds);
   1048 
   1049   parseG(&n, "{"_"0"_":{"_"0"_":null,"_"1"_":1},"_"1"_":{"_"0"_":"_"0"_","_"1"_":1}, "_"2"_":{"_"0"_":"_"0"_","_"1"_":1}, "_"3"_":{"_"0"_":"_"0"_","_"1"_":1}, "_"4"_":{"_"0"_":"_"0"_","_"1"_":1}, "_"5"_": 1}");
   1050   logVarG(&n);
   1051   B = serialG(&n);
   1052   logI("len %u", lenG(B));
   1053   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1054   s = sToString((smallt *) B->B);
   1055   ck_assert_str_eq(s, "[0x62,0x30,0x00,0x58,0x02,0x30,0x00,0x40,0x31,0x00,0x02,0x31,0x00,0x02,0x30,0x00,0x45,0x30,0x00,0x31,0x00,0x02,0x32,0x00,0x02,0x30,0x00,0x45,0x30,0x00,0x31,0x00,0x02,0x33,0x00,0x02,0x30,0x00,0x45,0x30,0x00,0x31,0x00,0x02,0x34,0x00,0x02,0x30,0x00,0x45,0x30,0x00,0x31,0x00,0x02,0x35,0x00,0x24]");
   1056   free(s);
   1057   deserialG(&ds, B);
   1058   s = toStringG(&ds);
   1059   ck_assert_str_eq(s, "{\"0\":{\"0\":null,\"1\":1},\"1\":{\"0\":\"0\",\"1\":1},\"2\":{\"0\":\"0\",\"1\":1},\"3\":{\"0\":\"0\",\"1\":1},\"4\":{\"0\":\"0\",\"1\":1},\"5\":1}");
   1060   free(s);
   1061   terminateG(B);
   1062   freeManyG(&n, &ds);
   1063 
   1064   // high nibble packed dicts
   1065   parseG(&n, "{\"a\": null,"_"0"_":{},"_"1"_":{}, "_"2"_":{}, "_"3"_":{}, "_"4"_":{}, "_"5"_": 1}");
   1066   logVarG(&n);
   1067   B = serialG(&n);
   1068   logI("len %u", lenG(B));
   1069   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1070   s = sToString((smallt *) B->B);
   1071   ck_assert_str_eq(s, "[0x72,0x61,0x00,0x80,0x30,0x00,0x05,0x00,0x31,0x00,0x00,0x32,0x00,0x00,0x33,0x00,0x00,0x34,0x00,0x00,0x35,0x00,0x24]");
   1072   free(s);
   1073   deserialG(&ds, B);
   1074   s = toStringG(&ds);
   1075   ck_assert_str_eq(s, "{\"a\":null,\"0\":{},\"1\":{},\"2\":{},\"3\":{},\"4\":{},\"5\":1}");
   1076   free(s);
   1077   terminateG(B);
   1078   freeManyG(&n, &ds);
   1079 
   1080 
   1081   // packed doubles
   1082   parseG(&n, "{"_"0"_":0.0,"_"1"_":1.0, "_"2"_":2.0, "_"3"_":3.0, "_"4"_":4.0, "_"5"_": null}");
   1083   logVarG(&n);
   1084   B = serialG(&n);
   1085   logI("len %u", lenG(B));
   1086   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1087   s = sToString((smallt *) B->B);
   1088   ck_assert_str_eq(s, "[0x62,0x30,0x00,0x59,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x31,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x40,0x34,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x40,0x35,0x00,0x00]");
   1089   free(s);
   1090   deserialG(&ds, B);
   1091   s = toStringG(&ds);
   1092   ck_assert_str_eq(s, "{\"0\":0.000000e+00,\"1\":1.000000e+00,\"2\":2.000000e+00,\"3\":3.000000e+00,\"4\":4.000000e+00,\"5\":null}");
   1093   free(s);
   1094   terminateG(B);
   1095   freeManyG(&n, &ds);
   1096 
   1097   // high nibble packed doubles
   1098   parseG(&n, "{\"a\": null, "_"0"_":0.0,"_"1"_":1.0, "_"2"_":2.0, "_"3"_":3.0, "_"4"_":4.0, "_"5"_": null}");
   1099   logVarG(&n);
   1100   B = serialG(&n);
   1101   logI("len %u", lenG(B));
   1102   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1103   s = sToString((smallt *) B->B);
   1104   ck_assert_str_eq(s, "[0x72,0x61,0x00,0x90,0x30,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x31,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x40,0x34,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x40,0x35,0x00,0x00]");
   1105   free(s);
   1106   deserialG(&ds, B);
   1107   s = toStringG(&ds);
   1108   ck_assert_str_eq(s, "{\"a\":null,\"0\":0.000000e+00,\"1\":1.000000e+00,\"2\":2.000000e+00,\"3\":3.000000e+00,\"4\":4.000000e+00,\"5\":null}");
   1109   free(s);
   1110   terminateG(B);
   1111   freeManyG(&n, &ds);
   1112 
   1113 
   1114   // packed ints
   1115   parseG(&n, "{\"1\":1,\"2\":2,\"3\":3,\"4\":4,\"Z\":\"l\"}");
   1116   logVarG(&n);
   1117   B = serialG(&n);
   1118   logI("len %u", lenG(B));
   1119   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1120   s = sToString((smallt *) B->B);
   1121   ck_assert_str_eq(s, "[0x52,0x31,0x00,0x4a,0x02,0x32,0x00,0x04,0x33,0x00,0x06,0x34,0x00,0x08,0x5a,0x00,0x05,0x6c,0x00]");
   1122   free(s);
   1123   deserialG(&ds, B);
   1124   s = toStringG(&ds);
   1125   ck_assert_str_eq(s, "{\"1\":1,\"2\":2,\"3\":3,\"4\":4,\"Z\":\"l\"}");
   1126   free(s);
   1127   terminateG(B);
   1128   freeManyG(&n, &ds);
   1129 
   1130   // high nibble packed ints
   1131   parseG(&n, "{\"0\":null,\"1\":1,\"2\":2,\"3\":3,\"4\":4,\"Z\":\"l\"}");
   1132   logVarG(&n);
   1133   B = serialG(&n);
   1134   logI("len %u", lenG(B));
   1135   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1136   s = sToString((smallt *) B->B);
   1137   ck_assert_str_eq(s, "[0x62,0x30,0x00,0xa0,0x31,0x00,0x04,0x02,0x32,0x00,0x04,0x33,0x00,0x06,0x34,0x00,0x08,0x5a,0x00,0x05,0x6c,0x00]");
   1138   free(s);
   1139   deserialG(&ds, B);
   1140   s = toStringG(&ds);
   1141   ck_assert_str_eq(s, "{\"0\":null,\"1\":1,\"2\":2,\"3\":3,\"4\":4,\"Z\":\"l\"}");
   1142   free(s);
   1143   terminateG(B);
   1144   freeManyG(&n, &ds);
   1145 
   1146 
   1147   // packed strings
   1148   parseG(&n, "{\"1\":\"1\",\"2\":\"2\",\"3\":\"3\",\"4\":\"4\",\"Z\":null}");
   1149   logVarG(&n);
   1150   B = serialG(&n);
   1151   logI("len %u", lenG(B));
   1152   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1153   s = sToString((smallt *) B->B);
   1154   ck_assert_str_eq(s, "[0x52,0x31,0x00,0x4b,0x31,0x00,0x32,0x00,0x32,0x00,0x33,0x00,0x33,0x00,0x34,0x00,0x34,0x00,0x5a,0x00,0x00]");
   1155   free(s);
   1156   deserialG(&ds, B);
   1157   s = toStringG(&ds);
   1158   ck_assert_str_eq(s, "{\"1\":\"1\",\"2\":\"2\",\"3\":\"3\",\"4\":\"4\",\"Z\":null}");
   1159   free(s);
   1160   terminateG(B);
   1161   freeManyG(&n, &ds);
   1162 
   1163   // high nibble packed strings
   1164   parseG(&n, "{\"0\":null,\"1\":\"1\",\"2\":\"2\",\"3\":\"3\",\"4\":\"4\",\"Z\":null}");
   1165   logVarG(&n);
   1166   B = serialG(&n);
   1167   logI("len %u", lenG(B));
   1168   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1169   s = sToString((smallt *) B->B);
   1170   ck_assert_str_eq(s, "[0x62,0x30,0x00,0xb0,0x31,0x00,0x04,0x31,0x00,0x32,0x00,0x32,0x00,0x33,0x00,0x33,0x00,0x34,0x00,0x34,0x00,0x5a,0x00,0x00]");
   1171   free(s);
   1172   deserialG(&ds, B);
   1173   s = toStringG(&ds);
   1174   ck_assert_str_eq(s, "{\"0\":null,\"1\":\"1\",\"2\":\"2\",\"3\":\"3\",\"4\":\"4\",\"Z\":null}");
   1175   free(s);
   1176   terminateG(B);
   1177   freeManyG(&n, &ds);
   1178 
   1179   // packed arrays
   1180   parseG(&n, "{\"1\":[],\"2\":[1],\"3\":[\"3r\"],\"4\":[true],\"Z\":null}");
   1181   logVarG(&n);
   1182   B = serialG(&n);
   1183   logI("len %u", lenG(B));
   1184   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1185   s = sToString((smallt *) B->B);
   1186   ck_assert_str_eq(s, "[0x52,0x31,0x00,0x4c,0x00,0x32,0x00,0x01,0x24,0x33,0x00,0x01,0x15,0x33,0x72,0x00,0x34,0x00,0x01,0x01,0x5a,0x00,0x00]");
   1187   free(s);
   1188   deserialG(&ds, B);
   1189   s = toStringG(&ds);
   1190   ck_assert_str_eq(s, "{\"1\":[],\"2\":[1],\"3\":[\"3r\"],\"4\":[true],\"Z\":null}");
   1191   free(s);
   1192   terminateG(B);
   1193   freeManyG(&n, &ds);
   1194 
   1195   // high nibble packed arrays
   1196   parseG(&n, "{\"0\":null,\"1\":[],\"2\":[1],\"3\":[\"3r\"],\"4\":[true],\"Z\":null}");
   1197   logVarG(&n);
   1198   B = serialG(&n);
   1199   logI("len %u", lenG(B));
   1200   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1201   s = sToString((smallt *) B->B);
   1202   ck_assert_str_eq(s, "[0x62,0x30,0x00,0xc0,0x31,0x00,0x04,0x00,0x32,0x00,0x01,0x24,0x33,0x00,0x01,0x15,0x33,0x72,0x00,0x34,0x00,0x01,0x01,0x5a,0x00,0x00]");
   1203   free(s);
   1204   deserialG(&ds, B);
   1205   s = toStringG(&ds);
   1206   ck_assert_str_eq(s, "{\"0\":null,\"1\":[],\"2\":[1],\"3\":[\"3r\"],\"4\":[true],\"Z\":null}");
   1207   free(s);
   1208   terminateG(B);
   1209   freeManyG(&n, &ds);
   1210 
   1211   // smallBytes
   1212   parseG(&n, "{"_"0"_":null,"_"z"_":[true,3]}");
   1213   createSmallBytes(b);
   1214   pushG(&b, 1);
   1215   pushG(&b, 2);
   1216   pushG(&b, 3);
   1217   pushG(&b, 4);
   1218   pushG(&b, 5);
   1219   pushG(&b, 6);
   1220   setG(&n, "bytes", &b);
   1221   logVarG(&n);
   1222   B = serialG(&n);
   1223   logI("len %u", lenG(B));
   1224   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1225   s = sToString((smallt *) B->B);
   1226   ck_assert_str_eq(s, "[0x32,0x30,0x00,0x60,0x7a,0x00,0x02,0x11,0x64,0x62,0x79,0x74,0x65,0x73,0x00,0x67,0x01,0x02,0x03,0x04,0x05,0x06]");
   1227   free(s);
   1228   deserialG(&ds, B);
   1229   s = toStringG(&ds);
   1230   ck_assert_str_eq(s, "{"_"0"_":null,"_"z"_":[true,3],"_"bytes"_":[0x01,0x02,0x03,0x04,0x05,0x06]}");
   1231   free(s);
   1232   terminateG(B);
   1233   freeManyG(&n, &ds);
   1234 
   1235   parseG(&n, "{"_"0"_":null,"_"z"_":[true,3],"_"1"_":null}");
   1236   initiateG(&b);
   1237   pushG(&b, 1);
   1238   pushG(&b, 2);
   1239   pushG(&b, 3);
   1240   pushG(&b, 4);
   1241   pushG(&b, 5);
   1242   pushG(&b, 6);
   1243   setG(&n, "bytes", &b);
   1244   logVarG(&n);
   1245   B = serialG(&n);
   1246   logI("len %u", lenG(B));
   1247   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1248   s = sToString((smallt *) B->B);
   1249   ck_assert_str_eq(s, "[0x42,0x30,0x00,0x60,0x7a,0x00,0x02,0x11,0x64,0x31,0x00,0x70,0x62,0x79,0x74,0x65,0x73,0x00,0x06,0x01,0x02,0x03,0x04,0x05,0x06]");
   1250   free(s);
   1251   deserialG(&ds, B);
   1252   s = toStringG(&ds);
   1253   ck_assert_str_eq(s, "{"_"0"_":null,"_"z"_":[true,3],"_"1"_":null,"_"bytes"_":[0x01,0x02,0x03,0x04,0x05,0x06]}");
   1254   free(s);
   1255   terminateG(B);
   1256   freeManyG(&n, &ds);
   1257 
   1258 END_TEST
   1259 
   1260 
   1261 // array with values, dict, array, uniforms, packed test high/low nibbles
   1262 START_TEST(arrayT)
   1263 
   1264   // STEPS
   1265   // init
   1266   // init allocate
   1267   // terminate
   1268   // allocate
   1269   // string
   1270   // duplicate
   1271 
   1272   createNetSerial(n);
   1273   createNetSerial(ds);
   1274   char *s;
   1275   smallBytest *B;
   1276   createSmallArray(A);
   1277   createSmallArray(a);
   1278 
   1279   // null and uniform array
   1280   initiateG(&A);
   1281   pushG(&A, NULL);
   1282   initiateG(&a);
   1283   pushG(&a, 1);
   1284   pushG(&a, 2);
   1285   pushG(&a, 3);
   1286   pushG(&a, 4);
   1287   pushG(&A, &a);
   1288   setTopG(&n, &A);
   1289   logVarG(&n);
   1290   B = serialG(&n);
   1291   logI("len %u", lenG(B));
   1292   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1293   s = sToString((smallt *) B->B);
   1294   ck_assert_str_eq(s, "[0x26,0xf0,0x44,0x02,0x04,0x06,0x08]");
   1295   free(s);
   1296   deserialG(&ds, B);
   1297   s = toStringG(&ds);
   1298   //ck_assert_str_eq(s, "[null,null]");
   1299   ck_assert_str_eq(s, "[null,[1,2,3,4]]");
   1300   free(s);
   1301   terminateG(B);
   1302   freeManyG(&n, &ds);
   1303 
   1304   // uniform array in high low
   1305   initiateG(&A);
   1306   pushG(&A, FALSE);
   1307   initiateG(&a);
   1308   pushG(&a, 1);
   1309   pushG(&a, 2);
   1310   pushG(&a, 3);
   1311   pushG(&a, 4);
   1312   pushG(&A, &a);
   1313   setTopG(&n, &A);
   1314   logVarG(&n);
   1315   B = serialG(&n);
   1316   logI("len %u", lenG(B));
   1317   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1318   s = sToString((smallt *) B->B);
   1319   ck_assert_str_eq(s, "[0x26,0x01,0x4f,0x04,0x02,0x04,0x06,0x08]");
   1320   free(s);
   1321   deserialG(&ds, B);
   1322   s = toStringG(&ds);
   1323   //ck_assert_str_eq(s, "[null,null]");
   1324   ck_assert_str_eq(s, "[false,[1,2,3,4]]");
   1325   free(s);
   1326   terminateG(B);
   1327   freeManyG(&n, &ds);
   1328 
   1329   // uniform array in high nibble
   1330   initiateG(&A);
   1331   pushG(&A, "1");
   1332   initiateG(&a);
   1333   pushG(&a, 1);
   1334   pushG(&a, 2);
   1335   pushG(&a, 3);
   1336   pushG(&a, 4);
   1337   pushG(&A, &a);
   1338   setTopG(&n, &A);
   1339   logVarG(&n);
   1340   B = serialG(&n);
   1341   logI("len %u", lenG(B));
   1342   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1343   s = sToString((smallt *) B->B);
   1344   ck_assert_str_eq(s, "[0x26,0xf5,0x31,0x00,0x44,0x02,0x04,0x06,0x08]");
   1345   free(s);
   1346   deserialG(&ds, B);
   1347   s = toStringG(&ds);
   1348   ck_assert_str_eq(s, "[\"1\",[1,2,3,4]]");
   1349   free(s);
   1350   terminateG(B);
   1351   freeManyG(&n, &ds);
   1352 
   1353   // high nibble array
   1354   parseG(&n, "[null, [1,null]]");
   1355   logVarG(&n);
   1356   B = serialG(&n);
   1357   logI("len %u", lenG(B));
   1358   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1359   s = sToString((smallt *) B->B);
   1360   ck_assert_str_eq(s, "[0x26,0x60,0x02,0x24,0x00]");
   1361   free(s);
   1362   deserialG(&ds, B);
   1363   s = toStringG(&ds);
   1364   ck_assert_str_eq(s, "[null,[1,null]]");
   1365   free(s);
   1366   terminateG(B);
   1367   freeManyG(&n, &ds);
   1368 
   1369   // low and high undefined
   1370   parseG(&n, "[null,null,1]");
   1371   logVarG(&n);
   1372   B = serialG(&n);
   1373   logI("len %u", lenG(B));
   1374   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1375   s = sToString((smallt *) B->B);
   1376   ck_assert_str_eq(s, "[0x36,0x00,0x24]");
   1377   free(s);
   1378   deserialG(&ds, B);
   1379   s = toStringG(&ds);
   1380   ck_assert_str_eq(s, "[null,null,1]");
   1381   free(s);
   1382   terminateG(B);
   1383   freeManyG(&n, &ds);
   1384 
   1385   // low and high nibble bool
   1386   parseG(&n, "[null,true,false,false,true,true,false,true,false,true,true,true,true,true]");
   1387   logVarG(&n);
   1388   B = serialG(&n);
   1389   logI("len %u", lenG(B));
   1390   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1391   s = sToString((smallt *) B->B);
   1392   ck_assert_str_eq(s, "[0xe6,0x01,0x10,0x59,0x11,0x11,0x11,0x11,0x1f,0x11,0x11]");
   1393   free(s);
   1394   deserialG(&ds, B);
   1395   s = toStringG(&ds);
   1396   ck_assert_str_eq(s, "[null,true,false,false,true,true,false,true,false,true,true,true,true,true]");
   1397   free(s);
   1398   terminateG(B);
   1399   freeManyG(&n, &ds);
   1400 
   1401   // low and high nibble bool - ctx->boolOffset != 0 ctx->nibble == lowNbl ctx->boolShift == 8
   1402   parseG(&n, "[true,false,false,true,null,true,false,true,false,true,true,true,true,true]");
   1403   logVarG(&n);
   1404   B = serialG(&n);
   1405   logI("len %u", lenG(B));
   1406   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1407   s = sToString((smallt *) B->B);
   1408   ck_assert_str_eq(s, "[0xe6,0x01,0x91,0x11,0x01,0x51,0x11,0x11,0x1f,0x11,0x11]");
   1409   free(s);
   1410   deserialG(&ds, B);
   1411   s = toStringG(&ds);
   1412   ck_assert_str_eq(s, "[true,false,false,true,null,true,false,true,false,true,true,true,true,true]");
   1413   free(s);
   1414   terminateG(B);
   1415   freeManyG(&n, &ds);
   1416 
   1417 
   1418   // dict in array
   1419   parseG(&n, "[{\"0\":null,\"1\":1},{\"2\":2},{\"3\":3},null]");
   1420   logVarG(&n);
   1421   B = serialG(&n);
   1422   logI("len %u", lenG(B));
   1423   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1424   s = sToString((smallt *) B->B);
   1425   ck_assert_str_eq(s, "[0x46,0x22,0x30,0x00,0x40,0x31,0x00,0x02,0x4e,0x01,0x32,0x00,0x04,0x4e,0x01,0x33,0x00,0x06,0x00]");
   1426   free(s);
   1427   deserialG(&ds, B);
   1428   s = toStringG(&ds);
   1429   ck_assert_str_eq(s, "[{\"0\":null,\"1\":1},{\"2\":2},{\"3\":3},null]");
   1430   free(s);
   1431   terminateG(B);
   1432   freeManyG(&n, &ds);
   1433 
   1434   // double in array
   1435   parseG(&n, "[1.0,2.0,null]");
   1436   logVarG(&n);
   1437   B = serialG(&n);
   1438   logI("len %u", lenG(B));
   1439   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1440   s = sToString((smallt *) B->B);
   1441   ck_assert_str_eq(s, "[0x36,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00]");
   1442   free(s);
   1443   deserialG(&ds, B);
   1444   s = toStringG(&ds);
   1445   ck_assert_str_eq(s, "[1.000000e+00,2.000000e+00,null]");
   1446   free(s);
   1447   terminateG(B);
   1448   freeManyG(&n, &ds);
   1449 
   1450   // int in array
   1451   parseG(&n, "[1,2,null]");
   1452   logVarG(&n);
   1453   B = serialG(&n);
   1454   logI("len %u", lenG(B));
   1455   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1456   s = sToString((smallt *) B->B);
   1457   ck_assert_str_eq(s, "[0x36,0x24,0x44,0x00]");
   1458   free(s);
   1459   deserialG(&ds, B);
   1460   s = toStringG(&ds);
   1461   ck_assert_str_eq(s, "[1,2,null]");
   1462   free(s);
   1463   terminateG(B);
   1464   freeManyG(&n, &ds);
   1465 
   1466   // string in array
   1467   parseG(&n, "[\"1\",\"2\",null]");
   1468   logVarG(&n);
   1469   B = serialG(&n);
   1470   logI("len %u", lenG(B));
   1471   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1472   s = sToString((smallt *) B->B);
   1473   ck_assert_str_eq(s, "[0x36,0x55,0x31,0x00,0x32,0x00,0x00]");
   1474   free(s);
   1475   deserialG(&ds, B);
   1476   s = toStringG(&ds);
   1477   ck_assert_str_eq(s, "[\"1\",\"2\",null]");
   1478   free(s);
   1479   terminateG(B);
   1480   freeManyG(&n, &ds);
   1481 
   1482   // array in array
   1483   parseG(&n, "[[],[1,2],null]");
   1484   logVarG(&n);
   1485   B = serialG(&n);
   1486   logI("len %u", lenG(B));
   1487   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1488   s = sToString((smallt *) B->B);
   1489   ck_assert_str_eq(s, "[0x36,0x0f,0x00,0x4f,0x02,0x02,0x04,0x00]");
   1490   free(s);
   1491   deserialG(&ds, B);
   1492   s = toStringG(&ds);
   1493   ck_assert_str_eq(s, "[[],[1,2],null]");
   1494   free(s);
   1495   terminateG(B);
   1496   freeManyG(&n, &ds);
   1497 
   1498 
   1499   // packed dicts
   1500   parseG(&n, "[{\"1\":1},{\"2\":2},{\"3\":3},{\"4\":4},null]");
   1501   logVarG(&n);
   1502   B = serialG(&n);
   1503   logI("len %u", lenG(B));
   1504   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1505   s = sToString((smallt *) B->B);
   1506   ck_assert_str_eq(s, "[0x56,0x48,0x01,0x31,0x00,0x24,0x01,0x32,0x00,0x44,0x01,0x33,0x00,0x64,0x01,0x34,0x00,0x84,0x01,0x00]");
   1507   free(s);
   1508   deserialG(&ds, B);
   1509   s = toStringG(&ds);
   1510   ck_assert_str_eq(s, "[{\"1\":1},{\"2\":2},{\"3\":3},{\"4\":4},null]");
   1511   free(s);
   1512   terminateG(B);
   1513   freeManyG(&n, &ds);
   1514 
   1515   // high nibble packed dicts
   1516   parseG(&n, "[null,{\"1\":1},{\"2\":2},{\"3\":3},{\"4\":4},null]");
   1517   logVarG(&n);
   1518   B = serialG(&n);
   1519   logI("len %u", lenG(B));
   1520   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1521   s = sToString((smallt *) B->B);
   1522   ck_assert_str_eq(s, "[0x66,0x80,0x04,0x01,0x31,0x00,0x24,0x01,0x32,0x00,0x44,0x01,0x33,0x00,0x64,0x01,0x34,0x00,0x84,0x01,0x00]");
   1523   free(s);
   1524   deserialG(&ds, B);
   1525   s = toStringG(&ds);
   1526   ck_assert_str_eq(s, "[null,{\"1\":1},{\"2\":2},{\"3\":3},{\"4\":4},null]");
   1527   free(s);
   1528   terminateG(B);
   1529   freeManyG(&n, &ds);
   1530 
   1531   // packed doubles
   1532   parseG(&n, "[1.0,2.0,3.0,4.0,null]");
   1533   logVarG(&n);
   1534   B = serialG(&n);
   1535   logI("len %u", lenG(B));
   1536   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1537   s = sToString((smallt *) B->B);
   1538   ck_assert_str_eq(s, "[0x56,0x49,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x40,0x00]");
   1539   free(s);
   1540   deserialG(&ds, B);
   1541   s = toStringG(&ds);
   1542   ck_assert_str_eq(s, "[1.000000e+00,2.000000e+00,3.000000e+00,4.000000e+00,null]");
   1543   free(s);
   1544   terminateG(B);
   1545   freeManyG(&n, &ds);
   1546 
   1547   // high nibble packed doubles
   1548   parseG(&n, "[null,1.0,2.0,3.0,4.0,null]");
   1549   logVarG(&n);
   1550   B = serialG(&n);
   1551   logI("len %u", lenG(B));
   1552   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1553   s = sToString((smallt *) B->B);
   1554   ck_assert_str_eq(s, "[0x66,0x90,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x40,0x00]");
   1555   free(s);
   1556   deserialG(&ds, B);
   1557   s = toStringG(&ds);
   1558   ck_assert_str_eq(s, "[null,1.000000e+00,2.000000e+00,3.000000e+00,4.000000e+00,null]");
   1559   free(s);
   1560   terminateG(B);
   1561   freeManyG(&n, &ds);
   1562 
   1563   // packed ints
   1564   parseG(&n, "[1,2,3,4,null]");
   1565   logVarG(&n);
   1566   B = serialG(&n);
   1567   logI("len %u", lenG(B));
   1568   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1569   s = sToString((smallt *) B->B);
   1570   ck_assert_str_eq(s, "[0x56,0x4a,0x02,0x04,0x06,0x08,0x00]");
   1571   free(s);
   1572   deserialG(&ds, B);
   1573   s = toStringG(&ds);
   1574   ck_assert_str_eq(s, "[1,2,3,4,null]");
   1575   free(s);
   1576   terminateG(B);
   1577   freeManyG(&n, &ds);
   1578 
   1579   // high nibble packed ints
   1580   parseG(&n, "[null,1,2,3,4,null]");
   1581   logVarG(&n);
   1582   B = serialG(&n);
   1583   logI("len %u", lenG(B));
   1584   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1585   s = sToString((smallt *) B->B);
   1586   ck_assert_str_eq(s, "[0x66,0xa0,0x04,0x02,0x04,0x06,0x08,0x00]");
   1587   free(s);
   1588   deserialG(&ds, B);
   1589   s = toStringG(&ds);
   1590   ck_assert_str_eq(s, "[null,1,2,3,4,null]");
   1591   free(s);
   1592   terminateG(B);
   1593   freeManyG(&n, &ds);
   1594 
   1595   // packed strings
   1596   parseG(&n, "[\"1\",\"2\",\"3\",\"4\",null]");
   1597   logVarG(&n);
   1598   B = serialG(&n);
   1599   logI("len %u", lenG(B));
   1600   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1601   s = sToString((smallt *) B->B);
   1602   ck_assert_str_eq(s, "[0x56,0x4b,0x31,0x00,0x32,0x00,0x33,0x00,0x34,0x00,0x00]");
   1603   free(s);
   1604   deserialG(&ds, B);
   1605   s = toStringG(&ds);
   1606   ck_assert_str_eq(s, "[\"1\",\"2\",\"3\",\"4\",null]");
   1607   free(s);
   1608   terminateG(B);
   1609   freeManyG(&n, &ds);
   1610 
   1611   // high nibble packed strings
   1612   parseG(&n, "[null,\"1\",\"2\",\"3\",\"4\",null]");
   1613   logVarG(&n);
   1614   B = serialG(&n);
   1615   logI("len %u", lenG(B));
   1616   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1617   s = sToString((smallt *) B->B);
   1618   ck_assert_str_eq(s, "[0x66,0xb0,0x04,0x31,0x00,0x32,0x00,0x33,0x00,0x34,0x00,0x00]");
   1619   free(s);
   1620   deserialG(&ds, B);
   1621   s = toStringG(&ds);
   1622   ck_assert_str_eq(s, "[null,\"1\",\"2\",\"3\",\"4\",null]");
   1623   free(s);
   1624   terminateG(B);
   1625   freeManyG(&n, &ds);
   1626 
   1627   // packed arrays
   1628   parseG(&n, "[[1],[2],[3],[4],null]");
   1629   logVarG(&n);
   1630   B = serialG(&n);
   1631   logI("len %u", lenG(B));
   1632   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1633   s = sToString((smallt *) B->B);
   1634   ck_assert_str_eq(s, "[0x56,0x4c,0x01,0x24,0x01,0x44,0x01,0x64,0x01,0x84,0x01,0x00]");
   1635   free(s);
   1636   deserialG(&ds, B);
   1637   s = toStringG(&ds);
   1638   ck_assert_str_eq(s, "[[1],[2],[3],[4],null]");
   1639   free(s);
   1640   terminateG(B);
   1641   freeManyG(&n, &ds);
   1642 
   1643   // high nibble packed arrays
   1644   parseG(&n, "[null,[1],[2],[3],[4],null]");
   1645   logVarG(&n);
   1646   B = serialG(&n);
   1647   logI("len %u", lenG(B));
   1648   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1649   s = sToString((smallt *) B->B);
   1650   ck_assert_str_eq(s, "[0x66,0xc0,0x04,0x01,0x24,0x01,0x44,0x01,0x64,0x01,0x84,0x01,0x00]");
   1651   free(s);
   1652   deserialG(&ds, B);
   1653   s = toStringG(&ds);
   1654   ck_assert_str_eq(s, "[null,[1],[2],[3],[4],null]");
   1655   free(s);
   1656   terminateG(B);
   1657   freeManyG(&n, &ds);
   1658 
   1659   // smallBytes
   1660   parseG(&n, "[1,2,null]");
   1661   createSmallBytes(b);
   1662   pushG(&b, 1);
   1663   pushG(&b, 2);
   1664   pushG(&b, 3);
   1665   pushG(&b, 4);
   1666   pushG(&b, 5);
   1667   pushG(&b, 6);
   1668   pushG(&n, &b);
   1669   logVarG(&n);
   1670   B = serialG(&n);
   1671   logI("len %u", lenG(B));
   1672   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1673   s = sToString((smallt *) B->B);
   1674   ck_assert_str_eq(s, "[0x46,0x24,0x44,0x70,0x06,0x01,0x02,0x03,0x04,0x05,0x06]");
   1675   free(s);
   1676   deserialG(&ds, B);
   1677   s = toStringG(&ds);
   1678   ck_assert_str_eq(s, "[1,2,null,[0x01,0x02,0x03,0x04,0x05,0x06]]");
   1679   free(s);
   1680   terminateG(B);
   1681   freeManyG(&n, &ds);
   1682 
   1683   parseG(&n, "[1,2]");
   1684   initiateG(&b);
   1685   pushG(&b, 1);
   1686   pushG(&b, 2);
   1687   pushG(&b, 3);
   1688   pushG(&b, 4);
   1689   pushG(&b, 5);
   1690   pushG(&b, 6);
   1691   pushG(&n, &b);
   1692   logVarG(&n);
   1693   B = serialG(&n);
   1694   logI("len %u", lenG(B));
   1695   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1696   s = sToString((smallt *) B->B);
   1697   ck_assert_str_eq(s, "[0x36,0x24,0x44,0x67,0x01,0x02,0x03,0x04,0x05,0x06]");
   1698   free(s);
   1699   deserialG(&ds, B);
   1700   s = toStringG(&ds);
   1701   ck_assert_str_eq(s, "[1,2,[0x01,0x02,0x03,0x04,0x05,0x06]]");
   1702   free(s);
   1703   terminateG(B);
   1704   freeManyG(&n, &ds);
   1705 
   1706 END_TEST
   1707 
   1708 
   1709 START_TEST(variousT)
   1710 
   1711   createNetSerial(n);
   1712   createNetSerial(ds);
   1713   char *s;
   1714   smallBytest *B;
   1715 
   1716 
   1717   // array dict int bool string
   1718   parseG(&n, "[0, \"asd\", {\"rpc\":\"ds\", \"id\":1, \"p\":true}, [true, \"user\", [[false,\"name\",1], [true, \"name2\", 12340], [false, \"zxc\", 234]]]]");
   1719   logVarG(&n);
   1720   B = serialG(&n);
   1721   logI("len %u", lenG(B));
   1722   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1723   s = sToString((smallt *) B->B);
   1724   ck_assert_str_eq(s, "[0x46,0x04,0x25,0x61,0x73,0x64,0x00,0x03,0x72,0x70,0x63,0x00,0x45,0x64,0x73,0x00,0x69,0x64,0x00,0x02,0x70,0x00,0xb1,0x36,0x51,0x75,0x73,0x65,0x72,0x00,0x6f,0x03,0x03,0x51,0x6e,0x61,0x6d,0x65,0x00,0x24,0x03,0x51,0x6e,0x61,0x6d,0x65,0x32,0x00,0x84,0x8d,0x18,0x03,0x01,0x45,0x7a,0x78,0x63,0x00,0xd4,0x03]");
   1725   free(s);
   1726   deserialG(&ds, B);
   1727   s = toStringG(&ds);
   1728   ck_assert_str_eq(s, "[0,\"asd\",{\"rpc\":\"ds\",\"id\":1,\"p\":true},[true,\"user\",[[false,\"name\",1],[true,\"name2\",12340],[false,\"zxc\",234]]]]");
   1729   free(s);
   1730   terminateG(B);
   1731   freeManyG(&n, &ds);
   1732 
   1733   parseG(&n, "[[{a:1}, null, {a:1}, {a:1}]]");
   1734   logVarG(&n);
   1735   B = serialG(&n);
   1736   logI("len %u", lenG(B));
   1737   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1738   s = sToString((smallt *) B->B);
   1739   ck_assert_str_eq(s, "[0x6f,0x01,0x04,0x4e,0x01,0x61,0x00,0x02,0xe0,0x14,0x61,0x00,0x02,0x4e,0x01,0x61,0x00,0x02]");
   1740   free(s);
   1741   deserialG(&ds, B);
   1742   s = toStringG(&ds);
   1743   ck_assert_str_eq(s, "[[{\"a\":1},null,{\"a\":1},{\"a\":1}]]");
   1744   free(s);
   1745   terminateG(B);
   1746   freeManyG(&n, &ds);
   1747 
   1748 END_TEST
   1749 
   1750 Suite * netSerialSuite(void) {
   1751   Suite *s;
   1752   TCase *tc_core;
   1753 
   1754   s = suite_create("netSerial");
   1755 
   1756   /* Core test case */
   1757   tc_core = tcase_create("Core");
   1758 
   1759 
   1760   tcase_add_test(tc_core, topT);
   1761   tcase_add_test(tc_core, uniformDictT);
   1762   tcase_add_test(tc_core, uniformArrayT);
   1763   tcase_add_test(tc_core, dictT);
   1764   tcase_add_test(tc_core, arrayT);
   1765   tcase_add_test(tc_core, variousT);
   1766 
   1767   //TODO register tests
   1768 
   1769   suite_add_tcase(s, tc_core);
   1770 
   1771   ret s;
   1772 }
   1773 
   1774 int main(int ARGC, char** ARGV) {
   1775 
   1776   argc = ARGC; argv = ARGV;
   1777 
   1778   //dont initialize libsheepy, it conflicts with libcheck - initLibsheepy(ARGV[0]);
   1779   setLogMode(LOG_FUNC);
   1780 
   1781   int number_failed;
   1782   Suite *s;
   1783   SRunner *sr;
   1784 
   1785   s = netSerialSuite();
   1786   sr = srunner_create(s);
   1787 
   1788   srunner_run_all(sr, CK_NORMAL);
   1789   number_failed = srunner_ntests_failed(sr);
   1790   srunner_free(sr);
   1791 
   1792   exit((number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
   1793 }
   1794 // vim: set expandtab ts=2 sw=2: