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

commit 8f365963169d8e803c92caf8c76998f43ea4a166
parent ece1cad1fa489cba56515be4f3c23a8d899f5ebd
Author: Remy Noulin <loader2x@gmail.com>
Date:   Tue, 12 May 2020 19:49:20 +0200

add CuTest for libsheepySmall.c and libsheepyObject

.gitignore                       |    2 +
src/json/CuTest                  |    1 +
src/json/libsheepyObjectCuTest.c | 2380 ++++++++++++++++++++++++++++++++++++++
src/json/runCuTest.sh            |    2 +
src/libsheepySmallCuTest.c       | 1744 ++++++++++++++++++++++++++++
src/runCuTest.sh                 |    8 +-
src/runSmallCuTest.sh            |    3 +
7 files changed, 4136 insertions(+), 4 deletions(-)

Diffstat:
M.gitignore | 2++
Asrc/json/CuTest | 2++
Asrc/json/libsheepyObjectCuTest.c | 2380+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/json/runCuTest.sh | 2++
Asrc/libsheepySmallCuTest.c | 1744+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/runCuTest.sh | 8++++----
Asrc/runSmallCuTest.sh | 3+++
7 files changed, 4137 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -12,6 +12,8 @@ showdir sumNums cfp libsheepyCuTest +libsheepySmallCuTest +libsheepyObjectCuTest example/search example/regexDemo example/dmce diff --git a/src/json/CuTest b/src/json/CuTest @@ -0,0 +1 @@ +../CuTest+ \ No newline at end of file diff --git a/src/json/libsheepyObjectCuTest.c b/src/json/libsheepyObjectCuTest.c @@ -0,0 +1,2380 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "CuTest/CuTest.h" + +#define ck_assert_str_eq(a,b) CuAssertStrEquals(tc, b, a) +#define ck_assert_str_ne(a,b) CuAssertStrNotEquals(tc, b, a) +#define ck_assert_ptr_eq(a,b) CuAssertPtrEquals(tc, b, a) +#define ck_assert_ptr_ne(a,b) CuAssertPtrNotEquals(tc, b, a) +#define ck_assert_uint_eq(a,b) CuAssertUintEquals(tc, b, a) +#define ck_assert_uint_ne(a,b) CuAssertUintNotEquals(tc, b, a) +#define ck_assert_int_eq(a,b) CuAssertIntEquals(tc, b, a) +#define ck_assert_int_ne(a,b) CuAssertIntNotEquals(tc, b, a) +#define ck_assert(a) CuAssertTrue(tc, a) + + +#include "../libsheepy.h" +#include "../libsheepyObject.h" + +#ifdef __GNUC__ +#define UNUSED __attribute__ ((unused)) +#else +#define UNUSED +#endif + +// TODO redirect stderr + +void cSmallDictT(CuTest *tc) { + + // local object + createSmallDict(obj); + ck_assert_str_eq(obj.type, "smallDict"); + // object + createAllocateSmallDict(obj2); + ck_assert_str_eq(obj2->type, "smallDict"); + // toString + char *s = obj2->f->toString(obj2); + ck_assert_str_eq(s, "{}"); + free(s); + // duplicate + smallDictt *o; + createAllocateSmallBool(oBool2); + oBool2->f->set(oBool2, true); + obj2->f->set(obj2, "lib", (baset *)oBool2); + finishO(oBool2); + o = obj2->f->duplicate(obj2); + smallBoolt *oBool3; + oBool3 = (smallBoolt *)o->f->get(o, "lib"); + ck_assert_ptr_ne(oBool3, NULL); + ck_assert(oBool3->value->value == true); + finishO(oBool3); + terminateO(o); + // toString + createAllocateUndefined(oU); + obj2->f->set(obj2, "u", (baset *)oU); + finishO(oU); + createAllocateSmallString(oStr); + oStr->f->set(oStr, "sheepy"); + obj2->f->set(obj2, "str", (baset *)oStr); + finishO(oStr); + s = obj2->f->toString(obj2); + ck_assert_str_eq(s, "{\"lib\":true,\"u\":null,\"str\":\"sheepy\"}"); + free(s); + // dispose + o = obj2->f->duplicate(obj2); + undefinedt *u = (undefinedt *) o->f->get(o, "u"); + smallStringt *st = (smallStringt *) o->f->get(o, "str"); + oBool2 = (smallBoolt *) o->f->get(o, "lib"); + smallt *data = sDictGetTiny(o->d, "u"); + sFree(data); + data = sDictGetTiny(o->d, "str"); + sFree(data); + data = sDictGetTiny(o->d, "lib"); + sFree(data); + o->f->dispose(o); + ck_assert_uint_eq(o->f->len(o), 0); + terminateO(u); + smashO(st); + smashO(oBool2); + terminateO(o); + // smash + o = obj2->f->duplicate(obj2); + u = (undefinedt *) o->f->get(o, "u"); + st = (smallStringt *) o->f->get(o, "str"); + oBool2 = (smallBoolt *) o->f->get(o, "lib"); + data = sDictGetTiny(o->d, "u"); + sFree(data); + data = sDictGetTiny(o->d, "str"); + sFree(data); + data = sDictGetTiny(o->d, "lib"); + sFree(data); + o->f->smash(&o); + terminateO(u); + smashO(st); + smashO(oBool2); + ck_assert_ptr_eq(o, NULL); + // set NULL (not possible) + obj2->f->set(obj2, NULL, NULL); + obj2->f->set(obj2, "no", NULL); + ck_assert_uint_eq(obj2->f->len(obj2), 3); + // get non existing element + oBool3 = (smallBoolt *)obj2->f->get(obj2, "non existing"); + ck_assert_ptr_eq(oBool3, NULL); + ck_assert_ptr_eq(obj2->f->get(obj2, NULL), NULL); + // delete element + obj2->f->del(obj2, "lib"); + oBool3 = (smallBoolt *)obj2->f->get(obj2, "lib"); + ck_assert_ptr_eq(oBool3, NULL); + // delete non existing element + obj2->f->del(obj2, NULL); + obj2->f->del(obj2, "non existing"); + // has + ck_assert(!obj2->f->has(obj2, "qwe")); + ck_assert(!obj2->f->has(obj2, NULL)); + ck_assert(obj2->f->has(obj2, "u")); + // keys + char **keys = obj2->f->keys(obj2); + ck_assert_uint_eq(listLengthS(keys), 2); + ck_assert_str_eq(keys[0], "u"); + ck_assert_str_eq(keys[1], "str"); + listFreeS(keys); + // empty dict + initiateAllocateSmallDict(&o); + keys = o->f->keys(o); + ck_assert_ptr_eq(keys, NULL); + terminateO(o); + // values + smallArrayt *values = obj2->f->values(obj2); + s = toStringO(values); + ck_assert_str_eq(s, "[null,\"sheepy\"]"); + free(s); + values->f->smash(&values); + // empty dict + initiateAllocateSmallDict(&o); + values = o->f->values(o); + ck_assert_ptr_eq(values, NULL); + terminateO(o); + // merge + smallDictt *oM; + o = obj2->f->duplicate(obj2); + initiateAllocateSmallDict(&oM); + initiateAllocateSmallString(&st); + st->f->set(st, "SHEEPY MERGED"); + oM->f->set(oM, "str", (baset *) st); + finishO(st); + s = toStringO(o); + ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}"); + free(s); + o->f->merge(o, oM); + s = toStringO(o); + ck_assert_str_eq(s, "{\"u\":null,\"str\":\"SHEEPY MERGED\"}"); + free(s); + oM->f->smash(&oM); + terminateO(o); + // empty dict + o = obj2->f->duplicate(obj2); + initiateAllocateSmallDict(&oM); + s = toStringO(o); + ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}"); + free(s); + o->f->merge(o, oM); + s = toStringO(o); + ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}"); + free(s); + oM->f->smash(&oM); + terminateO(o); + // NULL dict + o = obj2->f->duplicate(obj2); + s = toStringO(o); + ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}"); + free(s); + o->f->merge(o, NULL); + s = toStringO(o); + ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}"); + free(s); + terminateO(o); + // append + o = obj2->f->duplicate(obj2); + initiateAllocateSmallDict(&oM); + initiateAllocateSmallString(&st); + initiateAllocateUndefined(&oU); + st->f->set(st, "SHEEPY MERGED"); + oM->f->set(oM, "str", (baset *) st); + finishO(st); + oM->f->set(oM, "u2", (baset *) oU); + finishO(oU); + s = toStringO(o); + ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}"); + free(s); + o->f->append(o, oM); + s = toStringO(o); + ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\",\"u2\":null}"); + free(s); + data = sDictGetTiny(oM->d, "str"); + sFree(data); + oM->f->smash(&oM); + terminateO(o); + // empty dict + o = obj2->f->duplicate(obj2); + initiateAllocateSmallDict(&oM); + s = toStringO(o); + ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}"); + free(s); + o->f->append(o, oM); + s = toStringO(o); + ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}"); + free(s); + oM->f->smash(&oM); + terminateO(o); + // NULL dict + o = obj2->f->duplicate(obj2); + s = toStringO(o); + ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}"); + free(s); + o->f->append(o, NULL); + s = toStringO(o); + ck_assert_str_eq(s, "{\"u\":null,\"str\":\"sheepy\"}"); + free(s); + terminateO(o); + // len + ck_assert_uint_eq(obj2->f->len(obj2), 2); + // empty dict + initiateAllocateSmallDict(&o); + ck_assert_uint_eq(o->f->len(o), 0); + terminateO(o); + // empty + o = obj2->f->duplicate(obj2); + o->f->empty(o); + ck_assert_uint_eq(o->f->len(o), 0); + terminateO(o); + // typeString type typeStrings + initiateAllocateSmallDict(&oM); + o = allocSmallDict(); + oU = allocUndefined(); + o->f->set(o, "u", (baset *)oU); + finishO(oU); + st = allocSmallString("sheepy"); + o->f->set(o, "str", (baset *) st); + finishO(st); + oBool2 = allocSmallBool(true); + o->f->set(o, "b", (baset *)oBool2); + finishO(oBool2); + oBool2 = allocSmallBool(true); + o->f->set(o, "B", (baset *)oBool2); + finishO(oBool2); + o->f->del(o, "B"); + // typeString + s = (char *)o->f->typeString(o, "b"); + ck_assert_str_eq(s, "bool"); + // non existing key + ck_assert_ptr_eq(o->f->typeString(o, "B"), NULL); + // empty object + ck_assert_ptr_eq(oM->f->typeString(oM, "B"), NULL); + // type + char c; + c = o->f->type(o, "str"); + ck_assert_uint_eq(c, STRING); + // non existing key + ck_assert(!o->f->type(o, "B")); + // empty object + ck_assert(!oM->f->type(oM, "B")); + // typeStrings + smallDictt *oT = o->f->typeStrings(o); + s = toStringO(oT); + ck_assert_str_eq(s, "{\"u\":\"undefined\",\"str\":\"string\",\"b\":\"bool\"}"); + free(s); + terminateO(oT); + // empty object + oT = oM->f->typeStrings(oM); + ck_assert_ptr_eq(oT, NULL); + terminateO(o); + terminateO(oM); + // free local object + obj.f->free(&obj); + ck_assert_str_eq(obj.type, "smallDict"); + // free object + obj2->f->terminate(&obj2); + ck_assert_ptr_eq(obj2, NULL); + +} + + +void cSmallJsonT(CuTest *tc) { + + // local object + createSmallJson(obj); + ck_assert_str_eq(obj.type, "smallJson"); + // object + createAllocateSmallJson(obj2); + ck_assert_str_eq(obj2->type, "smallJson"); + // toString + char *s = obj2->f->toString(obj2); + ck_assert_str_eq(s, "{}"); + free(s); + createAllocateSmallInt(oInt); + oInt->f->set(oInt, 123); + obj2->f->set(obj2, "int", (baset *) oInt); + finishO(oInt); + initiateAllocateSmallInt(&oInt); + oInt->f->set(oInt, 123); + obj2->f->set(obj2, "int2", (baset *) oInt); + finishO(oInt); + // no effect - no push to dictionary + initiateAllocateSmallInt(&oInt); + obj2->f->push(obj2, (baset *) oInt); + finishO(oInt); + s = obj2->f->toString(obj2); + ck_assert_str_eq(s, "{\"int\":123,\"int2\":123}"); + free(s); + terminateO(obj2); + initiateAllocateSmallJson(&obj2); + createAllocateSmallInt(oInt2); + oInt2->f->set(oInt2, 123); + obj2->f->push(obj2, (baset *) oInt2); + finishO(oInt2); + initiateAllocateSmallInt(&oInt2); + oInt2->f->set(oInt2, 123); + obj2->f->push(obj2, (baset *) oInt2); + finishO(oInt2); + // no effect - no set with key to array + initiateAllocateSmallInt(&oInt2); + obj2->f->set(obj2, "noEffect", (baset *) oInt2); + finishO(oInt2); + s = obj2->f->toString(obj2); + ck_assert_str_eq(s, "[123,123]"); + free(s); + // duplicate + smallJsont *o; + o = obj2->f->duplicate(obj2); + s = toStringO(o); + ck_assert_str_eq(s, "[123,123]"); + free(s); + terminateO(o); + terminateO(obj2); + initiateAllocateSmallJson(&obj2); + createAllocateSmallInt(oInt3); + oInt3->f->set(oInt3, 123); + obj2->f->set(obj2, "int", (baset *) oInt3); + finishO(oInt3); + o = obj2->f->duplicate(obj2); + s = toStringO(o); + ck_assert_str_eq(s, "{\"int\":123}"); + free(s); + terminateO(o); + // dispose + // array + initiateAllocateSmallJson(&o); + initiateAllocateSmallInt(&oInt); + oInt->f->set(oInt, 123); + o->f->push(o, (baset*)oInt); + finishO(oInt); + ck_assert_uint_eq(o->topA->count, 1); + smallt *i = sArrayGetTiny(o->topA, 0); + o->f->dispose(o); + ck_assert_ptr_eq(o->topA, NULL); + sFree(i); + terminateO(o); + // dictionary + initiateAllocateSmallJson(&o); + initiateAllocateSmallInt(&oInt); + oInt->f->set(oInt, 123); + o->f->set(o, "in", (baset*)oInt); + finishO(oInt); + ck_assert_uint_eq(o->top->count, 1); + smallt *data = o->top->elements.data; + sFree(data); + o->f->dispose(o); + ck_assert_ptr_eq(o->top, NULL); + terminateO(o); + // smash + initiateAllocateSmallJson(&o); + // array + initiateAllocateSmallInt(&oInt); + oInt->f->set(oInt, 123); + o->f->push(o, (baset*)oInt); + finishO(oInt); + ck_assert_uint_eq(o->topA->count, 1); + i = sArrayGetTiny(o->topA, 0); + o->f->smash(&o); + ck_assert_ptr_eq(o, NULL); + sFree(i); + // dict + initiateAllocateSmallJson(&o); + initiateAllocateSmallInt(&oInt); + oInt->f->set(oInt, 123); + o->f->set(o, "in", (baset*)oInt); + finishO(oInt); + ck_assert_uint_eq(o->top->count, 1); + data = o->top->elements.data; + sFree(data); + o->f->smash(&o); + ck_assert_ptr_eq(o, NULL); + // setType* + initiateAllocateSmallJson(&o); + o->f->setTypeUndefined(o); + ck_assert_str_eq(o->f->getTopType(o), "undefined"); + o->f->setTypeBool(o); + ck_assert_str_eq(o->f->getTopType(o), "bool"); + o->f->setTypeDouble(o); + ck_assert_str_eq(o->f->getTopType(o), "double"); + o->f->setTypeInt(o); + ck_assert_str_eq(o->f->getTopType(o), "int"); + o->f->setTypeString(o); + ck_assert_str_eq(o->f->getTopType(o), "string"); + o->f->setTypeDict(o); + ck_assert_str_eq(o->f->getTopType(o), "dict"); + o->f->setTypeArray(o); + ck_assert_str_eq(o->f->getTopType(o), "array"); + terminateO(o); + // getTopTypeJson setTopJson getTopJson - undefined bool double int string + baset *b; + smallJsont *o2; + initiateAllocateSmallJson(&o); + ck_assert_ptr_eq(o->f->getTopType(o), NULL); + // non json object + createAllocateSmallContainer(jcontainer); + // setTop + o->f->setTop(o, (baset *)jcontainer); + terminateO(jcontainer); + ck_assert_ptr_eq(o->f->getTopType(o), NULL); + // getTop + b = o->f->getTop(o); + ck_assert_ptr_eq(b, NULL); + // undefined + createAllocateUndefined(jUndef); + // setTop + o->f->setTop(o, (baset *)jUndef); + finishO(jUndef); + // getTopType + ck_assert_str_eq(o->f->getTopType(o), "undefined"); + // getTop + b = o->f->getTop(o); + ck_assert_str_eq(b->type, "undefined"); + finishO(b); + // duplicateO + o2 = duplicateO(o); + // toStringO + s = toStringO(o2); + ck_assert_str_eq(s, "null"); + free(s); + // stringify + s = o->f->stringify(o,2); + ck_assert_str_eq(s, "null"); + free(s); + // toYML + s = o->f->toYML(o,2); + ck_assert_str_eq(s, "---\n null"); + free(s); + // smash + o2->f->smash(&o2); + // freeO + freeO(o); + ck_assert_ptr_eq(o->f->getTopType(o), NULL); + terminateO(o); + // cBool + initiateAllocateSmallJson(&o); + createAllocateSmallBool(jBool); + // setTop + o->f->setTop(o, (baset *)jBool); + finishO(jBool); + // getTopType + ck_assert_str_eq(o->f->getTopType(o), "bool"); + // getTop + b = o->f->getTop(o); + ck_assert_str_eq(b->type, "smallBool"); + finishO(b); + // duplicateO + o2 = duplicateO(o); + // toStringO + s = toStringO(o2); + ck_assert_str_eq(s, "false"); + free(s); + // stringify + s = o->f->stringify(o,2); + ck_assert_str_eq(s, "false"); + free(s); + // toYML + s = o->f->toYML(o,2); + ck_assert_str_eq(s, "---\n false"); + free(s); + // smash + o2->f->smash(&o2); + // freeO + freeO(o); + ck_assert_ptr_eq(o->f->getTopType(o), NULL); + terminateO(o); + // cDouble + initiateAllocateSmallJson(&o); + createAllocateSmallDouble(jDouble); + // setTop + o->f->setTop(o, (baset *)jDouble); + finishO(jDouble); + // getTopType + ck_assert_str_eq(o->f->getTopType(o), "double"); + // getTop + b = o->f->getTop(o); + ck_assert_str_eq(b->type, "smallDouble"); + finishO(b); + // duplicateO + o2 = duplicateO(o); + // toStringO + s = toStringO(o2); + ck_assert_str_eq(s, "0.000000e+00"); + free(s); + // stringify + s = o->f->stringify(o,2); + ck_assert_str_eq(s, "0.000000e+00"); + free(s); + // toYML + s = o->f->toYML(o,2); + ck_assert_str_eq(s, "---\n 0.000000e+00"); + free(s); + // smash + o2->f->smash(&o2); + // freeO + freeO(o); + ck_assert_ptr_eq(o->f->getTopType(o), NULL); + terminateO(o); + // cInt + initiateAllocateSmallJson(&o); + createAllocateSmallInt(jInt); + // setTop + o->f->setTop(o, (baset *)jInt); + finishO(jInt); + // getTopType + ck_assert_str_eq(o->f->getTopType(o), "int"); + // getTop + b = o->f->getTop(o); + ck_assert_str_eq(b->type, "smallInt"); + finishO(b); + // duplicateO + o2 = duplicateO(o); + // toStringO + s = toStringO(o2); + ck_assert_str_eq(s, "0"); + free(s); + // stringify + s = o->f->stringify(o,2); + ck_assert_str_eq(s, "0"); + free(s); + // toYML + s = o->f->toYML(o,2); + ck_assert_str_eq(s, "---\n 0"); + free(s); + // smash + o2->f->smash(&o2); + // freeO + freeO(o); + ck_assert_ptr_eq(o->f->getTopType(o), NULL); + terminateO(o); + // string + initiateAllocateSmallJson(&o); + createAllocateSmallString(jString); + jString->f->set(jString, "sheepy"); + // setTop + o->f->setTop(o, (baset *)jString); + finishO(jString); + // getTopType + ck_assert_str_eq(o->f->getTopType(o), "string"); + // getTop + b = o->f->getTop(o); + ck_assert_str_eq(b->type, "smallString"); + finishO(b); + // duplicateO + o2 = duplicateO(o); + // toStringO + s = toStringO(o2); + ck_assert_str_eq(s, "sheepy"); + free(s); + // stringify + s = o->f->stringify(o,2); + ck_assert_str_eq(s, "\"sheepy\""); + free(s); + // toYML + s = o->f->toYML(o,2); + ck_assert_str_eq(s, "---\n \"sheepy\""); + free(s); + // smash + o2->f->smash(&o2); + // freeO + freeO(o); + ck_assert_ptr_eq(o->f->getTopType(o), NULL); + terminateO(o); + // dict + initiateAllocateSmallJson(&o); + createAllocateSmallDict(jdict); + // setTop + o->f->setTop(o, (baset *)jdict); + finishO(jdict); + // getTopType + ck_assert_str_eq(o->f->getTopType(o), "dict"); + // getTop + b = o->f->getTop(o); + ck_assert_str_eq(b->type, "smallDict"); + finishO(b); + // duplicateO + o2 = duplicateO(o); + // toStringO + s = toStringO(o2); + ck_assert_str_eq(s, "{}"); + free(s); + // stringify + s = o->f->stringify(o,2); + ck_assert_str_eq(s, "{}\n"); + free(s); + // toYML + s = o->f->toYML(o,2); + ck_assert_str_eq(s, "---\n {}\n"); + free(s); + // smash + o2->f->smash(&o2); + // freeO + freeO(o); + ck_assert_ptr_eq(o->f->getTopType(o), NULL); + terminateO(o); + // array + initiateAllocateSmallJson(&o); + createAllocateSmallArray(jArray); + // setTop + o->f->setTop(o, (baset *)jArray); + finishO(jArray); + // getTopType + ck_assert_str_eq(o->f->getTopType(o), "array"); + // getTop + b = o->f->getTop(o); + ck_assert_str_eq(b->type, "smallArray"); + finishO(b); + // duplicateO + o2 = duplicateO(o); + // toStringO + s = toStringO(o2); + ck_assert_str_eq(s, "[]"); + free(s); + // stringify + s = o->f->stringify(o,2); + ck_assert_str_eq(s, "[]\n"); + free(s); + // toYML + s = o->f->toYML(o,2); + ck_assert_str_eq(s, "---\n []\n"); + free(s); + // smash + o2->f->smash(&o2); + // freeO + freeO(o); + ck_assert_ptr_eq(o->f->getTopType(o), NULL); + terminateO(o); + // get + smallIntt *in = (smallIntt *) obj2->f->get(obj2, "int"); + ck_assert(in->value->value == 123); + createAllocateSmallDict(oD2); + smallIntt *in2 = duplicateO(in); + oD2->f->set(oD2, "int", (baset *)in2); + finishO(in2); + in2 = duplicateO(in); + oD2->f->set(oD2, "int2", (baset *)in2); + finishO(in2); + obj2->f->set(obj2, "dict", (baset *)oD2); + finishO(oD2); + createAllocateSmallArray(oTA2); + in2 = duplicateO(in); + oTA2->f->push(oTA2, (baset *)in2); + finishO(in2); + in2 = duplicateO(in); + oTA2->f->push(oTA2, (baset *)in2); + finishO(in2); + smashO(in); + obj2->f->set(obj2, "array", (baset *)oTA2); + finishO(oTA2); + // get dict element + in = (smallIntt *) obj2->f->get(obj2, "\"dict\".\"int2\""); + ck_assert(in->value->value == 123); + smashO(in); + // non existing element + in = (smallIntt *) obj2->f->get(obj2, "\"dict\".\"void\""); + ck_assert_ptr_eq(in, NULL); + // missing " at the end + in = (smallIntt *) obj2->f->get(obj2, "\"dict\".\"int2"); + ck_assert_ptr_eq(in, NULL); + // get array element + in = (smallIntt *) obj2->f->get(obj2, "\"array\"[0]"); + ck_assert(in->value->value == 123); + smashO(in); + // missing ] at the end + in = (smallIntt *) obj2->f->get(obj2, "\"array\"[0"); + ck_assert_ptr_eq(in, NULL); + // json array + createAllocateSmallJson(json); + createAllocateSmallInt(oInt4); + oInt4->f->set(oInt4, 345); + json->f->push(json, (baset *) oInt4); + finishO(oInt4); + in = (smallIntt *) json->f->get(json, "[0]"); + ck_assert(in->value->value == 345); + smashO(in); + // set get json path + createSmallJson(jpath); + // dict is top + jpath.f->parse(&jpath, "{ \"a\": {\"a\": true}, \"b\": 234, \"c\": [\"qwe\",32]}"); + // get non existing element in 'c' array + b = jpath.f->get(&jpath,"\"c\"[3]"); + ck_assert_ptr_eq(b, NULL); + finishO(b); + // dictionary keys should not be unescaped + createSmallBool(ba); + jpath.f->set(&jpath, "b\\\\", cBa(&ba)); + jBool = (smallBoolt*)jpath.f->get(&jpath,"b\\\\"); + ck_assert(jBool->value->value == false); + finishO(jBool); + // keys in json paths should be unescaped + createSmallBool(bb); + bb.f->set(&bb, true); + jpath.f->set(&jpath, "\"b\\\\\"", (baset*)&bb); + jBool = (smallBoolt*)jpath.f->get(&jpath,"\"b\\\\\""); + ck_assert(jBool->value->value == true); + finishO(jBool); + freeO(&jpath); + // array is top + // get dict in dict + jpath.f->parse(&jpath, "[1,{\"a\": {\"a\": true}, \"b\": 234, \"c\": [\"qwe\",32]}, [[11],22,33]]"); + b = jpath.f->get(&jpath,"[1].\"a\""); + ck_assert_str_eq(b->type, "smallDict"); + finishO(b); + // get bool in dict + jBool = (smallBoolt*)jpath.f->get(&jpath,"[1]\"a\"\"a\""); + ck_assert(jBool->value->value == true); + finishO(jBool); + // get array in array + jArray = (smallArrayt*)jpath.f->get(&jpath,"[2][0]"); + ck_assert_str_eq(jArray->type, "smallArray"); + ck_assert_uint_eq(lenO(jArray), 1); + finishG(jArray); + // get element in array + in = (smallIntt*)(jpath.f->get(&jpath,"[2][0][0]")); + ck_assert_uint_eq(in->value->value, 11); + finishG(in); + // set element in array with negative index + createSmallBool(be); + jpath.f->set(&jpath, "[-1][0][0]", (baset*)&be); + // get element in array with negative index + jBool = (smallBoolt*)jpath.f->get(&jpath,"[-1][0][0]"); + ck_assert(jBool->value->value == false); + finishG(jBool); + // set new element in dict + createSmallBool(b2); + o2 = jpath.f->set(&jpath, "[1]\"a\"\"b\\\"\"", (baset*)&b2); + ck_assert_ptr_ne(o2, NULL); + jBool = (smallBoolt*)jpath.f->get(&jpath,"[1]\"a\"\"b\\\"\""); + ck_assert(jBool->value->value == false); + finishG(jBool); + createSmallBool(b3); + o2 = jpath.f->set(&jpath, "[1]\"a\"\"b\\\\\"", (baset*)&b3); + ck_assert_ptr_ne(o2, NULL); + jBool = (smallBoolt*)jpath.f->get(&jpath,"[1]\"a\"\"b\\\\\""); + ck_assert(jBool->value->value == false); + finishG(jBool); + // escape key in json path + // \\\"" + char *ks = jpath.f->makeKey(&jpath, "\\\\\\\"\""); + ck_assert_str_eq(ks, "\"\\\\\\\\\\\\\\\"\\\"\""); + createSmallBool(b4); + iPrependS(&ks, "[1]"); + o2 = jpath.f->set(&jpath, ks, (baset*)&b4); + ck_assert_ptr_ne(o2, NULL); + jBool = (smallBoolt*)jpath.f->get(&jpath,ks); + ck_assert(jBool->value->value == false); + finishG(jBool); + free(ks); + // wrong path + b = jpath.f->get(&jpath,"[3][0][0]"); + ck_assert_ptr_eq(b, NULL); + finishG(b); + // missing index + b = jpath.f->get(&jpath,"[][0][0]"); + ck_assert_ptr_eq(b, NULL); + finishG(b); + // try to assign dictionary key to array, wrong + createSmallBool(b0); + o2 = jpath.f->set(&jpath, "[2][0]\"sdf\\\"", (baset*)&b0); + ck_assert_ptr_eq(o2, NULL); + freeO(&jpath); + // len + initiateAllocateSmallJson(&o); + ck_assert_uint_eq(o->f->len(o), 0); + o->f->setTypeUndefined(o); + ck_assert_uint_eq(o->f->len(o), 1); + o->f->setTypeBool(o); + ck_assert_uint_eq(o->f->len(o), 1); + o->f->setTypeDouble(o); + ck_assert_uint_eq(o->f->len(o), 1); + o->f->setTypeInt(o); + ck_assert_uint_eq(o->f->len(o), 1); + o->f->setTypeString(o); + ck_assert_uint_eq(o->f->len(o), 0); + o->f->setTypeDict(o); + ck_assert_uint_eq(o->f->len(o), 0); + o->f->setTypeArray(o); + ck_assert_uint_eq(o->f->len(o), 0); + terminateO(o); + // empty + initiateAllocateSmallJson(&o); + // empty empty + o->f->empty(o); + o->f->setTypeString(o); + sFree((smallt *)o->topS); + o->topS = allocSStringTiny("er"); + o->f->empty(o); + ck_assert_uint_eq(o->f->len(o), 0); + o->f->setTypeDict(o); + initiateAllocateSmallInt(&in); + o->f->set(o, "wer", (baset *)in); + finishO(in); + o->f->empty(o); + ck_assert_uint_eq(o->f->len(o), 0); + o->f->setTypeArray(o); + initiateAllocateSmallInt(&in); + o->f->push(o, (baset *)in); + finishO(in); + o->f->empty(o); + ck_assert_uint_eq(o->f->len(o), 0); + terminateO(o); + // stringify + // array + initiateAllocateSmallString(&jString); + jString->f->set(jString, "sheepy"); + json->f->push(json, (baset *) jString); + finishO(jString); + initiateAllocateSmallDict(&jdict); + json->f->push(json, (baset *) jdict); + finishO(jdict); + initiateAllocateSmallArray(&jArray); + json->f->push(json, (baset *) jArray); + finishO(jArray); + initiateAllocateSmallDict(&jdict); + initiateAllocateSmallString(&jString); + jString->f->set(jString, "sheepy"); + jdict->f->set(jdict, "string", (baset *) jString); + finishO(jString); + initiateAllocateSmallContainer(&jcontainer); + jdict->f->set(jdict, "container", (baset *) jcontainer); + finishO(jcontainer); + json->f->push(json, (baset *) jdict); + finishO(jdict); + initiateAllocateSmallArray(&jArray); + initiateAllocateSmallString(&jString); + jString->f->set(jString, "sheepy"); + jArray->f->push(jArray, (baset *) jString); + finishO(jString); + initiateAllocateSmallContainer(&jcontainer); + jArray->f->push(jArray, (baset *) jcontainer); + finishO(jcontainer); + json->f->push(json, (baset *) jArray); + finishO(jArray); + + s = json->f->stringify(json, 2); + 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"); + free(s); + // empty + createAllocateSmallJson(json2); + s = json2->f->stringify(json2, 2); + ck_assert_str_eq(s, "{}"); + free(s); + // dict + initiateAllocateSmallString(&jString); + jString->f->set(jString, "sheepy"); + json2->f->set(json2, "s", (baset *) jString); + finishO(jString); + initiateAllocateSmallDict(&jdict); + json2->f->set(json2, "d",(baset *) jdict); + finishO(jdict); + initiateAllocateSmallArray(&jArray); + json2->f->set(json2, "a", (baset *) jArray); + finishO(jArray); + initiateAllocateSmallDict(&jdict); + initiateAllocateSmallString(&jString); + jString->f->set(jString, "sheepy"); + jdict->f->set(jdict, "string", (baset *) jString); + finishO(jString); + initiateAllocateSmallContainer(&jcontainer); + jdict->f->set(jdict, "container", (baset *) jcontainer); + finishO(jcontainer); + json2->f->set(json2, "d2",(baset *) jdict); + finishO(jdict); + initiateAllocateSmallArray(&jArray); + initiateAllocateSmallString(&jString); + jString->f->set(jString, "sheepy"); + jArray->f->push(jArray, (baset *) jString); + finishO(jString); + initiateAllocateSmallContainer(&jcontainer); + jArray->f->push(jArray, (baset *) jcontainer); + finishO(jcontainer); + json2->f->set(json2, "a2", (baset *) jArray); + finishO(jArray); + initiateAllocateSmallInt(&oInt4); + oInt4->f->set(oInt4, 345); + json2->f->set(json2, "int", (baset *) oInt4); + finishO(oInt4); + s = json2->f->stringify(json2, 2); + 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"); + free(s); + // toYML + // array + s = json->f->toYML(json, 2); + ck_assert_str_eq(s, "---\n - 345\n - sheepy\n - {}\n - []\n - string: sheepy\n container: \"<data container>\"\n - - sheepy\n - \"<data container>\"\n"); + free(s); + // empty + createAllocateSmallJson(json3); + s = json3->f->toYML(json3, 2); + ck_assert_str_eq(s, "---\n"); + free(s); + terminateO(json3); + // dict + s = json2->f->toYML(json2, 2); + 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"); + free(s); + terminateO(json2); + terminateO(json); + // parse + // top null - undefined + initiateAllocateSmallJson(&json); + json->f->parse(json, "null"); + ck_assert_str_eq(json->f->getTopType(json), "undefined"); + terminateO(json); + // top bool + initiateAllocateSmallJson(&json); + json->f->parse(json, "true"); + ck_assert_str_eq(json->f->getTopType(json), "bool"); + terminateO(json); + // top double + initiateAllocateSmallJson(&json); + json->f->parse(json, "0.01"); + ck_assert_str_eq(json->f->getTopType(json), "double"); + terminateO(json); + // top int + initiateAllocateSmallJson(&json); + json->f->parse(json, "10"); + ck_assert_str_eq(json->f->getTopType(json), "int"); + terminateO(json); + // top string + initiateAllocateSmallJson(&json); + json->f->parse(json, "\"wef\""); + ck_assert_str_eq(json->f->getTopType(json), "string"); + terminateO(json); + // from file dictionary + char **file = readText("file.json"); + char *jsonText = join(file, "\n"); + createAllocateSmallJson(jsOfromF); + jsOfromF->f->parse(jsOfromF, jsonText); + s = toStringO(jsOfromF); + //printf("JSON FILE: %s\n", s); + ck_assert_str_eq(s, "{\"dasd\":\"asd\",\"asd\":234,\"dict\":{\"array\":[1,1],\"asd\":true,\"float\":3.434000e+01},\"bool\":false,\"zzz\":null}"); + free(s); + free(jsonText); + listFreeS(file); + terminateO(jsOfromF); + // json array top + file = readText("fileA.json"); + jsonText = join(file, "\n"); + initiateAllocateSmallJson(&jsOfromF); + jsOfromF->f->parse(jsOfromF, jsonText); + s = toStringO(jsOfromF); + ck_assert_str_eq(s, "[\"asd\",234,{\"array\":[1,1],\"asd\":true,\"float\":3.434000e+01}]"); + free(s); + free(jsonText); + listFreeS(file); + terminateO(jsOfromF); + // wrong json incomplete dict + initiateAllocateSmallJson(&json); + json->f->parse(json, "{\"wef\": {"); + s = toStringO(json); + ck_assert_str_eq(s, "{}"); + free(s); + terminateO(json); + // wrong json incomplete array + initiateAllocateSmallJson(&json); + json->f->parse(json, "{\"wef\": ["); + s = toStringO(json); + ck_assert_str_eq(s, "{}"); + free(s); + terminateO(json); + // wrong json incomplete string + initiateAllocateSmallJson(&json); + json->f->parse(json, "{\"wef\": \"wer"); + s = toStringO(json); + ck_assert_str_eq(s, "{}"); + free(s); + terminateO(json); + // wrong json incomplete top dict + initiateAllocateSmallJson(&json); + json->f->parse(json, "{ \"wef"); + s = toStringO(json); + ck_assert_str_eq(s, "{}"); + free(s); + terminateO(json); + // wrong json incomplete top array + initiateAllocateSmallJson(&json); + json->f->parse(json, "[\"wef"); + s = toStringO(json); + ck_assert_str_eq(s, "{}"); + free(s); + terminateO(json); + // wrong json incomplete top string + initiateAllocateSmallJson(&json); + json->f->parse(json, "\"wef"); + s = toStringO(json); + ck_assert_str_eq(s, "{}"); + free(s); + terminateO(json); + // parseYML + // yml only top dict or array - NO: top null undefined top bool top double top int top string + // from file dictionary + file = readText("file.yml"); + jsonText = join(file, "\n"); + initiateAllocateSmallJson(&jsOfromF); + jsOfromF->f->parseYML(jsOfromF, jsonText); + s = toStringO(jsOfromF); + ck_assert_str_eq(s, "{\"dict\":{\"array\":[1,1],\"float\":3.434000e+01,\"asd\":true},\"dasd\":\"asd\",\"asd\":234,\"bool\":false,\"zzz\":null}"); + free(s); + free(jsonText); + listFreeS(file); + terminateO(jsOfromF); + // json array top + file = readText("fileA.yml"); + jsonText = join(file, "\n"); + initiateAllocateSmallJson(&jsOfromF); + jsOfromF->f->parseYML(jsOfromF, jsonText); + s = toStringO(jsOfromF); + //printf("JSON FILE: %s\n", toStringO(jsOfromF)); + ck_assert_str_eq(s, "[{\"dict\":\"hello\",\"array\":[1,1],\"float\":3.434000e+01,\"asd\":true},\"asd\",234]"); + free(s); + free(jsonText); + listFreeS(file); + terminateO(jsOfromF); + // serial deserial + smallBytest *B; + initiateAllocateSmallJson(&o); + ck_assert_ptr_eq(o->f->serial(o), NULL); + // non json object + initiateAllocateSmallContainer(&jcontainer); + o->f->setTop(o, (baset *)jcontainer); + ck_assert_ptr_eq(o->f->serial(o), NULL); + terminateO(jcontainer); + // undefined + undefinedt *oU = allocUndefined(); + o->f->setTop(o, (baset *)oU); + finishO(oU); + B = o->f->serial(o); + s = sToString((smallt *) B->B); + ck_assert_str_eq(s, "[0x01]"); + free(s); + freeO(o); + o->f->deserial(o, B); + s = toStringO(o); + ck_assert_str_eq(s, "null"); + free(s); + terminateO(B); + terminateO(o); + // Bool + initiateAllocateSmallJson(&o); + smallBoolt *oBool = allocSmallBool(true); + o->f->setTop(o, (baset *)oBool); + finishO(oBool); + B = o->f->serial(o); + s = sToString((smallt *) B->B); + ck_assert_str_eq(s, "[0x02,0x01]"); + free(s); + o->f->deserial(o, B); + s = toStringO(o); + ck_assert_str_eq(s, "true"); + free(s); + terminateO(B); + terminateO(o); + // Double + initiateAllocateSmallJson(&o); + smallDoublet *od = allocSmallDouble(10); + o->f->setTop(o, (baset *)od); + finishO(od); + B = o->f->serial(o); + s = sToString((smallt *) B->B); + ck_assert_str_eq(s, "[0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x24,0x40]"); + free(s); + o->f->deserial(o, B); + s = toStringO(o); + ck_assert_str_eq(s, "1.000000e+01"); + free(s); + terminateO(B); + terminateO(o); + // Int + initiateAllocateSmallJson(&o); + oInt = allocSmallInt(85); + o->f->setTop(o, (baset *)oInt); + finishO(oInt); + B = o->f->serial(o); + s = sToString((smallt *) B->B); + ck_assert_str_eq(s, "[0x07,0x55,0x00,0x00,0x00,0x00,0x00,0x00,0x00]"); + free(s); + o->f->deserial(o, B); + s = toStringO(o); + ck_assert_str_eq(s, "85"); + free(s); + terminateO(B); + terminateO(o); + // string + initiateAllocateSmallJson(&o); + smallStringt *st = allocSmallString("sheepy"); + o->f->setTop(o, (baset *)st); + finishO(st); + B = o->f->serial(o); + s = sToString((smallt *) B->B); + ck_assert_str_eq(s, "[0x08,0x73,0x68,0x65,0x65,0x70,0x79,0x00]"); + free(s); + o->f->deserial(o, B); + s = toStringO(o); + ck_assert_str_eq(s, "sheepy"); + free(s); + terminateO(B); + terminateO(o); + // dict + initiateAllocateSmallJson(&o); + smallDictt *sDD = allocSmallDict(); + o->f->setTop(o, (baset *)sDD); + finishO(sDD); + B = o->f->serial(o); + s = sToString((smallt *) B->B); + ck_assert_str_eq(s, "[0x04,0x00,0x00,0x00,0x00]"); + free(s); + o->f->deserial(o, B); + s = toStringO(o); + ck_assert_str_eq(s, "{}"); + free(s); + terminateO(B); + terminateO(o); + // array + initiateAllocateSmallJson(&o); + smallArrayt *sAA = allocSmallArray(); + o->f->setTop(o, (baset *)sAA); + finishO(sAA); + B = o->f->serial(o); + s = sToString((smallt *) B->B); + ck_assert_str_eq(s, "[0x0a,0x00,0x00,0x00,0x00]"); + free(s); + o->f->deserial(o, B); + s = toStringO(o); + ck_assert_str_eq(s, "[]"); + free(s); + terminateO(B); + terminateO(o); + // deserial non json object + initiateAllocateSmallJson(&o); + initiateAllocateSmallBytes(&B); + sContainert *c = allocSContainer(NULL); + B->B = sSerial((smallt *) c); + sFree((smallt *) c); + o->f->deserial(o, B); + ck_assert_uint_eq(o->topIsA, 0/*=JSON_IS_EMPTY*/); + terminateO(B); + terminateO(o); + // deserial empty sBytest + initiateAllocateSmallJson(&o); + initiateAllocateSmallBytes(&B); + o->f->deserial(o, B); + ck_assert_uint_eq(o->topIsA, 0/*=JSON_IS_EMPTY*/); + terminateO(B); + terminateO(o); + // NULL object + initiateAllocateSmallJson(&o); + o->f->setTypeUndefined(o); + sFree((smallt *) o->topU); + o->topU = NULL; + ck_assert_ptr_eq(o->f->serial(o),NULL); + o->f->deserial(o, NULL); + terminateO(o); + // free local object + obj.f->free(&obj); + ck_assert_str_eq(obj.type, "smallJson"); + // free object + obj2->f->terminate(&obj2); + ck_assert_ptr_eq(obj2, NULL); + initiateAllocateSmallJson(&o); + terminateO(o); + ck_assert_ptr_eq(o, NULL); + // undefined + initiateAllocateSmallJson(&o); + o->f->setTypeUndefined(o); + terminateO(o); + ck_assert_ptr_eq(o, NULL); + // bool + initiateAllocateSmallJson(&o); + o->f->setTypeBool(o); + terminateO(o); + ck_assert_ptr_eq(o, NULL); + // double + initiateAllocateSmallJson(&o); + o->f->setTypeDouble(o); + terminateO(o); + ck_assert_ptr_eq(o, NULL); + // int + initiateAllocateSmallJson(&o); + o->f->setTypeInt(o); + terminateO(o); + ck_assert_ptr_eq(o, NULL); + // string + initiateAllocateSmallJson(&o); + o->f->setTypeString(o); + terminateO(o); + ck_assert_ptr_eq(o, NULL); + // dict + initiateAllocateSmallJson(&o); + o->f->setTypeDict(o); + terminateO(o); + ck_assert_ptr_eq(o, NULL); + // array + initiateAllocateSmallJson(&o); + o->f->setTypeArray(o); + terminateO(o); + ck_assert_ptr_eq(o, NULL); + +} + + +void cSmallArrayT(CuTest *tc) { + + // local object + createSmallArray(obj); + ck_assert_str_eq(obj.type, "smallArray"); + // object + createAllocateSmallArray(obj2); + ck_assert_str_eq(obj2->type, "smallArray"); + // toString + char *s = obj2->f->toString(obj2); + ck_assert_str_eq(s, "[]"); + free(s); + createAllocateUndefined(oU); + obj2->f->push(obj2, (baset *)oU); + finishO(oU); + createAllocateSmallInt(oInt); + oInt->f->set(oInt, 123); + obj2->f->push(obj2, (baset *)oInt); + finishO(oInt); + createAllocateSmallString(oStr); + oStr->f->set(oStr, "sheepy"); + obj2->f->push(obj2, (baset *)oStr); + finishO(oStr); + s = obj2->f->toString(obj2); + ck_assert_str_eq(s, "[null,123,\"sheepy\"]"); + free(s); + // delete an element + smallArrayt *o2; + o2 = obj2->f->duplicate(obj2); + o2->f->delElem(o2, 0); + s = o2->f->toString(o2); + ck_assert_str_eq(s, "[123,\"sheepy\"]"); + free(s); + terminateO(o2); + // duplicate + smallArrayt *o; + o = obj2->f->duplicate(obj2); + undefinedt *u; + u = (undefinedt *) o->f->getAt(o, 0); + ck_assert(isOType(u, "undefined")); + terminateO(u); + smallIntt *in; + in = (smallIntt *) o->f->getAt(o, 1); + ck_assert(in->value->value == 123); + smashO(in); + smallStringt *st; + st = (smallStringt *) o->f->getAt(o, 2); + ck_assert(strEq(st->f->get(st), "sheepy")); + smashO(st); + terminateO(o); + // delete an element + o2 = obj2->f->duplicate(obj2); + o2->f->delElem(o2, 0); + o = o2->f->duplicate(o2); + in = (smallIntt *) o->f->getAt(o, 0); + ck_assert(in->value->value == 123); + smashO(in); + st = (smallStringt *) o->f->getAt(o, 1); + ck_assert(strEq(st->f->get(st), "sheepy")); + smashO(st); + terminateO(o); + terminateO(o2); + // fromArray + initiateAllocateSmallArray(&o); + char *array[] = {"1", "22", "333"}; + char *arrayNULL[] = {"1", NULL, "333"}; + // copy array to list + o->f->fromArray(o, (void *)array, 3); + ck_assert_uint_eq(o->f->len(o),3); + smallStringt *strFrom; + strFrom = (smallStringt*) o->f->getAt(o,0); + ck_assert_str_eq(strFrom->f->get(strFrom), "1"); + smashO(strFrom); + strFrom = (smallStringt*) o->f->getAt(o,1); + ck_assert_str_eq(strFrom->f->get(strFrom), "22"); + smashO(strFrom); + strFrom = (smallStringt*) o->f->getAt(o,2); + ck_assert_str_eq(strFrom->f->get(strFrom), "333"); + smashO(strFrom); + // array with NULL inside + o->f->fromArray(o, (void *)arrayNULL, 3); + ck_assert_uint_eq(o->f->len(o),3); + strFrom = (smallStringt*) o->f->getAt(o,0); + ck_assert_str_eq(strFrom->f->get(strFrom), "1"); + smashO(strFrom); + strFrom = (smallStringt*) o->f->getAt(o,1); + ck_assert_ptr_eq(strFrom, NULL); + strFrom = (smallStringt*) o->f->getAt(o,2); + ck_assert_str_eq(strFrom->f->get(strFrom), "333"); + smashO(strFrom); + // char** list + char **shpList = listCreateS("lib", "sheepy"); + o->f->fromArray(o, shpList, 0); + ck_assert_uint_eq(o->f->len(o),2); + listFreeS(shpList); + // NULL pointer to list - list not changed + o->f->fromArray(o, (void *)arrayNULL, 3); + o->f->fromArray(o, NULL, 3); + ck_assert_uint_eq(o->f->len(o),3); + strFrom = (smallStringt*) o->f->getAt(o,0); + ck_assert_str_eq(strFrom->f->get(strFrom), "1"); + smashO(strFrom); + strFrom = (smallStringt*) o->f->getAt(o,1); + ck_assert_ptr_eq(strFrom, NULL); + strFrom = (smallStringt*) o->f->getAt(o,2); + ck_assert_str_eq(strFrom->f->get(strFrom), "333"); + smashO(strFrom); + terminateO(o); + // push + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 654); + o->f->push(o, (baset *)in); + finishO(in); + in = (smallIntt *) o->f->getAt(o, 3); + ck_assert_uint_eq(o->f->len(o), 4); + ck_assert_uint_eq(in->value->value, 654); + smashO(in); + // NULL + o->f->push(o, NULL); + ck_assert_uint_eq(o->f->len(o), 4); + terminateO(o); + // pop + o = obj2->f->duplicate(obj2); + ck_assert_uint_eq(o->f->len(o), 3); + st = (smallStringt *) o->f->pop(o); + ck_assert_uint_eq(o->f->len(o), 2); + ck_assert_str_eq(st->f->get(st), "sheepy"); + terminateO(st); + in = (smallIntt *) o->f->pop(o); + ck_assert_uint_eq(in->value->value, 123); + terminateO(in); + u = (undefinedt *) o->f->pop(o); + ck_assert(isOType(u, "undefined")); + terminateO(u); + // empty list + u = (undefinedt *) o->f->pop(o); + ck_assert_ptr_eq(u,NULL); + // after initialize + o->f->free(o); + ck_assert_uint_eq(o->f->len(o), 0); + u = (undefinedt *) o->f->pop(o); + ck_assert_uint_eq(o->f->len(o), 0); + ck_assert_ptr_eq(u,NULL); + terminateO(o); + // append + o = obj2->f->duplicate(obj2); + o2 = obj2->f->duplicate(obj2); + in = (smallIntt *) o2->f->getAt(o2, 1); + in->value->value = 789; + o2->f->setAt(o2, 1, (baset *)in); + finishO(in); + o->f->append(o, o2); + s = toStringO(o); + ck_assert_str_eq(s, "[null,123,\"sheepy\",null,789,\"sheepy\"]"); + free(s); + // same list + o->f->append(o, o); + s = toStringO(o); + ck_assert_str_eq(s, "[null,123,\"sheepy\",null,789,\"sheepy\"]"); + free(s); + o->f->free(o); + o2->f->smash(&o2); + // empty list + list + o2 = obj2->f->duplicate(obj2); + in = (smallIntt *) o2->f->getAt(o2, 1); + in->value->value = 789; + o2->f->setAt(o2, 1, (baset *)in); + finishO(in); + o->f->append(o, o2); + s = toStringO(o); + ck_assert_str_eq(s, "[null,789,\"sheepy\"]"); + free(s); + // list + empty list + o2->f->dispose(o2); + o->f->append(o, o2); + s = toStringO(o); + ck_assert_str_eq(s, "[null,789,\"sheepy\"]"); + free(s); + // empty list + empty list + o->f->free(o); + o->f->append(o, o2); + s = toStringO(o); + ck_assert_str_eq(s, "[]"); + free(s); + terminateO(o2); + // NULL list + o->f->append(o, NULL); + s = toStringO(o); + ck_assert_str_eq(s, "[]"); + free(s); + terminateO(o); + // slice + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->slice(o,1,-1); + s = toStringO(o); + ck_assert_str_eq(s, "[123,\"sheepy\"]"); + free(s); + terminateO(o); + // start outside + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->slice(o,20,-1); + s = toStringO(o); + ck_assert_str_eq(s, "[]"); + free(s); + terminateO(o); + // start negative and outside + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->slice(o,-20,1); + s = toStringO(o); + ck_assert_str_eq(s, "[null]"); + free(s); + terminateO(o); + // end outside + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->slice(o,2,40); + s = toStringO(o); + ck_assert_str_eq(s, "[\"sheepy\",5345]"); + free(s); + terminateO(o); + // end negative and outside + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->slice(o,2,-40); + s = toStringO(o); + ck_assert_str_eq(s, "[]"); + free(s); + terminateO(o); + // end before start + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->slice(o,3,2); + s = toStringO(o); + ck_assert_str_eq(s, "[]"); + free(s); + terminateO(o); + // negative start last element + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->slice(o,-1,0); + s = toStringO(o); + ck_assert_str_eq(s, "[5345]"); + free(s); + terminateO(o); + // start = end + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->slice(o,1,1); + s = toStringO(o); + ck_assert_str_eq(s, "[]"); + free(s); + terminateO(o); + // empty list + initiateAllocateSmallArray(&o); + o->f->slice(o,0,0); + s = toStringO(o); + ck_assert_str_eq(s, "[]"); + free(s); + terminateO(o); + // insert + o = obj2->f->duplicate(obj2); + o2 = obj2->f->duplicate(obj2); + in = (smallIntt *) o2->f->getAt(o2, 1); + in->value->value = 789; + o2->f->setAt(o2, 1, (baset *)in); + finishO(in); + o->f->insert(o, 0, o2); + s = toStringO(o); + ck_assert_str_eq(s, "[null,789,\"sheepy\",null,123,\"sheepy\"]"); + free(s); + terminateO(o); + o2->f->smash(&o2); + // negative index + o = obj2->f->duplicate(obj2); + o2 = obj2->f->duplicate(obj2); + in = (smallIntt *) o2->f->getAt(o2, 1); + in->value->value = 789; + o2->f->setAt(o2, 1, (baset *)in); + finishO(in); + o->f->insert(o, -1, o2); + s = toStringO(o); + ck_assert_str_eq(s, "[null,123,\"sheepy\",null,789,\"sheepy\"]"); + free(s); + terminateO(o); + o2->f->smash(&o2); + // edge + o = obj2->f->duplicate(obj2); + o2 = obj2->f->duplicate(obj2); + in = (smallIntt *) o2->f->getAt(o2, 1); + in->value->value = 789; + o2->f->setAt(o2, 1, (baset *)in); + finishO(in); + o->f->insert(o, 3, o2); + s = toStringO(o); + ck_assert_str_eq(s, "[null,123,\"sheepy\",null,789,\"sheepy\"]"); + free(s); + terminateO(o); + o2->f->smash(&o2); + // outside + o = obj2->f->duplicate(obj2); + o2 = obj2->f->duplicate(obj2); + in = (smallIntt *) o2->f->getAt(o2, 1); + in->value->value = 789; + o2->f->setAt(o2, 1, (baset *)in); + finishO(in); + o->f->insert(o, 4, o2); + s = toStringO(o); + ck_assert_str_eq(s, "[null,123,\"sheepy\"]"); + free(s); + o->f->insert(o, -5, o2); + s = toStringO(o); + ck_assert_str_eq(s, "[null,123,\"sheepy\"]"); + free(s); + terminateO(o); + terminateO(o2); + // negative index in a one element list + o = obj2->f->duplicate(obj2); + o2 = obj2->f->duplicate(obj2); + in = (smallIntt *) o2->f->getAt(o2, 1); + in->value->value = 789; + o2->f->setAt(o2, 1, (baset *)in); + finishO(in); + o->f->delElem(o, 1); + o->f->delElem(o, 2); + o->f->trim(o); + o->f->insert(o, -1, o2); + s = toStringO(o); + ck_assert_str_eq(s, "[null,null,789,\"sheepy\"]"); + free(s); + terminateO(o); + o2->f->smash(&o2); + // empty list + initiateAllocateSmallArray(&o); + o2 = obj2->f->duplicate(obj2); + in = (smallIntt *) o2->f->getAt(o2, 1); + in->value->value = 789; + o2->f->setAt(o2, 1, (baset *)in); + finishO(in); + o->f->insert(o, 0, o2); + s = toStringO(o); + ck_assert_str_eq(s, "[null,789,\"sheepy\"]"); + free(s); + terminateO(o); + o2->f->dispose(o2); + // empty insert list + o = obj2->f->duplicate(obj2); + o->f->insert(o, 0, o2); + s = toStringO(o); + ck_assert_str_eq(s, "[null,123,\"sheepy\"]"); + free(s); + terminateO(o); + o2->f->smash(&o2); + //NULL insert + o = obj2->f->duplicate(obj2); + o->f->insert(o, 0, NULL); + s = toStringO(o); + ck_assert_str_eq(s, "[null,123,\"sheepy\"]"); + free(s); + terminateO(o); + // del + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->del(o,1,-1); + s = toStringO(o); + ck_assert_str_eq(s, "[null,5345]"); + free(s); + terminateO(o); + // start outside + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->del(o,20,-1); + s = toStringO(o); + ck_assert_str_eq(s, "[null,123,\"sheepy\",5345]"); + free(s); + terminateO(o); + // start negative and outside + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->del(o,-20,1); + s = toStringO(o); + ck_assert_str_eq(s, "[123,\"sheepy\",5345]"); + free(s); + terminateO(o); + // end outside + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->del(o,2,40); + s = toStringO(o); + ck_assert_str_eq(s, "[null,123]"); + free(s); + terminateO(o); + // end negative and outside + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->del(o,2,-40); + s = toStringO(o); + ck_assert_str_eq(s, "[null,123,\"sheepy\",5345]"); + free(s); + terminateO(o); + // end before start + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->del(o,3,2); + s = toStringO(o); + ck_assert_str_eq(s, "[null,123,\"sheepy\",5345]"); + free(s); + terminateO(o); + // negative start last element + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->del(o,-1,0); + s = toStringO(o); + ck_assert_str_eq(s, "[null,123,\"sheepy\"]"); + free(s); + terminateO(o); + // start = end + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + in->f->set(in, 5345); + o->f->push(o, (baset *) in); + finishO(in); + o->f->del(o,1,1); + s = toStringO(o); + ck_assert_str_eq(s, "[null,123,\"sheepy\",5345]"); + free(s); + terminateO(o); + // empty list + initiateAllocateSmallArray(&o); + o->f->del(o,0,0); + s = toStringO(o); + ck_assert_str_eq(s, "[]"); + free(s); + terminateO(o); + // len + ck_assert_uint_eq(obj2->f->len(obj2), 3); + // trim + o = obj2->f->duplicate(obj2); + ck_assert_uint_eq(o->f->len(o), 3); + st = (smallStringt *) o->f->pop(o); + terminateO(st); + o->f->delElem(o, 0); + o->f->trim(o); + ck_assert_uint_eq(o->f->len(o), 1); + s = toStringO(o); + ck_assert_str_eq(s, "[123]"); + free(s); + terminateO(o); + // getAt + o = obj2->f->duplicate(obj2); + u = (undefinedt *) o->f->getAt(o, 0); + ck_assert_str_eq(u->type, "undefined"); + terminateO(u); + st = (smallStringt *) o->f->getAt(o, -1); + ck_assert_str_eq(st->type, "smallString"); + smashO(st); + // outside + u = (undefinedt *) o->f->getAt(o, 4); + ck_assert_ptr_eq(u, NULL); + u = (undefinedt *) o->f->getAt(o, -4); + ck_assert_ptr_eq(u, NULL); + terminateO(o); + // empty + initiateAllocateSmallArray(&o); + u = (undefinedt *) o->f->getAt(o, 0); + ck_assert_ptr_eq(u, NULL); + terminateO(o); + // setAt + o = obj2->f->duplicate(obj2); + initiateAllocateSmallInt(&in); + o->f->setAt(o, 0, (baset *) in); + finishO(in); + s = toStringO(o); + ck_assert_str_eq(s, "[0,123,\"sheepy\"]"); + free(s); + initiateAllocateSmallInt(&in); + o->f->setAt(o, -1, (baset *) in); + finishO(in); + s = toStringO(o); + ck_assert_str_eq(s, "[0,123,0]"); + free(s); + // outside + o->f->setAt(o, 4, (baset *) in); + s = toStringO(o); + ck_assert_str_eq(s, "[0,123,0]"); + free(s); + o->f->setAt(o, -4, (baset *) in); + s = toStringO(o); + ck_assert_str_eq(s, "[0,123,0]"); + free(s); + terminateO(o); + // empty + o = obj2->f->duplicate(obj2); + o->f->empty(o); + ck_assert(o->f->isEmpty(o)); + terminateO(o); + // isEmpty + o = obj2->f->duplicate(obj2); + ck_assert(!o->f->isEmpty(o)); + terminateO(o); + initiateAllocateSmallArray(&o); + ck_assert(o->f->isEmpty(o)); + terminateO(o); + // typeString type typeStrings types + initiateAllocateSmallArray(&o2); + o = allocSmallArray(); + oU = allocUndefined(); + o->f->push(o, (baset *)oU); + finishO(oU); + oInt = allocSmallInt(123); + o->f->push(o, (baset *)oInt); + finishO(oInt); + oStr = allocSmallString("sheepy"); + o->f->push(o, (baset *)oStr); + finishO(oStr); + o->f->push(o, NULL); + // typeString + s = (char *)o->f->typeString(o, 0); + ck_assert_str_eq(s, "undefined"); + // type + char c = o->f->type(o, 2); + ck_assert_uint_eq(c, STRING); + // negative index + c = o->f->type(o, -2); + ck_assert_uint_eq(c, INT); + // outside + ck_assert(!o->f->type(o, 10)); + ck_assert(!o->f->type(o, -14)); + // NULL element + c = o->f->type(o, 0); + ck_assert_uint_eq(c, UNDEFINED); + // empty object + ck_assert(!o2->f->type(o2, 0)); + // typeStrings + char **l = o->f->typeStrings(o); + s = join(l, ","); + ck_assert_str_eq(s, "undefined,int,string"); + free(s); + free(l); + // empty object + ck_assert_ptr_eq(o2->f->typeStrings(o2), NULL); + // types + smallBytest *B = o->f->types(o); + s = sToStringTiny((smallt *)B->B); + ck_assert_str_eq(s, "[0x01,0x07,0x08]"); + free(s); + // empty object + ck_assert_ptr_eq(o2->f->types(o2), NULL); + terminateO(B); + terminateO(o); + terminateO(o2); + // free local object + obj.f->free(&obj); + ck_assert_str_eq(obj.type, "smallArray"); + // free object + obj2->f->terminate(&obj2); + ck_assert_ptr_eq(obj2, NULL); + // init NULL + initiateAllocateSmallArray(NULL); + +} + + +void cUndefinedT(CuTest *tc) { + + // local object + createUndefined(obj); + ck_assert_str_eq(obj.type, "undefined"); + // object + createAllocateUndefined(obj2); + ck_assert_str_eq(obj2->type, "undefined"); + // toString + char *s = obj2->f->toString(obj2); + ck_assert_str_eq(s, "null"); + free(s); + // duplicate + undefinedt *o; + o = obj2->f->duplicate(obj2); + terminateO(o); + // free local object + obj.f->free(&obj); + ck_assert_str_eq(obj.type, "undefined"); + // free object + obj2->f->terminate(&obj2); + ck_assert_ptr_eq(obj2, NULL); + +} + + + +void cSmallBytesT(CuTest *tc) { + + // local object + createSmallBytes(obj); + ck_assert_str_eq(obj.type, "smallBytes"); + // object + createAllocateSmallBytes(obj2); + ck_assert_str_eq(obj2->type, "smallBytes"); + // alloc - pushBuffer + smallBytest *obj3 = allocSmallBytes(NULL, 0); + terminateO(obj3); + // toString + char *s = obj2->f->toString(obj2); + ck_assert_str_eq(s, "[]"); + free(s); + // duplicate + obj2->B = allocSBytes(); + sBytesPush(&(obj2->B), 2); + obj3 = duplicateO(obj2); + ck_assert_uint_eq(obj3->B->data, 2); + terminateO(obj3); + // get + obj3 = duplicateO(obj2); + char *r = obj3->f->get(obj3); + ck_assert_uint_eq(*r, 2); + terminateO(obj3); + // push + obj3 = duplicateO(obj2); + obj3->f->push(obj3, 4); + r = obj3->f->get(obj3); + ck_assert_uint_eq(r[1], 4); + terminateO(obj3); + // getAt + obj3 = duplicateO(obj2); + char c = obj3->f->getAt(obj3,0); + ck_assert_uint_eq(c, 2); + c = obj3->f->getAt(obj3,1); + ck_assert_uint_eq(c, 0); + terminateO(obj3); + // NULL + initiateAllocateSmallBytes(&obj3); + c = obj3->f->getAt(obj3,0); + ck_assert_uint_eq(c, 0); + terminateO(obj3); + // free local object + obj.f->free(&obj); + ck_assert_str_eq(obj.type, "smallBytes"); + // free object + obj2->f->terminate(&obj2); + ck_assert_ptr_eq(obj2, NULL); + +} + + +void putsOT(CuTest *tc) { + + createAllocateSmallArray(l); + + // object + putsO(l); + // NULL + putsO(NULL); + + terminateO(l); + +} + + +void execOT(CuTest *tc) { + + createAllocateSmallArray(l); + + // command + execO("ls libsheepyObjectTest.c", l, NULL); + ck_assert_uint_eq(l->f->len(l),1); + ck_assert_str_eq(l->f->getAtS(l, 0), "libsheepyObjectTest.c"); + freeO(l); + + // invalid command + execO("randomComand", l, NULL); + ck_assert_uint_eq(l->f->len(l),0); + terminateO(l); + // NULL command + ck_assert_int_eq(execO(NULL, NULL, NULL), 0); + +} + + +void walkDirOT(CuTest *tc) { + + smallArrayt *l; + + // existing directory + l = walkDirO("../dirTest.null"); + ck_assert_uint_eq(l->f->len(l),3); + ck_assert_str_eq(l->f->getAtS(l, 0), "../dirTest.null/one"); + ck_assert_str_eq(l->f->getAtS(l, 1), "../dirTest.null/two/four"); + ck_assert_str_eq(l->f->getAtS(l, 2), "../dirTest.null/two/three"); + terminateO(l); + // empty path + ck_assert_ptr_eq(walkDirO(""), NULL); + // non existing directory + l = walkDirO("nonExisting.null"); + ck_assert(l->f->isEmpty(l)); + terminateO(l); + // NULL path + ck_assert_ptr_eq(walkDirO(NULL), NULL); + +} + + +void expandHomeOT(CuTest *tc) { + + // no ~/ + createAllocateSmallString(v); + v->f->set(v, "sheepy"); + expandHomeO(v); + ck_assert(v->f->equalS(v, "sheepy")); + terminateO(v); + // NULL var + expandHomeO(NULL); + +} + + +void chDirOT(CuTest *tc) { + + // change directory + smallStringt *c; + c = getCwdO(); + createAllocateSmallString(v); + v->f->set(v, "../dirTest.null"); + ck_assert(chDirO(v)); + char *s = getCwd(); + ck_assert((size_t)findS(s, "dirTest.null")); + chDirO(c); + free(s); + terminateO(c); + // non existing dir + createAllocateSmallString(n); + n->f->set(n, "RandomNonExistingDir"); + ck_assert(!chDirO(n)); + // NULL path + ck_assert(!chDirO(NULL)); + terminateO(v); + terminateO(n); + +} + + +void fileExistsOT(CuTest *tc) { + + createAllocateSmallArray(sA); + char **l = listCreateS("../libsheepyTest.c", "wefwepfk34.c", "../../src", ""); + sA->f->fromArrayNFree(sA, l, 0); + // detect existing file + smallStringt *S = sA->f->getAtSmallString(sA, 0); + ck_assert(fileExistsO(S)); + finishO(S); + // non existing file + S = sA->f->getAtSmallString(sA, 1); + ck_assert(!fileExistsO(S)); + finishO(S); + // folder + S = sA->f->getAtSmallString(sA, 2); + ck_assert(fileExistsO(S)); + finishO(S); + // empty path + S = sA->f->getAtSmallString(sA, 3); + ck_assert(!fileExistsO(S)); + finishO(S); + // NULL path + ck_assert(!fileExistsO(NULL)); + terminateO(sA); + +} + + +void fileChmodOT(CuTest *tc) { + + // existing file + createAllocateSmallString(v); + v->f->set(v, "../chmodTest.null"); + ck_assert(fileChmodO(v, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)); + ck_assert(fileChmodO(v, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)); + // non existing file + createAllocateSmallString(n); + n->f->set(n, "qweqwe_null"); + ck_assert(!fileChmodO(n, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)); + // empty path + createAllocateSmallString(e); + e->f->set(e, ""); + ck_assert(!fileChmodO(e,0)); + // NULL path + ck_assert(!fileChmodO(NULL,0)); + terminateO(v); + terminateO(n); + terminateO(e); + +} + + +void fileSizeOT(CuTest *tc) { + + // existing file + createAllocateSmallString(s); + s->f->set(s, "../sizeTest.null"); + ck_assert_uint_eq(fileSizeO(s), 743); + // empty file + createAllocateSmallString(v); + v->f->set(v, "../chmodTest.null"); + ck_assert_uint_eq(fileSizeO(v), 0); + // non existing file + createAllocateSmallString(n); + n->f->set(n, "qweqwe_null"); + ck_assert_int_eq(fileSizeO(n), -1); + // empty path + createAllocateSmallString(e); + e->f->set(e, ""); + ck_assert_int_eq(fileSizeO(e), -1); + // NULL path + ck_assert_int_eq(fileSizeO(NULL), -1); + terminateO(s); + terminateO(v); + terminateO(n); + terminateO(e); + +} + + +void mkdirParentsOT(CuTest *tc) { + + // directory + rmAll("mkdirTest.null/null"); + createAllocateSmallString(s); + s->f->set(s, "mkdirTest.null/null"); + ck_assert_int_eq(mkdirParentsO(s),1); + // not allowed + createAllocateSmallString(v); + v->f->set(v, "/usr/null"); + ck_assert_int_eq(mkdirParentsO(v),0); + // empty path + createAllocateSmallString(e); + e->f->set(e, ""); + ck_assert_int_eq(mkdirParentsO(e),0); + // NULL path + ck_assert_int_eq(mkdirParentsO(NULL),0); + terminateO(s); + terminateO(e); + terminateO(v); + +} + + +void rmAllOT(CuTest *tc) { + + // directory + createAllocateSmallString(s); + s->f->set(s, "rmAllTest.null/null"); + mkdirParents("rmAllTest.null/null"); + ck_assert_int_eq(rmAllO(s),1); + // empty path + createAllocateSmallString(e); + e->f->set(e,""); + ck_assert_int_eq(rmAllO(e),0); + // too little permissions + createAllocateSmallString(v); + v->f->set(v,"/var/lock"); + ck_assert_int_eq(rmAllO(v),0); + // NULL path + ck_assert_int_eq(rmAllO(NULL),0); + terminateO(s); + terminateO(e); + terminateO(v); + + +} + + +void copyOT(CuTest *tc) { + + // file + createAllocateSmallString(s); + createAllocateSmallString(d); + s->f->set(s, "../chmodTest.null"); + d->f->set(d, "../copyTest.null"); + ck_assert_int_eq(copyO(s, d),1); + ck_assert(fileExists("../copyTest.null")); + // too little permissions + fileChmod("../copyTest.null", 1); + ck_assert_int_eq(copyO(d, d),0); + fileChmod("../copyTest.null", 777); + rmAll("../copyTest.null"); + // empty path + createAllocateSmallString(e); + e->f->set(e, ""); + ck_assert_int_eq(copyO(e, d),0); + ck_assert(!fileExists("copyTest.null")); + ck_assert_int_eq(copyO(s, e),0); + ck_assert(!fileExists("copyTest.null")); + // NULL path + ck_assert_int_eq(copyO(NULL, d),0); + ck_assert_int_eq(copyO(s, NULL),0); + ck_assert_int_eq(copyO(NULL, NULL),0); + terminateO(s); + terminateO(d); + terminateO(e); + +} + + +void randomSOT(CuTest *tc) { + + // get random string + smallStringt *s = randomSO(10); + ck_assert_ptr_ne(s, NULL); + terminateO(s); + // invalid length (0) + ck_assert_ptr_eq(randomSO(0), NULL); + + randomUrandomClose(); + +} + + +void randomAlphaNumSOT(CuTest *tc) { + + // get random string + smallStringt *s = randomAlphaNumSO(10); + ck_assert_ptr_ne(s, NULL); + terminateO(s); + // invalid length (0) + ck_assert_ptr_eq(randomAlphaNumSO(0), NULL); + + randomUrandomClose(); + +} + + +void readLineOT(CuTest *tc) { + + FILE *fp; + smallStringt *s; + + // file with data + fp = fopen("../textTest.null", "r"); + s = readLineO(fp); + fclose(fp); + ck_assert_str_eq(s->f->get(s), "LINE 1"); + terminateO(s); + // empty file or end of stream + fp = fopen("../chmodTest.null", "r"); + s = readLineO(fp); + fclose(fp); + ck_assert_str_eq(ssGet(s), ""); + terminateO(s); + // NULL stream + ck_assert_ptr_eq(readLineO(NULL), NULL); + + +} + + +void toSmalltT(CuTest *tc) { + + smallStringt *s; + smallIntt *i; + + // undefined + createAllocateUndefined(u); + sUndefinedt *su = (sUndefinedt *) toSmallt((baset *)u); + finishO(u); + ck_assert(isSType(su, UNDEFINED)); + sFree((smallt *) su); + // smallArray + createAllocateSmallArray(a); + initiateAllocateSmallString(&s); + s->f->set(s, "sheepy"); + a->f->push(a, (baset *) s); + finishO(s); + initiateAllocateSmallInt(&i); + i->f->set(i, 20); + a->f->push(a, (baset *) i); + finishO(i); + sArrayt *sa = (sArrayt *) toSmallt((baset *)a); + finishO(a); + ck_assert_uint_eq(sa->count, 2); + char *S = sToString((smallt *) sa); + ck_assert_str_eq(S, "[\"sheepy\",20]"); + free(S); + sFree((smallt *) sa); + // smallDict + createAllocateSmallDict(d); + initiateAllocateSmallString(&s); + s->f->set(s, "sheepy"); + d->f->set(d, "s", (baset *) s); + finishO(s); + initiateAllocateSmallInt(&i); + i->f->set(i, 20); + d->f->set(d, "i", (baset *) i); + finishO(i); + sDictt *sd = (sDictt *) toSmallt((baset *)d); + finishO(d); + ck_assert_uint_eq(sd->count, 2); + S = sToString((smallt *) sd); + ck_assert_str_eq(S, "{\"s\":\"sheepy\",\"i\":20}"); + free(S); + sFree((smallt *) sd); + // smallJson + createAllocateSmallJson(j); + smallt *so = toSmallt((baset *)j); + ck_assert_ptr_ne(so, NULL); + ck_assert_int_eq(so->type, CONTAINER); + ck_assert_ptr_eq(((sContainert*)so)->data, j); + sFree(so); // sFree does terminateO(j); because smallJson is stored in a container + // NULL + ck_assert_ptr_eq(toSmallt(NULL), NULL); + +} + + +void toBasetT(CuTest *tc) { + + // bool + sBoolt *sb = allocSBool(true); + smallBoolt *b = (smallBoolt *) toBaset((smallt *)sb); + ck_assert(b->value->value); + terminateO(b); + // container + sContainert *sc = allocSContainer(strdup("sheepy")); + smallContainert *c = (smallContainert *) toBaset((smallt *)sc); + ck_assert_str_eq(c->data->data, "sheepy"); + free(c->data->data); + terminateO(c); + // double + sDoublet *sD = allocSDouble(10); + smallDoublet *D = (smallDoublet *) toBaset((smallt *)sD); + ck_assert_uint_eq((uint)D->value->value, 10); + terminateO(D); + // int + sIntt *si = allocSInt(10); + smallIntt *i = (smallIntt *) toBaset((smallt *)si); + ck_assert_uint_eq(i->value->value, 10); + terminateO(i); + // string + sStringt *ss = allocSStringTiny("sheepy"); + smallStringt *s = (smallStringt *) toBaset((smallt *)ss); + ck_assert_str_eq(sStringGetTiny(ss), "sheepy"); + terminateO(s); + // undefined + sUndefinedt *su = allocSUndefined(); + undefinedt *u = (undefinedt *) toBaset((smallt *)su); + ck_assert(isOType(u, "undefined")); + sFree((smallt *) su); + terminateO(u); + // smallArray + sArrayt *sa = allocSArray(); + ss = allocSStringTiny("sheepy"); + sArrayPushTiny(&sa, (smallt *) ss); + si = allocSInt(20); + sArrayPushTiny(&sa, (smallt *) si); + smallArrayt *a = (smallArrayt *) toBaset((smallt *)sa); + ck_assert_uint_eq(a->a->count, 2); + char *S = toStringO(a); + ck_assert_str_eq(S, "[\"sheepy\",20]"); + free(S); + terminateO(a); + // smallDict + sDictt *sd = allocSDict(); + ss = allocSStringTiny("sheepy"); + sDictPushTiny(&sd, "s", (smallt *) ss); + si = allocSInt(20); + sDictPushTiny(&sd, "i", (smallt *) si); + smallDictt *d = (smallDictt *) toBaset((smallt *)sd); + ck_assert_uint_eq(d->d->count, 2); + S = toStringO(d); + ck_assert_str_eq(S, "{\"s\":\"sheepy\",\"i\":20}"); + free(S); + terminateO(d); + // NULL + ck_assert_ptr_eq(toBaset(NULL), NULL); + +} + + + + +int main(int n, char**v) { + // disable btrace to make the test run faster + btraceDisable(); + CuString *output = CuStringNew(); + CuSuite *suite = CuSuiteNew(); + + SUITE_ADD_TEST(suite, cSmallDictT); + SUITE_ADD_TEST(suite, cSmallJsonT); + SUITE_ADD_TEST(suite, cSmallArrayT); + SUITE_ADD_TEST(suite, cUndefinedT); + SUITE_ADD_TEST(suite, cSmallBytesT); + SUITE_ADD_TEST(suite, putsOT); + SUITE_ADD_TEST(suite, execOT); + SUITE_ADD_TEST(suite, walkDirOT); + SUITE_ADD_TEST(suite, expandHomeOT); + SUITE_ADD_TEST(suite, chDirOT); + SUITE_ADD_TEST(suite, fileExistsOT); + SUITE_ADD_TEST(suite, fileChmodOT); + SUITE_ADD_TEST(suite, fileSizeOT); + SUITE_ADD_TEST(suite, mkdirParentsOT); + SUITE_ADD_TEST(suite, rmAllOT); + SUITE_ADD_TEST(suite, copyOT); + SUITE_ADD_TEST(suite, randomSOT); + SUITE_ADD_TEST(suite, randomAlphaNumSOT); + SUITE_ADD_TEST(suite, readLineOT); + SUITE_ADD_TEST(suite, toSmalltT); + SUITE_ADD_TEST(suite, toBasetT); + + + CuSuiteRun(suite); + CuSuiteDetails(suite, output); + printf ("%s\n", output->buffer); + return suite->failCount; +} diff --git a/src/json/runCuTest.sh b/src/json/runCuTest.sh @@ -0,0 +1,2 @@ +gcc -mrdrnd -g3 -std=gnu11 -o libsheepyObjectCuTest libsheepyObjectCuTest.c CuTest/CuTest.c ../libsheepySmall.c libsheepyObject.c libsheepyCSmallJson.c libsheepyCUndefined.c libsheepyCSmallBytes.c libsheepyCSmallDict.c libsheepyCSmallArray.c libsheepyCSmallBool.c libsheepyCSmallContainer.c libsheepyCSmallDouble.c libsheepyCSmallInt.c libsheepyCSmallString.c ../../release/libsheepy.c laxjson.c ymlParser.c ymlApi.c ymlScanner.c ymlReader.c ../tpool.c -mrdrnd -Wall -Wextra -pthread -rdynamic -fprofile-arcs -ftest-coverage +./libsheepyObjectCuTest diff --git a/src/libsheepySmallCuTest.c b/src/libsheepySmallCuTest.c @@ -0,0 +1,1744 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "CuTest/CuTest.h" + +#define ck_assert_str_eq(a,b) CuAssertStrEquals(tc, b, a) +#define ck_assert_str_ne(a,b) CuAssertStrNotEquals(tc, b, a) +#define ck_assert_ptr_eq(a,b) CuAssertPtrEquals(tc, b, a) +#define ck_assert_ptr_ne(a,b) CuAssertPtrNotEquals(tc, b, a) +#define ck_assert_uint_eq(a,b) CuAssertUintEquals(tc, b, a) +#define ck_assert_uint_ne(a,b) CuAssertUintNotEquals(tc, b, a) +#define ck_assert_int_eq(a,b) CuAssertIntEquals(tc, b, a) +#define ck_assert_int_ne(a,b) CuAssertIntNotEquals(tc, b, a) +#define ck_assert(a) CuAssertTrue(tc, a) + + +#include "libsheepySmall.h" + +void isSTypeFT(CuTest *tc) { + + sBoolt *b; + b = allocSBool(false); + ck_assert(isSTypeF((smallt *)b, BOOL)); + free(b); + // NULL + ck_assert(!isSTypeF(NULL, UNDEFINED)); + +} + +void sSizeT(CuTest *tc) { + + sBoolt *b; + b = allocSBool(false); + ck_assert_uint_eq(sSizeTiny((smallt *)b), sizeof(sBoolt)); + free(b); + + sContainert *c; + c = allocSContainer(strdup("sheepy")); + ck_assert_uint_eq(sSizeTiny((smallt *)c), sizeof(sContainert)); + free(c->data); + free(c); + + sDictt *d; + d = allocSDict(); + ck_assert_uint_eq(sSizeTiny((smallt *)d), sizeof(sDictt)); + // with elements + b = allocSBool(false); + sDictPushTiny(&d, "a", (smallt *) b); + ck_assert_uint_eq(sSizeTiny((smallt *)d), sizeof(sDictt) + sizeof(sDictElemt *)*(d->count-1)); + sDictFreeTiny(d); + + sDoublet *D; + D = allocSDouble(10); + ck_assert_uint_eq(sSizeTiny((smallt *)D), sizeof(sDoublet)); + free(D); + + sIntt *i; + i = allocSInt(10); + ck_assert_uint_eq(sSizeTiny((smallt *)i), sizeof(sIntt)); + free(i); + + sStringt *s; + s = allocSStringTiny(""); + ck_assert_uint_eq(sSizeTiny((smallt *)s), sizeof(sStringt)); + free(s); + // string + s = allocSStringTiny("sheepy"); + ck_assert_uint_eq(sSizeTiny((smallt *)s), sizeof(sStringt) + strlen("sheepy")); + free(s); + + sArrayt *a; + a = allocSArray(); + ck_assert_uint_eq(sSizeTiny((smallt *)a), sizeof(sArrayt)); + b = allocSBool(false); + sArrayPushTiny(&a, (smallt *) b); + D = allocSDouble(10); + sArrayPushTiny(&a, (smallt *) D); + s = allocSStringTiny("sheepy"); + sArrayPushTiny(&a, (smallt *) s); + ck_assert_uint_eq(sSizeTiny((smallt *)a), sizeof(sArrayt) + sizeof(smallt *)*(a->count-1)); + sArrayFreeTiny(a); + + sUndefinedt *u; + u = allocSUndefined(); + ck_assert_uint_eq(sSizeTiny((smallt *)u), sizeof(sUndefinedt)); + free(u); + + sBytest *B; + B = allocSBytes(); + ck_assert_uint_eq(sSizeTiny((smallt *)B), sizeof(sBytest)); + sBytesPush(&B, 1); + sBytesPush(&B, 2); + sBytesPush(&B, 3); + ck_assert_uint_eq(sSizeTiny((smallt *)B), sizeof(sBytest) + sizeof(char) * (B->count-1)); + free(B); + + // non existing object type - size 0 + sUndefinedt *NIL; + NIL = allocSUndefined(); + NIL->type += 100; + ck_assert_uint_eq(sSizeTiny((smallt *)NIL), 0); + free(NIL); + +} + + + +void allocSBoolT(CuTest *tc) { + + sBoolt *o; + o = allocSBool(false); + ck_assert_uint_eq(o->type, BOOL); + ck_assert(!o->value); + free(o); + +} + + +void allocSContainerT(CuTest *tc) { + + sContainert *o; + o = allocSContainer(strdup("sheepy")); + ck_assert_uint_eq(o->type, CONTAINER); + ck_assert_str_eq(o->data, "sheepy"); + free(o->data); + free(o); + +} + + +void allocSDictT(CuTest *tc) { + + sDictt *o; + o = allocSDict(); + ck_assert_uint_eq(o->type, DICT); + ck_assert_uint_eq(o->count, 0); + free(o); + +} + + +void allocSDoubleT(CuTest *tc) { + + sDoublet *o; + o = allocSDouble(1.5); + ck_assert_uint_eq(o->type, DOUBLE); + // TODO use ck_assert_float_eq when available + ck_assert_uint_eq(o->value*2, 3); + free(o); + +} + + +void allocSIntT(CuTest *tc) { + + sIntt *o; + o = allocSInt(1); + ck_assert_uint_eq(o->type, INT); + ck_assert_uint_eq(o->value, 1); + free(o); + +} + + +void allocSStringT(CuTest *tc) { + + sStringt *o; + o = allocSStringTiny("sheepy"); + ck_assert_uint_eq(o->type, STRING); + ck_assert_uint_ne(o->data, 0); + free(o); + +} + + +void allocSArrayT(CuTest *tc) { + + sArrayt *o; + o = allocSArray(); + ck_assert_uint_eq(o->type, ARRAY); + ck_assert_uint_eq(o->count, 0); + free(o); + +} + + +void allocSUndefinedT(CuTest *tc) { + + sUndefinedt *o; + o = allocSUndefined(); + ck_assert_uint_eq(o->type, UNDEFINED); + free(o); + +} + + +void allocSBytesT(CuTest *tc) { + + sBytest *o; + o = allocSBytes(); + ck_assert_uint_eq(o->type, BYTES); + ck_assert_uint_eq(o->count, 0); + free(o); + +} + + +void sFreeT(CuTest *tc) { + + // dict + sDictt *o = allocSDict(); + sFree((smallt *) o); + // array + sArrayt *a = allocSArray(); + sFree((smallt *) a); + // other objects + sUndefinedt *u = allocSUndefined(); + sFree((smallt *) u); + // non existing object type - size 0 + sUndefinedt *NIL; + NIL = allocSUndefined(); + NIL->type += 100; + sFree((smallt *) NIL); + // NULL + sFree(NULL); + +} + + +void sDictFreeT(CuTest *tc) { + + sDictt *o = allocSDict(); + sDictt *d = allocSDict(); + sDictPushTiny(&o, "d" , (smallt *)d); + sArrayt *a = allocSArray(); + sDictPushTiny(&o, "a" , (smallt *)a); + sDictFreeTiny(o); + +} + + +void sArrayFreeT(CuTest *tc) { + + sArrayt *o = allocSArray(); + sDictt *d = allocSDict(); + sArrayPushTiny(&o, (smallt *)d); + sArrayt *a = allocSArray(); + sArrayPushTiny(&o, (smallt *)a); + sArrayFreeTiny(o); + +} + + +void sBoolToStringT(CuTest *tc) { + + sBoolt *o; + o = allocSBool(false); + char *S = sBoolToStringTiny(o); + ck_assert_str_eq(S, "false"); + free(S); + o->value = true; + S = sBoolToStringTiny(o); + ck_assert_str_eq(S, "true"); + free(S); + free(o); + +} + + +void sContainerToStringT(CuTest *tc) { + + sContainert *o; + o = allocSContainer(strdup("sheepy")); + char *S = sContainerToStringTiny(o); + ck_assert_str_eq(S, "<data container>"); + free(S); + free(o->data); + free(o); + +} + + +void sDictToStringT(CuTest *tc) { + + sDictt *o; + o = allocSDict(); + char *S = sDictToStringTiny(o); + ck_assert_str_eq(S, "{}"); + free(S); + // elements + sBoolt *b = allocSBool(false); + sDictPushTiny(&o, "a", (smallt *) b); + sContainert *c = allocSContainer(strdup("sheepy")); + sDictPushTiny(&o, "c", (smallt *) c); + sStringt *s = allocSStringTiny(""); + sDictPushTiny(&o, "s", (smallt *) s); + S = sDictToStringTiny(o); + ck_assert_str_eq(S, "{\"a\":false,\"c\":\"<data container>\",\"s\":\"\"}"); + free(S); + free(c->data); + sDictFreeTiny(o); + +} + + +void sDoubleToStringT(CuTest *tc) { + + sDoublet *o; + o = allocSDouble(1.5); + char *S = sDoubleToStringTiny(o); + ck_assert_str_eq(S, "1.500000e+00"); + free(S); + free(o); + +} + + +void sIntToStringT(CuTest *tc) { + + sIntt *o; + o = allocSInt(1); + char *S = sIntToStringTiny(o); + ck_assert_str_eq(S, "1"); + free(S); + free(o); + +} + + +void sStringToStringT(CuTest *tc) { + + sStringt *o; + o = allocSStringTiny("sheepy"); + char *S = sStringToStringTiny(o); + ck_assert_str_eq(S, "sheepy"); + free(S); + free(o); + +} + + +void sArrayToStringT(CuTest *tc) { + + sArrayt *o; + o = allocSArray(); + char *S = sArrayToStringTiny(o); + ck_assert_str_eq(S, "[]"); + free(S); + // elements + sBoolt *b = allocSBool(false); + sArrayPushTiny(&o, (smallt *) b); + sContainert *c = allocSContainer(strdup("sheepy")); + sArrayPushTiny(&o, (smallt *) c); + sStringt *s = allocSStringTiny(""); + sArrayPushTiny(&o, (smallt *) s); + sUndefinedt *u = allocSUndefined(); + sArrayPushTiny(&o, (smallt *) u); + sArraySetTiny(o, 3, NULL); + S = sArrayToStringTiny(o); + ck_assert_str_eq(S, "[false,\"<data container>\",\"\"]"); + free(S); + free(c->data); + sArrayFreeTiny(o); + // array with 1 NULL element + o = allocSArray(); + sArrayPushTiny(&o, NULL); + S = sArrayToStringTiny(o); + ck_assert_str_eq(S, "[]"); + free(S); + sArrayFreeTiny(o); + +} + + +void sUndefinedToStringT(CuTest *tc) { + + sUndefinedt *o; + o = allocSUndefined(); + char *S = sUndefinedToStringTiny(o); + ck_assert_str_eq(S, "null"); + free(S); + free(o); + +} + + +void sBytesToStringT(CuTest *tc) { + + sBytest *o; + o = allocSBytes(); + char *S = sBytesToStringTiny(o); + ck_assert_str_eq(S, "[]"); + free(S); + sBytesPush(&o, 1); + sBytesPush(&o, 2); + sBytesPush(&o, 3); + S = sBytesToStringTiny(o); + ck_assert_str_eq(S, "[0x01,0x02,0x03]"); + free(S); + free(o); + +} + + +void sToStringT(CuTest *tc) { + + sBoolt *b; + b = allocSBool(false); + char *S = sToString((smallt *)b); + ck_assert_str_eq(S, "false"); + free(S); + free(b); + + sContainert *c; + c = allocSContainer(strdup("sheepy")); + S = sToString((smallt *)c); + ck_assert_str_eq(S, "<data container>"); + free(S); + free(c->data); + free(c); + + sDictt *d; + d = allocSDict(); + S = sToString((smallt *)d); + ck_assert_str_eq(S, "{}"); + free(S); + sDictFreeTiny(d); + + sDoublet *D; + D = allocSDouble(10); + S = sToString((smallt *)D); + ck_assert_str_eq(S, "1.000000e+01"); + free(S); + free(D); + + sIntt *i; + i = allocSInt(10); + S = sToString((smallt *)i); + ck_assert_str_eq(S, "10"); + free(S); + free(i); + + sStringt *s; + s = allocSStringTiny(""); + S = sToString((smallt *)s); + ck_assert_str_eq(S, ""); + free(S); + free(s); + + sArrayt *a; + a = allocSArray(); + S = sToString((smallt *)a); + ck_assert_str_eq(S, "[]"); + free(S); + sArrayFreeTiny(a); + + sUndefinedt *u; + u = allocSUndefined(); + S = sToString((smallt *)u); + ck_assert_str_eq(S, "null"); + free(S); + free(u); + + sBytest *B; + B = allocSBytes(); + S = sToString((smallt *)B); + ck_assert_str_eq(S, "[]"); + free(S); + free(B); + + // non existing object type - size 0 + sUndefinedt *NIL; + NIL = allocSUndefined(); + NIL->type += 100; + S = sToString((smallt *)NIL); + ck_assert_ptr_eq(S, NULL); + free(NIL); + + // NULL + S = sToString(NULL); + ck_assert_ptr_eq(S, NULL); + +} + + +void sTypesT(CuTest *tc) { + + sDictt *o; + o = allocSDict(); + // elements + sBoolt *b = allocSBool(false); + sDictPushTiny(&o, "a", (smallt *) b); + sContainert *c = allocSContainer(strdup("sheepy")); + sDictPushTiny(&o, "c", (smallt *) c); + sStringt *s = allocSStringTiny(""); + sDictPushTiny(&o, "s", (smallt *) s); + char *S = sTypesTiny((smallt *)o); + ck_assert_str_eq(S, "[\"bool\",\"container\",\"string\"]"); + free(S); + free(c->data); + sDictFreeTiny(o); + +} + + +void sTypesToBytesT(CuTest *tc) { + + // dict + sDictt *o; + o = allocSDict(); + // elements + sBoolt *b = allocSBool(false); + sDictPushTiny(&o, "a", (smallt *) b); + sContainert *c = allocSContainer(strdup("sheepy")); + sDictPushTiny(&o, "c", (smallt *) c); + sStringt *s = allocSStringTiny(""); + sDictPushTiny(&o, "s", (smallt *) s); + sBytest *t = sTypesToBytesTiny((smallt *)o); + char *S = sBytesToStringTiny(t); + ck_assert_str_eq(S, "[0x02,0x03,0x08]"); + free(S); + free(t); + free(c->data); + sDictFreeTiny(o); + + // array + sArrayt *a; + a = allocSArray(); + // elements + b = allocSBool(false); + sArrayPushTiny(&a, (smallt *) b); + c = allocSContainer(strdup("sheepy")); + sArrayPushTiny(&a, (smallt *) c); + s = allocSStringTiny(""); + sArrayPushTiny(&a, (smallt *) s); + sUndefinedt *u = allocSUndefined(); + sArrayPushTiny(&a, (smallt *) u); + sArraySetTiny(a, 3, NULL); + t = sTypesToBytesTiny((smallt *)a); + S = sBytesToStringTiny(t); + ck_assert_str_eq(S, "[0x02,0x03,0x08]"); + free(S); + free(t); + free(c->data); + sArrayFreeTiny(a); + + // non existing object type - size 0 + sUndefinedt *NIL; + NIL = allocSUndefined(); + NIL->type += 100; + t = sTypesToBytesTiny((smallt *)NIL); + ck_assert_ptr_eq(t, NULL); + free(NIL); + +} + + +void sDictTypeStringsT(CuTest *tc) { + + sDictt *o; + o = allocSDict(); + // elements + sBoolt *b = allocSBool(false); + sDictPushTiny(&o, "a", (smallt *) b); + sContainert *c = allocSContainer(strdup("sheepy")); + sDictPushTiny(&o, "c", (smallt *) c); + sStringt *s = allocSStringTiny(""); + sDictPushTiny(&o, "s", (smallt *) s); + char **t = sDictTypeStrings(o); + char *S = join(t, ","); + ck_assert_str_eq(S, "bool,container,string"); + free(S); + free(t); + free(c->data); + sDictFreeTiny(o); + +} + + +void sDictTypesT(CuTest *tc) { + + sDictt *o; + o = allocSDict(); + // elements + sBoolt *b = allocSBool(false); + sDictPushTiny(&o, "a", (smallt *) b); + sContainert *c = allocSContainer(strdup("sheepy")); + sDictPushTiny(&o, "c", (smallt *) c); + sStringt *s = allocSStringTiny(""); + sDictPushTiny(&o, "s", (smallt *) s); + sBytest *t = sDictTypesTiny(o); + char *S = sBytesToStringTiny(t); + ck_assert_str_eq(S, "[0x02,0x03,0x08]"); + free(S); + free(t); + free(c->data); + sDictFreeTiny(o); + +} + + +void sArrayTypeStringsT(CuTest *tc) { + + sArrayt *o; + o = allocSArray(); + // elements + sBoolt *b = allocSBool(false); + sArrayPushTiny(&o, (smallt *) b); + sContainert *c = allocSContainer(strdup("sheepy")); + sArrayPushTiny(&o, (smallt *) c); + sStringt *s = allocSStringTiny(""); + sArrayPushTiny(&o, (smallt *) s); + sUndefinedt *u = allocSUndefined(); + sArrayPushTiny(&o, (smallt *) u); + sArraySetTiny(o, 3, NULL); + char **t = sArrayTypeStrings(o); + char *S = join(t, ","); + ck_assert_str_eq(S, "bool,container,string"); + free(S); + free(t); + free(c->data); + sArrayFreeTiny(o); + +} + + +void sArrayTypesT(CuTest *tc) { + + sArrayt *o; + o = allocSArray(); + // elements + sBoolt *b = allocSBool(false); + sArrayPushTiny(&o, (smallt *) b); + sContainert *c = allocSContainer(strdup("sheepy")); + sArrayPushTiny(&o, (smallt *) c); + sStringt *s = allocSStringTiny(""); + sArrayPushTiny(&o, (smallt *) s); + sUndefinedt *u = allocSUndefined(); + sArrayPushTiny(&o, (smallt *) u); + sArraySetTiny(o, 3, NULL); + sBytest *t = sArrayTypesTiny(o); + char *S = sBytesToStringTiny(t); + ck_assert_str_eq(S, "[0x02,0x03,0x08]"); + free(S); + free(t); + free(c->data); + sArrayFreeTiny(o); + +} + + +void sDuplicateT(CuTest *tc) { + char *S; + + sBoolt *b, *b2; + b = allocSBool(true); + b2 = (sBoolt *) sDuplicate((smallt *)b); + ck_assert(b2->value); + free(b2); + free(b); + + sContainert *c, *c2; + c = allocSContainer(strdup("sheepy")); + c2 = (sContainert *) sDuplicate((smallt *)c); + ck_assert_str_eq(c2->data, c->data); + free(c2); + free(c->data); + free(c); + + sDictt *d, *d2; + d = allocSDict(); + d2 = (sDictt *) sDuplicateTiny((smallt *)d); + ck_assert_uint_eq(d2->count, 0); + sDictFreeTiny(d2); + // with elements + b = allocSBool(false); + sDictPushTiny(&d, "a", (smallt *) b); + d2 = (sDictt *) sDuplicateTiny((smallt *)d); + S = sDictToStringTiny(d2); + ck_assert_str_eq(S, "{\"a\":false}"); + free(S); + sDictFreeTiny(d2); + sDictFreeTiny(d); + + sDoublet *D, *D2; + D = allocSDouble(10); + D2 = (sDoublet *) sDuplicate((smallt *)D); + ck_assert_uint_eq((uint)D2->value, (uint)D->value); + free(D2); + free(D); + + sIntt *i, *i2; + i = allocSInt(10); + i2 = (sIntt *) sDuplicate((smallt *)i); + ck_assert_uint_eq(i2->value, i->value); + free(i2); + free(i); + + sStringt *s, *s2; + s = allocSStringTiny(""); + s2 = (sStringt *) sDuplicate((smallt *)s); + ck_assert_str_eq((char*)s, (char*)s2); + free(s2); + free(s); + // string + s = allocSStringTiny("sheepy"); + s2 = (sStringt *) sDuplicate((smallt *)s); + ck_assert_str_eq((char*)s, (char*)s2); + free(s2); + free(s); + + sArrayt *a, *a2; + a = allocSArray(); + a2 = (sArrayt *) sDuplicate((smallt *)a); + ck_assert_uint_eq(a2->count, 0); + sArrayFreeTiny(a2); + b = allocSBool(false); + sArrayPushTiny(&a, (smallt *) b); + D = allocSDouble(10); + sArrayPushTiny(&a, (smallt *) D); + s = allocSStringTiny("sheepy"); + sArrayPushTiny(&a, (smallt *) s); + a2 = (sArrayt *) sDuplicate((smallt *)a); + S = sArrayToStringTiny(a2); + ck_assert_str_eq(S, "[false,1.000000e+01,\"sheepy\"]"); + free(S); + sArrayFreeTiny(a2); + sArrayFreeTiny(a); + + sUndefinedt *u, *u2 = NULL; + u = allocSUndefined(); + u2 = (sUndefinedt *) sDuplicate((smallt *)u); + ck_assert_uint_eq(u2->type, UNDEFINED); + free(u2); + free(u); + + sBytest *B, *B2; + B = allocSBytes(); + B2 = (sBytest *) sDuplicate((smallt *)B); + sBytesPush(&B, 1); + sBytesPush(&B, 2); + sBytesPush(&B, 3); + ck_assert_uint_eq(B2->count, 0); + free(B2); + B2 = (sBytest *) sDuplicate((smallt *)B); + S = sToStringTiny((smallt *)B); + ck_assert_str_eq(S, "[0x01,0x02,0x03]"); + free(S); + S = sToStringTiny((smallt *)B2); + ck_assert_str_eq(S, "[0x01,0x02,0x03]"); + free(S); + free(B2); + free(B); + + // NULL + ck_assert_ptr_eq(sDuplicate(NULL), NULL); + +} + + +void sDictDuplicateT(CuTest *tc) { + + sDictt *o, *d; + o = allocSDict(); + // elements + sBoolt *b = allocSBool(true); + sDictPushTiny(&o, "a", (smallt *) b); + sContainert *c = allocSContainer(strdup("sheepy")); + sDictPushTiny(&o, "c", (smallt *) c); + sStringt *s = allocSStringTiny(""); + sDictPushTiny(&o, "s", (smallt *) s); + d = sDictDuplicateTiny(o); + char *S = sDictToStringTiny(d); + ck_assert_str_eq(S, "{\"a\":true,\"c\":\"<data container>\",\"s\":\"\"}"); + free(S); + free(c->data); + sDictFreeTiny(d); + sDictFreeTiny(o); + +} + + +void sArrayDuplicateT(CuTest *tc) { + + sArrayt *a = allocSArray(); + sBoolt *b = allocSBool(false); + sArrayPushTiny(&a, (smallt *) b); + sDoublet *D = allocSDouble(10); + sArrayPushTiny(&a, (smallt *) D); + sStringt *s = allocSStringTiny("sheepy"); + sArrayPushTiny(&a, (smallt *) s); + sArrayPushTiny(&a, NULL); + sArrayPushTiny(&a, NULL); + sArrayt *a2 = sArrayDuplicateTiny(a); + char *S = sArrayToStringTiny(a2); + ck_assert_str_eq(S, "[false,1.000000e+01,\"sheepy\"]"); + free(S); + sArrayFreeTiny(a2); + sArrayFreeTiny(a); + +} + + +void sDictGetT(CuTest *tc) { + + sDictt *o; + o = allocSDict(); + // elements + sBoolt *b = allocSBool(false); + sDictPushTiny(&o, "a", (smallt *) b); + sContainert *c = allocSContainer(strdup("sheepy")); + sDictPushTiny(&o, "c", (smallt *) c); + sStringt *s = allocSStringTiny(""); + sDictPushTiny(&o, "s", (smallt *) s); + b = (sBoolt *)sDictGet(o, "a"); + ck_assert_uint_eq(b->type, BOOL); + // invalid key + ck_assert_ptr_eq(sDictGet(o, "X"), NULL); + free(c->data); + sDictFreeTiny(o); + +} + + +void sDictSetPT(CuTest *tc) { + + sDictt *o = NULL; + sBoolt *b1, *b2; + // elements + sBoolt *b = allocSBool(false); + b1 = b; + sDictSetP(&o, "a", (smallt *) b); + b2 = allocSBool(true); + sDictSetP(&o, "a2", (smallt *) b2); + b = allocSBool(true); + sDictSetP(&o, "a", (smallt *) b); + b = allocSBool(false); + sDictSetP(&o, "a2", (smallt *) b); + // b1 and b2 is not freed by sDictSetP + ck_assert(!b1->value); + ck_assert(b2->value); + sFree((smallt *) b1); + sFree((smallt *) b2); + // set NULL (not changed) + sDictSetP(&o, "a", NULL); + b = (sBoolt *)sDictGet(o, "a"); + ck_assert(b->value); + b = (sBoolt *)sDictGet(o, "a2"); + ck_assert(!b->value); + sDictFreeTiny(o); + +} + + +void sDictSetT(CuTest *tc) { + + sDictt *o = NULL; + // elements + sBoolt *b = allocSBool(false); + sDictSetTiny(&o, "a", (smallt *) b); + b = allocSBool(true); + sDictSetTiny(&o, "a2", (smallt *) b); + b = allocSBool(true); + sDictSetTiny(&o, "a", (smallt *) b); + b = allocSBool(false); + sDictSetTiny(&o, "a2", (smallt *) b); + // set NULL (not changed) + sDictSetTiny(&o, "a", NULL); + b = (sBoolt *)sDictGet(o, "a"); + ck_assert(b->value); + b = (sBoolt *)sDictGet(o, "a2"); + ck_assert(!b->value); + sDictFreeTiny(o); + +} + + +void sDictPushT(CuTest *tc) { + + sDictt *o = NULL; + // elements + sBoolt *b = allocSBool(false); + sDictPushTiny(&o, "a", (smallt *) b); + b = allocSBool(true); + sDictPushTiny(&o, "a2", (smallt *) b); + b = allocSBool(true); + sDictPushTiny(&o, "a3", (smallt *) b); + b = allocSBool(true); + sDictPushTiny(&o, "a4", (smallt *) b); + b = allocSBool(true); + sDictPushTiny(&o, "aq", (smallt *) b); + b = allocSBool(true); + sDictPushTiny(&o, "aw", (smallt *) b); + b = allocSBool(true); + sDictPushTiny(&o, "ae", (smallt *) b); + b = allocSBool(true); + sDictPushTiny(&o, "ar", (smallt *) b); + b = allocSBool(true); + sDictPushTiny(&o, "at", (smallt *) b); + b = allocSBool(true); + sDictPushTiny(&o, "ay", (smallt *) b); + b = allocSBool(true); + sDictPushTiny(&o, "au", (smallt *) b); + sContainert *c = allocSContainer(strdup("sheepy")); + sDictPushTiny(&o, "c", (smallt *) c); + sStringt *s = allocSStringTiny(""); + sDictPushTiny(&o, "s", (smallt *) s); + // set NULL + sDictPushTiny(&o, "a", NULL); + b = (sBoolt *)sDictGet(o, "a"); + ck_assert_uint_eq(b->type, BOOL); + b = (sBoolt *)sDictGet(o, "au"); + ck_assert(b->value); + ck_assert_uint_eq(o->count, 13); + // TODO 16 depends on defines SDICT_REALLOC_STEPS and SDICT_MIN_ELEMENTS + ck_assert_uint_eq(o->maxCount, 16); + free(c->data); + sDictFreeTiny(o); + +} + + +void sDictDelT(CuTest *tc) { + + sDictt *o = NULL; + // elements + sBoolt *b = allocSBool(false); + sDictPushTiny(&o, "a", (smallt *) b); + sDictDelTiny(o, "a"); + b = (sBoolt *)sDictGet(o, "a"); + ck_assert_ptr_eq(b, NULL); + sDictFreeTiny(o); + +} + + +void sStringGetT(CuTest *tc) { + + sStringt *s = allocSStringTiny("qweqwe"); + char *S = sStringGetTiny(s); + ck_assert_str_eq(S, "qweqwe"); + free(s); + +} + + +void sStringSetT(CuTest *tc) { + + sStringt *s = allocSStringTiny("qweqwe"); + sStringSetTiny(&s, "sheepy"); + char *S = sStringGetTiny(s); + ck_assert_str_eq(S, "sheepy"); + free(s); + +} + + +void sArrayPushT(CuTest *tc) { + + sArrayt *a = allocSArray(); + sBoolt *b = allocSBool(false); + sArrayPushTiny(&a, (smallt *) b); + sDoublet *D = allocSDouble(10); + sArrayPushTiny(&a, (smallt *) D); + sStringt *s = allocSStringTiny("sheepy"); + sArrayPushTiny(&a, (smallt *) s); + sArrayPushTiny(&a, NULL); + sArrayPushTiny(&a, NULL); + ck_assert_uint_eq(a->count, 5); + // TODO depends on defines SARRAY_REALLOC_STEPS and SARRAY_MIN_ELEMENTS + ck_assert_uint_eq(a->maxCount, 8); + sArrayFreeTiny(a); + //NULL + a = NULL; + b = allocSBool(false); + sArrayPushTiny(&a, (smallt *) b); + sArrayFreeTiny(a); + +} + + +void sArrayPrependT(CuTest *tc) { + + sArrayt *a = allocSArray(); + sBoolt *b = allocSBool(false); + sArrayPrependTiny(&a, (smallt *) b); + sDoublet *D = allocSDouble(10); + sArrayPrependTiny(&a, (smallt *) D); + sStringt *s = allocSStringTiny("sheepy"); + sArrayPrependTiny(&a, (smallt *) s); + sArrayPrependTiny(&a, NULL); + sArrayPrependTiny(&a, NULL); + ck_assert_uint_eq(a->count, 5); + // TODO depends on defines SARRAY_REALLOC_STEPS and SARRAY_MIN_ELEMENTS + ck_assert_uint_eq(a->maxCount, 8); + sArrayFreeTiny(a); + //NULL + a = NULL; + b = allocSBool(false); + sArrayPrependTiny(&a, (smallt *) b); + sArrayFreeTiny(a); + +} + + +void sArrayPopT(CuTest *tc) { + + char *S; + sArrayt *a = allocSArray(); + sBoolt *b = allocSBool(false); + sArrayPushTiny(&a, (smallt *) b); + sDoublet *D = allocSDouble(10); + sArrayPushTiny(&a, (smallt *) D); + sStringt *s = allocSStringTiny("sheepy"); + sArrayPushTiny(&a, (smallt *) s); + sArrayPushTiny(&a, NULL); + sArrayPushTiny(&a, NULL); + s = (sStringt *) sArrayPopTiny(a); + ck_assert_ptr_eq(s, NULL); + ck_assert_uint_eq(a->count, 4); + // TODO depends on defines SARRAY_REALLOC_STEPS and SARRAY_MIN_ELEMENTS + ck_assert_uint_eq(a->maxCount, 8); + s = (sStringt *) sArrayPopTiny(a); + ck_assert_ptr_eq(s, NULL); + ck_assert_uint_eq(a->count, 3); + // TODO depends on defines SARRAY_REALLOC_STEPS and SARRAY_MIN_ELEMENTS + ck_assert_uint_eq(a->maxCount, 8); + s = (sStringt *) sArrayPopTiny(a); + S = sStringGetTiny(s); + ck_assert_str_eq(S, "sheepy"); + free(s); + ck_assert_uint_eq(a->count, 2); + // TODO depends on defines SARRAY_REALLOC_STEPS and SARRAY_MIN_ELEMENTS + ck_assert_uint_eq(a->maxCount, 8); + D = (sDoublet *) sArrayPopTiny(a); + ck_assert_uint_eq((uint32_t)D->value, 10); + free(D); + ck_assert_uint_eq(a->count, 1); + // TODO depends on defines SARRAY_REALLOC_STEPS and SARRAY_MIN_ELEMENTS + ck_assert_uint_eq(a->maxCount, 8); + b = (sBoolt *) sArrayPopTiny(a); + ck_assert(!b->value); + free(b); + ck_assert_uint_eq(a->count, 0); + // TODO depends on defines SARRAY_REALLOC_STEPS and SARRAY_MIN_ELEMENTS + ck_assert_uint_eq(a->maxCount, 8); + sArrayFreeTiny(a); + +} + + +void sArrayDequeueT(CuTest *tc) { + + char *S; + sArrayt *a = allocSArray(); + sBoolt *b = allocSBool(false); + sArrayPrependTiny(&a, (smallt *) b); + sDoublet *D = allocSDouble(10); + sArrayPrependTiny(&a, (smallt *) D); + sStringt *s = allocSStringTiny("sheepy"); + sArrayPrependTiny(&a, (smallt *) s); + sArrayPrependTiny(&a, NULL); + sArrayPrependTiny(&a, NULL); + s = (sStringt *) sArrayDequeueTiny(a); + ck_assert_ptr_eq(s, NULL); + ck_assert_uint_eq(a->count, 4); + // TODO depends on defines SARRAY_REALLOC_STEPS and SARRAY_MIN_ELEMENTS + ck_assert_uint_eq(a->maxCount, 8); + s = (sStringt *) sArrayDequeueTiny(a); + ck_assert_ptr_eq(s, NULL); + ck_assert_uint_eq(a->count, 3); + // TODO depends on defines SARRAY_REALLOC_STEPS and SARRAY_MIN_ELEMENTS + ck_assert_uint_eq(a->maxCount, 8); + s = (sStringt *) sArrayDequeueTiny(a); + S = sStringGetTiny(s); + ck_assert_str_eq(S, "sheepy"); + free(s); + ck_assert_uint_eq(a->count, 2); + // TODO depends on defines SARRAY_REALLOC_STEPS and SARRAY_MIN_ELEMENTS + ck_assert_uint_eq(a->maxCount, 8); + D = (sDoublet *) sArrayDequeueTiny(a); + ck_assert_uint_eq((uint32_t)D->value, 10); + free(D); + ck_assert_uint_eq(a->count, 1); + // TODO depends on defines SARRAY_REALLOC_STEPS and SARRAY_MIN_ELEMENTS + ck_assert_uint_eq(a->maxCount, 8); + b = (sBoolt *) sArrayDequeueTiny(a); + ck_assert(!b->value); + free(b); + ck_assert_uint_eq(a->count, 0); + // TODO depends on defines SARRAY_REALLOC_STEPS and SARRAY_MIN_ELEMENTS + ck_assert_uint_eq(a->maxCount, 8); + sArrayFreeTiny(a); + +} + + +void sArrayGetT(CuTest *tc) { + + sArrayt *a = allocSArray(); + sBoolt *b = allocSBool(false); + sArrayPushTiny(&a, (smallt *) b); + sDoublet *D = allocSDouble(10); + sArrayPushTiny(&a, (smallt *) D); + sStringt *s = allocSStringTiny("sheepy"); + sArrayPushTiny(&a, (smallt *) s); + sArrayPushTiny(&a, NULL); + sArrayPushTiny(&a, NULL); + b = (sBoolt *) sArrayGetTiny(a, 0); + ck_assert(!b->value); + ck_assert_uint_eq(a->count, 5); + // TODO depends on defines SARRAY_REALLOC_STEPS and SARRAY_MIN_ELEMENTS + ck_assert_uint_eq(a->maxCount, 8); + sArrayFreeTiny(a); + +} + + +void sArraySetPT(CuTest *tc) { + + sArrayt *a = allocSArray(); + sBoolt *b = allocSBool(false); + sArrayPushTiny(&a, (smallt *) b); + sDoublet *D = allocSDouble(10); + sArrayPushTiny(&a, (smallt *) D); + sStringt *s = allocSStringTiny("sheepy"); + sArrayPushTiny(&a, (smallt *) s); + sArrayPushTiny(&a, NULL); + sArrayPushTiny(&a, NULL); + b = (sBoolt *) sArrayGetTiny(a, 0); + sBoolt *b2 = allocSBool(true); + sArraySetP(a, 0, (smallt *) b2); + b2 = (sBoolt *) sArrayGetTiny(a, 0); + ck_assert(!b->value); + ck_assert(b2->value); + sFree((smallt *) b); + ck_assert_uint_eq(a->count, 5); + // TODO depends on defines SARRAY_REALLOC_STEPS and SARRAY_MIN_ELEMENTS + ck_assert_uint_eq(a->maxCount, 8); + sArrayFreeTiny(a); + +} + + +void sArraySetT(CuTest *tc) { + + sArrayt *a = allocSArray(); + sBoolt *b = allocSBool(false); + sArrayPushTiny(&a, (smallt *) b); + sDoublet *D = allocSDouble(10); + sArrayPushTiny(&a, (smallt *) D); + sStringt *s = allocSStringTiny("sheepy"); + sArrayPushTiny(&a, (smallt *) s); + sArrayPushTiny(&a, NULL); + sArrayPushTiny(&a, NULL); + b = (sBoolt *) sArrayGetTiny(a, 0); + b = allocSBool(true); + sArraySetTiny(a, 0, (smallt *) b); + b = (sBoolt *) sArrayGetTiny(a, 0); + ck_assert(b->value); + ck_assert_uint_eq(a->count, 5); + // TODO depends on defines SARRAY_REALLOC_STEPS and SARRAY_MIN_ELEMENTS + ck_assert_uint_eq(a->maxCount, 8); + sArrayFreeTiny(a); + +} + + +void sArrayReverseT(CuTest *tc) { + + sArrayt *a = allocSArray(); + sBoolt *b = allocSBool(false); + sArrayPushTiny(&a, (smallt *) b); + sDoublet *D = allocSDouble(10); + sArrayPushTiny(&a, (smallt *) D); + sStringt *s = allocSStringTiny("sheepy"); + sArrayPushTiny(&a, (smallt *) s); + sArrayPushTiny(&a, NULL); + sArrayPushTiny(&a, NULL); + sArrayReverseTiny(a); + b = (sBoolt *) sArrayGetTiny(a, 4); + ck_assert(!b->value); + ck_assert_uint_eq(a->count, 5); + sArrayFreeTiny(a); + +} + + +void sArrayDelT(CuTest *tc) { + + sArrayt *a = allocSArray(); + sBoolt *b = allocSBool(false); + sArrayPushTiny(&a, (smallt *) b); + sDoublet *D = allocSDouble(10); + sArrayPushTiny(&a, (smallt *) D); + sStringt *s = allocSStringTiny("sheepy"); + sArrayPushTiny(&a, (smallt *) s); + sArrayDelTiny(a, 0); + b = (sBoolt *) sArrayGetTiny(a, 0); + ck_assert_ptr_eq(b, NULL); + sArrayFreeTiny(a); + +} + +void sArrayDelRangeT(CuTest *tc) { + + sArrayt *a = allocSArray(); + sBoolt *b = allocSBool(false); + sArrayPushTiny(&a, (smallt *) b); + sDoublet *D = allocSDouble(10); + sArrayPushTiny(&a, (smallt *) D); + sStringt *s = allocSStringTiny("sheepy"); + sArrayPushTiny(&a, (smallt *) s); + sArrayDelRangeTiny(a, 0,1); + ck_assert_uint_eq(a->count, 2); + D = (sDoublet *) sArrayGetTiny(a, 0); + ck_assert_uint_eq((uint32_t)(D->value), 10); + sArrayFreeTiny(a); + +} + + + +void sBytesGetT(CuTest *tc) { + + char *T = "sheepy"; + sBytest *B = allocSBytes(); + sBytesPushBuffer(&B, T, strlen(T)+1); + char *S = sBytesGet(B); + ck_assert_str_eq(S, "sheepy"); + free(B); + +} + + +void sBytesPushT(CuTest *tc) { + + sBytest *B = allocSBytes(); + sBytesPush(&B, 1); + sBytesPush(&B, 2); + sBytesPush(&B, 3); + ck_assert_uint_eq(B->count, 3); + free(B); + //NULL + B = NULL; + sBytesPush(&B, 1); + sBytesPush(&B, 2); + sBytesPush(&B, 3); + ck_assert_uint_eq(B->count, 3); + free(B); + +} + + +void sBytesPushBufferT(CuTest *tc) { + + char s[] = {1,2,3}; + sBytest *B = NULL; + sBytesPushBuffer(&B, s, 3); + ck_assert_uint_eq(B->count, 3); + char *S = sBytesToStringTiny(B); + ck_assert_str_eq(S, "[0x01,0x02,0x03]"); + free(S); + // push to existing + sBytesPushBuffer(&B, s, 3); + ck_assert_uint_eq(B->count, 6); + S = sBytesToStringTiny(B); + ck_assert_str_eq(S, "[0x01,0x02,0x03,0x01,0x02,0x03]"); + free(S); + free(B); + // null + B = NULL; + sBytesPushBuffer(&B, NULL, 3); + ck_assert_uint_eq(B->count, 0); + free(B); + // size 0 + B = NULL; + sBytesPushBuffer(&B, s, 0); + ck_assert_uint_eq(B->count, 0); + free(B); + +} + + +void sSerialT(CuTest *tc) { + + char *S; + + // dict + sDictt *d = allocSDict(); + sBytest *r = sSerial((smallt *) d); + S = sBytesToStringTiny(r); + ck_assert_str_eq(S, "[0x04,0x00,0x00,0x00,0x00]"); + free(S); + sDictFreeTiny(d); + free(r); + + // array + sArrayt *a = allocSArray(); + r = sSerial((smallt *) a); + S = sBytesToStringTiny(r); + ck_assert_str_eq(S, "[0x0a,0x00,0x00,0x00,0x00]"); + free(S); + sArrayFreeTiny(a); + free(r); + + // undefined + sUndefinedt *u = allocSUndefined(); + r = sSerial((smallt *) u); + S = sBytesToStringTiny(r); + ck_assert_str_eq(S, "[0x01]"); + free(S); + free(u); + free(r); + //NULL + ck_assert_ptr_eq(sSerial(NULL), NULL); + +} + + +void sDictSerialElementsT(CuTest *tc) { + + sBytest *r = NULL; + sDictt *o = NULL; + char *S; + + // elements + // bool + sBoolt *b = allocSBool(true); + sDictPushTiny(&o, "a", (smallt *) b); + // undefined + sUndefinedt *u = allocSUndefined(); + sDictPushTiny(&o, "u", (smallt *) u); + // container + sContainert *c = allocSContainer(strdup("sheepy")); + sDictPushTiny(&o, "c", (smallt *) c); + free(c->data); + // double + sDoublet *D = allocSDouble(10); + sDictPushTiny(&o, "d", (smallt *) D); + // int + sIntt *i = allocSInt(10); + sDictPushTiny(&o, "i", (smallt *) i); + // string + sStringt *s = allocSStringTiny("sheepy"); + sDictPushTiny(&o, "s", (smallt *) s); + // bytes + sBytest *B = allocSBytes(); + sBytesPush(&B, 1); + sBytesPush(&B, 2); + sDictPushTiny(&o, "B", (smallt *) B); + // dict + sDictt *d = allocSDict(); + b = allocSBool(true); + sDictPushTiny(&d, "b", (smallt *) b); + sDictPushTiny(&o, "D", (smallt *) d); + // array + sArrayt *a = allocSArray(); + b = allocSBool(true); + sArrayPushTiny(&a, (smallt *) b); + sDictPushTiny(&o, "A", (smallt *) a); + + sDictSerialElementsTiny(&r, o); + /* printf ("final count %d\n", r->count); */ + /* S = sToStringTiny((smallt *) o); */ + /* printf("%d %s\n", (int)strlen(S), S); */ + /* free(S); */ + S = sBytesToStringTiny(r); + /* // debug */ + /* char *ref = "[4,9,0,0,0,97,0,2,1,117,0,1,99,0,3,100,0,6,0,0,0,0,0,0,36,64,105,0,7,10,0,0,0,0,0,0,0,115,0,8,115,104,101,101,112,121,0,66,0,11,2,0,0,0,1,2,68,0,4,1,0,0,0,98,0,2,1,65,0,10,1,0,0,0,2,1]"; */ + /* printf("%d %d\n", (int)strlen(ref), (int)strlen(S)); */ + /* puts(ref); */ + /* puts(S); */ + /* for (size_t i = 0; i < strlen(ref);i++) { */ + /* if (i < strlen(S)) { */ + /* if (ref[i] != S[i]) printf(">'%c' '%c' %d<", ref[i], S[i], (int)i); */ + /* } else { */ + /* printf(">%c X<", ref[i]); */ + /* } */ + /* } */ + /* puts(""); */ + ck_assert_str_eq(S, "[0x04,0x09,0x00,0x00,0x00,0x61,0x00,0x02,0x01,0x75,0x00,0x01,0x63,0x00,0x03,0x64,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x24,0x40,0x69,0x00,0x07,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x73,0x00,0x08,0x73,0x68,0x65,0x65,0x70,0x79,0x00,0x42,0x00,0x0b,0x02,0x00,0x00,0x00,0x01,0x02,0x44,0x00,0x04,0x01,0x00,0x00,0x00,0x62,0x00,0x02,0x01,0x41,0x00,0x0a,0x01,0x00,0x00,0x00,0x02,0x01]"); + free(S); + sDictFreeTiny(o); + free(r); + +} + + +void sArraySerialElementsT(CuTest *tc) { + + sBytest *r = NULL; + sArrayt *o = NULL; + char *S; + + // elements + // bool + sBoolt *b = allocSBool(true); + sArrayPushTiny(&o, (smallt *) b); + // undefined + sUndefinedt *u = allocSUndefined(); + sArrayPushTiny(&o, (smallt *) u); + // container + sContainert *c = allocSContainer(strdup("sheepy")); + sArrayPushTiny(&o, (smallt *) c); + // double + sDoublet *D = allocSDouble(10); + sArrayPushTiny(&o, (smallt *) D); + // int + sIntt *i = allocSInt(10); + sArrayPushTiny(&o, (smallt *) i); + // string + sStringt *s = allocSStringTiny("sheepy"); + sArrayPushTiny(&o, (smallt *) s); + // bytes + sBytest *B = allocSBytes(); + sBytesPush(&B, 1); + sBytesPush(&B, 2); + sArrayPushTiny(&o, (smallt *) B); + // dict + sDictt *d = allocSDict(); + sArrayPushTiny(&o, (smallt *) d); + // array + sArrayt *a = allocSArray(); + sArrayPushTiny(&o, (smallt *) a); + + sArraySerialElementsTiny(&r, o); + /* printf("final count %d\n", r->count); */ + /* S = sToStringTiny((smallt *) o); */ + /* printf("%d %s\n", (int)strlen(S), S); */ + /* free(S); */ + S = sBytesToStringTiny(r); + ck_assert_str_eq(S, "[0x0a,0x09,0x00,0x00,0x00,0x02,0x01,0x01,0x03,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x24,0x40,0x07,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x73,0x68,0x65,0x65,0x70,0x79,0x00,0x0b,0x02,0x00,0x00,0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0x00]"); + free(S); + free(c->data); + sArrayFreeTiny(o); + free(r); + // array with 1 NULL element + r = NULL; + o = allocSArray(); + sArrayPushTiny(&o, NULL); + sArraySerialElementsTiny(&r, o); + S = sBytesToStringTiny(r); + ck_assert_str_eq(S, "[0x0a,0x01,0x00,0x00,0x00,0x01]"); + free(S); + free(r); + sArrayFreeTiny(o); + +} + + +void sDeserialT(CuTest *tc) { + sBytest *r = NULL; + char *S; + + // undefined + sUndefinedt *u = allocSUndefined(); + r = sSerialTiny((smallt *) u); + free(u); + u = (sUndefinedt *) sDeserial(r); + free(r); + S = sToStringTiny((smallt *) u); + //printf("%s\n", S); + ck_assert_str_eq(S, "null"); + free(S); + free(u); + + // bool + sBoolt *b = allocSBool(true); + r = sSerialTiny((smallt *) b); + free(b); + b = (sBoolt *) sDeserial(r); + free(r); + S = sToStringTiny((smallt *) b); + //printf("%s\n", S); + ck_assert_str_eq(S, "true"); + free(S); + free(b); + // container + sContainert *c = allocSContainer(strdup("sheepy")); + r = sSerialTiny((smallt *) c); + free(c->data); + free(c); + c = (sContainert *) sDeserial(r); + free(r); + S = sToStringTiny((smallt *) c); + //printf("%s\n", S); + ck_assert_str_eq(S, "<data container>"); + free(S); + free(c); + // double + sDoublet *D = allocSDouble(10); + r = sSerialTiny((smallt *) D); + free(D); + D = (sDoublet *) sDeserial(r); + free(r); + S = sToStringTiny((smallt *) D); + //printf("%s\n", S); + ck_assert_str_eq(S, "1.000000e+01"); + free(S); + free(D); + // int + sIntt *i = allocSInt(10); + r = sSerialTiny((smallt *) i); + free(i); + i = (sIntt *) sDeserial(r); + free(r); + S = sToStringTiny((smallt *) i); + //printf("%s\n", S); + ck_assert_str_eq(S, "10"); + free(S); + free(i); + // string + sStringt *s = allocSStringTiny("sheepy"); + r = sSerialTiny((smallt *) s); + free(s); + s = (sStringt *) sDeserial(r); + free(r); + S = sToStringTiny((smallt *) s); + //printf("%s\n", S); + ck_assert_str_eq(S, "sheepy"); + free(S); + free(s); + // bytes + sBytest *B = allocSBytes(); + sBytesPush(&B, 1); + sBytesPush(&B, 2); + r = sSerialTiny((smallt *) B); + free(B); + B = (sBytest *) sDeserial(r); + free(r); + S = sToStringTiny((smallt *) B); + //printf("%s\n", S); + ck_assert_str_eq(S, "[0x01,0x02]"); + free(S); + free(B); + //empty sBytes + B = allocSBytes(); + ck_assert_ptr_eq(sDeserial(B), NULL); + free(B); + //NULL + ck_assert_ptr_eq(sDeserial(NULL), NULL); + + +} + + +void sDictDeserialElementsT(CuTest *tc) { + sBytest *r = NULL; + sDictt *o = NULL; + char *S; + + // elements + // bool + sBoolt *b = allocSBool(true); + sDictPushTiny(&o, "a", (smallt *) b); + // undefined + sUndefinedt *u = allocSUndefined(); + sDictPushTiny(&o, "u", (smallt *) u); + // container + sContainert *c = allocSContainer(strdup("sheepy")); + sDictPushTiny(&o, "c", (smallt *) c); + free(c->data); + // double + sDoublet *D = allocSDouble(10); + sDictPushTiny(&o, "d", (smallt *) D); + // int + sIntt *i = allocSInt(10); + sDictPushTiny(&o, "i", (smallt *) i); + // string + sStringt *s = allocSStringTiny("sheepy"); + sDictPushTiny(&o, "s", (smallt *) s); + // bytes + sBytest *B = allocSBytes(); + sBytesPush(&B, 1); + sBytesPush(&B, 2); + sDictPushTiny(&o, "B", (smallt *) B); + // dict + sDictt *d = allocSDict(); + b = allocSBool(true); + sDictPushTiny(&d, "b", (smallt *) b); + sDictPushTiny(&o, "D", (smallt *) d); + // array + sArrayt *a = allocSArray(); + b = allocSBool(true); + sArrayPushTiny(&a, (smallt *) b); + sDictPushTiny(&o, "A", (smallt *) a); + sDictSerialElementsTiny(&r, o); + sDictFreeTiny(o); + /* S = sToStringTiny((smallt *) r); */ + /* printf("%d %s\n", (int)strlen(S), S); */ + /* free(S); */ + o = (sDictt *) sDeserialTiny(r); + S = sToStringTiny((smallt *) o); + ck_assert_str_eq(S, "{\"a\":true,\"u\":null,\"c\":\"<data container>\",\"d\":1.000000e+01,\"i\":10,\"s\":\"sheepy\",\"B\":[0x01,0x02],\"D\":{\"b\":true},\"A\":[true]}"); + free(S); + sDictFreeTiny(o); + free(r); + +} + + +void sArrayDeserialElementsT(CuTest *tc) { + + sBytest *src = NULL; + sArrayt *r = NULL; + sUndefinedt *u; + char *S; + + // empty array + r = allocSArray(); + sArraySerialElementsTiny(&src, r); + sArrayFreeTiny(r); + r = (sArrayt *) sDeserialTiny(src); + S = sToStringTiny((smallt *) r); + ck_assert_str_eq(S, "[]"); + free(S); + sArrayFreeTiny(r); + free(src); + // array + src = NULL; + r = NULL; + // undefined + u = allocSUndefined(); + sArrayPushTiny(&r, (smallt *) u); + // bool + sBoolt *b = allocSBool(true); + sArrayPushTiny(&r, (smallt *) b); + // container + sContainert *c = allocSContainer(strdup("sheepy")); + sArrayPushTiny(&r, (smallt *) c); + free(c->data); + // double + sDoublet *D = allocSDouble(10); + sArrayPushTiny(&r, (smallt *) D); + // int + sIntt *i = allocSInt(10); + sArrayPushTiny(&r, (smallt *) i); + // string + sStringt *s = allocSStringTiny("sheepy"); + sArrayPushTiny(&r, (smallt *) s); + // bytes + sBytest *B = allocSBytes(); + sBytesPush(&B, 1); + sBytesPush(&B, 2); + sArrayPushTiny(&r, (smallt *) B); + // dict + sDictt *d = allocSDict(); + sArrayPushTiny(&r, (smallt *) d); + // array + sArrayt *a = allocSArray(); + sArrayPushTiny(&r, (smallt *) a); + + sArraySerialElementsTiny(&src, r); + sArrayFreeTiny(r); + /* S = sToStringTiny((smallt *) src); */ + /* printf("%d %s\n", (int)strlen(S), S); */ + /* free(S); */ + r = (sArrayt *) sDeserialTiny(src); + S = sToStringTiny((smallt *) r); + //printf("%s\n", S); + ck_assert_str_eq(S, "[null,true,\"<data container>\",1.000000e+01,10,\"sheepy\",[0x01,0x02],{},[]]"); + free(S); + sArrayFreeTiny(r); + free(src); + +} + + + + +int main(int n, char**v) { + // disable btrace to make the test run faster + btraceDisable(); + CuString *output = CuStringNew(); + CuSuite *suite = CuSuiteNew(); + + SUITE_ADD_TEST(suite, isSTypeFT); + SUITE_ADD_TEST(suite, sSizeT); + SUITE_ADD_TEST(suite, allocSBoolT); + SUITE_ADD_TEST(suite, allocSContainerT); + SUITE_ADD_TEST(suite, allocSDictT); + SUITE_ADD_TEST(suite, allocSDoubleT); + SUITE_ADD_TEST(suite, allocSIntT); + SUITE_ADD_TEST(suite, allocSStringT); + SUITE_ADD_TEST(suite, allocSArrayT); + SUITE_ADD_TEST(suite, allocSUndefinedT); + SUITE_ADD_TEST(suite, allocSBytesT); + SUITE_ADD_TEST(suite, sFreeT); + SUITE_ADD_TEST(suite, sDictFreeT); + SUITE_ADD_TEST(suite, sArrayFreeT); + SUITE_ADD_TEST(suite, sBoolToStringT); + SUITE_ADD_TEST(suite, sContainerToStringT); + SUITE_ADD_TEST(suite, sDictToStringT); + SUITE_ADD_TEST(suite, sDoubleToStringT); + SUITE_ADD_TEST(suite, sIntToStringT); + SUITE_ADD_TEST(suite, sStringToStringT); + SUITE_ADD_TEST(suite, sArrayToStringT); + SUITE_ADD_TEST(suite, sUndefinedToStringT); + SUITE_ADD_TEST(suite, sBytesToStringT); + SUITE_ADD_TEST(suite, sToStringT); + SUITE_ADD_TEST(suite, sTypesT); + SUITE_ADD_TEST(suite, sTypesToBytesT); + SUITE_ADD_TEST(suite, sDictTypeStringsT); + SUITE_ADD_TEST(suite, sDictTypesT); + SUITE_ADD_TEST(suite, sArrayTypeStringsT); + SUITE_ADD_TEST(suite, sArrayTypesT); + SUITE_ADD_TEST(suite, sDuplicateT); + SUITE_ADD_TEST(suite, sDictDuplicateT); + SUITE_ADD_TEST(suite, sArrayDuplicateT); + SUITE_ADD_TEST(suite, sDictGetT); + SUITE_ADD_TEST(suite, sDictSetPT); + SUITE_ADD_TEST(suite, sDictSetT); + SUITE_ADD_TEST(suite, sDictPushT); + SUITE_ADD_TEST(suite, sDictDelT); + SUITE_ADD_TEST(suite, sStringGetT); + SUITE_ADD_TEST(suite, sStringSetT); + SUITE_ADD_TEST(suite, sArrayPushT); + SUITE_ADD_TEST(suite, sArrayPrependT); + SUITE_ADD_TEST(suite, sArrayPopT); + SUITE_ADD_TEST(suite, sArrayDequeueT); + SUITE_ADD_TEST(suite, sArrayGetT); + SUITE_ADD_TEST(suite, sArraySetPT); + SUITE_ADD_TEST(suite, sArraySetT); + SUITE_ADD_TEST(suite, sArrayReverseT); + SUITE_ADD_TEST(suite, sArrayDelT); + SUITE_ADD_TEST(suite, sArrayDelRangeT); + SUITE_ADD_TEST(suite, sBytesGetT); + SUITE_ADD_TEST(suite, sBytesPushT); + SUITE_ADD_TEST(suite, sBytesPushBufferT); + SUITE_ADD_TEST(suite, sSerialT); + SUITE_ADD_TEST(suite, sDictSerialElementsT); + SUITE_ADD_TEST(suite, sArraySerialElementsT); + SUITE_ADD_TEST(suite, sDeserialT); + SUITE_ADD_TEST(suite, sDictDeserialElementsT); + SUITE_ADD_TEST(suite, sArrayDeserialElementsT); + + + CuSuiteRun(suite); + CuSuiteDetails(suite, output); + printf ("%s\n", output->buffer); + return suite->failCount; +} diff --git a/src/runCuTest.sh b/src/runCuTest.sh @@ -1,7 +1,7 @@ -gcc -mrdrnd -DunitTest -g3 -std=gnu99 -fprofile-arcs -ftest-coverage -pipe -c -o libsheepy.o libsheepy.c -gcc -mrdrnd -DunitTest -g3 -std=gnu99 -fprofile-arcs -ftest-coverage -pipe -o libsheepyCuTest.o -c libsheepyCuTest.c -gcc -mrdrnd -DunitTest -g3 -std=gnu99 -fprofile-arcs -ftest-coverage -pipe -c -o CuTest.o CuTest/CuTest.c -gcc -o libsheepyCuTest libsheepyCuTest.o CuTest.o libsheepy.o -pthread -rdynamic -fprofile-arcs -ftest-coverage +gcc -mrdrnd -DunitTest -g3 -std=gnu99 -Wall -Wextra -fprofile-arcs -ftest-coverage -pipe -c -o libsheepy.o libsheepy.c +gcc -mrdrnd -DunitTest -g3 -std=gnu99 -Wall -Wextra -fprofile-arcs -ftest-coverage -pipe -o libsheepyCuTest.o -c libsheepyCuTest.c +gcc -mrdrnd -DunitTest -g3 -std=gnu99 -Wall -Wextra -fprofile-arcs -ftest-coverage -pipe -c -o CuTest.o CuTest/CuTest.c +gcc -o libsheepyCuTest libsheepyCuTest.o CuTest.o libsheepy.o -Wall -Wextra -pthread -rdynamic -fprofile-arcs -ftest-coverage chmod 222 writeOnlyText.null touch chmodTest.null diff --git a/src/runSmallCuTest.sh b/src/runSmallCuTest.sh @@ -0,0 +1,3 @@ +gcc -o libsheepySmallCuTest libsheepySmallCuTest.c CuTest/CuTest.c libsheepySmall.c ../release/libsheepy.c -mrdrnd -Wall -Wextra -pthread -rdynamic -fprofile-arcs -ftest-coverage +./libsheepySmallCuTest +gcov -b libsheepySmall.c