7 #include "../libsheepy.h" 8 #include "../libsheepyObject.h" 11 #define UNUSED __attribute__ ((unused)) 18 START_TEST(cSmallDictT)
115 keys = o->
f->keys(o);
123 values->
f->
smash(&values);
126 values = o->
f->values(o);
134 st->
f->set(st,
"SHEEPY MERGED");
135 oM->
f->set(oM,
"str", (
baset *) st);
163 o->
f->merge(o, NULL);
173 st->
f->set(st,
"SHEEPY MERGED");
174 oM->
f->set(oM,
"str", (
baset *) st);
176 oM->
f->set(oM,
"u2", (
baset *) oU);
206 o->
f->append(o, NULL);
226 o->
f->set(o,
"u", (
baset *)oU);
229 o->
f->set(o,
"str", (
baset *) st);
232 o->
f->set(o,
"b", (
baset *)oBool2);
235 o->
f->set(o,
"B", (
baset *)oBool2);
239 s = (
char *)o->
f->typeString(o,
"b");
247 c = o->
f->type(o,
"str");
260 oT = oM->
f->typeStrings(oM);
274 START_TEST(cSmallJsonT)
291 oInt->
f->set(oInt, 123);
308 oInt2->
f->set(oInt2, 123);
328 oInt3->f->set(oInt3, 123);
340 oInt->
f->set(oInt, 123);
341 o->
f->push(o, (
baset*)oInt);
352 oInt->
f->set(oInt, 123);
353 o->
f->set(o,
"in", (
baset*)oInt);
365 oInt->
f->set(oInt, 123);
366 o->
f->push(o, (
baset*)oInt);
376 oInt->
f->set(oInt, 123);
377 o->
f->set(o,
"in", (
baset*)oInt);
386 o->
f->setTypeUndefined(o);
388 o->
f->setTypeBool(o);
390 o->
f->setTypeDouble(o);
394 o->
f->setTypeString(o);
396 o->
f->setTypeDict(o);
398 o->
f->setTypeArray(o);
418 o->
f->setTop(o, (
baset *)jUndef);
433 s = o->
f->stringify(o,2);
437 s = o->
f->toYML(o,2);
465 s = o->
f->stringify(o,2);
469 s = o->
f->toYML(o,2);
482 o->
f->setTop(o, (
baset *)jDouble);
497 s = o->
f->stringify(o,2);
501 s = o->
f->toYML(o,2);
514 o->
f->setTop(o, (
baset *)jInt);
529 s = o->
f->stringify(o,2);
533 s = o->
f->toYML(o,2);
562 s = o->
f->stringify(o,2);
566 s = o->
f->toYML(o,2);
594 s = o->
f->stringify(o,2);
598 s = o->
f->toYML(o,2);
626 s = o->
f->stringify(o,2);
630 s = o->
f->toYML(o,2);
644 oD2->f->set(oD2,
"int", (
baset *)in2);
647 oD2->f->set(oD2,
"int2", (
baset *)in2);
653 oTA2->f->push(oTA2, (
baset *)in2);
656 oTA2->f->push(oTA2, (
baset *)in2);
690 jpath.f->parse(&
jpath,
"{ \"a\": {\"a\": true}, \"b\": 234, \"c\": [\"qwe\",32]}");
711 jpath.f->parse(&
jpath,
"[1,{\"a\": {\"a\": true}, \"b\": 234, \"c\": [\"qwe\",32]}, [[11],22,33]]");
776 o->
f->setTypeUndefined(o);
778 o->
f->setTypeBool(o);
780 o->
f->setTypeDouble(o);
784 o->
f->setTypeString(o);
786 o->
f->setTypeDict(o);
788 o->
f->setTypeArray(o);
795 o->
f->setTypeString(o);
800 o->
f->setTypeDict(o);
802 o->
f->set(o,
"wer", (
baset *)in);
806 o->
f->setTypeArray(o);
808 o->
f->push(o, (
baset *)in);
816 jString->
f->set(jString,
"sheepy");
827 jString->
f->set(jString,
"sheepy");
828 jdict->
f->set(jdict,
"string", (
baset *) jString);
831 jdict->
f->set(jdict,
"container", (
baset *) jcontainer);
837 jString->
f->set(jString,
"sheepy");
838 jArray->
f->push(jArray, (
baset *) jString);
841 jArray->
f->push(jArray, (
baset *) jcontainer);
847 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");
851 s = json2->f->stringify(json2, 2);
856 jString->
f->set(jString,
"sheepy");
857 json2->f->set(json2,
"s", (
baset *) jString);
860 json2->f->set(json2,
"d",(
baset *) jdict);
863 json2->f->set(json2,
"a", (
baset *) jArray);
867 jString->
f->set(jString,
"sheepy");
868 jdict->
f->set(jdict,
"string", (
baset *) jString);
871 jdict->
f->set(jdict,
"container", (
baset *) jcontainer);
873 json2->f->set(json2,
"d2",(
baset *) jdict);
877 jString->
f->set(jString,
"sheepy");
878 jArray->
f->push(jArray, (
baset *) jString);
881 jArray->
f->push(jArray, (
baset *) jcontainer);
883 json2->f->set(json2,
"a2", (
baset *) jArray);
886 oInt4->
f->set(oInt4, 345);
887 json2->f->set(json2,
"int", (
baset *) oInt4);
889 s = json2->f->stringify(json2, 2);
890 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");
895 ck_assert_str_eq(s,
"---\n - 345\n - sheepy\n - {}\n - []\n - string: sheepy\n container: \"<data container>\"\n - - sheepy\n - \"<data container>\"\n");
899 s = json3->f->toYML(json3, 2);
904 s = json2->f->toYML(json2, 2);
905 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");
942 ck_assert_str_eq(s,
"{\"dasd\":\"asd\",\"asd\":234,\"dict\":{\"array\":[1,1],\"asd\":true,\"float\":3.434000e+01},\"bool\":false,\"zzz\":null}");
949 jsonText =
join(file,
"\n");
953 ck_assert_str_eq(s,
"[\"asd\",234,{\"array\":[1,1],\"asd\":true,\"float\":3.434000e+01}]");
960 json->f->parse(
json,
"{\"wef\": {");
967 json->f->parse(
json,
"{\"wef\": [");
974 json->f->parse(
json,
"{\"wef\": \"wer");
1004 jsonText =
join(file,
"\n");
1008 ck_assert_str_eq(s,
"{\"dict\":{\"array\":[1,1],\"float\":3.434000e+01,\"asd\":true},\"dasd\":\"asd\",\"asd\":234,\"bool\":false,\"zzz\":null}");
1015 jsonText =
join(file,
"\n");
1020 ck_assert_str_eq(s,
"[{\"dict\":\"hello\",\"array\":[1,1],\"float\":3.434000e+01,\"asd\":true},\"asd\",234]");
1031 o->
f->setTop(o, (
baset *)jcontainer);
1036 o->
f->setTop(o, (
baset *)oU);
1038 B = o->
f->serial(o);
1043 o->
f->deserial(o, B);
1052 o->
f->setTop(o, (
baset *)oBool);
1054 B = o->
f->serial(o);
1058 o->
f->deserial(o, B);
1067 o->
f->setTop(o, (
baset *)od);
1069 B = o->
f->serial(o);
1073 o->
f->deserial(o, B);
1082 o->
f->setTop(o, (
baset *)oInt);
1084 B = o->
f->serial(o);
1088 o->
f->deserial(o, B);
1097 o->
f->setTop(o, (
baset *)st);
1099 B = o->
f->serial(o);
1103 o->
f->deserial(o, B);
1112 o->
f->setTop(o, (
baset *)sDD);
1114 B = o->
f->serial(o);
1118 o->
f->deserial(o, B);
1127 o->
f->setTop(o, (
baset *)sAA);
1129 B = o->
f->serial(o);
1133 o->
f->deserial(o, B);
1145 o->
f->deserial(o, B);
1152 o->
f->deserial(o, B);
1158 o->
f->setTypeUndefined(o);
1162 o->
f->deserial(o, NULL);
1175 o->
f->setTypeUndefined(o);
1180 o->
f->setTypeBool(o);
1185 o->
f->setTypeDouble(o);
1190 o->
f->setTypeInt(o);
1195 o->
f->setTypeString(o);
1200 o->
f->setTypeDict(o);
1205 o->
f->setTypeArray(o);
1212 START_TEST(cSmallArrayT)
1228 oInt->
f->set(oInt, 123);
1232 oStr->
f->set(oStr,
"sheepy");
1241 o2->
f->delElem(o2, 0);
1265 o2->
f->delElem(o2, 0);
1271 r =
strEq(st->
f->get(st),
"sheepy");
1281 o->
f->fromArray(o, (
void *)array, 3);
1294 o->
f->fromArray(o, (
void *)arrayNULL, 3);
1306 o->
f->fromArray(o, shpList, 0);
1310 o->
f->fromArray(o, (
void *)arrayNULL, 3);
1311 o->
f->fromArray(o, NULL, 3);
1325 in->
f->set(in, 654);
1326 o->
f->push(o, (
baset *)in);
1333 o->
f->push(o, NULL);
1363 in->value->value = 789;
1364 o2->
f->setAt(o2, 1, (
baset *)in);
1366 o->
f->append(o, o2);
1380 in->value->value = 789;
1381 o2->
f->setAt(o2, 1, (
baset *)in);
1383 o->
f->append(o, o2);
1389 o->
f->append(o, o2);
1395 o->
f->append(o, o2);
1401 o->
f->append(o, NULL);
1409 in->
f->set(in, 5345);
1410 o->
f->push(o, (
baset *) in);
1412 o->
f->slice(o,1,-1);
1420 in->
f->set(in, 5345);
1421 o->
f->push(o, (
baset *) in);
1423 o->
f->slice(o,20,-1);
1431 in->
f->set(in, 5345);
1432 o->
f->push(o, (
baset *) in);
1434 o->
f->slice(o,-20,1);
1442 in->
f->set(in, 5345);
1443 o->
f->push(o, (
baset *) in);
1445 o->
f->slice(o,2,40);
1453 in->
f->set(in, 5345);
1454 o->
f->push(o, (
baset *) in);
1456 o->
f->slice(o,2,-40);
1464 in->
f->set(in, 5345);
1465 o->
f->push(o, (
baset *) in);
1475 in->
f->set(in, 5345);
1476 o->
f->push(o, (
baset *) in);
1478 o->
f->slice(o,-1,0);
1486 in->
f->set(in, 5345);
1487 o->
f->push(o, (
baset *) in);
1505 in->value->value = 789;
1506 o2->
f->setAt(o2, 1, (
baset *)in);
1508 o->
f->insert(o, 0, o2);
1518 in->value->value = 789;
1519 o2->
f->setAt(o2, 1, (
baset *)in);
1521 o->
f->insert(o, -1, o2);
1531 in->value->value = 789;
1532 o2->
f->setAt(o2, 1, (
baset *)in);
1534 o->
f->insert(o, 3, o2);
1544 in->value->value = 789;
1545 o2->
f->setAt(o2, 1, (
baset *)in);
1547 o->
f->insert(o, 4, o2);
1551 o->
f->insert(o, -5, o2);
1561 in->value->value = 789;
1562 o2->
f->setAt(o2, 1, (
baset *)in);
1564 o->
f->delElem(o, 1);
1565 o->
f->delElem(o, 2);
1567 o->
f->insert(o, -1, o2);
1577 in->value->value = 789;
1578 o2->
f->setAt(o2, 1, (
baset *)in);
1580 o->
f->insert(o, 0, o2);
1588 o->
f->insert(o, 0, o2);
1596 o->
f->insert(o, 0, NULL);
1604 in->
f->set(in, 5345);
1605 o->
f->push(o, (
baset *) in);
1615 in->
f->set(in, 5345);
1616 o->
f->push(o, (
baset *) in);
1626 in->
f->set(in, 5345);
1627 o->
f->push(o, (
baset *) in);
1637 in->
f->set(in, 5345);
1638 o->
f->push(o, (
baset *) in);
1648 in->
f->set(in, 5345);
1649 o->
f->push(o, (
baset *) in);
1659 in->
f->set(in, 5345);
1660 o->
f->push(o, (
baset *) in);
1670 in->
f->set(in, 5345);
1671 o->
f->push(o, (
baset *) in);
1681 in->
f->set(in, 5345);
1682 o->
f->push(o, (
baset *) in);
1703 o->f->delElem(o, 0);
1732 o->f->setAt(o, 0, (
baset *) in);
1738 o->f->setAt(o, -1, (
baset *) in);
1744 o->f->setAt(o, 4, (
baset *) in);
1748 o->f->setAt(o, -4, (
baset *) in);
1769 o->f->push(o, (
baset *)oU);
1772 o->f->push(o, (
baset *)oInt);
1775 o->f->push(o, (
baset *)oStr);
1777 o->f->push(o, NULL);
1779 s = (
char *)o->f->typeString(o, 0);
1782 char c = o->f->
type(o, 2);
1785 c = o->f->type(o, -2);
1791 c = o->f->type(o, 0);
1796 const char **
l = o->f->typeStrings(o);
1825 START_TEST(cUndefinedT)
1852 START_TEST(cSmallBytesT)
1875 char *r = obj3->
f->get(obj3);
1880 obj3->
f->push(obj3, 4);
1881 r = obj3->
f->get(obj3);
1886 char c = obj3->
f->getAt(obj3,0);
1888 c = obj3->
f->getAt(obj3,1);
1893 c = obj3->
f->getAt(obj3,0);
1925 execO(
"ls libsheepyObjectTest.c", l, NULL);
1931 execO(
"randomComand", l, NULL);
1940 START_TEST(walkDirOT)
1963 START_TEST(expandHomeOT)
1967 v->f->set(v,
"sheepy");
1983 v->f->set(v,
"../dirTest.null");
1986 bool r = (size_t)
findS(s,
"dirTest.null");
1993 n->f->set(n,
"RandomNonExistingDir");
2003 START_TEST(fileExistsOT)
2006 char **l =
listCreateS(
"../libsheepyTest.c",
"wefwepfk34.c",
"../../src",
"");
2007 sA->f->fromArrayNFree(sA, l, 0);
2013 S = sA->
f->getAtSmallString(sA, 1);
2017 S = sA->
f->getAtSmallString(sA, 2);
2021 S = sA->
f->getAtSmallString(sA, 3);
2031 START_TEST(fileChmodOT)
2035 v->f->set(v,
"../chmodTest.null");
2036 ck_assert(
fileChmodO(v, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH));
2040 n->f->set(n,
"qweqwe_null");
2055 START_TEST(fileSizeOT)
2059 s->f->set(s,
"../sizeTest.null");
2063 v->f->set(v,
"../chmodTest.null");
2067 n->f->set(n,
"qweqwe_null");
2083 START_TEST(mkdirParentsOT)
2088 s->f->set(s,
"mkdirTest.null/null");
2092 v->f->set(v,
"/usr/null");
2111 s->f->set(s,
"rmAllTest.null/null");
2120 v->f->set(v,
"/var/lock");
2137 s->f->set(s,
"../chmodTest.null");
2138 d->
f->set(
d,
"../copyTest.null");
2165 START_TEST(randomSOT)
2179 START_TEST(randomAlphaNumSOT)
2193 START_TEST(readLineOT)
2199 fp = fopen("../textTest.
null", "r");
2205 fp = fopen("../chmodTest.null", "r");
2217 START_TEST(toSmalltT)
2231 s->f->
set(s, "sheepy");
2248 s->f->
set(s, "sheepy");
2275 START_TEST(toBasetT)
2286 free(c->data->data);
2347 s = suite_create(
"libsheepy");
2350 tc_core = tcase_create(
"Object");
2356 tcase_add_test(tc_core, cSmallDictT);
2357 tcase_add_test(tc_core, cSmallJsonT);
2358 tcase_add_test(tc_core, cSmallArrayT);
2359 tcase_add_test(tc_core, cUndefinedT);
2360 tcase_add_test(tc_core, cSmallBytesT);
2361 tcase_add_test(tc_core, putsOT);
2362 tcase_add_test(tc_core, execOT);
2363 tcase_add_test(tc_core, walkDirOT);
2364 tcase_add_test(tc_core, expandHomeOT);
2365 tcase_add_test(tc_core, chDirOT);
2366 tcase_add_test(tc_core, fileExistsOT);
2367 tcase_add_test(tc_core, fileChmodOT);
2368 tcase_add_test(tc_core, fileSizeOT);
2369 tcase_add_test(tc_core, mkdirParentsOT);
2370 tcase_add_test(tc_core, rmAllOT);
2371 tcase_add_test(tc_core, copyOT);
2372 tcase_add_test(tc_core, randomSOT);
2373 tcase_add_test(tc_core, randomAlphaNumSOT);
2374 tcase_add_test(tc_core, readLineOT);
2375 tcase_add_test(tc_core, toSmalltT);
2376 tcase_add_test(tc_core, toBasetT);
2379 suite_add_tcase(s, tc_core);
2390 sr = srunner_create(s);
2392 srunner_run_all(sr, CK_NORMAL);
2393 number_failed = srunner_ntests_failed(sr);
2396 exit((number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
smallIntt * allocSmallInt(int64_t value)
int copyO(smallStringt *src, smallStringt *dst)
copy files recursively
ck_assert_int_eq(execO(NULL, NULL, NULL), 0)
createAllocateSmallJson(obj2)
oBool2 f set(oBool2, true)
char * sToString(smallt *obj)
stringify object
initiateAllocateSmallInt & oInt2
initiateAllocateSmallInt & oInt
smallStringt * getCwdO(void)
jpath f parse &[\"qwe\,32] jpath
sStringt * allocSStringTiny(const char *data)
allocate a small string
#define ssGet(obj)
get a pointer to the string in the smallString object
ck_assert_uint_eq(o->f->len(o), 0)
sIntt * allocSInt(int64_t value)
allocate a small int
execO("ls libsheepyObjectTest.c", l, NULL)
char * joinCS(const char **list, const char *delim)
join list, the elements are seperated with delim in the resulting string
createAllocateSmallInt(oInt)
smallBoolt * allocSmallBool(bool value)
char * getCwd(void)
get current working directory
int mkdirParentsO(smallStringt *path)
void sBytesPush(sBytest **bytes, char data)
push char to bytes
END_TEST pError0(rmAll("mkdirTest.null/null"))
createAllocateSmallBytes(obj2)
ck_assert_str_eq(obj.type, "smallDict")
#define null
convenience defines
sBytest * sSerial(smallt *obj)
serialize object to small bytes
void initiateAllocateSmallJson(smallJsont **self)
END_TEST Suite * libsheepySuite(void)
base class for the small objects all small objects have a type
sBytest * allocSBytes(void)
allocate a small bytes object
ssize_t fileSizeO(smallStringt *filePath)
smallArrayt * allocSmallArray(void)
int rmAll(const char *path)
remove all delete recursively files and directories
void setLogMode(int mode)
set log mode LOG_VERBOSE, LOG_CONCISE, .
void sArrayPushTiny(sArrayt **array, smallt *data)
push data to array
void initiateAllocateSmallInt(smallIntt **self)
#define isOType(obj, className)
test obj type
smallStringFunctionst * f
obj2 f push(obj2,(baset *) oInt)
bool fileExistsO(smallStringt *filePath)
pErrorNULL(iPrependS(&ks, "[1]"))
createAllocateSmallString(oStr)
char ** readText(const char *filePath)
return text from filePath in a list new line characters are removed
sContainert * allocSContainer(void *data)
allocate a small container The container holds a pointer to a user buffer
initiateAllocateSmallString & jString
bool fileChmodO(smallStringt *filePath, mode_t mode)
sUndefinedt * allocSUndefined(void)
allocate a small undefined object
smallArrayt * walkDirO(const char *dirPath)
list all files in a directory recursively the directories are not listed
createAllocateSmallBool(oBool2)
createAllocateSmallDict(obj2)
char * iPrependS(char **string1, const char *string2)
prepend strings
END_TEST createSmallJson(obj)
initiateAllocateSmallInt & oInt4
bool fileChmod(const char *filePath, mode_t mode)
like chmod in stdlibc but return true/false
char * join(char **list, const char *delim)
join list, the elements are seperated with delim in the resulting string when updating this function...
void initiateAllocateSmallDict(smallDictt **self)
#define toStringO(obj)
convert data in obj to string
initiateAllocateUndefined & oU
int main(int ARGC UNUSED, char **ARGV UNUSED)
ck_assert_ptr_ne(oBool3, NULL)
initiateAllocateSmallDict & jdict
#define LOG_VERBOSE
LOG MODES when a new mode is added, add symbols in log_tags in libsheepy.c.
randomUrandomClose()
close /dev/urandom in libsheepy call this function when random are not needed anymore ...
sDictt * allocSDict(void)
allocate a small dict
char * findS(const char *string, const char *needle)
find String
void initiateAllocateSmallString(smallStringt **self)
smallt * sDictGetTiny(sDictt *dict, const char *key)
get object stored at key
int mkdirParents(const char *path)
recursive mkdir
baset * toBaset(smallt *obj)
convert smallt object to baset
void sDictPushTiny(sDictt **dict, const char *key, smallt *data)
push new key-value
sDoublet * allocSDouble(double value)
allocate a small double
END_TEST createUndefined(obj)
ck_assert(oBool3->value->value==true)
smallBytest * allocSmallBytes(void *data, uint32_t size)
ck_assert_ptr_eq(o, NULL)
smallDictt * allocSmallDict(void)
toStringSmallArrayFt toString
END_TEST createSmallArray(obj)
smallStringt * randomAlphaNumSO(uint64_t length)
initiateAllocateSmallArray(NULL)
initiateAllocateSmallJson & json
smallStringt * readLineO(FILE *fp)
END_TEST createSmallBytes(obj)
createAllocateSmallArray(jArray)
createAllocateSmallDouble(jDouble)
createAllocateUndefined(oU)
char * sToStringTiny(smallt *obj)
stringify a small object
void initiateAllocateSmallContainer(smallContainert **self)
#define isSType(obj, sType)
true when object is type sType
undefinedt * allocUndefined(void)
void initiateAllocateSmallBytes(smallBytest **self)
initiateAllocateSmallContainer & jcontainer
initiateAllocateSmallJson & jsOfromF
smallStringt * randomSO(uint64_t length)
smallt * toSmallt(baset *obj)
convert baset object to smallt
createAllocateSmallContainer(jcontainer)
sBoolt * allocSBool(bool value)
allocate a small bool
smallStringt * allocSmallString(const char *string)
smallDoublet * allocSmallDouble(double value)
smallt * sArrayGetTiny(sArrayt *array, uint32_t index)
get object at index
bool fileExists(const char *filePath)
detect files and directories
size_t listLengthS(char **list)
list Length String return number of elements until the first NULL element
duplicateSmallArrayFt duplicate
sArrayt * allocSArray(void)
allocate a small array
int rmAllO(smallStringt *path)
void initiateAllocateUndefined(undefinedt **self)
#define duplicateO(obj)
create a copy of obj