commit d3a05853f0ced8036098d94219bbbb3c4bd16b6c
parent 9be00f858a789f8b2f01a6427430e6475f40e28c
Author: Remy Noulin <loader2x@gmail.com>
Date: Tue, 12 May 2020 12:29:01 +0200
add CuTest for libsheepy.c
.gitignore | 3 +
src/CuTest/CuTest.c | 123 +-
src/CuTest/CuTest.h | 47 +-
src/libsheepyCuTest.c | 9073 +++++++++++++++++++++++++++++++++++++++++++++++++
src/runCuTest.sh | 9 +
5 files changed, 9222 insertions(+), 33 deletions(-)
Diffstat:
5 files changed, 9222 insertions(+), 33 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,3 +1,4 @@
+*.gch
*.dSYM
*.sw*
.gdb_history
@@ -10,6 +11,7 @@ readme
showdir
sumNums
cfp
+libsheepyCuTest
example/search
example/regexDemo
example/dmce
@@ -39,6 +41,7 @@ example/mve
example/logging
example/threads
utils/runMemtest
+utils/genCuTest
utils/reference
a
*.o
diff --git a/src/CuTest/CuTest.c b/src/CuTest/CuTest.c
@@ -165,7 +165,7 @@ void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, c
CuString string;
CuStringInit(&string);
- if (message2 != NULL)
+ if (message2 != NULL)
{
CuStringAppend(&string, message2);
CuStringAppend(&string, ": ");
@@ -180,7 +180,7 @@ void CuAssert_Line(CuTest* tc, const char* file, int line, const char* message,
CuFail_Line(tc, file, line, NULL, message);
}
-void CuAssertStrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
+void CuAssertStrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
const char* expected, const char* actual)
{
CuString string;
@@ -192,7 +192,7 @@ void CuAssertStrEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
}
CuStringInit(&string);
- if (message != NULL)
+ if (message != NULL)
{
CuStringAppend(&string, message);
CuStringAppend(&string, ": ");
@@ -205,34 +205,16 @@ void CuAssertStrEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
CuFailInternal(tc, file, line, &string);
}
-void CuAssertIntEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
- int expected, int actual)
-{
- char buf[STRING_MAX];
- if (expected == actual) return;
- sprintf(buf, "expected <%d> but was <%d>", expected, actual);
- CuFail_Line(tc, file, line, message, buf);
-}
-
-void CuAssertDblEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
+void CuAssertDblEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
double expected, double actual, double delta)
{
char buf[STRING_MAX];
if (fabs(expected - actual) <= delta) return;
- sprintf(buf, "expected <%f> but was <%f>", expected, actual);
+ sprintf(buf, "expected <%f> but was <%f>", expected, actual);
CuFail_Line(tc, file, line, message, buf);
}
-void CuAssertPtrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
- void* expected, void* actual)
-{
- char buf[STRING_MAX];
- if (expected == actual) return;
- sprintf(buf, "expected pointer <0x%p> but was <0x%p>", expected, actual);
- CuFail_Line(tc, file, line, message, buf);
-}
-
/*-------------------------------------------------------------------------*
* CuSuite
@@ -340,3 +322,98 @@ void CuSuiteDetails(CuSuite* testSuite, CuString* details)
CuStringAppendFormat(details, "Fails: %d\n", testSuite->failCount);
}
}
+
+
+/*-------------------------------------------------------------------------*
+ * CuTest changes by Remy Noulin
+ *-------------------------------------------------------------------------*/
+
+
+void CuAssertStrNotEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
+ const char* expected, const char* actual)
+{
+ CuString string;
+ if ((expected == NULL && actual == NULL) ||
+ (expected != NULL && actual != NULL &&
+ strcmp(expected, actual) == 0))
+ {
+ CuStringInit(&string);
+ if (message != NULL)
+ {
+ CuStringAppend(&string, message);
+ CuStringAppend(&string, ": ");
+ }
+ CuStringAppend(&string, "expected <");
+ CuStringAppend(&string, expected);
+ CuStringAppend(&string, "> not equal to <");
+ CuStringAppend(&string, actual);
+ CuStringAppend(&string, ">");
+ CuFailInternal(tc, file, line, &string);
+ }
+
+ return;
+}
+
+void CuAssertPtrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
+ const void* expected, const void* actual)
+{
+ char buf[STRING_MAX];
+ if (expected == actual) return;
+ sprintf(buf, "expected pointer <0x%p> but was <0x%p>", expected, actual);
+ CuFail_Line(tc, file, line, message, buf);
+}
+
+void CuAssertPtrNotEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
+ const void* expected, const void* actual)
+{
+ char buf[STRING_MAX];
+ if (expected == actual)
+ {
+ sprintf(buf, "expected pointer <0x%p> not equal to <0x%p>", expected, actual);
+ CuFail_Line(tc, file, line, message, buf);
+ return;
+ }
+}
+
+void CuAssertUintEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
+ uint64_t expected, uint64_t actual)
+{
+ char buf[STRING_MAX];
+ if (expected == actual) return;
+ sprintf(buf, "expected <%d> but was <%d>", expected, actual);
+ CuFail_Line(tc, file, line, message, buf);
+}
+
+void CuAssertUintNotEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
+ uint64_t expected, uint64_t actual)
+{
+ char buf[STRING_MAX];
+ if (expected == actual)
+ {
+ sprintf(buf, "expected <%d> not equal to <%d>", expected, actual);
+ CuFail_Line(tc, file, line, message, buf);
+ return;
+ }
+}
+
+void CuAssertIntEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
+ int64_t expected, int64_t actual)
+{
+ char buf[STRING_MAX];
+ if (expected == actual) return;
+ sprintf(buf, "expected <%d> but was <%d>", expected, actual);
+ CuFail_Line(tc, file, line, message, buf);
+}
+
+void CuAssertIntNotEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
+ int64_t expected, int64_t actual)
+{
+ char buf[STRING_MAX];
+ if (expected == actual)
+ {
+ sprintf(buf, "expected <%d> not equal to <%d>", expected, actual);
+ CuFail_Line(tc, file, line, message, buf);
+ return;
+ }
+}
+
diff --git a/src/CuTest/CuTest.h b/src/CuTest/CuTest.h
@@ -3,6 +3,7 @@
#include <setjmp.h>
#include <stdarg.h>
+#include <stdint.h>
#define CUTEST_VERSION "CuTest 1.5b"
@@ -58,18 +59,31 @@ void CuTestDelete(CuTest *t);
/* Internal versions of assert functions -- use the public versions */
void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, const char* message);
void CuAssert_Line(CuTest* tc, const char* file, int line, const char* message, int condition);
-void CuAssertStrEquals_LineMsg(CuTest* tc,
- const char* file, int line, const char* message,
+void CuAssertStrEquals_LineMsg(CuTest* tc,
+ const char* file, int line, const char* message,
const char* expected, const char* actual);
-void CuAssertIntEquals_LineMsg(CuTest* tc,
- const char* file, int line, const char* message,
- int expected, int actual);
-void CuAssertDblEquals_LineMsg(CuTest* tc,
- const char* file, int line, const char* message,
+void CuAssertDblEquals_LineMsg(CuTest* tc,
+ const char* file, int line, const char* message,
double expected, double actual, double delta);
-void CuAssertPtrEquals_LineMsg(CuTest* tc,
- const char* file, int line, const char* message,
- void* expected, void* actual);
+
+/* Remy Noulin changes */
+void CuAssertIntEquals_LineMsg(CuTest* tc,
+ const char* file, int line, const char* message,
+ int64_t expected, int64_t actual);
+void CuAssertStrNotEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
+ const char* expected, const char* actual);
+void CuAssertPtrEquals_LineMsg(CuTest* tc,
+ const char* file, int line, const char* message,
+ const void* expected, const void* actual);
+void CuAssertPtrNotEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
+ const void* expected, const void* actual);
+void CuAssertUintEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
+ uint64_t expected, uint64_t actual);
+void CuAssertUintNotEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
+ uint64_t expected, uint64_t actual);
+void CuAssertIntNotEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
+ int64_t expected, int64_t actual);
+/* End Remy Noulin changes */
/* public assert functions */
@@ -89,6 +103,19 @@ void CuAssertPtrEquals_LineMsg(CuTest* tc,
#define CuAssertPtrNotNull(tc,p) CuAssert_Line((tc),__FILE__,__LINE__,"null pointer unexpected",((p) != NULL))
#define CuAssertPtrNotNullMsg(tc,msg,p) CuAssert_Line((tc),__FILE__,__LINE__,(msg),((p) != NULL))
+/* Remy Noulin changes */
+#define CuAssertStrNotEquals(tc,ex,ac) CuAssertStrNotEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
+#define CuAssertStrNotEquals_Msg(tc,ms,ex,ac) CuAssertStrNotEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
+#define CuAssertUintEquals(tc,ex,ac) CuAssertUintEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
+#define CuAssertUintEquals_Msg(tc,ms,ex,ac) CuAssertUintEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
+#define CuAssertUintNotEquals(tc,ex,ac) CuAssertUintNotEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
+#define CuAssertUintNotEquals_Msg(tc,ms,ex,ac) CuAssertUintNotEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
+#define CuAssertIntNotEquals(tc,ex,ac) CuAssertIntNotEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
+#define CuAssertIntNotEquals_Msg(tc,ms,ex,ac) CuAssertIntNotEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
+#define CuAssertPtrNotEquals(tc,ex,ac) CuAssertPtrNotEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
+#define CuAssertPtrNotEquals_Msg(tc,ms,ex,ac) CuAssertPtrNotEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
+/* End Remy Noulin changes */
+
/* CuSuite */
#define MAX_TEST_CASES 1024
diff --git a/src/libsheepyCuTest.c b/src/libsheepyCuTest.c
@@ -0,0 +1,9073 @@
+#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"
+
+// TODO redirect stderr
+
+void setLogFileT(CuTest *tc) {
+
+ FILE *f;
+
+ // open log file
+ f = setLogFile("test.log");
+ ck_assert_ptr_ne(f, NULL);
+
+ // read only location
+ f = setLogFile("/test.log");
+ ck_assert_ptr_eq(f, NULL);
+
+ // open all log slots
+ f = setLogFile("test1.log");
+ ck_assert_ptr_ne(f, NULL);
+
+ f = setLogFile("test2.log");
+ ck_assert_ptr_ne(f, NULL);
+
+ f = setLogFile("test3.log");
+ ck_assert_ptr_ne(f, NULL);
+
+ f = setLogFile("test4.log");
+ ck_assert_ptr_ne(f, NULL);
+
+ f = setLogFile("test5.log");
+ ck_assert_ptr_ne(f, NULL);
+
+ f = setLogFile("test6.log");
+ ck_assert_ptr_ne(f, NULL);
+
+ f = setLogFile("test7.log");
+ ck_assert_ptr_ne(f, NULL);
+
+ f = setLogFile("test8.log");
+ ck_assert_ptr_ne(f, NULL);
+
+ f = setLogFile("test9.log");
+ ck_assert_ptr_ne(f, NULL);
+
+ f = setLogFile("test10.log");
+ ck_assert_ptr_ne(f, NULL);
+
+ f = setLogFile("test11.log");
+ ck_assert_ptr_ne(f, NULL);
+
+ f = setLogFile("test12.log");
+ ck_assert_ptr_ne(f, NULL);
+
+ f = setLogFile("test13.log");
+ ck_assert_ptr_ne(f, NULL);
+
+ f = setLogFile("test14.log");
+ ck_assert_ptr_ne(f, NULL);
+
+ f = setLogFile("test15.log");
+ ck_assert_ptr_eq(f, NULL);
+
+ closeLogFiles();
+ rmAll("test1.log");
+ rmAll("test2.log");
+ rmAll("test3.log");
+ rmAll("test4.log");
+ rmAll("test5.log");
+ rmAll("test6.log");
+ rmAll("test7.log");
+ rmAll("test8.log");
+ rmAll("test9.log");
+ rmAll("test10.log");
+ rmAll("test11.log");
+ rmAll("test12.log");
+ rmAll("test13.log");
+ rmAll("test14.log");
+
+ // NULL
+ ck_assert_ptr_eq(setLogFile(NULL), NULL);
+
+}
+
+
+void closeLogFilesT(CuTest *tc) {
+
+ closeLogFiles();
+ closeLogFiles();
+
+}
+
+
+void getLogModeT(CuTest *tc) {
+
+ ck_assert_int_eq(getLogMode(), LOG_DATE);
+
+}
+
+
+void setLogModeT(CuTest *tc) {
+
+ // set mode
+ setLogMode(LOG_CONCISE);
+ ck_assert_int_eq(getLogMode(), LOG_CONCISE);
+
+ setLogMode(LOG_DATE);
+ ck_assert_int_eq(getLogMode(), LOG_DATE);
+
+ setLogMode(LOG_FUNC);
+ ck_assert_int_eq(getLogMode(), LOG_FUNC);
+
+ setLogMode(LOG_PROG);
+ ck_assert_int_eq(getLogMode(), LOG_PROG);
+
+ setLogMode(LOG_PROGNDATE);
+ ck_assert_int_eq(getLogMode(), LOG_PROGNDATE);
+
+ setLogMode(LOG_VOID);
+ ck_assert_int_eq(getLogMode(), LOG_VOID);
+
+ setLogMode(LOG_UTF8);
+ ck_assert_int_eq(getLogMode(), LOG_UTF8);
+
+ setLogMode(LOG_VERBOSE);
+ ck_assert_int_eq(getLogMode(), LOG_VERBOSE);
+
+ // set invalid value
+ setLogMode(LOG_CONCISE+10);
+ ck_assert_int_eq(getLogMode(), LOG_VERBOSE);
+
+ // invalid log mode
+ setLogMode(-1);
+ setLogMode(LOG_INVALID_MODE);
+
+}
+
+
+void _pLogT(CuTest *tc) {
+
+ setLogFile("test.log");
+
+ // default log mode
+ puts("Default mode");
+ pLog(LOG_CRITICAL, "pLog test");
+ pLog(LOG_ERROR, "pLog test");
+ pLog(LOG_WARNING, "pLog test");
+ pLog(LOG_INFO, "pLog test\nmultiline");
+ pLog(LOG_PASS, "pLog test");
+ // invalid log level
+ pLog(LOG_INFO+20, "pLog test");
+ pLog(-1, "pLog test");
+
+ // concise mode
+ puts("LOG_CONCISE mode");
+ setLogMode(LOG_CONCISE);
+ pLog(LOG_CRITICAL, "pLog test");
+ pLog(LOG_ERROR, "pLog test");
+ pLog(LOG_WARNING, "pLog test");
+ pLog(LOG_INFO, "pLog test");
+ pLog(LOG_PASS, "pLog test");
+ // invalid log level
+ pLog(LOG_INFO+20, "pLog test");
+
+ // verbose mode
+ puts("LOG_VERBOSE mode");
+ setLogMode(LOG_VERBOSE);
+ pLog(LOG_CRITICAL, "pLog test");
+ pLog(LOG_ERROR, "pLog test");
+ pLog(LOG_WARNING, "pLog test");
+ pLog(LOG_INFO, "pLog test");
+ pLog(LOG_PASS, "pLog test");
+ // invalid log level
+ pLog(LOG_INFO+20, "pLog test");
+
+ // date mode
+ puts("LOG_DATE mode");
+ setLogMode(LOG_DATE);
+ pLog(LOG_CRITICAL, "pLog test");
+ pLog(LOG_ERROR, "pLog test");
+ pLog(LOG_WARNING, "pLog test");
+ pLog(LOG_INFO, "pLog test");
+ pLog(LOG_PASS, "pLog test");
+ // invalid log level
+ pLog(LOG_INFO+20, "pLog test");
+
+ // function mode
+ puts("LOG_FUNC mode");
+ setLogMode(LOG_FUNC);
+ pLog(LOG_CRITICAL, "pLog test");
+ pLog(LOG_ERROR, "pLog test");
+ pLog(LOG_WARNING, "pLog test");
+ pLog(LOG_INFO, "pLog test");
+ pLog(LOG_PASS, "pLog test");
+ // invalid log level
+ pLog(LOG_INFO+20, "pLog test");
+
+ // program name mode
+ puts("LOG_PROG mode");
+ setLogMode(LOG_PROG);
+ pLog(LOG_CRITICAL, "pLog test");
+ pLog(LOG_ERROR, "pLog test");
+ pLog(LOG_WARNING, "pLog test");
+ pLog(LOG_INFO, "pLog test");
+ pLog(LOG_PASS, "pLog test");
+ // invalid log level
+ pLog(LOG_INFO+20, "pLog test");
+
+ // program name and date mode
+ puts("LOG_PROGNDATE mode");
+ setLogMode(LOG_PROGNDATE);
+ pLog(LOG_CRITICAL, "pLog test");
+ pLog(LOG_ERROR, "pLog test");
+ pLog(LOG_WARNING, "pLog test");
+ pLog(LOG_INFO, "pLog test");
+ pLog(LOG_PASS, "pLog test");
+ // invalid log level
+ pLog(LOG_INFO+20, "pLog test");
+
+ // void mode
+ puts("LOG_VOID mode");
+ setLogMode(LOG_VOID);
+ pLog(LOG_CRITICAL, "pLog test");
+ pLog(LOG_ERROR, "pLog test");
+ pLog(LOG_WARNING, "pLog test");
+ pLog(LOG_INFO, "pLog test");
+ pLog(LOG_PASS, "pLog test");
+ // invalid log level
+ pLog(LOG_INFO+20, "pLog test");
+
+ // void mode
+ puts("LOG_UTF8 mode");
+ setLogMode(LOG_UTF8);
+ pLog(LOG_CRITICAL, "pLog test");
+ pLog(LOG_ERROR, "pLog test");
+ pLog(LOG_WARNING, "pLog test");
+ pLog(LOG_INFO, "pLog test");
+ pLog(LOG_PASS, "pLog test");
+ // invalid log level
+ pLog(LOG_INFO+20, "pLog test");
+
+ closeLogFiles();
+ rmAll("test.log");
+
+}
+
+
+void initTest(void) { }
+
+
+void initLibsheepyFT(CuTest *tc) {
+
+ // regular program
+ initLibsheepy("test");
+
+ // program compiled with sheepy with init function
+ initLibsheepyF("/.sheepy/build/test", initTest);
+
+}
+
+
+void getProgPathT(CuTest *tc) {
+
+ const char *s;
+
+ // getProgPath stored prog path
+ s = getProgPath();
+ ck_assert_ptr_ne(s, NULL);
+
+ initLibsheepy("test");
+
+ // getProgPath stored prog path
+ s = getProgPath();
+ ck_assert_str_eq(s, "test");
+
+ // program compiled with sheepy with init function
+ initLibsheepyF("/.sheepy/build/test", initTest);
+
+ // getProgPath stored prog path
+ s = getProgPath();
+ ck_assert_str_eq(s, "/test");
+
+}
+
+
+void getRealProgPathT(CuTest *tc) {
+
+ const char *s;
+
+ // getProgPath real prog path
+ s = getProgPath();
+ ck_assert_ptr_ne(s, NULL);
+
+ initLibsheepy("test");
+
+ s = getRealProgPath();
+ ck_assert_ptr_ne(s, NULL);
+ freeRealProgPath();
+
+}
+
+
+void systemNFreeFT(CuTest *tc) {
+
+ int r;
+
+ // normal command
+ r = systemNFree(strdup("echo TEST"));
+ ck_assert_int_eq(r, 0);
+
+ // NULL
+ r = systemNFree(NULL);
+ ck_assert_int_ne(r, 0);
+
+}
+
+
+void getModificationTimeT(CuTest *tc) {
+
+ // get time
+ ck_assert_int_ne(getModificationTime("libsheepy.c"), 0);
+
+ // missing file
+ ck_assert_int_eq(getModificationTime("nonexistingfile"), 0);
+
+ // NULL
+ ck_assert_int_eq(getModificationTime(NULL), 0);
+
+}
+
+
+void setModificationTimeT(CuTest *tc) {
+
+ time_t t;
+
+ // set time
+ t = getModificationTime("chmodTest.null");
+ ck_assert_int_eq(setModificationTime("chmodTest.null", t), 1);
+
+ // non existing file
+ ck_assert_int_eq(setModificationTime("/chmodTest.null", t), 0);
+
+ // NULL
+ ck_assert_int_eq(setModificationTime(NULL, t), 0);
+
+}
+
+
+void equalModificationTimesT(CuTest *tc) {
+
+ // equal time
+ ck_assert(equalModificationTimes("chmodTest.null", "chmodTest.null"));
+
+ // not equal
+ ck_assert(!equalModificationTimes("chmodTest.null", "libsheepy.c"));
+
+ // non existing
+ ck_assert(!equalModificationTimes("/chmodTest.null", "libsheepy.c"));
+ ck_assert(!equalModificationTimes("chmodTest.null", "/libsheepy.c"));
+
+ // NULL
+ ck_assert(!equalModificationTimes(NULL, "libsheepy.c"));
+ ck_assert(!equalModificationTimes("chmodTest.null", NULL));
+
+}
+
+
+void shDirnameT(CuTest *tc) {
+
+ char *s;
+
+ // path
+ s = shDirname("release/libsheepy.a");
+ ck_assert_str_eq(s, "release");
+ free(s);
+
+ // one item path
+ s = shDirname("sheepy.lib");
+ ck_assert_str_eq(s, "./");
+ free(s);
+
+ // empty
+ s = shDirname(" ");
+ ck_assert_str_eq(s, "./");
+ free(s);
+
+ // NULL
+ ck_assert_ptr_eq(shDirname(NULL), NULL);
+
+}
+
+
+void bDirnameT(CuTest *tc) {
+
+ char s[100] = "release/libsheepy.a";
+
+ // path
+ bDirname(s);
+ ck_assert_str_eq(s, "release");
+
+ // one item path
+ strCpy(s, "sheepy.lib");
+ bDirname(s);
+ ck_assert_str_eq(s, "./");
+
+ // empty
+ strCpy(s, " ");
+ bDirname(s);
+ ck_assert_str_eq(s, "./");
+
+ // NULL
+ ck_assert_ptr_eq(bDirname(NULL), NULL);
+
+}
+
+
+void bLDirnameT(CuTest *tc) {
+
+ char s[100] = "release/libsheepy.a";
+
+ // path
+ bLDirname(s, sizeof s);
+ ck_assert_str_eq(s, "release");
+
+ // buffer shorter than path
+ strcpy(s, "release/anotherdir/libsheepy.a");
+ bLDirname(s, 10);
+ ck_assert_str_eq(s, "release");
+ strcpy(s, "release/anotherdir/libsheepy.a");
+ bLDirname(s, 9);
+ ck_assert_str_eq(s, "release/");
+
+ // one item path
+ strCpy(s, "sheepy.lib");
+ bLDirname(s, sizeof s);
+ ck_assert_str_eq(s, "./");
+
+ // empty
+ strCpy(s, " ");
+ bLDirname(s, sizeof s);
+ ck_assert_str_eq(s, "./");
+
+ // size 0 - no change in s
+ bLDirname(s, 0);
+ ck_assert_str_eq(s, "./");
+
+ // NULL
+ ck_assert_ptr_eq(bLDirname(NULL, 0), NULL);
+
+}
+
+
+void expandHomeT(CuTest *tc) {
+
+ // no ~/
+ char *s;
+ s = expandHome("sheepy");
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // NULL path
+ ck_assert_ptr_eq(expandHome(NULL), NULL);
+
+}
+
+
+void iExpandHomeT(CuTest *tc) {
+
+ // no ~/
+ char *s = strdup("sheepy");
+ iExpandHome(&s);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // NULL path
+ s = NULL;
+ iExpandHome(&s);
+ ck_assert_ptr_eq(s, NULL);
+ // NULL var
+ iExpandHome(NULL);
+
+}
+
+
+void bExpandHomeT(CuTest *tc) {
+
+ // no ~/
+ char s[100] = "sheepy";
+ bExpandHome(s);
+ ck_assert_str_eq(s, "sheepy");
+ // NULL
+ ck_assert_ptr_eq(bExpandHome(NULL), NULL);
+
+}
+
+
+void bLExpandHomeT(CuTest *tc) {
+
+ // no ~/
+ char s[100] = "sheepy";
+ bLExpandHome(s, sizeof s);
+ ck_assert_str_eq(s, "sheepy");
+ // shorter buffer size
+ bLExpandHome(s, 3);
+ ck_assert_str_eq(s, "sh");
+ // size 0
+ bLExpandHome(s, 0);
+ ck_assert_str_eq(s, "sh");
+ // NULL
+ ck_assert_ptr_eq(bLExpandHome(NULL, sizeof s), NULL);
+
+}
+
+
+void normalizePathT(CuTest *tc) {
+
+ // test
+ char *s;
+ s = normalizePath("test/.././file.txt");
+ ck_assert_str_eq(s, "file.txt");
+ free(s);
+ // remove end /
+ s = normalizePath("/home/");
+ ck_assert_str_eq(s, "/home");
+ free(s);
+ // cancel path and keep leading /
+ s = normalizePath("/home/..");
+ ck_assert_str_eq(s, "/");
+ free(s);
+ // cancel path
+ s = normalizePath("home/..");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // multiple /
+ s = normalizePath("/home///stuff");
+ ck_assert_str_eq(s, "/home/stuff");
+ free(s);
+ // remove . and .. and keep leading /
+ s = normalizePath("/a/./b/../../c/");
+ ck_assert_str_eq(s, "/c");
+ free(s);
+ // keep leading /
+ s = normalizePath("/../");
+ ck_assert_str_eq(s, "/");
+ free(s);
+ // keep leading ..
+ s = normalizePath(".././/");
+ ck_assert_str_eq(s, "..");
+ free(s);
+ // remove .
+ s = normalizePath("./");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // keep / before .
+ s = normalizePath("/.");
+ ck_assert_str_eq(s, "/");
+ free(s);
+ // remove .
+ s = normalizePath(".");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // / not changed
+ s = normalizePath("/");
+ ck_assert_str_eq(s, "/");
+ free(s);
+ // // becomes /
+ s = normalizePath("//");
+ ck_assert_str_eq(s, "/");
+ free(s);
+ // remove leading .
+ s = normalizePath("/./werwer");
+ ck_assert_str_eq(s, "/werwer");
+ free(s);
+ // keep leading .. and remove .. in path
+ s = normalizePath(".././test/../test/file");
+ ck_assert_str_eq(s, "../test/file");
+ free(s);
+ s = normalizePath("../d1/./d2/../f1");
+ ck_assert_str_eq(s, "../d1/f1");
+ free(s);
+ s = normalizePath("a/b/c/../d/../e");
+ ck_assert_str_eq(s, "a/b/e");
+ free(s);
+ // dont remove .. when there are only .. in front
+ s = normalizePath("../../test/test/file");
+ ck_assert_str_eq(s, "../../test/test/file");
+ free(s);
+ // empty path
+ s = normalizePath("");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // NULL path
+ ck_assert_ptr_eq(normalizePath(NULL), NULL);
+
+}
+
+
+void iNormalizePathT(CuTest *tc) {
+
+ // test
+ char *s = strdup("test/.././file.txt");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "file.txt");
+ free(s);
+ // remove end /
+ s = strdup("/home/");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "/home");
+ free(s);
+ // cancel path and keep leading /
+ s = strdup("/home/..");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "/");
+ free(s);
+ // cancel path
+ s = strdup("home/..");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // multiple /
+ s = strdup("/home///stuff");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "/home/stuff");
+ free(s);
+ // remove . and .. and keep leading /
+ s = strdup("/a/./b/../../c/");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "/c");
+ free(s);
+ // keep leading /
+ s = strdup("/../");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "/");
+ free(s);
+ // keep leading ..
+ s = strdup(".././/");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "..");
+ free(s);
+ // remove .
+ s = strdup("./");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // keep / before .
+ s = strdup("/.");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "/");
+ free(s);
+ // remove .
+ s = strdup(".");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // / not changed
+ s = strdup("/");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "/");
+ free(s);
+ // // becomes /
+ s = strdup("//");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "/");
+ free(s);
+ // remove leading .
+ s = strdup("/./werwer");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "/werwer");
+ free(s);
+ // keep leading .. and remove .. in path
+ s = strdup(".././test/../test/file");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "../test/file");
+ free(s);
+ s = strdup("../d1/./d2/../f1");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "../d1/f1");
+ free(s);
+ s = strdup("a/b/c/../d/../e");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "a/b/e");
+ free(s);
+ // dont remove .. when there are only .. in front
+ s = strdup("../../test/test/file");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "../../test/test/file");
+ free(s);
+ // empty path
+ s = strdup("");
+ iNormalizePath(&s);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty NULL path
+ s = NULL;
+ ck_assert_ptr_eq(iNormalizePath(&s), NULL);
+ // NULL path
+ ck_assert_ptr_eq(iNormalizePath(NULL), NULL);
+
+}
+
+
+void bNormalizePathT(CuTest *tc) {
+
+ // test
+ char s[100] = "test/.././file.txt";
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "file.txt");
+ // remove end /
+ strcpy(s, "/home/");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "/home");
+ // cancel path and keep leading /
+ strcpy(s, "/home/..");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "/");
+ // cancel path
+ strcpy(s, "home/..");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "");
+ // multiple /
+ strcpy(s, "/home///stuff");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "/home/stuff");
+ // remove . and .. and keep leading /
+ strcpy(s, "/a/./b/../../c/");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "/c");
+ // keep leading /
+ strcpy(s, "/../");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "/");
+ // keep leading ..
+ strcpy(s, ".././/");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "..");
+ // remove .
+ strcpy(s, "./");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "");
+ // keep / before .
+ strcpy(s, "/.");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "/");
+ // remove .
+ strcpy(s, ".");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "");
+ // / not changed
+ strcpy(s, "/");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "/");
+ // // becomes /
+ strcpy(s, "//");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "/");
+ // remove leading .
+ strcpy(s, "/./werwer");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "/werwer");
+ // keep leading .. and remove .. in path
+ strcpy(s, ".././test/../test/file");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "../test/file");
+ strcpy(s, "../d1/./d2/../f1");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "../d1/f1");
+ strcpy(s, "a/b/c/../d/../e");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "a/b/e");
+ // dont remove .. when there are only .. in front
+ strcpy(s, "../../test/test/file");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "../../test/test/file");
+ // empty path
+ strcpy(s, "");
+ bNormalizePath(s);
+ ck_assert_str_eq(s, "");
+ // NULL path
+ ck_assert_ptr_eq(bNormalizePath(NULL), NULL);
+
+}
+
+
+void bLNormalizePathT(CuTest *tc) {
+
+ // test
+ char s[100] = "test/.././file.txt";
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "file.txt");
+ // remove end /
+ strcpy(s, "/home/");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "/home");
+ // cancel path and keep leading /
+ strcpy(s, "/home/..");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "/");
+ // cancel path
+ strcpy(s, "home/..");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "");
+ // multiple /
+ strcpy(s, "/home///stuff");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "/home/stuff");
+ // remove . and .. and keep leading /
+ strcpy(s, "/a/./b/../../c/");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "/c");
+ // keep leading /
+ strcpy(s, "/../");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "/");
+ // keep leading ..
+ strcpy(s, ".././/");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "..");
+ // remove .
+ strcpy(s, "./");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "");
+ // keep / before .
+ strcpy(s, "/.");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "/");
+ // remove .
+ strcpy(s, ".");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "");
+ // / not changed
+ strcpy(s, "/");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "/");
+ // // becomes /
+ strcpy(s, "//");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "/");
+ // remove leading .
+ strcpy(s, "/./werwer");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "/werwer");
+ // keep leading .. and remove .. in path
+ strcpy(s, ".././test/../test/file");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "../test/file");
+ strcpy(s, "../d1/./d2/../f1");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "../d1/f1");
+ strcpy(s, "a/b/c/../d/../e");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "a/b/e");
+ // dont remove .. when there are only .. in front
+ strcpy(s, "../../test/test/file");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "../../test/test/file");
+ // empty path
+ strcpy(s, "");
+ bLNormalizePath(s, sizeof s);
+ ck_assert_str_eq(s, "");
+ // shorter buffer than path
+ strcpy(s, "a/b/c/../d/../e");
+ bLNormalizePath(s, 4);
+ ck_assert_str_eq(s, "a/b");
+ strcpy(s, "a/b/c/../d/../e");
+ // size 0 - no change in path
+ bLNormalizePath(s, 0);
+ ck_assert_str_eq(s, "a/b/c/../d/../e");
+ // NULL path
+ ck_assert_ptr_eq(bLNormalizePath(NULL, sizeof s), NULL);
+
+}
+
+
+void timeToST(CuTest *tc) {
+
+ char *s = timeToS(0);
+ ck_assert_str_eq(s, "Thu Jan 1 01:00:00 1970");
+ free(s);
+
+}
+
+
+void chDirT(CuTest *tc) {
+
+ // change directory
+ char *c = getCwd();
+ ck_assert(chDir("dirTest.null"));
+ char *s = getCwd();
+ ck_assert((size_t)findS(s, "dirTest.null"));
+ chDir(c);
+ freeManyS(c,s);
+ // non existing dir
+ ck_assert(!chDir("RandomNonExistingDir"));
+ // NULL path
+ ck_assert(!chDir(NULL));
+
+}
+
+
+void isDirT(CuTest *tc) {
+
+ // dir
+ ck_assert(isDir("dirTest.null"));
+
+ // non existing dir
+ ck_assert(!isDir("RandomNonExistingDir"));
+
+ // blank
+ ck_assert(!isDir(" "));
+
+ // NULL path
+ ck_assert(!isDir(NULL));
+
+}
+
+
+void isLinkT(CuTest *tc) {
+
+ // link
+ ck_assert(isLink("linkTest.null"));
+
+ // not link
+ ck_assert(!isLink("textTest.null"));
+
+ // non existing link
+ ck_assert(!isLink("RandomNonExistingDir"));
+
+ // blank
+ ck_assert(!isLink(" "));
+
+ // NULL path
+ ck_assert(!isLink(NULL));
+
+}
+
+
+void fileExistsT(CuTest *tc) {
+
+ // detect existing file
+ ck_assert(fileExists("libsheepyTest.c"));
+ // non existing file
+ ck_assert(!fileExists("wefwepfk34.c"));
+ // folder
+ ck_assert(fileExists("../src"));
+ // empty path
+ ck_assert(!fileExists(""));
+ // NULL path
+ ck_assert(!fileExists(NULL));
+
+}
+
+
+void fileChmodT(CuTest *tc) {
+
+ // existing file
+ ck_assert(fileChmod("chmodTest.null", S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH));
+ ck_assert(fileChmod("chmodTest.null", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH));
+ // non existing file
+ ck_assert(!fileChmod("qweqwe_null", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH));
+ // empty path
+ ck_assert(!fileChmod("",0));
+ // NULL path
+ ck_assert(!fileChmod(NULL,0));
+
+}
+
+
+void fileSizeT(CuTest *tc) {
+
+ // existing file
+ ck_assert_uint_eq(fileSize("sizeTest.null"), 743);
+ // empty file
+ ck_assert_uint_eq(fileSize("chmodTest.null"), 0);
+ // non existing file
+ ck_assert_int_eq(fileSize("qweqwe_null"), -1);
+ // empty path
+ ck_assert_int_eq(fileSize(""), -1);
+ // NULL path
+ ck_assert_int_eq(fileSize(NULL), -1);
+
+}
+
+
+void readFileToST(CuTest *tc) {
+
+ char *l;
+
+ // text
+ l = readFileToS("textTest.null");
+ ck_assert_str_eq(l, "LINE 1\nANOTHER line\n");
+ free(l);
+
+ // empty text
+ l = readFileToS("chmodTest.null");
+ ck_assert_str_eq(l, "");
+ free(l);
+
+ // write only file
+ ck_assert_ptr_eq(readFileToS("writeOnlyText.null"), NULL);
+
+ // blank path
+ ck_assert_ptr_eq(readFileToS(""), NULL);
+
+ // NULL path
+ ck_assert_ptr_eq(readFileToS(NULL), NULL);
+
+ // non existing path
+ if (fileExists("nonExistingFile"))
+ rmAll("nonExistingFile");
+ ck_assert_ptr_eq(readFileToS("nonExistingFile"), NULL);
+
+}
+
+
+void bReadFileToST(CuTest *tc) {
+
+ char l[100];
+
+ // text
+ bReadFileToS("textTest.null", l);
+ ck_assert_str_eq(l, "LINE 1\nANOTHER line\n");
+
+ // empty text
+ bReadFileToS("chmodTest.null", l);
+ ck_assert_str_eq(l, "");
+
+ // write only file
+ ck_assert_ptr_eq(bReadFileToS("writeOnlyText.null", l), NULL);
+
+ // blank path
+ ck_assert_ptr_eq(bReadFileToS("", l), NULL);
+
+ // NULL path
+ ck_assert_ptr_eq(bReadFileToS(NULL, l), NULL);
+
+ // NULL buffer
+ ck_assert_ptr_eq(bReadFileToS("wqe", NULL), NULL);
+
+ // non existing path
+ if (fileExists("nonExistingFile"))
+ rmAll("nonExistingFile");
+ ck_assert_ptr_eq(bReadFileToS("nonExistingFile", l), NULL);
+
+}
+
+
+void bLReadFileToST(CuTest *tc) {
+
+ char l[100];
+
+ // text
+ bLReadFileToS("textTest.null", l, sizeof l);
+ ck_assert_str_eq(l, "LINE 1\nANOTHER line\n");
+
+ // shorter buffer
+ bLReadFileToS("textTest.null", l, 3);
+ ck_assert_str_eq(l, "LI");
+
+ // empty text
+ bLReadFileToS("chmodTest.null", l, sizeof l);
+ ck_assert_str_eq(l, "");
+
+ // size 0 buffer - no change
+ strcpy(l, "libsheepy");
+ bLReadFileToS("textTest.null", l, 0);
+ ck_assert_str_eq(l, "libsheepy");
+
+ // write only file
+ ck_assert_ptr_eq(bLReadFileToS("writeOnlyText.null", l, sizeof l), NULL);
+
+ // blank path
+ ck_assert_ptr_eq(bLReadFileToS("", l, sizeof l), NULL);
+
+ // NULL path
+ ck_assert_ptr_eq(bLReadFileToS(NULL, l, sizeof l), NULL);
+
+ // NULL buffer
+ ck_assert_ptr_eq(bLReadFileToS("wqe", NULL, sizeof l), NULL);
+
+ // non existing path
+ if (fileExists("nonExistingFile"))
+ rmAll("nonExistingFile");
+ ck_assert_ptr_eq(bLReadFileToS("nonExistingFile", l, sizeof l), NULL);
+
+}
+
+
+void readFileT(CuTest *tc) {
+
+ char *l;
+ ssize_t sz;
+
+ // text
+ sz = readFile("textTest.null", (void **) &l);
+ l[19] = 0;
+ ck_assert_str_eq(l, "LINE 1\nANOTHER line");
+ ck_assert_int_eq(sz, 20);
+ free(l);
+
+ // empty text
+ // allocated 0 bytes
+ sz = readFile("chmodTest.null", (void **) &l);
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert_int_eq(sz, 0);
+ free(l);
+
+ // write only file
+ ck_assert_int_eq(readFile("writeOnlyText.null", (void **) &l), -1);
+
+ // blank path
+ ck_assert_int_eq(readFile("", (void **) &l), -1);
+
+ // NULL buffer
+ ck_assert_int_eq(readFile("lib", NULL), -1);
+
+ // NULL path
+ ck_assert_int_eq(readFile(NULL, (void **) &l), -1);
+
+ // non existing path
+ if (fileExists("nonExistingFile"))
+ rmAll("nonExistingFile");
+ ck_assert_int_eq(readFile("nonExistingFile", (void **) &l), -1);
+
+}
+
+
+void bReadFileT(CuTest *tc) {
+
+ char l[100];
+ ssize_t sz;
+
+ // text
+ sz = bReadFile("textTest.null", l);
+ l[19] = 0;
+ ck_assert_str_eq(l, "LINE 1\nANOTHER line");
+ ck_assert_int_eq(sz, 20);
+
+ // empty text
+ sz = bReadFile("chmodTest.null", l);
+ ck_assert_str_eq(l, "LINE 1\nANOTHER line");
+ ck_assert_int_eq(sz, 0);
+
+ // write only file
+ ck_assert_int_eq(bReadFile("writeOnlyText.null", l), -1);
+
+ // blank path
+ ck_assert_int_eq(bReadFile("", l), -1);
+
+ // NULL buffer
+ ck_assert_int_eq(bReadFile("lib", NULL), -1);
+
+ // NULL path
+ ck_assert_int_eq(bReadFile(NULL, l), -1);
+
+ // non existing path
+ if (fileExists("nonExistingFile"))
+ rmAll("nonExistingFile");
+ ck_assert_int_eq(bReadFile("nonExistingFile", l), -1);
+
+}
+
+
+void bLReadFileT(CuTest *tc) {
+
+ char l[100];
+ ssize_t sz;
+
+ // text
+ sz = bLReadFile("textTest.null", l, sizeof l);
+ l[19] = 0;
+ ck_assert_str_eq(l, "LINE 1\nANOTHER line");
+ ck_assert_int_eq(sz, 20);
+
+ // shorter buffer
+ l[0] = 'a';
+ l[1] = 'a';
+ sz = bLReadFile("textTest.null", l, 1);
+ ck_assert_str_eq(l, "LaNE 1\nANOTHER line");
+ ck_assert_int_eq(sz, 1);
+
+ // empty text - l not changed
+ sz = bLReadFile("chmodTest.null", l, sizeof l);
+ ck_assert_str_eq(l, "LaNE 1\nANOTHER line");
+ ck_assert_int_eq(sz, 0);
+
+ // size 0 - l not changed
+ sz = bLReadFile("chmodTest.null", l, 0);
+ ck_assert_str_eq(l, "LaNE 1\nANOTHER line");
+ ck_assert_int_eq(sz, 0);
+
+ // write only file
+ ck_assert_int_eq(bLReadFile("writeOnlyText.null", l, sizeof l), -1);
+
+ // blank path
+ ck_assert_int_eq(bLReadFile("", l, sizeof l), -1);
+
+ // NULL buffer
+ ck_assert_int_eq(bLReadFile("lib", NULL, sizeof l), -1);
+
+ // NULL path
+ ck_assert_int_eq(bLReadFile(NULL, l, sizeof l), -1);
+
+ // non existing path
+ if (fileExists("nonExistingFile"))
+ rmAll("nonExistingFile");
+ ck_assert_int_eq(bLReadFile("nonExistingFile", l, sizeof l), -1);
+
+}
+
+
+void writeFileST(CuTest *tc) {
+
+ char *l;
+ int r;
+
+ // write textOutTest.null
+ l = readFileToS("textTest.null");
+ r = writeFileS("textOutTest.null", l);
+ ck_assert(r);
+ free(l);
+
+ // check textOutTest.null
+ l = readFileToS("textOutTest.null");
+ ck_assert_uint_eq(strlen(l),20);
+ ck_assert_str_eq(l, "LINE 1\nANOTHER line\n");
+ // non existing file
+ // make sure the file doesnt exist
+ if (fileExists("nonExistingFile"))
+ rmAll("nonExistingFile");
+ ck_assert(writeFileS("nonExistingFile",l));
+ if (fileExists("nonExistingFile"))
+ rmAll("nonExistingFile");
+ // blank file name
+ ck_assert(!writeFileS(" ",l));
+ // read only path
+ ck_assert(!writeFileS("/nonExistingFile",l));
+ // NULL path
+ ck_assert(!writeFileS(NULL,l));
+ free(l);
+ // NULL string
+ ck_assert(!writeFileS("a",NULL));
+
+}
+
+
+void writeFileT(CuTest *tc) {
+
+ char *l;
+ int r;
+
+ // write textOutTest.null
+ l = readFileToS("textTest.null");
+ r = writeFile("textOutTest.null", l, strlen(l)+1);
+ ck_assert(r);
+ free(l);
+
+ // check textOutTest.null
+ l = readFileToS("textOutTest.null");
+ ck_assert_uint_eq(strlen(l),20);
+ ck_assert_str_eq(l, "LINE 1\nANOTHER line\n");
+ // non existing file
+ // make sure the file doesnt exist
+ if (fileExists("nonExistingFile"))
+ rmAll("nonExistingFile");
+ ck_assert(writeFile("nonExistingFile",l, strlen(l)+1));
+ // 0 length
+ ck_assert(writeFile("nonExistingFile", l, 0));
+ if (fileExists("nonExistingFile"))
+ rmAll("nonExistingFile");
+ // blank file name
+ ck_assert(!writeFile(" ",l, 1));
+ // read only path
+ ck_assert(!writeFile("/nonExistingFile",l, 1));
+ // NULL path
+ ck_assert(!writeFile(NULL,l, 1));
+ free(l);
+ // NULL buffer
+ ck_assert(!writeFile("a",NULL, 1));
+
+}
+
+
+void walkDirT(CuTest *tc) {
+
+ char **l;
+
+ // existing directory
+ l = walkDir("dirTest.null");
+ ck_assert_uint_eq(listLengthS(l),3);
+ ck_assert_str_eq(l[0], "dirTest.null/one");
+ ck_assert_str_eq(l[1], "dirTest.null/two/four");
+ ck_assert_str_eq(l[2], "dirTest.null/two/three");
+ listFreeS(l);
+ // empty path
+ ck_assert_ptr_eq(walkDir(""), NULL);
+ // non existing directory
+ l = walkDir("nonExisting.null");
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL path
+ ck_assert_ptr_eq(walkDir(NULL), NULL);
+
+}
+
+
+void walkDirDirT(CuTest *tc) {
+
+ char **l;
+
+ // existing directory
+ l = walkDirDir("dirTest.null");
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "dirTest.null/symlinkLoop");
+ ck_assert_str_eq(l[1], "dirTest.null/two");
+ listFreeS(l);
+ // empty path
+ ck_assert_ptr_eq(walkDirDir(""), NULL);
+ // non existing directory
+ l = walkDirDir("nonExisting.null");
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL path
+ ck_assert_ptr_eq(walkDirDir(NULL), NULL);
+
+}
+
+
+void readDirT(CuTest *tc) {
+
+ char **l;
+
+ // existing directory
+ l = readDir("dirTest.null");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "one");
+ listFreeS(l);
+ // empty path
+ ck_assert_ptr_eq(readDir(""), NULL);
+ // non existing directory
+ l = readDir("nonExisting.null");
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL path
+ ck_assert_ptr_eq(readDir(NULL), NULL);
+
+}
+
+
+void readDirDirT(CuTest *tc) {
+
+ char **l;
+
+ // existing directory
+ l = readDirDir("dirTest.null");
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "symlinkLoop");
+ ck_assert_str_eq(l[1], "two");
+ listFreeS(l);
+ // empty path
+ ck_assert_ptr_eq(readDirDir(""), NULL);
+ // non existing directory
+ l = readDirDir("nonExisting.null");
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL path
+ ck_assert_ptr_eq(readDirDir(NULL), NULL);
+
+}
+
+
+void walkDirAllT(CuTest *tc) {
+
+ char **l;
+
+ // existing directory
+ l = walkDirAll("dirTest.null");
+ ck_assert_uint_eq(listLengthS(l),5);
+ ck_assert_str_eq(l[0], "dirTest.null/one");
+ ck_assert_str_eq(l[1], "dirTest.null/symlinkLoop");
+ ck_assert_str_eq(l[2], "dirTest.null/two");
+ ck_assert_str_eq(l[3], "dirTest.null/two/four");
+ ck_assert_str_eq(l[4], "dirTest.null/two/three");
+ listFreeS(l);
+ // empty path
+ ck_assert_ptr_eq(walkDirAll(""), NULL);
+ // non existing directory
+ l = walkDirAll("nonExisting.null");
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL path
+ ck_assert_ptr_eq(walkDirAll(NULL), NULL);
+
+}
+
+
+void readDirAllT(CuTest *tc) {
+
+ char **l;
+
+ // existing directory
+ l = readDirAll("dirTest.null");
+ ck_assert_uint_eq(listLengthS(l),3);
+ ck_assert_str_eq(l[0], "one");
+ ck_assert_str_eq(l[1], "symlinkLoop");
+ ck_assert_str_eq(l[2], "two");
+ listFreeS(l);
+ // empty path
+ ck_assert_ptr_eq(readDirAll(""), NULL);
+ // non existing directory
+ l = readDirAll("nonExisting.null");
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL path
+ ck_assert_ptr_eq(readDirAll(NULL), NULL);
+
+}
+
+
+void mkdirParentsT(CuTest *tc) {
+
+ // directory
+ rmAll("mkdirTest.null/null");
+ ck_assert_int_eq(mkdirParents("mkdirTest.null/null"),1);
+ ck_assert_int_eq(mkdirParents("mkdirTest.null/null/"),1);
+ // not allowed
+ ck_assert_int_eq(mkdirParents("/usr/null"),0);
+ ck_assert_int_eq(mkdirParents("/usr/null/null"),0);
+ // empty path
+ ck_assert_int_eq(mkdirParents(""),0);
+ // NULL path
+ ck_assert_int_eq(mkdirParents(NULL),0);
+
+}
+
+
+void rmAllT(CuTest *tc) {
+
+ // directory
+ mkdirParents("rmAllTest.null/null");
+ ck_assert_int_eq(rmAll("rmAllTest.null"),1);
+ // empty path
+ ck_assert_int_eq(rmAll(""),0);
+ // too little permissions
+ ck_assert_int_eq(rmAll("/var/lock"),0);
+ // NULL path
+ ck_assert_int_eq(rmAll(NULL),0);
+
+}
+
+
+void copyT(CuTest *tc) {
+
+ // file
+ rmAll("copyTest.null");
+ rmAll("copy2Test.null");
+ ck_assert_int_eq(copy("chmodTest.null", "copyTest.null"),1);
+ ck_assert(fileExists("copyTest.null"));
+ // too little permissions
+ fileChmod("copyTest.null", 0);
+ ck_assert_int_eq(copy("copyTest.null", "copy2Test.null"),0);
+ fileChmod("copyTest.null", S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
+ rmAll("copyTest.null");
+ // give dir another name
+ ck_assert_int_eq(copy("dirTest.null", "copyTest.null"),1);
+ // copy dir to non existing dir
+ ck_assert_int_eq(copy("dirTest.null", "copyTest.null/we/"),1);
+ // copy file to dir (wrong final slash in dst missing)
+ ck_assert_int_eq(copy("chmodTest.null", "copyTest.null"),0);
+ // copy file to dir (with final slash in dst)
+ ck_assert_int_eq(copy("chmodTest.null", "copyTest.null/"),1);
+ // copy content of source dir to new dst
+ ck_assert_int_eq(copy("dirTest.null/", "copyTest.null/content"),1);
+ char **l = walkDirAll("copyTest.null");
+ // copy results
+ ck_assert_int_eq(listLengthS(l), 17);
+ ck_assert_str_eq(l[0], "copyTest.null/chmodTest.null");
+ ck_assert_str_eq(l[1], "copyTest.null/content");
+ ck_assert_str_eq(l[2], "copyTest.null/content/one");
+ ck_assert_str_eq(l[3], "copyTest.null/content/two");
+ ck_assert_str_eq(l[4], "copyTest.null/content/two/four");
+ ck_assert_str_eq(l[5], "copyTest.null/content/two/three");
+ ck_assert_str_eq(l[6], "copyTest.null/dirTest.null");
+ ck_assert_str_eq(l[7], "copyTest.null/dirTest.null/one");
+ ck_assert_str_eq(l[8], "copyTest.null/dirTest.null/two");
+ ck_assert_str_eq(l[9], "copyTest.null/dirTest.null/two/four");
+ ck_assert_str_eq(l[10], "copyTest.null/dirTest.null/two/three");
+ ck_assert_str_eq(l[11], "copyTest.null/we");
+ ck_assert_str_eq(l[12], "copyTest.null/we/dirTest.null");
+ ck_assert_str_eq(l[13], "copyTest.null/we/dirTest.null/one");
+ ck_assert_str_eq(l[14], "copyTest.null/we/dirTest.null/two");
+ ck_assert_str_eq(l[15], "copyTest.null/we/dirTest.null/two/four");
+ ck_assert_str_eq(l[16], "copyTest.null/we/dirTest.null/two/three");
+ listFreeS(l);
+ rmAll("copyTest.null");
+ // copy dir to read only destination, no mkdir
+ ck_assert_int_eq(copy("mkdirTest.null/", "/newdir"),0);
+ // copy dir to read only destination, new dir
+ ck_assert_int_eq(copy("mkdirTest.null", "/newdir"),0);
+ // non existing source
+ ck_assert_int_eq(copy("nonExistingFile", "copyTest.null"),0);
+ // empty path
+ ck_assert_int_eq(copy("", "copyTest.null"),0);
+ ck_assert(!fileExists("copyTest.null"));
+ ck_assert_int_eq(copy("chmodTest.null", ""),0);
+ ck_assert(!fileExists("copyTest.null"));
+ // NULL path
+ ck_assert_int_eq(copy(NULL, "copyTest.null"),0);
+ ck_assert_int_eq(copy("chmodTest.null", NULL),0);
+ ck_assert_int_eq(copy(NULL, NULL),0);
+
+}
+
+
+void shRenameT(CuTest *tc) {
+
+ // regualar file
+ ck_assert_int_eq(shRename("renameTest.null", "rename2Test.null"), 1);
+ ck_assert_int_eq(shRename("rename2Test.null", "renameTest.null"), 1);
+ // dir
+ ck_assert_int_eq(shRename("mkdirTest.null", "rename2Test.null"), 1);
+ ck_assert_int_eq(shRename("rename2Test.null", "mkdirTest.null"), 1);
+ // non existing source
+ ck_assert_int_eq(shRename("rename2Test.null", "renameTest.null"), 0);
+ // already existing destination
+ ck_assert_int_eq(shRename("mkdirTest.null", "renameTest.null"), 0);
+ // blank paths
+ ck_assert_int_eq(shRename(" ", "renameTest.null"), 0);
+ ck_assert_int_eq(shRename("qwe", ""), 0);
+ // NULL
+ ck_assert_int_eq(shRename(NULL, "renameTest.null"), 0);
+ ck_assert_int_eq(shRename("mkdirTest.null", NULL), 0);
+
+}
+
+
+void shMoveT(CuTest *tc) {
+
+ // regualar file
+ ck_assert_int_eq(shMove("renameTest.null", "rename2Test.null"), 1);
+ ck_assert_int_eq(shMove("rename2Test.null", "renameTest.null"), 1);
+ // dir
+ ck_assert_int_eq(shMove("mkdirTest.null", "rename2Test.null"), 1);
+ ck_assert_int_eq(shMove("rename2Test.null/mkdirTest.null", "."), 1);
+ rmAll("rename2Test.null");
+ // non existing source
+ ck_assert_int_eq(shMove("rename2Test.null", "renameTest.null"), 0);
+ // already existing destination
+ ck_assert_int_eq(shMove("mkdirTest.null", "renameTest.null"), 0);
+ // blank paths
+ ck_assert_int_eq(shMove(" ", "renameTest.null"), 0);
+ ck_assert_int_eq(shMove("qwe", ""), 0);
+ // NULL
+ ck_assert_int_eq(shMove(NULL, "renameTest.null"), 0);
+ ck_assert_int_eq(shMove("mkdirTest.null", NULL), 0);
+
+}
+
+
+void setSoftwareRandomT(CuTest *tc) {
+
+ // open /dev/urandom
+ setSoftwareRandom();
+ randomUrandomClose();
+
+}
+
+
+void setHardwareRandomT(CuTest *tc) {
+
+ // open /dev/urandom
+ setHardwareRandom();
+ setSoftwareRandom();
+ randomUrandomClose();
+
+}
+
+
+void randomOpenCloseT(CuTest *tc) {
+
+ // open /dev/urandom
+ ck_assert_int_eq(randomUrandomOpen(),1);
+ randomUrandomClose();
+
+}
+
+
+void randomWordT(CuTest *tc) {
+
+ // get random value
+ randomUrandomOpen();
+ ck_assert_int_ne(randomWord(),0);
+ randomUrandomClose();
+ // error when /dev/urandom is closed
+ ck_assert_int_eq(randomWord(),0);
+
+}
+
+
+void randomWordFromHWT(CuTest *tc) {
+
+ // get random value
+ setHardwareRandom();
+ randomWordFromHW();
+
+ // string
+ char *s = randomS(10);
+ ck_assert_ptr_ne(s, NULL);
+ free(s);
+ setSoftwareRandom();
+ randomUrandomClose();
+
+}
+
+
+void randomChoiceT(CuTest *tc) {
+
+ // get random value
+ randomUrandomOpen();
+ ck_assert_int_ne(randomChoice(10),10);
+ // invalid range (0)
+ ck_assert_int_eq(randomChoice(0),0);
+ randomUrandomClose();
+ // error when /dev/urandom is closed
+ ck_assert_int_eq(randomChoice(10),10);
+
+}
+
+
+void randomST(CuTest *tc) {
+
+ // get random string
+ char *s = randomS(10);
+ ck_assert_ptr_ne(s, NULL);
+ free(s);
+ // invalid length (0)
+ ck_assert_ptr_eq(randomS(0), NULL);
+
+}
+
+
+void bRandomST(CuTest *tc) {
+
+ char s[11];
+ char *r;
+ // get random string
+ r = bRandomS(s, 10);
+ ck_assert_ptr_ne(r, NULL);
+ // invalid length (0)
+ ck_assert_ptr_eq(bRandomS(s, 0), NULL);
+ // NULL
+ ck_assert_ptr_eq(bRandomS(NULL, 10), NULL);
+
+}
+
+
+void randomAlphaNumST(CuTest *tc) {
+
+ // get random string
+ char *s = randomAlphaNumS(10);
+ ck_assert_ptr_ne(s, NULL);
+ free(s);
+ // invalid length (0)
+ ck_assert_ptr_eq(randomAlphaNumS(0), NULL);
+
+}
+
+
+void bRandomAlphaNumST(CuTest *tc) {
+
+ char s[11];
+ char *r;
+ // get random string
+ r = bRandomAlphaNumS(s, 10);
+ ck_assert_ptr_ne(r, NULL);
+ // invalid length (0)
+ ck_assert_ptr_eq(bRandomAlphaNumS(s, 0), NULL);
+ // NULL
+ ck_assert_ptr_eq(bRandomAlphaNumS(NULL, 10), NULL);
+
+}
+
+
+void readST(CuTest *tc) {
+
+ char *s = readS();
+ ck_assert_str_eq(s, "aaaaaaaaaaaaaaaaaaaa");
+ free(s);
+
+}
+
+
+void bLReadST(CuTest *tc) {
+
+ char s[21];
+ bLReadS(s, 21);
+ ck_assert_str_eq(s, "aaaaaaaaaaaaaaaaaaaa");
+ // size 1
+ ck_assert_ptr_eq(bLReadS(s, 1), NULL);
+ // NULL
+ ck_assert_ptr_eq(bLReadS(NULL, 2), NULL);
+
+}
+
+
+void readEnterT(CuTest *tc) {
+
+ readEnter();
+
+}
+
+
+void readLineT(CuTest *tc) {
+
+ FILE *fp;
+ char *s;
+
+ // file with data
+ fp = fopen("textTest.null", "r");
+ s = readLine(fp);
+ fclose(fp);
+ ck_assert_str_eq(s, "LINE 1");
+ free(s);
+ // empty file or end of stream
+ fp = fopen("chmodTest.null", "r");
+ s = readLine(fp);
+ ck_assert_ptr_ne(s, NULL);
+ ck_assert(isEmptyS(s));
+ free(s);
+ fclose(fp);
+ // NULL stream
+ ck_assert_ptr_eq(readLine(NULL), NULL);
+
+
+}
+
+
+void dupST(CuTest *tc) {
+
+ // string
+ char *s = dupS("sheepy");
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(dupS(NULL), NULL);
+
+}
+
+
+void shPrintfST(CuTest *tc) {
+
+ shPrintfS("\nWEE %d\n", 234);
+ shPrintfS(NULL);
+
+}
+
+
+void shEprintfT(CuTest *tc) {
+
+ shEPrintfS("\nWEE %d\n", 234);
+ shEPrintfS(NULL);
+
+}
+
+void freeManyST(CuTest *tc) {
+
+ // not possible to know if a pointer is already freed
+ char *s1 = emptySF();
+ char *s2 = emptySF();
+ freeManyS(s1, s2);
+
+}
+
+
+void logNFreeT(CuTest *tc) {
+
+ char *s = strdup("libsheepy");
+ logNFree(s);
+ logNFree(NULL);
+
+}
+
+
+void strCpyT(CuTest *tc) {
+
+ char s[1024];
+
+ // copy string
+ strCpy(s, "lib");
+ ck_assert_str_eq(s, "lib");
+ // NULL
+ s[0] = 0;
+ strCpy(s, NULL);
+ ck_assert_str_eq(s, "");
+ ck_assert_ptr_eq(strCpy(NULL, "lib"), NULL);
+
+}
+
+
+void strLCpyT(CuTest *tc) {
+
+ char s[1024];
+
+ // copy string
+ strLCpy(s, 100, "lib");
+ ck_assert_str_eq(s, "lib");
+ // truncate src
+ s[0] = 0;
+ s[1] = 0;
+ s[2] = 0;
+ strLCpy(s, 3, "lib");
+ ck_assert_str_eq(s, "li");
+ s[0] = 'a';
+ s[1] = 'a';
+ s[2] = 'a';
+ s[3] = 0;
+ strLCpy(s, 3, "lib");
+ ck_assert_str_eq(s, "li");
+ // size 0 - no change in s
+ strLCpy(s, 0, "libsheepy");
+ ck_assert_str_eq(s, "li");
+ // NULL
+ s[0] = 0;
+ strLCpy(s, 1, NULL);
+ ck_assert_str_eq(s, "");
+ ck_assert_ptr_eq(strLCpy(NULL,1, "lib"), NULL);
+
+}
+
+
+void strCatT(CuTest *tc) {
+
+ char s[1024];
+
+ // append string
+ strCpy(s, "lib");
+ strCat(s, "sheepy");
+ ck_assert_str_eq(s, "libsheepy");
+ // empty string2
+ strCat(s, "");
+ ck_assert_str_eq(s, "libsheepy");
+ // NULL string2
+ strCat(s, NULL);
+ ck_assert_str_eq(s, "libsheepy");
+ // NULL parameter
+ ck_assert_ptr_eq(strCat(NULL, "ad"), NULL);
+
+}
+
+
+void strNCatT(CuTest *tc) {
+
+ char s[1024];
+
+ // append string
+ strCpy(s, "lib");
+ strNCat(s, "sheepy", 100);
+ ck_assert_str_eq(s, "libsheepy");
+ // empty string2
+ strNCat(s, "", 10);
+ ck_assert_str_eq(s, "libsheepy");
+ // truncate src
+ s[0] = 'a';
+ s[1] = 'a';
+ s[2] = 'a';
+ s[3] = 'a';
+ s[4] = 'a';
+ s[5] = 'a';
+ strCpy(s, "lib");
+ ck_assert_str_eq(s, "lib");
+ strNCat(s, "sheepy", 2);
+ ck_assert_str_eq(s, "libsh");
+ // NULL string2
+ strNCat(s, NULL, 1);
+ ck_assert_str_eq(s, "libsh");
+ // NULL parameter
+ ck_assert_ptr_eq(strNCat(NULL, "ad", 1), NULL);
+
+}
+
+
+void strLCatT(CuTest *tc) {
+
+ char s[1024];
+
+ // append string
+ strCpy(s, "lib");
+ strLCat(s, 100, "sheepy");
+ ck_assert_str_eq(s, "libsheepy");
+ // empty string2
+ strLCat(s, 20, "");
+ ck_assert_str_eq(s, "libsheepy");
+ // s strlen bigger than s size - keep s as it is
+ strLCat(s, 6, "qwqwe");
+ ck_assert_str_eq(s, "libsheepy");
+ // truncate src
+ s[0] = 'a';
+ s[1] = 'a';
+ s[2] = 'a';
+ s[3] = 'a';
+ s[4] = 'a';
+ s[5] = 'a';
+ strCpy(s, "lib");
+ ck_assert_str_eq(s, "lib");
+ strLNCat(s,100, "sheepy", 2);
+ ck_assert_str_eq(s, "libsh");
+ // truncate dst
+ s[0] = 'a';
+ s[1] = 'a';
+ s[2] = 'a';
+ s[3] = 'a';
+ s[4] = 'a';
+ s[5] = 'a';
+ strCpy(s, "lib");
+ ck_assert_str_eq(s, "lib");
+ strLCat(s, 6, "sheepy");
+ ck_assert_str_eq(s, "libsh");
+ // NULL string2
+ strLCat(s, 1, NULL);
+ ck_assert_str_eq(s, "libsh");
+ // NULL parameter
+ ck_assert_ptr_eq(strLCat(NULL, 1, "ad"), NULL);
+
+}
+
+
+void strLNCatT(CuTest *tc) {
+
+ char s[1024];
+
+ // append string
+ strCpy(s, "lib");
+ strLNCat(s, 100, "sheepy", 100);
+ ck_assert_str_eq(s, "libsheepy");
+ // empty string2
+ strLNCat(s, 20, "", 10);
+ ck_assert_str_eq(s, "libsheepy");
+ // s strlen bigger than s size - keep s as it is
+ strLNCat(s, 6, "qwqwe", 1);
+ ck_assert_str_eq(s, "libsheepy");
+ // truncate dst
+ s[0] = 'a';
+ s[1] = 'a';
+ s[2] = 'a';
+ s[3] = 'a';
+ s[4] = 'a';
+ s[5] = 'a';
+ strCpy(s, "lib");
+ ck_assert_str_eq(s, "lib");
+ strLNCat(s, 6, "sheepy", 4);
+ ck_assert_str_eq(s, "libsh");
+ // NULL string2
+ strLNCat(s, 1, NULL, 1);
+ ck_assert_str_eq(s, "libsh");
+ // NULL parameter
+ ck_assert_ptr_eq(strLNCat(NULL, 1, "ad", 1), NULL);
+
+}
+
+
+void catST(CuTest *tc) {
+
+ char *s;
+ char *r;
+
+ // cat strings
+ s = strdup("#@#");
+ r = catS(s,"asd");
+ ck_assert_str_eq(r, "#@#asd");
+ free(s);
+ free(r);
+ // empty string
+ r = catS("");
+ ck_assert(isEmptyS(r));
+ free(r);
+ // cat empty string with string
+ r = catS("", "asd");
+ ck_assert_str_eq(r, "asd");
+ free(r);
+
+}
+
+
+void iCatST(CuTest *tc) {
+
+ char *s;
+ char r[100];
+
+ // cat strings
+ s = strdup("#@#");
+ iCatS(r, s,"asd");
+ ck_assert_str_eq(r, "#@#asd");
+ free(s);
+ // empty string
+ iCatS(r, "");
+ ck_assert(isEmptyS(r));
+ // cat empty string with string
+ iCatS(r, "", "asd");
+ ck_assert_str_eq(r, "asd");
+ // NULL
+ ck_assert_ptr_eq(iCatS(NULL, "wef","wef"), NULL);
+
+}
+
+
+void bLCatST(CuTest *tc) {
+
+ char *s;
+ char r[100];
+
+ // cat strings
+ s = strdup("#@#");
+ bLCatS(r, sizeof r, s,"asd");
+ ck_assert_str_eq(r, "#@#asd");
+ // shorter buffer
+ bLCatS(r, 3, s,"asd");
+ ck_assert_str_eq(r, "#@");
+ free(s);
+ // empty string
+ bLCatS(r, sizeof r, "");
+ ck_assert(isEmptyS(r));
+ // cat empty string with string
+ bLCatS(r, sizeof r, "", "asd");
+ ck_assert_str_eq(r, "asd");
+ // size 0 - no change in r
+ bLCatS(r, 0, "", "asd");
+ ck_assert_str_eq(r, "asd");
+ // NULL
+ ck_assert_ptr_eq(bLCatS(NULL, sizeof r, "wef","wef"), NULL);
+
+}
+
+
+void formatST(CuTest *tc) {
+
+ char *s;
+
+ // format
+ s = formatS("sheepy is num %d", 1);
+ ck_assert_str_eq(s, "sheepy is num 1");
+ free(s);
+ // NULL
+ ck_assert_ptr_eq(formatS(NULL), NULL);
+
+}
+
+
+void appendST(CuTest *tc) {
+
+ char *s;
+
+ // append string
+ s = appendS("lib", "sheepy");
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // empty string2
+ s = appendS("libsheepy", "");
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // NULL string2
+ s = appendS("libsheepy", NULL);
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // NULL string
+ s = appendS(NULL, "ad");
+ ck_assert_ptr_eq(s, NULL);
+
+}
+
+
+void appendCharST(CuTest *tc) {
+
+ char *s;
+
+ // append string
+ s = appendCharS("lib", 'C');
+ ck_assert_str_eq(s, "libC");
+ free(s);
+ // empty string2
+ s = appendCharS("libsheepy", 0);
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // NULL string
+ s = appendCharS(NULL, 'C');
+ ck_assert_ptr_eq(s, NULL);
+
+}
+
+
+void appendSCharT(CuTest *tc) {
+
+ char *s;
+
+ // append string
+ s = appendSChar('l', "sheepy");
+ ck_assert_str_eq(s, "lsheepy");
+ free(s);
+ // empty string2
+ s = appendSChar('l', "");
+ ck_assert_str_eq(s, "l");
+ free(s);
+ // NULL string2
+ s = appendSChar('l', NULL);
+ ck_assert_str_eq(s, "l");
+ free(s);
+
+}
+
+
+void iAppendST(CuTest *tc) {
+
+ char *s;
+
+ // append string
+ s = strdup("lib");
+ iAppendS(&s, "sheepy");
+ ck_assert_str_eq(s, "libsheepy");
+ // empty string2
+ iAppendS(&s, "");
+ ck_assert_str_eq(s, "libsheepy");
+ // NULL string2
+ iAppendS(&s, NULL);
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // NULL string
+ s = NULL;
+ iAppendS(&s, "ad");
+ ck_assert_str_eq(s, "ad");
+ free(s);
+ // NULL parameter
+ iAppendS(NULL, "ad");
+
+}
+
+
+void iAppendCharST(CuTest *tc) {
+
+ char *s;
+
+ // append string
+ s = strdup("lib");
+ iAppendCharS(&s, 'C');
+ ck_assert_str_eq(s, "libC");
+ // empty string2
+ iAppendCharS(&s, 0);
+ ck_assert_str_eq(s, "libC");
+ free(s);
+ // NULL string
+ s = NULL;
+ iAppendCharS(&s, 'C');
+ ck_assert_str_eq(s, "C");
+ free(s);
+ // NULL parameter
+ ck_assert_ptr_eq(iAppendCharS(NULL, 'C'), NULL);
+
+}
+
+
+void iAppendNFreeST(CuTest *tc) {
+
+ char *s;
+
+ // append string
+ s = strdup("lib");
+ iAppendNFreeS(&s, strdup("sheepy"));
+ ck_assert_str_eq(s, "libsheepy");
+ // empty string2
+ iAppendNFreeS(&s, strdup(""));
+ ck_assert_str_eq(s, "libsheepy");
+ // NULL string2
+ iAppendNFreeS(&s, NULL);
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // NULL string
+ s = NULL;
+ iAppendNFreeS(&s, strdup("ad"));
+ ck_assert_str_eq(s, "ad");
+ free(s);
+ // NULL parameter
+ s = strdup("ad");
+ iAppendNFreeS(NULL, s);
+ free(s);
+
+}
+
+
+void iAppendManyST(CuTest *tc) {
+
+ char *s;
+
+ // append string
+ s = strdup("lib");
+ iAppendManyS(&s, "sheepy","2");
+ ck_assert_str_eq(s, "libsheepy2");
+ // empty string2
+ iAppendManyS(&s, "", "");
+ ck_assert_str_eq(s, "libsheepy2");
+ // NULL string2
+ iAppendManyS(&s, "a", NULL);
+ ck_assert_str_eq(s, "libsheepy2a");
+ //not allowed - iAppendManyS(&s, NULL);
+ free(s);
+ // NULL string (allocate)
+ s = NULL;
+ iAppendManyS(&s, "ad", "");
+ ck_assert_str_eq(s, "ad");
+ free(s);
+ // NULL parameter
+ iAppendManyS(NULL, "ad", "");
+
+}
+
+
+void bAppendManyST(CuTest *tc) {
+
+ char s[100];
+
+ // append string
+ strcpy(s, "lib");
+ bAppendManyS(s, "sheepy","2");
+ ck_assert_str_eq(s, "libsheepy2");
+ // empty string2
+ bAppendManyS(s, "", "");
+ ck_assert_str_eq(s, "libsheepy2");
+ // NULL string2
+ bAppendManyS(s, "a", NULL);
+ ck_assert_str_eq(s, "libsheepy2a");
+ //not allowed - bAppendManyS(s, NULL);
+ // NULL parameter
+ ck_assert_ptr_eq(bAppendManyS(NULL, "ad", ""), NULL);
+
+}
+
+
+void bLAppendManyST(CuTest *tc) {
+
+ char s[100];
+
+ // append string
+ strcpy(s, "lib");
+ bLAppendManyS(s, sizeof s, "sheepy","2");
+ ck_assert_str_eq(s, "libsheepy2");
+ // shorter buffer
+ strcpy(s, "lib");
+ bLAppendManyS(s, 5, "sheepy","2");
+ ck_assert_str_eq(s, "libs");
+ // empty string2
+ bLAppendManyS(s, sizeof s, "", "");
+ ck_assert_str_eq(s, "libs");
+ // NULL string2
+ bLAppendManyS(s, sizeof s, "a", NULL);
+ ck_assert_str_eq(s, "libsa");
+ // size 0 - no change
+ bLAppendManyS(s, 0, "a", NULL);
+ ck_assert_str_eq(s, "libsa");
+ //not allowed - bLAppendManyS(s, sizeof s, NULL);
+ // NULL parameter
+ ck_assert_ptr_eq(bLAppendManyS(NULL, sizeof s, "ad", ""), NULL);
+
+}
+
+
+void prependST(CuTest *tc) {
+
+ char *s;
+
+ s = prependS("sheepy", "lib");
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+
+}
+
+
+void prependCharST(CuTest *tc) {
+
+ char *s;
+
+ s = prependCharS("sheepy", 'l');
+ ck_assert_str_eq(s, "lsheepy");
+ free(s);
+
+}
+
+
+void prependSCharT(CuTest *tc) {
+
+ char *s;
+
+ s = prependSChar('C', "lib");
+ ck_assert_str_eq(s, "libC");
+ free(s);
+
+}
+
+
+void iPrependST(CuTest *tc) {
+
+ char *s;
+
+ // append string
+ s = strdup("lib");
+ iPrependS(&s, "sheepy");
+ ck_assert_str_eq(s, "sheepylib");
+ // empty string2
+ iPrependS(&s, "");
+ ck_assert_str_eq(s, "sheepylib");
+ // NULL string2
+ iPrependS(&s, NULL);
+ ck_assert_str_eq(s, "sheepylib");
+ free(s);
+ // NULL string
+ s = NULL;
+ iPrependS(&s, "ad");
+ ck_assert_str_eq(s, "ad");
+ free(s);
+ // NULL parameter
+ ck_assert_ptr_eq(iPrependS(NULL, "ad"), NULL);
+
+}
+
+
+void iPrependCharST(CuTest *tc) {
+
+ char *s;
+
+ // append string
+ s = strdup("lib");
+ iPrependCharS(&s, 'C');
+ ck_assert_str_eq(s, "Clib");
+ // empty string2
+ iPrependCharS(&s, 0);
+ ck_assert_str_eq(s, "Clib");
+ free(s);
+ // NULL string
+ s = NULL;
+ iPrependCharS(&s, 'C');
+ ck_assert_str_eq(s, "C");
+ free(s);
+ // NULL parameter
+ ck_assert_ptr_eq(iPrependCharS(NULL, 'a'), NULL);
+
+}
+
+
+void iPrependNFreeST(CuTest *tc) {
+
+ char *s;
+
+ // append string
+ s = strdup("lib");
+ iPrependNFreeS(&s, strdup("sheepy"));
+ ck_assert_str_eq(s, "sheepylib");
+ // empty string2
+ iPrependNFreeS(&s, strdup(""));
+ ck_assert_str_eq(s, "sheepylib");
+ // NULL string2
+ iPrependNFreeS(&s, NULL);
+ ck_assert_str_eq(s, "sheepylib");
+ free(s);
+ // NULL string
+ s = NULL;
+ iPrependNFreeS(&s, strdup("ad"));
+ ck_assert_str_eq(s, "ad");
+ free(s);
+ // NULL parameter
+ s = strdup("ad");
+ ck_assert_ptr_eq(iPrependNFreeS(NULL, s), NULL);
+ free(s);
+
+}
+
+
+void bPrependST(CuTest *tc) {
+
+ char s[100];
+
+ // append string
+ strcpy(s, "lib");
+ bPrependS(s, "sheepy");
+ ck_assert_str_eq(s, "sheepylib");
+ // empty string2
+ bPrependS(s, "");
+ ck_assert_str_eq(s, "sheepylib");
+ // NULL string2
+ bPrependS(s, NULL);
+ ck_assert_str_eq(s, "sheepylib");
+ // empty string
+ bEmptyS(s);
+ bPrependS(s, "ad");
+ ck_assert_str_eq(s, "ad");
+ // NULL parameter
+ ck_assert_ptr_eq(bPrependS(NULL, "ad"), NULL);
+
+}
+
+
+void bLPrependST(CuTest *tc) {
+
+ char s[100];
+
+ // append string
+ strcpy(s, "lib");
+ bLPrependS(s, sizeof s, "sheepy");
+ ck_assert_str_eq(s, "sheepylib");
+ // shorter buffer
+ strcpy(s, "lib");
+ bLPrependS(s, 5, "sheepy");
+ ck_assert_str_eq(s, "shee");
+ // empty string2
+ bLPrependS(s, sizeof s, "");
+ ck_assert_str_eq(s, "shee");
+ // NULL string2
+ bLPrependS(s, sizeof s, NULL);
+ ck_assert_str_eq(s, "shee");
+ // empty string
+ bEmptyS(s);
+ bLPrependS(s, sizeof s, "ad");
+ ck_assert_str_eq(s, "ad");
+ // size 0 - no change
+ bLPrependS(s, 0, "ad");
+ ck_assert_str_eq(s, "ad");
+ // NULL parameter
+ ck_assert_ptr_eq(bLPrependS(NULL, sizeof s, "ad"), NULL);
+
+}
+
+
+void replaceST(CuTest *tc) {
+
+ // replace string, multiple character new delimeter
+ char *s = replaceS_max("#ee#ee#ad", "#","^^");
+ ck_assert_str_eq(s, "^^ee^^ee^^ad");
+ free(s);
+ // replace string, multiple character old delimeter
+ s = replaceS_max("AA##ee##ee#", "##","|");
+ ck_assert_str_eq(s, "AA|ee|ee#");
+ free(s);
+ // replace one time at the start of string
+ s = replaceS("#ee#ee#ad", "#","^^",1);
+ ck_assert_str_eq(s, "^^ee#ee#ad");
+ free(s);
+ // replace one time
+ s = replaceS("AA##ee##ee#", "##","|",1);
+ ck_assert_str_eq(s, "AA|ee##ee#");
+ free(s);
+ // NULL new delimiter, one time: same as empty delimiter
+ s = replaceS("AA##ee##ee#", "##",NULL,1);
+ ck_assert_str_eq(s, "AAee##ee#");
+ free(s);
+ // empty string
+ s = replaceS("", "##",NULL,1);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty old delimiter
+ ck_assert_ptr_eq(replaceS("qwe", "","|",1), NULL);
+ // NULL old delimiter
+ ck_assert_ptr_eq(replaceS("qwe", NULL,"|",1), NULL);
+ // NULL string
+ ck_assert_ptr_eq(replaceS(NULL, "##","|",1), NULL);
+ // empty old delimiter
+ ck_assert_ptr_eq(replaceS("AA##ee##ee#", "","|",1), NULL);
+
+}
+
+
+void replaceCharSST(CuTest *tc) {
+
+ // replace string, multiple character new delimeter
+ char *s = replaceCharSS("#ee#ee#ad", '#',"^^", 0);
+ ck_assert_str_eq(s, "^^ee^^ee^^ad");
+ free(s);
+ // replace one time at the start of string
+ s = replaceCharSS("#ee#ee#ad", '#',"^^",1);
+ ck_assert_str_eq(s, "^^ee#ee#ad");
+ free(s);
+ // replace one time
+ s = replaceCharSS("AA##ee##ee#", '#',"|",1);
+ ck_assert_str_eq(s, "AA|#ee##ee#");
+ free(s);
+ // NULL new delimiter, one time: same as empty delimiter
+ s = replaceCharSS("AA#ee##ee#", '#',NULL,1);
+ ck_assert_str_eq(s, "AAee##ee#");
+ free(s);
+ // empty string
+ s = replaceCharSS("", '#',NULL,1);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty old delimiter
+ ck_assert_ptr_eq(replaceCharSS("qwe", 0,"|",1), NULL);
+ // NULL string
+ ck_assert_ptr_eq(replaceCharSS(NULL, '#',"|",1), NULL);
+ // empty old delimiter
+ ck_assert_ptr_eq(replaceCharSS("AA##ee##ee#", 0,"|",1), NULL);
+
+}
+
+
+void replaceSCharST(CuTest *tc) {
+
+ // replace string, multiple character new delimeter
+ char *s = replaceSCharS("#ee#ee#ad", "#",'^',0);
+ ck_assert_str_eq(s, "^ee^ee^ad");
+ free(s);
+ // replace string, multiple character old delimeter
+ s = replaceSCharS("AA##ee##ee#", "##",'|',0);
+ ck_assert_str_eq(s, "AA|ee|ee#");
+ free(s);
+ // replace string empty char, multiple character old delimeter
+ s = replaceSCharS("AA##ee##ee#", "##", 0,0);
+ ck_assert_str_eq(s, "AAeeee#");
+ free(s);
+ // replace one time at the start of string
+ s = replaceSCharS("#ee#ee#ad", "#",'^',1);
+ ck_assert_str_eq(s, "^ee#ee#ad");
+ free(s);
+ // replace one time
+ s = replaceSCharS("AA##ee##ee#", "##",'|',1);
+ ck_assert_str_eq(s, "AA|ee##ee#");
+ free(s);
+ // empty string
+ s = replaceSCharS("", "##",0,1);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty old delimiter
+ ck_assert_ptr_eq(replaceSCharS("qwe", "",'|',1), NULL);
+ // NULL old delimiter
+ ck_assert_ptr_eq(replaceSCharS("qwe", NULL,'|',1), NULL);
+ // NULL string
+ ck_assert_ptr_eq(replaceSCharS(NULL, "##",'|',1), NULL);
+ // empty old delimiter
+ ck_assert_ptr_eq(replaceSCharS("AA##ee##ee#", "",'|',1), NULL);
+
+}
+
+
+void replaceCharCharST(CuTest *tc) {
+
+ // replace string, multiple character new delimeter
+ char *s = replaceCharCharS("#ee#ee#ad", '#','^', 0);
+ ck_assert_str_eq(s, "^ee^ee^ad");
+ free(s);
+ // replace one time at the start of string
+ s = replaceCharCharS("#ee#ee#ad", '#','^',1);
+ ck_assert_str_eq(s, "^ee#ee#ad");
+ free(s);
+ // replace one time
+ s = replaceCharCharS("AA#ee##ee#", '#','|',1);
+ ck_assert_str_eq(s, "AA|ee##ee#");
+ free(s);
+ // empty string
+ s = replaceCharCharS("", '#','^',1);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty old delimiter
+ ck_assert_ptr_eq(replaceCharCharS("qwe", 0,'|',1), NULL);
+ // NULL string
+ ck_assert_ptr_eq(replaceCharCharS(NULL, '#','|',1), NULL);
+ // empty old delimiter
+ ck_assert_ptr_eq(replaceCharCharS("AA##ee##ee#", 0,'|',1), NULL);
+
+}
+
+
+void iReplaceST(CuTest *tc) {
+
+ char *s;
+ // replace string, multiple character new delimeter
+ s = strdup("#ee#ee#ad");
+ iReplaceS_max(&s, "#","^^");
+ ck_assert_str_eq(s, "^^ee^^ee^^ad");
+ free(s);
+ // replace string, multiple character old delimeter
+ s = strdup("AA##ee##ee#");
+ iReplaceS_max(&s, "##","|");
+ ck_assert_str_eq(s, "AA|ee|ee#");
+ free(s);
+ // replace one time at the start of string
+ s = strdup("#ee#ee#ad");
+ iReplaceS(&s, "#","^^",1);
+ ck_assert_str_eq(s, "^^ee#ee#ad");
+ free(s);
+ // replace one time
+ s = strdup("AA##ee##ee#");
+ iReplaceS(&s, "##","|",1);
+ ck_assert_str_eq(s, "AA|ee##ee#");
+ free(s);
+ // NULL new delimiter, one time: same as empty delimiter
+ s = strdup("AA##ee##ee#");
+ iReplaceS(&s, "##",NULL,1);
+ ck_assert_str_eq(s, "AAee##ee#");
+ free(s);
+ // empty string
+ emptyS(s);
+ iReplaceS(&s, "##",NULL,1);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty old delimiter
+ s = strdup("qwe");
+ iReplaceS(&s, "","|",1);
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // NULL old delimiter
+ s = strdup("qwe");
+ iReplaceS(&s, NULL,"|",1);
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // NULL string
+ s = NULL;
+ iReplaceS(&s, "##","|",1);
+ // NULL var
+ iReplaceS(NULL, "##","|",1);
+
+}
+
+
+void iReplaceCharSST(CuTest *tc) {
+
+ char *s;
+ // replace string, multiple character new delimeter
+ s = strdup("#ee#ee#ad");
+ iReplaceCharSS(&s, '#',"^^", 0);
+ ck_assert_str_eq(s, "^^ee^^ee^^ad");
+ free(s);
+ // replace one time at the start of string
+ s = strdup("#ee#ee#ad");
+ iReplaceCharSS(&s, '#',"^^",1);
+ ck_assert_str_eq(s, "^^ee#ee#ad");
+ free(s);
+ // replace one time
+ s = strdup("AA#ee##ee#");
+ iReplaceCharSS(&s, '#',"|",1);
+ ck_assert_str_eq(s, "AA|ee##ee#");
+ free(s);
+ // NULL new delimiter, one time: same as empty delimiter
+ s = strdup("AA#ee##ee#");
+ iReplaceCharSS(&s, '#',NULL,1);
+ ck_assert_str_eq(s, "AAee##ee#");
+ free(s);
+ // empty string
+ emptyS(s);
+ iReplaceCharSS(&s, '#',NULL,1);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty old delimiter
+ s = strdup("qwe");
+ iReplaceCharSS(&s, 0,"|",1);
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // NULL string
+ s = NULL;
+ iReplaceCharSS(&s, '#',"|",1);
+ // NULL var
+ iReplaceCharSS(NULL, '#',"|",1);
+
+}
+
+
+void iReplaceSCharST(CuTest *tc) {
+
+ char *s;
+ // replace string, multiple character new delimeter
+ s = strdup("#ee#ee#ad");
+ iReplaceSCharS(&s, "#",'^', 0);
+ ck_assert_str_eq(s, "^ee^ee^ad");
+ free(s);
+ // replace string, multiple character old delimeter
+ s = strdup("AA##ee##ee#");
+ iReplaceSCharS(&s, "##",'|', 0);
+ ck_assert_str_eq(s, "AA|ee|ee#");
+ free(s);
+ // replace one time at the start of string
+ s = strdup("#ee#ee#ad");
+ iReplaceSCharS(&s, "#",'^',1);
+ ck_assert_str_eq(s, "^ee#ee#ad");
+ free(s);
+ // replace one time
+ s = strdup("AA##ee##ee#");
+ iReplaceSCharS(&s, "##",'|',1);
+ ck_assert_str_eq(s, "AA|ee##ee#");
+ free(s);
+ // empty string
+ emptyS(s);
+ iReplaceSCharS(&s, "##", 0,1);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty old delimiter
+ s = strdup("qwe");
+ iReplaceSCharS(&s, "",'|',1);
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // NULL old delimiter
+ s = strdup("qwe");
+ iReplaceSCharS(&s, NULL,'|',1);
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // NULL string
+ s = NULL;
+ iReplaceSCharS(&s, "##",'|',1);
+ // NULL var
+ iReplaceSCharS(NULL, "##",'|',1);
+
+}
+
+
+void iReplaceCharCharST(CuTest *tc) {
+
+ char *s;
+ // replace string, multiple character new delimeter
+ s = strdup("#ee#ee#ad");
+ iReplaceCharCharS(&s, '#','^', 0);
+ ck_assert_str_eq(s, "^ee^ee^ad");
+ free(s);
+ // replace one time at the start of string
+ s = strdup("#ee#ee#ad");
+ iReplaceCharCharS(&s, '#','^',1);
+ ck_assert_str_eq(s, "^ee#ee#ad");
+ free(s);
+ // replace one time
+ s = strdup("AA#ee##ee#");
+ iReplaceCharCharS(&s, '#','|',1);
+ ck_assert_str_eq(s, "AA|ee##ee#");
+ free(s);
+ // empty string
+ emptyS(s);
+ iReplaceCharCharS(&s, '#', 0,1);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty old delimiter
+ s = strdup("qwe");
+ iReplaceCharCharS(&s, 0,'|',1);
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // NULL string
+ s = NULL;
+ iReplaceCharCharS(&s, '#','|',1);
+ // NULL var
+ iReplaceCharCharS(NULL, '#','|',1);
+
+}
+
+
+void bReplaceST(CuTest *tc) {
+
+ char s[100];
+ // replace string, multiple character new delimeter
+ strcpy(s, "#ee#ee#ad");
+ bReplaceS_max(s, "#","^^");
+ ck_assert_str_eq(s, "^^ee^^ee^^ad");
+ // replace string, multiple character old delimeter
+ strcpy(s, "AA##ee##ee#");
+ bReplaceS_max(s, "##","|");
+ ck_assert_str_eq(s, "AA|ee|ee#");
+ // replace one time at the start of string
+ strcpy(s, "#ee#ee#ad");
+ bReplaceS(s, "#","^^",1);
+ ck_assert_str_eq(s, "^^ee#ee#ad");
+ // replace one time
+ strcpy(s, "AA##ee##ee#");
+ bReplaceS(s, "##","|",1);
+ ck_assert_str_eq(s, "AA|ee##ee#");
+ // NULL new delimiter, one time: same as empty delimiter
+ strcpy(s, "AA##ee##ee#");
+ bReplaceS(s, "##",NULL,1);
+ ck_assert_str_eq(s, "AAee##ee#");
+ // empty string
+ bEmptyS(s);
+ bReplaceS(s, "##",NULL,1);
+ ck_assert_str_eq(s, "");
+ // empty old delimiter
+ strcpy(s, "qwe");
+ bReplaceS(s, "","|",1);
+ ck_assert_str_eq(s, "qwe");
+ // NULL old delimiter
+ strcpy(s, "qwe");
+ bReplaceS(s, NULL,"|",1);
+ ck_assert_str_eq(s, "qwe");
+ // NULL var
+ ck_assert_ptr_eq(bReplaceS(NULL, "##","|",1), NULL);
+
+}
+
+
+void bLReplaceST(CuTest *tc) {
+
+ char s[100];
+ // replace string, multiple character new delimeter
+ strcpy(s, "#ee#ee#ad");
+ bLReplaceS_max(s, sizeof s, "#","^^");
+ ck_assert_str_eq(s, "^^ee^^ee^^ad");
+ // shorter buffer
+ strcpy(s, "#ee#ee#ad");
+ bLReplaceS_max(s, 5, "#","^^");
+ ck_assert_str_eq(s, "^^ee");
+ // replace string, multiple character old delimeter
+ strcpy(s, "AA##ee##ee#");
+ bLReplaceS_max(s, sizeof s, "##","|");
+ ck_assert_str_eq(s, "AA|ee|ee#");
+ // replace one time at the start of string
+ strcpy(s, "#ee#ee#ad");
+ bLReplaceS(s, sizeof s, "#","^^",1);
+ ck_assert_str_eq(s, "^^ee#ee#ad");
+ // replace one time
+ strcpy(s, "AA##ee##ee#");
+ bLReplaceS(s, sizeof s, "##","|",1);
+ ck_assert_str_eq(s, "AA|ee##ee#");
+ // NULL new delimiter, one time: same as empty delimiter
+ strcpy(s, "AA##ee##ee#");
+ bLReplaceS(s, sizeof s, "##",NULL,1);
+ ck_assert_str_eq(s, "AAee##ee#");
+ // empty string
+ bEmptyS(s);
+ bLReplaceS(s, sizeof s, "##",NULL,1);
+ ck_assert_str_eq(s, "");
+ // empty old delimiter
+ strcpy(s, "qwe");
+ bLReplaceS(s, sizeof s, "","|",1);
+ ck_assert_str_eq(s, "qwe");
+ // NULL old delimiter
+ strcpy(s, "qwe");
+ bLReplaceS(s, sizeof s, NULL,"|",1);
+ ck_assert_str_eq(s, "qwe");
+ // size 0 - no change
+ strcpy(s, "qwe");
+ bLReplaceS(s, 0, "q","|",1);
+ ck_assert_str_eq(s, "qwe");
+ // NULL var
+ ck_assert_ptr_eq(bLReplaceS(NULL, sizeof s, "##","|",1), NULL);
+
+}
+
+
+void replaceManyST(CuTest *tc) {
+
+ // replace string, multiple character new delimeter
+ char *s = replaceManyS("#ee#ee#ad", "#","^^","ad","AD");
+ ck_assert_str_eq(s, "^^ee^^ee^^AD");
+ free(s);
+ // replace string, empty new delimeter
+ s = replaceManyS("#ee#ee#ad", "#","","ad","AD");
+ ck_assert_str_eq(s, "eeeeAD");
+ free(s);
+ // not enough olds:news pairs
+ s = replaceManyS("#ee#ee#ad", "#","","ad");
+ ck_assert_str_eq(s, "eeeead");
+ free(s);
+ // only 2 parameters
+ s = replaceManyS("#ee#ee#ad", "#");
+ ck_assert_ptr_eq(s, NULL);
+ free(s);
+ // NULL new delimiter: same as only 2 parameters or not enough olds:news pairs
+ s = replaceManyS("AA##ee##ee#", "##",NULL);
+ ck_assert_ptr_eq(s, NULL);
+ free(s);
+ // empty string
+ s = replaceManyS("", "##", "");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty string many pairs
+ s = replaceManyS("", "##", "", "$$", "");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty string many pairs empty olds
+ s = replaceManyS("", "##", "", "", "");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty string and NULL old delimiter
+ s = replaceManyS("", NULL,"|");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty string and NULL old delimiter not first - same as replace empty string
+ s = replaceManyS("","##","|", NULL,"|");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty old delimiter
+ ck_assert_ptr_eq(replaceManyS("AA##ee##ee#", "","|", "AA", "BB"), NULL);
+ // empty old delimiter not first
+ ck_assert_ptr_eq(replaceManyS("AA##ee##ee#", "##","|", "", "BB"), NULL);
+ // NULL string
+ ck_assert_ptr_eq(replaceManyS(NULL, "##","|"), NULL);
+ // NULL string many pairs
+ ck_assert_ptr_eq(replaceManyS(NULL, "##","|", "$$", ""), NULL);
+
+}
+
+
+void iReplaceManyST(CuTest *tc) {
+
+ char *s;
+ // replace string, multiple character new delimeter
+ s = strdup("#ee#ee#ad");
+ iReplaceManyS(&s, "#","^^","ad","AD");
+ ck_assert_str_eq(s, "^^ee^^ee^^AD");
+ free(s);
+ // replace string, empty new delimeter
+ s = strdup("#ee#ee#ad");
+ iReplaceManyS(&s, "#","","ad","AD");
+ ck_assert_str_eq(s, "eeeeAD");
+ free(s);
+ // not enough olds:news pairs
+ s = strdup("#ee#ee#ad");
+ iReplaceManyS(&s, "#","","ad");
+ ck_assert_str_eq(s, "eeeead");
+ free(s);
+ // only 2 parameters
+ // doesn't compile
+ /* s = strdup("#ee#ee#ad"); */
+ /* iReplaceManyS(&s, "#"); */
+ /* ck_assert_str_eq(s, "#ee#ee#ad"); */
+ /* free(s); */
+ // NULL new delimiter: same as only 2 parameters or not enough olds:news pairs
+ s = strdup("#ee#ee#ad");
+ iReplaceManyS(&s, "#", NULL);
+ ck_assert_str_eq(s, "#ee#ee#ad");
+ free(s);
+ // empty string
+ emptyS(s);
+ iReplaceManyS(&s, "#", "");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty string many pairs
+ emptyS(s);
+ iReplaceManyS(&s, "#", "", "%", "");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // many pairs empty olds
+ s = strdup("qw#e");
+ iReplaceManyS(&s, "#", "", "", "");
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // NULL old delimiter
+ s = strdup("qw#e");
+ iReplaceManyS(&s, NULL, "");
+ ck_assert_str_eq(s, "qw#e");
+ free(s);
+ // NULL old delimiter not first - same as replace empty string
+ s = strdup("qw#e");
+ iReplaceManyS(&s, "#","|", NULL, "");
+ ck_assert_str_eq(s, "qw|e");
+ free(s);
+ // empty old delimiter
+ s = strdup("qw#e");
+ iReplaceManyS(&s, "","|", NULL, "");
+ ck_assert_str_eq(s, "qw#e");
+ free(s);
+ // empty old delimiter not first
+ s = strdup("qw#e");
+ iReplaceManyS(&s, "#","|", "", "*");
+ ck_assert_str_eq(s, "qw|e");
+ free(s);
+ // NULL string
+ s = NULL;
+ iReplaceManyS(&s, "#","|", "$", "*");
+ ck_assert_ptr_eq(s, NULL);
+ free(s);
+ // NULL var
+ iReplaceManyS(NULL, "#","|", "$", "*");
+
+}
+
+
+void bReplaceManyST(CuTest *tc) {
+
+ char s[100];
+ // replace string, multiple character new delimeter
+ strcpy(s, "#ee#ee#ad");
+ bReplaceManyS(s, "#","^^","ad","AD");
+ ck_assert_str_eq(s, "^^ee^^ee^^AD");
+ // replace string, empty new delimeter
+ strcpy(s, "#ee#ee#ad");
+ bReplaceManyS(s, "#","","ad","AD");
+ ck_assert_str_eq(s, "eeeeAD");
+ // not enough olds:news pairs
+ strcpy(s, "#ee#ee#ad");
+ bReplaceManyS(s, "#","","ad");
+ ck_assert_str_eq(s, "eeeead");
+ // only 2 parameters
+ // doesn't compile
+ /* strcpy(s, "#ee#ee#ad"); */
+ /* bReplaceManyS(s, "#"); */
+ /* ck_assert_str_eq(s, "#ee#ee#ad"); */
+ /* free(s); */
+ // NULL new delimiter: same as only 2 parameters or not enough olds:news pairs
+ strcpy(s, "#ee#ee#ad");
+ bReplaceManyS(s, "#", NULL);
+ ck_assert_str_eq(s, "#ee#ee#ad");
+ // empty string
+ bEmptyS(s);
+ bReplaceManyS(s, "#", "");
+ ck_assert_str_eq(s, "");
+ // empty string many pairs
+ bEmptyS(s);
+ bReplaceManyS(s, "#", "", "%", "");
+ ck_assert_str_eq(s, "");
+ // many pairs empty olds
+ strcpy(s, "qw#e");
+ bReplaceManyS(s, "#", "", "", "");
+ ck_assert_str_eq(s, "qwe");
+ // NULL old delimiter
+ strcpy(s, "qw#e");
+ bReplaceManyS(s, NULL, "");
+ ck_assert_str_eq(s, "qw#e");
+ // NULL old delimiter not first - same as replace empty string
+ strcpy(s, "qw#e");
+ bReplaceManyS(s, "#","|", NULL, "");
+ ck_assert_str_eq(s, "qw|e");
+ // empty old delimiter
+ strcpy(s, "qw#e");
+ bReplaceManyS(s, "","|", NULL, "");
+ ck_assert_str_eq(s, "qw#e");
+ // empty old delimiter not first
+ strcpy(s, "qw#e");
+ bReplaceManyS(s, "#","|", "", "*");
+ ck_assert_str_eq(s, "qw|e");
+ // NULL var
+ ck_assert_ptr_eq(bReplaceManyS(NULL, "#","|", "$", "*"), NULL);
+
+}
+
+
+void bLReplaceManyST(CuTest *tc) {
+
+ char s[100];
+ // replace string, multiple character new delimeter
+ strcpy(s, "#ee#ee#ad");
+ bLReplaceManyS(s, sizeof s, "#","^^","ad","AD");
+ ck_assert_str_eq(s, "^^ee^^ee^^AD");
+ // shorter buffer
+ strcpy(s, "#ee#ee#ad");
+ bLReplaceManyS(s, 5, "#","^^","ad","AD");
+ ck_assert_str_eq(s, "^^ee");
+ // replace string, empty new delimeter
+ strcpy(s, "#ee#ee#ad");
+ bLReplaceManyS(s, sizeof s, "#","","ad","AD");
+ ck_assert_str_eq(s, "eeeeAD");
+ // not enough olds:news pairs
+ strcpy(s, "#ee#ee#ad");
+ bLReplaceManyS(s, sizeof s, "#","","ad");
+ ck_assert_str_eq(s, "eeeead");
+ // only 2 parameters
+ // doesn't compile
+ /* strcpy(s, "#ee#ee#ad"); */
+ /* bLReplaceManyS(s, sizeof s, "#"); */
+ /* ck_assert_str_eq(s, "#ee#ee#ad"); */
+ /* free(s); */
+ // NULL new delimiter: same as only 2 parameters or not enough olds:news pairs
+ strcpy(s, "#ee#ee#ad");
+ bLReplaceManyS(s, sizeof s, "#", NULL);
+ ck_assert_str_eq(s, "#ee#ee#ad");
+ // empty string
+ bEmptyS(s);
+ bLReplaceManyS(s, sizeof s, "#", "");
+ ck_assert_str_eq(s, "");
+ // empty string many pairs
+ bEmptyS(s);
+ bLReplaceManyS(s, sizeof s, "#", "", "%", "");
+ ck_assert_str_eq(s, "");
+ // many pairs empty olds
+ strcpy(s, "qw#e");
+ bLReplaceManyS(s, sizeof s, "#", "", "", "");
+ ck_assert_str_eq(s, "qwe");
+ // NULL old delimiter
+ strcpy(s, "qw#e");
+ bLReplaceManyS(s, sizeof s, NULL, "");
+ ck_assert_str_eq(s, "qw#e");
+ // NULL old delimiter not first - same as replace empty string
+ strcpy(s, "qw#e");
+ bLReplaceManyS(s, sizeof s, "#","|", NULL, "");
+ ck_assert_str_eq(s, "qw|e");
+ // empty old delimiter
+ strcpy(s, "qw#e");
+ bLReplaceManyS(s, sizeof s, "","|", NULL, "");
+ ck_assert_str_eq(s, "qw#e");
+ // empty old delimiter not first
+ strcpy(s, "qw#e");
+ bLReplaceManyS(s, sizeof s, "#","|", "", "*");
+ ck_assert_str_eq(s, "qw|e");
+ // size 0 - no change
+ bLReplaceManyS(s, 0, "#","|", "", "*");
+ ck_assert_str_eq(s, "qw|e");
+ // NULL var
+ ck_assert_ptr_eq(bLReplaceManyS(NULL, sizeof s, "#","|", "$", "*"), NULL);
+
+}
+
+
+void eqST(CuTest *tc) {
+
+ // identical strings
+ ck_assert(eqS("shee", "shee"));
+ // different strings
+ ck_assert(!eqS("shee", "SH"));
+ // empty strings
+ ck_assert(!eqS("shee", ""));
+ ck_assert(!eqS("", "SH"));
+ ck_assert(eqS("", ""));
+ // NULL string
+ ck_assert(!eqS(NULL,"a"));
+ ck_assert(!eqS("a", NULL));
+
+}
+
+
+void eqCharST(CuTest *tc) {
+
+ // identical strings
+ ck_assert(eqCharS('s', "s"));
+ // different strings
+ ck_assert(!eqCharS('s', "SH"));
+ // empty strings
+ ck_assert(!eqCharS('s', ""));
+ ck_assert(!eqCharS(0, "SH"));
+ ck_assert(eqCharS(0, ""));
+ // NULL string
+ ck_assert(!eqCharS(0,"a"));
+ ck_assert(!eqCharS('a', NULL));
+
+}
+
+
+void eqSCharT(CuTest *tc) {
+
+ // identical strings
+ ck_assert(eqSChar("s", 's'));
+ // different strings
+ ck_assert(!eqSChar("shee", 'S'));
+ // empty strings
+ ck_assert(!eqSChar("shee", 0));
+ ck_assert(!eqSChar("", 'S'));
+ ck_assert(eqSChar("", 0));
+ // NULL string
+ ck_assert(!eqSChar(NULL,'a'));
+ ck_assert(!eqS("a", 0));
+
+}
+
+
+void eqIST(CuTest *tc) {
+
+ // identical strings
+ ck_assert(eqIS("Ashee", "shee", 1));
+ ck_assert(eqIS("Ashee", "shee", -4));
+ // string at index shorter than string2
+ ck_assert(!eqIS("Ashee", "shee", 2));
+ // empty string
+ ck_assert(!eqIS("", "shee", 0));
+ ck_assert(!eqIS("Ashee", "", 0));
+ ck_assert(eqIS("", "", 0));
+ // index mismatch
+ ck_assert(!eqIS("Ashee", "shee", 0));
+ // index outside
+ ck_assert(!eqIS("Ashee", "shee", 10));
+ ck_assert(!eqIS("Ashee", "shee", -10));
+ // different strings
+ ck_assert(!eqIS("shee", "SH",0));
+ // NULL string
+ ck_assert(!eqIS(NULL,"a", 0));
+ ck_assert(!eqIS("a", NULL, 0));
+
+}
+
+
+void eqICharST(CuTest *tc) {
+
+ // identical strings
+ ck_assert(eqICharS("Ashee", 's', 1));
+ ck_assert(eqICharS("Ashee", 's', -4));
+ // string at index shorter than string2
+ ck_assert(!eqICharS("Ashee", 's', 2));
+ // empty string
+ ck_assert(!eqICharS("", 's', 0));
+ ck_assert(!eqICharS("Ashee", 0, 0));
+ ck_assert(eqICharS("", 0, 0));
+ // index mismatch
+ ck_assert(!eqICharS("Ashee", 's', 0));
+ // index outside
+ ck_assert(!eqICharS("Ashee", 's', 10));
+ ck_assert(!eqICharS("Ashee", 's', -10));
+ // different strings
+ ck_assert(!eqICharS("shee", 'S',0));
+ // NULL string
+ ck_assert(!eqICharS(NULL,'a', 0));
+ ck_assert(!eqICharS("a", 0, 0));
+
+}
+
+
+void startsWithST(CuTest *tc) {
+
+ // identical strings
+ ck_assert(startsWithS("shee", "shee"));
+ ck_assert(startsWithS("sheepy", "shee"));
+ // different strings
+ ck_assert(!startsWithS("shee", "SH"));
+ ck_assert(!startsWithS("shee", "sheep"));
+ ck_assert(!startsWithS("-shee", "shee"));
+ // NULL string
+ ck_assert(!startsWithS(NULL,"a"));
+ ck_assert(!startsWithS("a", NULL));
+
+}
+
+
+void startsWithCharST(CuTest *tc) {
+
+ // identical strings
+ ck_assert(startsWithCharS("shee", 's'));
+ ck_assert(startsWithCharS("sheepy", 's'));
+ ck_assert(startsWithCharS("", 0));
+ // different strings
+ ck_assert(!startsWithCharS("shee", 'S'));
+ ck_assert(!startsWithCharS("-shee", 's'));
+ ck_assert(!startsWithCharS("", '0'));
+ // NULL string
+ ck_assert(!startsWithCharS(NULL,'a'));
+ ck_assert(!startsWithCharS("a", 0));
+
+}
+
+
+void endsWithST(CuTest *tc) {
+
+ // identical strings
+ ck_assert(endsWithS("shee", "shee"));
+ ck_assert(endsWithS("sheepy", "eepy"));
+ // different strings
+ ck_assert(!endsWithS("shee", "SH"));
+ ck_assert(!endsWithS("shee", "sheep"));
+ ck_assert(!endsWithS("shee-", "shee"));
+ // NULL string
+ ck_assert(!endsWithS(NULL,"a"));
+ ck_assert(!endsWithS("a", NULL));
+
+}
+
+
+void endsWithCharST(CuTest *tc) {
+
+ // identical strings
+ ck_assert(endsWithCharS("shee", 'e'));
+ ck_assert(endsWithCharS("sheepy", 'y'));
+ ck_assert(endsWithCharS("", 0));
+ // different strings
+ ck_assert(!endsWithCharS("shee", 'E'));
+ ck_assert(!endsWithCharS("shee", 'p'));
+ ck_assert(!endsWithCharS("shee-", 'e'));
+ ck_assert(!endsWithCharS("", '0'));
+ // NULL string
+ ck_assert(!endsWithCharS(NULL,'a'));
+ ck_assert(!endsWithCharS("a", 0));
+
+}
+
+
+void countST(CuTest *tc) {
+
+ // positive count
+ ck_assert_int_eq(countS("shee", "shee"), 1);
+ ck_assert_int_eq(countS("aaa aaa", "a"), 6);
+ ck_assert_int_eq(countS("aaa aaa", "aa"), 2);
+ // 0 count
+ ck_assert_int_eq(countS("shee", "SH"), 0);
+ ck_assert_int_eq(countS("shee", "sheepy"), 0);
+ ck_assert_int_eq(countS("aaa aaa", "ab"), 0);
+ // NULL string
+ ck_assert_int_eq(countS(NULL,"a"), -1);
+ ck_assert_int_eq(countS("a", NULL), -1);
+
+}
+
+
+void countCharST(CuTest *tc) {
+
+ // positive count
+ ck_assert_int_eq(countCharS("shee", 's'), 1);
+ ck_assert_int_eq(countCharS("aaa aaa", 'a'), 6);
+ // 0 count
+ ck_assert_int_eq(countCharS("shee", 'S'), 0);
+ ck_assert_int_eq(countCharS("shee", 'y'), 0);
+ ck_assert_int_eq(countCharS("aaa aaa", 'b'), 0);
+ // empty string
+ ck_assert_int_eq(countCharS("", 'a'), 0);
+ ck_assert_int_eq(countCharS("", 0), -1);
+ // NULL string
+ ck_assert_int_eq(countCharS(NULL,'a'), -1);
+ ck_assert_int_eq(countCharS("a", 0), -1);
+
+}
+
+
+void isNumberT(CuTest *tc) {
+
+ // number
+ ck_assert(isNumber("-12.3"));
+ ck_assert(isNumber("-123"));
+ ck_assert(isNumber("123"));
+ ck_assert(isNumber("1e23"));
+ ck_assert(isNumber("12E-3"));
+ ck_assert(isNumber(".123"));
+ ck_assert(isNumber("-.123"));
+ ck_assert(isNumber("1E+32"));
+ // not a number
+ ck_assert(!isNumber(".12e3"));
+ ck_assert(!isNumber("-.12e3"));
+ ck_assert(!isNumber("-1-23"));
+ ck_assert(!isNumber("123-"));
+ ck_assert(!isNumber("-"));
+ ck_assert(!isNumber("-123."));
+ ck_assert(!isNumber("-1.2.3"));
+ ck_assert(!isNumber("1-2.3"));
+ ck_assert(!isNumber("12..3"));
+ ck_assert(!isNumber(".12.3"));
+ ck_assert(!isNumber("."));
+ ck_assert(!isNumber("E12"));
+ ck_assert(!isNumber("E1E2"));
+ ck_assert(!isNumber("E1.2"));
+ ck_assert(!isNumber("1E"));
+ ck_assert(!isNumber("1E2.3"));
+ ck_assert(!isNumber("1-"));
+ ck_assert(!isNumber("1E-"));
+ ck_assert(!isNumber("lib123sheepy"));
+ // string without number
+ ck_assert(!isNumber("s"));
+ // empty string
+ ck_assert(!isNumber(""));
+ // NULL string
+ ck_assert(!isNumber(NULL));
+
+}
+
+
+void isIntT(CuTest *tc) {
+
+ // integer
+ ck_assert(isInt("-123"));
+ ck_assert(isInt("123"));
+ // not a integer
+ ck_assert(!isInt("1e23"));
+ ck_assert(!isInt("12E-3"));
+ ck_assert(!isInt("-12.3"));
+ ck_assert(!isInt("-1-23"));
+ ck_assert(!isInt("123-"));
+ ck_assert(!isInt("-"));
+ ck_assert(!isInt("-123."));
+ ck_assert(!isInt(".123"));
+ ck_assert(!isInt("-1.2.3"));
+ ck_assert(!isInt("1-2.3"));
+ ck_assert(!isInt("12..3"));
+ ck_assert(!isInt("."));
+ ck_assert(!isInt("1E"));
+ ck_assert(!isInt("1-"));
+ ck_assert(!isInt("1E-"));
+ ck_assert(!isInt("lib123sheepy"));
+ // string without number
+ ck_assert(!isInt("s"));
+ // empty string
+ ck_assert(!isInt(""));
+ // NULL string
+ ck_assert(!isInt(NULL));
+
+}
+
+
+void parseIntT(CuTest *tc) {
+
+ // number
+ ck_assert_int_eq(parseInt("123sheepy"), 123);
+ ck_assert_int_eq(parseInt("lib123sheepy"), 123);
+ ck_assert_int_eq(parseInt("-123"), -123);
+ // out of range - TODO check stderr
+ parseInt("999999999999999999999999999999999999999");
+ // string without number
+ ck_assert_int_eq(parseInt("sheepy"), 0);
+ // NULL string
+ ck_assert_int_eq(parseInt(NULL), 0);
+
+}
+
+
+void parseIntCharT(CuTest *tc) {
+
+ // number
+ ck_assert_int_eq(parseIntChar('1'),1);
+ ck_assert_int_eq(parseIntChar('0'),0);
+ ck_assert_int_eq(parseIntChar('9'),9);
+ // not a number
+ ck_assert_int_eq(parseIntChar('a'),-1);
+ ck_assert_int_eq(parseIntChar(0),-1);
+
+}
+
+
+void parseDoubleT(CuTest *tc) {
+
+ // number
+ ck_assert_int_eq(parseDouble("123.2sheepy"), 123);
+ ck_assert_int_eq(parseDouble("lib123sheepy"), 123);
+ ck_assert_int_eq(parseDouble("-123"), -123);
+ // out of range - TODO check stderr
+ parseDouble("999999999999999999999999999999999999999");
+ // string without number
+ ck_assert_int_eq(parseDouble("sheepy"), 0);
+ // NULL string
+ ck_assert_int_eq(parseDouble(NULL), 0);
+
+}
+
+
+void intToST(CuTest *tc) {
+
+ // number
+ char *s = intToS(123);
+ ck_assert_str_eq(s, "123");
+ free(s);
+ s = intToS(-465464123);
+ ck_assert_str_eq(s, "-465464123");
+ free(s);
+
+}
+
+
+void bIntToST(CuTest *tc) {
+
+ // number
+ char s[50];
+ bIntToS(s, 123);
+ ck_assert_str_eq(s, "123");
+ bIntToS(s, -465464123);
+ ck_assert_str_eq(s, "-465464123");
+ // NULL
+ ck_assert_ptr_eq(bIntToS(NULL, 123), NULL);
+
+}
+
+
+void doubleToST(CuTest *tc) {
+
+ // number
+ char *s = doubleToS(123.4);
+ ck_assert_str_eq(s, "1.234000e+02");
+ free(s);
+ s = doubleToS(-4652445e5);
+ ck_assert_str_eq(s, "-4.652445e+11");
+ free(s);
+
+}
+
+
+void bDoubleToST(CuTest *tc) {
+
+ // number
+ char s[256];
+ bDoubleToS(s, 123.4);
+ ck_assert_str_eq(s, "1.234000e+02");
+ bDoubleToS(s, -4652445e5);
+ ck_assert_str_eq(s, "-4.652445e+11");
+ // NULL
+ ck_assert_ptr_eq(bDoubleToS(NULL, 123.4), NULL);
+
+}
+
+
+void lenST(CuTest *tc) {
+
+ // string
+ ck_assert_uint_eq(lenS("sheepy"), 6);
+ // NULL string
+ ck_assert_uint_eq(lenS(NULL), 0);
+
+}
+
+
+void upperST(CuTest *tc) {
+
+ // string
+ char *s = upperS("sheepy");
+ ck_assert_str_eq(s, "SHEEPY");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(upperS(NULL), NULL);
+
+}
+
+
+void iUpperST(CuTest *tc) {
+
+ char *s;
+ // string
+ s = strdup("sheepy");
+ iUpperS(&s);
+ ck_assert_str_eq(s, "SHEEPY");
+ free(s);
+ // NULL string
+ s = NULL;
+ iUpperS(&s);
+ ck_assert_ptr_eq(s, NULL);
+ // NULL var
+ iUpperS(NULL);
+
+}
+
+
+void bUpperST(CuTest *tc) {
+
+ char s[50];
+ // string
+ strcpy(s, "sheepy");
+ bUpperS(s);
+ ck_assert_str_eq(s, "SHEEPY");
+ // NULL var
+ ck_assert_ptr_eq(bUpperS(NULL), NULL);
+
+}
+
+
+void lowerST(CuTest *tc) {
+
+ // string
+ char *s = lowerS("SHeePY");
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(lowerS(NULL), NULL);
+
+}
+
+
+void iLowerST(CuTest *tc) {
+
+ char *s;
+ // string
+ s = strdup("SHEEPY");
+ iLowerS(&s);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // NULL string
+ s = NULL;
+ iLowerS(&s);
+ ck_assert_ptr_eq(s, NULL);
+ // NULL var
+ iLowerS(NULL);
+
+}
+
+
+void bLowerST(CuTest *tc) {
+
+ char s[50];
+ // string
+ strcpy(s, "SHEEPY");
+ bLowerS(s);
+ ck_assert_str_eq(s, "sheepy");
+ // NULL var
+ ck_assert_ptr_eq(bLowerS(NULL), NULL);
+
+}
+
+
+void trimST(CuTest *tc) {
+
+ // no spaces
+ char *s = trimS("SHeePY");
+ ck_assert_str_eq(s, "SHeePY");
+ free(s);
+ // heading spaces
+ s = trimS(" SHeePY");
+ ck_assert_str_eq(s, "SHeePY");
+ free(s);
+ // trailing spaces
+ s = trimS("SHeePY ");
+ ck_assert_str_eq(s, "SHeePY");
+ free(s);
+ // string with spaces in the middle
+ s = trimS(" SHe ePY ");
+ ck_assert_str_eq(s, "SHe ePY");
+ free(s);
+ // all spaces
+ s = trimS(" ");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(trimS(NULL), NULL);
+
+}
+
+
+void iTrimST(CuTest *tc) {
+
+ char *s;
+ // no spaces
+ s = strdup("SHeePY");
+ iTrimS(&s);
+ ck_assert_str_eq(s, "SHeePY");
+ free(s);
+ // heading spaces
+ s = strdup(" SHeePY");
+ iTrimS(&s);
+ ck_assert_str_eq(s, "SHeePY");
+ free(s);
+ // trailing spaces
+ s = strdup("SHeePY ");
+ iTrimS(&s);
+ ck_assert_str_eq(s, "SHeePY");
+ free(s);
+ // string with spaces in the middle
+ s = strdup(" SHe ePY ");
+ iTrimS(&s);
+ ck_assert_str_eq(s, "SHe ePY");
+ free(s);
+ // all spaces
+ s = strdup(" ");
+ iTrimS(&s);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // NULL string
+ s = NULL;
+ iTrimS(&s);
+ ck_assert_ptr_eq(s, NULL);
+ // NULL var
+ iTrimS(NULL);
+
+}
+
+
+void bTrimST(CuTest *tc) {
+
+ char s[50];
+ // no spaces
+ strcpy(s, "SHeePY");
+ bTrimS(s);
+ ck_assert_str_eq(s, "SHeePY");
+ // heading spaces
+ strcpy(s, " SHeePY");
+ bTrimS(s);
+ ck_assert_str_eq(s, "SHeePY");
+ // trailing spaces
+ strcpy(s, "SHeePY ");
+ bTrimS(s);
+ ck_assert_str_eq(s, "SHeePY");
+ // string with spaces in the middle
+ strcpy(s, " SHe ePY ");
+ bTrimS(s);
+ ck_assert_str_eq(s, "SHe ePY");
+ // all spaces
+ strcpy(s, " ");
+ bTrimS(s);
+ ck_assert_str_eq(s, "");
+ // NULL var
+ ck_assert_ptr_eq(bTrimS(NULL), NULL);
+
+}
+
+
+void lTrimST(CuTest *tc) {
+
+ // no spaces
+ char *s = lTrimS("SHeePY");
+ ck_assert_str_eq(s, "SHeePY");
+ free(s);
+ // heading spaces
+ s = lTrimS(" SHeePY");
+ ck_assert_str_eq(s, "SHeePY");
+ free(s);
+ // trailing spaces
+ s = lTrimS("SHeePY ");
+ ck_assert_str_eq(s, "SHeePY ");
+ free(s);
+ // string with spaces in the middle
+ s = lTrimS(" SHe ePY ");
+ ck_assert_str_eq(s, "SHe ePY ");
+ free(s);
+ // all spaces
+ s = lTrimS(" ");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(lTrimS(NULL), NULL);
+
+}
+
+
+void iLTrimST(CuTest *tc) {
+
+ char *s;
+ // no spaces
+ s = strdup("SHeePY");
+ iLTrimS(&s);
+ ck_assert_str_eq(s, "SHeePY");
+ free(s);
+ // heading spaces
+ s = strdup(" SHeePY");
+ iLTrimS(&s);
+ ck_assert_str_eq(s, "SHeePY");
+ free(s);
+ // trailing spaces
+ s = strdup("SHeePY ");
+ iLTrimS(&s);
+ ck_assert_str_eq(s, "SHeePY ");
+ free(s);
+ // string with spaces in the middle
+ s = strdup(" SHe ePY ");
+ iLTrimS(&s);
+ ck_assert_str_eq(s, "SHe ePY ");
+ free(s);
+ // all spaces
+ s = strdup(" ");
+ iLTrimS(&s);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // NULL string
+ s = NULL;
+ iLTrimS(&s);
+ ck_assert_ptr_eq(s, NULL);
+ // NULL var
+ iLTrimS(NULL);
+
+}
+
+
+void bLTrimST(CuTest *tc) {
+
+ char s[50];
+ // no spaces
+ strcpy(s, "SHeePY");
+ bLTrimS(s);
+ ck_assert_str_eq(s, "SHeePY");
+ // heading spaces
+ strcpy(s, " SHeePY");
+ bLTrimS(s);
+ ck_assert_str_eq(s, "SHeePY");
+ // trailing spaces
+ strcpy(s, "SHeePY ");
+ bLTrimS(s);
+ ck_assert_str_eq(s, "SHeePY ");
+ // string with spaces in the middle
+ strcpy(s, " SHe ePY ");
+ bLTrimS(s);
+ ck_assert_str_eq(s, "SHe ePY ");
+ // all spaces
+ strcpy(s, " ");
+ bLTrimS(s);
+ ck_assert_str_eq(s, "");
+ // NULL var
+ ck_assert_ptr_eq(bLTrimS(NULL), NULL);
+
+}
+
+
+void rTrimST(CuTest *tc) {
+
+ // no spaces
+ char *s = rTrimS("SHeePY");
+ ck_assert_str_eq(s, "SHeePY");
+ free(s);
+ // heading spaces
+ s = rTrimS(" SHeePY");
+ ck_assert_str_eq(s, " SHeePY");
+ free(s);
+ // trailing spaces
+ s = rTrimS("SHeePY ");
+ ck_assert_str_eq(s, "SHeePY");
+ free(s);
+ // string with spaces in the middle
+ s = rTrimS(" SHe ePY ");
+ ck_assert_str_eq(s, " SHe ePY");
+ free(s);
+ // all spaces
+ s = rTrimS(" ");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(rTrimS(NULL), NULL);
+
+}
+
+
+void iRTrimST(CuTest *tc) {
+
+ char *s;
+ // no spaces
+ s = strdup("SHeePY");
+ iRTrimS(&s);
+ ck_assert_str_eq(s, "SHeePY");
+ free(s);
+ // heading spaces
+ s = strdup(" SHeePY");
+ iRTrimS(&s);
+ ck_assert_str_eq(s, " SHeePY");
+ free(s);
+ // trailing spaces
+ s = strdup("SHeePY ");
+ iRTrimS(&s);
+ ck_assert_str_eq(s, "SHeePY");
+ free(s);
+ // string with spaces in the middle
+ s = strdup(" SHe ePY ");
+ iRTrimS(&s);
+ ck_assert_str_eq(s, " SHe ePY");
+ free(s);
+ // all spaces
+ s = strdup(" ");
+ iRTrimS(&s);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // NULL string
+ s = NULL;
+ iRTrimS(&s);
+ ck_assert_ptr_eq(s, NULL);
+ // NULL var
+ iRTrimS(NULL);
+
+}
+
+
+void bRTrimST(CuTest *tc) {
+
+ char s[100];
+ // no spaces
+ strcpy(s, "SHeePY");
+ bRTrimS(s);
+ ck_assert_str_eq(s, "SHeePY");
+ // heading spaces
+ strcpy(s, " SHeePY");
+ bRTrimS(s);
+ ck_assert_str_eq(s, " SHeePY");
+ // trailing spaces
+ strcpy(s, "SHeePY ");
+ bRTrimS(s);
+ ck_assert_str_eq(s, "SHeePY");
+ // string with spaces in the middle
+ strcpy(s, " SHe ePY ");
+ bRTrimS(s);
+ ck_assert_str_eq(s, " SHe ePY");
+ // all spaces
+ strcpy(s, " ");
+ bRTrimS(s);
+ ck_assert_str_eq(s, "");
+ // NULL var
+ ck_assert_ptr_eq(bRTrimS(NULL), NULL);
+
+}
+
+
+void uniqST(CuTest *tc) {
+
+ char *s;
+
+ // uniquify
+ s = uniqS("/qwd///", '/');
+ ck_assert_str_eq(s, "/qwd/");
+ free(s);
+ // short string
+ s = uniqS("?", '/');
+ ck_assert_str_eq(s, "?");
+ free(s);
+ // NULL
+ ck_assert_ptr_eq(uniqS(NULL, '/'), NULL);
+
+}
+
+
+void iUniqST(CuTest *tc) {
+
+ char *s;
+
+ // uniquify
+ s = strdup("/qwd///");
+ ck_assert_str_eq(iUniqS(&s, '/'), "/qwd/");
+ free(s);
+ // short string
+ s = strdup("?");
+ ck_assert_str_eq(iUniqS(&s, '/'), "?");
+ free(s);
+ // NULL string
+ s = NULL;
+ ck_assert_ptr_eq(iUniqS(&s, '/'), NULL);
+ // NULL
+ ck_assert_ptr_eq(iUniqS(NULL, '/'), NULL);
+
+}
+
+
+void bUniqST(CuTest *tc) {
+
+ char s[100];
+
+ // uniquify
+ strcpy(s, "/qwd///");
+ ck_assert_str_eq(bUniqS(s, '/'), "/qwd/");
+ // short string
+ strcpy(s, "?");
+ ck_assert_str_eq(bUniqS(s, '/'), "?");
+ // NULL
+ ck_assert_ptr_eq(bUniqS(NULL, '/'), NULL);
+
+}
+
+
+void getST(CuTest *tc) {
+
+ // get char
+ ck_assert_uint_eq(getS("sheepy", 0), 's');
+ // negative index
+ ck_assert_uint_eq(getS("sheepy", -1), 'y');
+ // outside string
+ ck_assert_uint_eq(getS("sheepy", 10), 0);
+ ck_assert_uint_eq(getS("sheepy", -10), 0);
+ // negative index in a one char string
+ ck_assert_uint_eq(getS("z", -1), 'z');
+ // empty string
+ ck_assert_uint_eq(getS("", 0), 0);
+ // NULL string
+ ck_assert_uint_eq(getS(NULL, 0), 0);
+
+}
+
+
+void setST(CuTest *tc) {
+
+ char *s;
+ s = strdup("sheepy");
+
+ // set char
+ setS(s, 0, 'S');
+ ck_assert_uint_eq(s[0], 'S');
+ // negative index
+ setS(s, -2, 'P');
+ ck_assert_uint_eq(s[4], 'P');
+ // outside string
+ setS(s, 20, 'Y');
+ setS(s, -20, 'Y');
+ ck_assert_str_eq(s, "SheePy");
+ free(s);
+ // negative index in a one char string
+ s = strdup("s");
+ setS(s, -1, 'S');
+ ck_assert_uint_eq(s[0], 'S');
+ free(s);
+ // empty string
+ emptyS(s);
+ setS(s, -1, 'S');
+ ck_assert_str_eq(s, "");
+ free(s);
+ // NULL string
+ setS(NULL, 0, 's');
+
+
+}
+
+
+void sliceST(CuTest *tc) {
+
+ // slice
+ char *s = sliceS("sheepy", 0,2);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ // negative index
+ s = sliceS("sheepy", -2,0);
+ ck_assert_str_eq(s, "py");
+ free(s);
+ // positive and negative indexes
+ s = sliceS("sheepy", 2,-2);
+ ck_assert_str_eq(s, "ee");
+ free(s);
+ // start = end
+ s = sliceS("sheepy", 2,-4);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end of string
+ s = sliceS("sheepy", 2,6);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(sliceS(NULL, 2,-4), NULL);
+ // start outside string
+ ck_assert_ptr_eq(sliceS("sheepy", 20,-4), NULL);
+ // end outside string
+ s = sliceS("sheepy", 2,40);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ s = sliceS("sheepy", -22,3);
+ ck_assert_str_eq(s, "she");
+ free(s);
+ ck_assert_ptr_eq(sliceS("sheepy", 2,-40), NULL);
+ // end before start
+ ck_assert_ptr_eq(sliceS("sheepy", 4,2), NULL);
+
+}
+
+
+void iSliceST(CuTest *tc) {
+
+ char *s;
+ // slice
+ s = strdup("sheepy");
+ iSliceS(&s, 0,2);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ // negative index
+ s = strdup("sheepy");
+ iSliceS(&s, -2,0);
+ ck_assert_str_eq(s, "py");
+ free(s);
+ // positive and negative indexes
+ s = strdup("sheepy");
+ iSliceS(&s, 2,-2);
+ ck_assert_str_eq(s, "ee");
+ free(s);
+ // start = end
+ s = strdup("sheepy");
+ iSliceS(&s, 2,-4);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end of string
+ s = strdup("sheepy");
+ iSliceS(&s, 2,6);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // NULL string
+ s = NULL;
+ iSliceS(&s, 2,-4);
+ ck_assert_ptr_eq(s, NULL);
+ // start outside string
+ s = strdup("sheepy");
+ iSliceS(&s, 20,-4);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end outside string
+ s = strdup("sheepy");
+ iSliceS(&s, 2,40);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ s = strdup("sheepy");
+ iSliceS(&s, -22,3);
+ ck_assert_str_eq(s, "she");
+ free(s);
+ s = strdup("sheepy");
+ iSliceS(&s, 2,-40);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end before start
+ s = strdup("sheepy");
+ iSliceS(&s, 4,2);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // NULL var
+ iSliceS(NULL, 0, 0);
+
+}
+
+
+void bSliceST(CuTest *tc) {
+
+ char s[100];
+ // slice
+ strcpy(s, "sheepy");
+ bSliceS(s, 0,2);
+ ck_assert_str_eq(s, "sh");
+ // negative index
+ strcpy(s, "sheepy");
+ bSliceS(s, -2,0);
+ ck_assert_str_eq(s, "py");
+ // positive and negative indexes
+ strcpy(s, "sheepy");
+ bSliceS(s, 2,-2);
+ ck_assert_str_eq(s, "ee");
+ // start = end
+ strcpy(s, "sheepy");
+ bSliceS(s, 2,-4);
+ ck_assert_str_eq(s, "");
+ // end of string
+ strcpy(s, "sheepy");
+ bSliceS(s, 2,6);
+ ck_assert_str_eq(s, "eepy");
+ // start outside string
+ strcpy(s, "sheepy");
+ bSliceS(s, 20,-4);
+ ck_assert_str_eq(s, "");
+ // end outside string
+ strcpy(s, "sheepy");
+ bSliceS(s, 2,40);
+ ck_assert_str_eq(s, "eepy");
+ strcpy(s, "sheepy");
+ bSliceS(s, -22,3);
+ ck_assert_str_eq(s, "she");
+ strcpy(s, "sheepy");
+ bSliceS(s, 2,-40);
+ ck_assert_str_eq(s, "");
+ // end before start
+ strcpy(s, "sheepy");
+ bSliceS(s, 4,2);
+ ck_assert_str_eq(s, "");
+ // NULL var
+ ck_assert_ptr_eq(bSliceS(NULL, 0, 0), NULL);
+
+}
+
+
+void insertST(CuTest *tc) {
+
+ char *s;
+
+ // insert
+ s = insertS("sheepy", 0, "lib");
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // negative index
+ s = insertS("libsheepy", -2, "P");
+ ck_assert_str_eq(s, "libsheepPy");
+ free(s);
+ // edge
+ s = insertS("qwe", 3, "C");
+ ck_assert_str_eq(s, "qweC");
+ free(s);
+ // outside string
+ s = insertS("qwe", 4, "C");
+ ck_assert_ptr_eq(s, NULL);
+ s = insertS("qwe", -5, "C");
+ ck_assert_ptr_eq(s, NULL);
+ // negative index in a one char string
+ s = insertS("s", -1, "S");
+ ck_assert_str_eq(s, "sS");
+ free(s);
+ // empty string
+ s = insertS("", 0, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+ s = insertS("", -1, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // empty insert string
+ s = insertS("a", 0, "");
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL insert string
+ s = insertS("a", 0, NULL);
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL string
+ s = insertS(NULL, 0, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+
+
+}
+
+
+void insertNFreeST(CuTest *tc) {
+
+ char *s, *a;
+
+ // insert
+ s = insertNFreeS("sheepy", 0, strdup("lib"));
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // negative index
+ s = insertNFreeS("libsheepy", -2, strdup("P"));
+ ck_assert_str_eq(s, "libsheepPy");
+ free(s);
+ // edge
+ s = insertNFreeS("qwe", 3, strdup("C"));
+ ck_assert_str_eq(s, "qweC");
+ free(s);
+ // outside string
+ a = strdup("C");
+ s = insertNFreeS("qwe", 4, a);
+ ck_assert_ptr_eq(s, NULL);
+ s = insertNFreeS("qwe", -5, a);
+ ck_assert_ptr_eq(s, NULL);
+ free(a);
+ // negative index in a one char string
+ s = insertNFreeS("s", -1, strdup("S"));
+ ck_assert_str_eq(s, "sS");
+ free(s);
+ // empty string
+ s = insertNFreeS("", 0, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+ s = insertNFreeS("", -1, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // empty insert string
+ s = insertNFreeS("a", 0, strdup(""));
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL insert string
+ s = insertNFreeS("a", 0, NULL);
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL string
+ s = insertNFreeS(NULL, 0, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+
+
+}
+
+
+void iInsertST(CuTest *tc) {
+
+ char *s;
+
+ // insert
+ s = strdup("sheepy");
+ iInsertS(&s, 0, "lib");
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // negative index
+ s = strdup("libsheepy");
+ iInsertS(&s, -2, "P");
+ ck_assert_str_eq(s, "libsheepPy");
+ free(s);
+ // edge
+ s = strdup("qwe");
+ iInsertS(&s, 3, "C");
+ ck_assert_str_eq(s, "qweC");
+ free(s);
+ // outside string
+ s = strdup("qwe");
+ iInsertS(&s, 4, "C");
+ ck_assert_str_eq(s, "qwe");
+ iInsertS(&s, -5, "C");
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // negative index in a one char string
+ s = strdup("s");
+ iInsertS(&s, -1, "S");
+ ck_assert_str_eq(s, "sS");
+ free(s);
+ // empty string
+ emptyS(s);
+ iInsertS(&s, 0, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+ emptyS(s);
+ iInsertS(&s, -1, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // empty insert string
+ s = strdup("a");
+ iInsertS(&s, 0, "");
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL insert string
+ s = strdup("a");
+ iInsertS(&s, 0, NULL);
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL string
+ s = NULL;
+ iInsertS(&s, 0, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // NULL var
+ iInsertS(NULL, 0, "s");
+
+}
+
+
+void iInsertNFreeST(CuTest *tc) {
+
+ char *s, *a, *r;
+
+ // insert
+ s = strdup("sheepy");
+ iInsertNFreeS(&s, 0, strdup("lib"));
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // negative index
+ s = strdup("libsheepy");
+ iInsertNFreeS(&s, -2, strdup("P"));
+ ck_assert_str_eq(s, "libsheepPy");
+ free(s);
+ // edge
+ s = strdup("qwe");
+ iInsertNFreeS(&s, 3, strdup("C"));
+ ck_assert_str_eq(s, "qweC");
+ free(s);
+ // outside string
+ s = strdup("qwe");
+ a = strdup("C");
+ r = iInsertNFreeS(&s, 4, a);
+ ck_assert_ptr_eq(r, NULL);
+ ck_assert_str_eq(s, "qwe");
+ r = iInsertNFreeS(&s, -5, a);
+ ck_assert_ptr_eq(r, NULL);
+ free(a);
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // negative index in a one char string
+ s = strdup("s");
+ iInsertNFreeS(&s, -1, strdup("S"));
+ ck_assert_str_eq(s, "sS");
+ free(s);
+ // empty string
+ emptyS(s);
+ iInsertNFreeS(&s, 0, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+ emptyS(s);
+ iInsertNFreeS(&s, -1, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // empty insert string
+ s = strdup("a");
+ iInsertNFreeS(&s, 0, strdup(""));
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL insert string
+ s = strdup("a");
+ iInsertNFreeS(&s, 0, NULL);
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL string
+ s = NULL;
+ iInsertNFreeS(&s, 0, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // NULL var
+ s = strdup("s");
+ r = iInsertNFreeS(NULL, 0, s);
+ ck_assert_ptr_eq(r, NULL);
+ free(s);
+
+}
+
+
+void bInsertST(CuTest *tc) {
+
+ char s[100];
+
+ // insert
+ strcpy(s, "sheepy");
+ bInsertS(s, 0, "lib");
+ ck_assert_str_eq(s, "libsheepy");
+ // negative index
+ strcpy(s, "libsheepy");
+ bInsertS(s, -2, "P");
+ ck_assert_str_eq(s, "libsheepPy");
+ // edge
+ strcpy(s, "qwe");
+ bInsertS(s, 3, "C");
+ ck_assert_str_eq(s, "qweC");
+ // outside string
+ strcpy(s, "qwe");
+ bInsertS(s, 4, "C");
+ ck_assert_str_eq(s, "qwe");
+ bInsertS(s, -5, "C");
+ ck_assert_str_eq(s, "qwe");
+ // negative index in a one char string
+ strcpy(s, "s");
+ bInsertS(s, -1, "S");
+ ck_assert_str_eq(s, "sS");
+ // empty string
+ bEmptyS(s);
+ bInsertS(s, 0, "s");
+ ck_assert_str_eq(s, "s");
+ bEmptyS(s);
+ bInsertS(s, -1, "s");
+ ck_assert_str_eq(s, "s");
+ // empty insert string
+ strcpy(s, "a");
+ bInsertS(s, 0, "");
+ ck_assert_str_eq(s, "a");
+ // NULL insert string
+ strcpy(s, "a");
+ bInsertS(s, 0, NULL);
+ ck_assert_str_eq(s, "a");
+ // NULL var
+ ck_assert_ptr_eq(bInsertS(NULL, 0, "s"), NULL);
+
+}
+
+
+void bLInsertST(CuTest *tc) {
+
+ char s[100];
+
+ // insert
+ strcpy(s, "sheepy");
+ bLInsertS(s, sizeof s, 0, "lib");
+ ck_assert_str_eq(s, "libsheepy");
+ // shorter buffer
+ strcpy(s, "sheepy");
+ bLInsertS(s, 5, 0, "lib");
+ ck_assert_str_eq(s, "libs");
+ // negative index
+ strcpy(s, "libsheepy");
+ bLInsertS(s, sizeof s, -2, "P");
+ ck_assert_str_eq(s, "libsheepPy");
+ // edge
+ strcpy(s, "qwe");
+ bLInsertS(s, sizeof s, 3, "C");
+ ck_assert_str_eq(s, "qweC");
+ // outside string
+ strcpy(s, "qwe");
+ bLInsertS(s, sizeof s, 4, "C");
+ ck_assert_str_eq(s, "qwe");
+ bLInsertS(s, sizeof s, -5, "C");
+ ck_assert_str_eq(s, "qwe");
+ // negative index in a one char string
+ strcpy(s, "s");
+ bLInsertS(s, sizeof s, -1, "S");
+ ck_assert_str_eq(s, "sS");
+ // empty string
+ bEmptyS(s);
+ bLInsertS(s, sizeof s, 0, "s");
+ ck_assert_str_eq(s, "s");
+ bEmptyS(s);
+ bLInsertS(s, sizeof s, -1, "s");
+ ck_assert_str_eq(s, "s");
+ // empty insert string
+ strcpy(s, "a");
+ bLInsertS(s, sizeof s, 0, "");
+ ck_assert_str_eq(s, "a");
+ // size 0 - no change
+ bLInsertS(s, 0, 0, "qwe");
+ ck_assert_str_eq(s, "a");
+ // NULL insert string
+ strcpy(s, "a");
+ bLInsertS(s, sizeof s, 0, NULL);
+ ck_assert_str_eq(s, "a");
+ // NULL var
+ ck_assert_ptr_eq(bLInsertS(NULL, sizeof s, 0, "s"), NULL);
+
+}
+
+
+void injectST(CuTest *tc) {
+
+ char *s;
+
+ // insert
+ s = injectS("sheepy", 0, 'L');
+ ck_assert_str_eq(s, "Lsheepy");
+ free(s);
+ // negative index
+ s = injectS("libsheepy", -2, 'P');
+ ck_assert_str_eq(s, "libsheepPy");
+ free(s);
+ // edge
+ s = injectS("qwe", 3, 'C');
+ ck_assert_str_eq(s, "qweC");
+ free(s);
+ // outside string
+ s = injectS("qwe", 4, 'C');
+ ck_assert_ptr_eq(s, NULL);
+ s = injectS("qwe", -5, 'C');
+ ck_assert_ptr_eq(s, NULL);
+ // negative index in a one char string
+ s = injectS("s", -2, 'S');
+ ck_assert_str_eq(s, "Ss");
+ free(s);
+ // empty string
+ s = injectS("", 0, 's');
+ ck_assert_str_eq(s, "s");
+ free(s);
+ s = injectS("", -1, 's');
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // NULL string
+ s = injectS(NULL, 0, 's');
+ ck_assert_str_eq(s, "s");
+ free(s);
+
+
+}
+
+
+void iInjectST(CuTest *tc) {
+
+ char *s;
+
+ // insert
+ s = strdup("sheepy");
+ iInjectS(&s, 0, 'L');
+ ck_assert_str_eq(s, "Lsheepy");
+ free(s);
+ // negative index
+ s = strdup("libsheepy");
+ iInjectS(&s, -2, 'P');
+ ck_assert_str_eq(s, "libsheepPy");
+ free(s);
+ // edge
+ s = strdup("qwe");
+ iInjectS(&s, 3, 'C');
+ ck_assert_str_eq(s, "qweC");
+ free(s);
+ // outside string
+ s = strdup("qwe");
+ iInjectS(&s, 4, 'C');
+ ck_assert_str_eq(s, "qwe");
+ iInjectS(&s, -5, 'C');
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // negative index in a one char string
+ s = strdup("s");
+ iInjectS(&s, -1, 'S');
+ ck_assert_str_eq(s, "sS");
+ free(s);
+ // empty string
+ emptyS(s);
+ iInjectS(&s, 0, 's');
+ ck_assert_str_eq(s, "s");
+ free(s);
+ emptyS(s);
+ iInjectS(&s, -1, 's');
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // NULL string
+ s = NULL;
+ iInjectS(&s, 0, 's');
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // NULL var
+ iInjectS(NULL, 0, 's');
+
+}
+
+
+void bInjectST(CuTest *tc) {
+
+ char s[100];
+
+ // insert
+ strcpy(s, "sheepy");
+ bInjectS(s, 0, 'L');
+ ck_assert_str_eq(s, "Lsheepy");
+ // negative index
+ strcpy(s, "libsheepy");
+ bInjectS(s, -2, 'P');
+ ck_assert_str_eq(s, "libsheepPy");
+ // edge
+ strcpy(s, "qwe");
+ bInjectS(s, 3, 'C');
+ ck_assert_str_eq(s, "qweC");
+ // outside string
+ strcpy(s, "qwe");
+ bInjectS(s, 4, 'C');
+ ck_assert_str_eq(s, "qwe");
+ bInjectS(s, -5, 'C');
+ ck_assert_str_eq(s, "qwe");
+ // negative index in a one char string
+ strcpy(s, "s");
+ bInjectS(s, -1, 'S');
+ ck_assert_str_eq(s, "sS");
+ // empty string
+ bEmptyS(s);
+ bInjectS(s, 0, 's');
+ ck_assert_str_eq(s, "s");
+ bEmptyS(s);
+ bInjectS(s, -1, 's');
+ ck_assert_str_eq(s, "s");
+ // NULL var
+ ck_assert_ptr_eq(bInjectS(NULL, 0, 's'), NULL);
+
+}
+
+
+void bLInjectST(CuTest *tc) {
+
+ char s[100];
+
+ // insert
+ strcpy(s, "sheepy");
+ bLInjectS(s, sizeof s, 0, 'L');
+ ck_assert_str_eq(s, "Lsheepy");
+ // shorter buffer
+ strcpy(s, "sheepy");
+ bLInjectS(s, 5, 0, 'L');
+ ck_assert_str_eq(s, "Lshe");
+ // negative index
+ strcpy(s, "libsheepy");
+ bLInjectS(s, sizeof s, -2, 'P');
+ ck_assert_str_eq(s, "libsheepPy");
+ // edge
+ strcpy(s, "qwe");
+ bLInjectS(s, sizeof s, 3, 'C');
+ ck_assert_str_eq(s, "qweC");
+ // outside string
+ strcpy(s, "qwe");
+ bLInjectS(s, sizeof s, 4, 'C');
+ ck_assert_str_eq(s, "qwe");
+ bLInjectS(s, sizeof s, -5, 'C');
+ ck_assert_str_eq(s, "qwe");
+ // negative index in a one char string
+ strcpy(s, "s");
+ bLInjectS(s, sizeof s, -1, 'S');
+ ck_assert_str_eq(s, "sS");
+ // empty string
+ bEmptyS(s);
+ bLInjectS(s, sizeof s, 0, 's');
+ ck_assert_str_eq(s, "s");
+ bEmptyS(s);
+ bLInjectS(s, sizeof s, -1, 's');
+ ck_assert_str_eq(s, "s");
+ // size 0 - no change
+ bLInjectS(s, 0, -1, 's');
+ ck_assert_str_eq(s, "s");
+ // NULL var
+ ck_assert_ptr_eq(bLInjectS(NULL, sizeof s, 0, 's'), NULL);
+
+}
+
+
+void delST(CuTest *tc) {
+
+ // del
+ char *s = delS("sheepy", 0,2);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // negative index
+ s = delS("sheepy", -2,0);
+ ck_assert_str_eq(s, "shee");
+ free(s);
+ // positive and negative indexes
+ s = delS("sheepy", 2,-2);
+ ck_assert_str_eq(s, "shpy");
+ free(s);
+ // start = end
+ s = delS("sheepy", 2,-4);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // delete entire string
+ s = delS("sheepy", 0,0);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end of string
+ s = delS("sheepy", 2,6);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(delS(NULL, 2,-4), NULL);
+ // start outside string
+ ck_assert_ptr_eq(delS("sheepy", 20,-4), NULL);
+ s = delS("sheepy", -20,-4);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // end outside string
+ s = delS("sheepy", 2,40);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ ck_assert_ptr_eq(delS("sheepy", 2,-40), NULL);
+ // end before start
+ ck_assert_ptr_eq(delS("sheepy", 4,2), NULL);
+
+}
+
+
+void iDelST(CuTest *tc) {
+
+ char *s;
+ // del
+ s = strdup("sheepy");
+ iDelS(&s, 0,2);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // negative index
+ s = strdup("sheepy");
+ iDelS(&s, -2,0);
+ ck_assert_str_eq(s, "shee");
+ free(s);
+ // positive and negative indexes
+ s = strdup("sheepy");
+ iDelS(&s, 2,-2);
+ ck_assert_str_eq(s, "shpy");
+ free(s);
+ // start = end
+ s = strdup("sheepy");
+ iDelS(&s, 2,-4);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // delete entire string
+ s = strdup("sheepy");
+ iDelS(&s, 0,0);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end of string
+ s = strdup("sheepy");
+ iDelS(&s, 2,6);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ // NULL string
+ s = NULL;
+ iDelS(&s, 2,-4);
+ ck_assert_ptr_eq(s, NULL);
+ // start outside string
+ s = strdup("sheepy");
+ iDelS(&s, 20,-4);
+ ck_assert_str_eq(s, "sheepy");
+ iDelS(&s, -20,-4);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // end outside string
+ s = strdup("sheepy");
+ iDelS(&s, 2,40);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ s = strdup("sheepy");
+ iDelS(&s, 2,-40);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // end before start
+ s = strdup("sheepy");
+ iDelS(&s, 4,2);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // NULL var
+ iDelS(NULL, 4,2);
+
+}
+
+
+void bDelST(CuTest *tc) {
+
+ char s[100];
+ // del
+ strcpy(s, "sheepy");
+ bDelS(s, 0,2);
+ ck_assert_str_eq(s, "eepy");
+ // negative index
+ strcpy(s, "sheepy");
+ bDelS(s, -2,0);
+ ck_assert_str_eq(s, "shee");
+ // positive and negative indexes
+ strcpy(s, "sheepy");
+ bDelS(s, 2,-2);
+ ck_assert_str_eq(s, "shpy");
+ // start = end
+ strcpy(s, "sheepy");
+ bDelS(s, 2,-4);
+ ck_assert_str_eq(s, "sheepy");
+ // delete entire string
+ strcpy(s, "sheepy");
+ bDelS(s, 0,0);
+ ck_assert_str_eq(s, "");
+ // end of string
+ strcpy(s, "sheepy");
+ bDelS(s, 2,6);
+ ck_assert_str_eq(s, "sh");
+ // start outside string
+ strcpy(s, "sheepy");
+ bDelS(s, 20,-4);
+ ck_assert_str_eq(s, "sheepy");
+ bDelS(s, -20,-4);
+ ck_assert_str_eq(s, "eepy");
+ // end outside string
+ strcpy(s, "sheepy");
+ bDelS(s, 2,40);
+ ck_assert_str_eq(s, "sh");
+ strcpy(s, "sheepy");
+ bDelS(s, 2,-40);
+ ck_assert_str_eq(s, "sheepy");
+ // end before start
+ strcpy(s, "sheepy");
+ bDelS(s, 4,2);
+ ck_assert_str_eq(s, "sheepy");
+ // NULL var
+ ck_assert_ptr_eq(bDelS(NULL, 4,2), NULL);
+
+}
+
+
+void findST(CuTest *tc) {
+
+ // find string in the middle
+ ck_assert_str_eq(findS("sheepy", "ee"), "eepy");
+ // find non existing string
+ ck_assert_ptr_eq(findS("sheepy", "$"), NULL);
+ // find NULL
+ ck_assert_ptr_eq(findS("sheepy", NULL), NULL);
+ // NULL string
+ ck_assert_ptr_eq(findS(NULL, "$"), NULL);
+
+}
+
+
+void findCharST(CuTest *tc) {
+
+ // find string in the middle
+ ck_assert_str_eq(findCharS("sheepy", 'e'), "eepy");
+ // find non existing string
+ ck_assert_ptr_eq(findCharS("sheepy", '$'), NULL);
+ // find 0
+ ck_assert_str_eq(findCharS("sheepy", 0), "");
+ // NULL string
+ ck_assert_ptr_eq(findCharS(NULL, '$'), NULL);
+
+}
+
+
+void hasST(CuTest *tc) {
+
+ // find string in the middle
+ ck_assert(hasS("sheepy", "ee"));
+ // find non existing string
+ ck_assert(!hasS("sheepy", "$"));
+ // find NULL
+ ck_assert(!hasS("sheepy", NULL));
+ // NULL string
+ ck_assert(!hasS(NULL, "$"));
+
+}
+
+
+void hasCharST(CuTest *tc) {
+
+ // find string in the middle
+ ck_assert(hasCharS("sheepy", 'e'));
+ // find non existing string
+ ck_assert(!hasCharS("sheepy", '$'));
+ // find 0
+ ck_assert(hasCharS("sheepy", 0));
+ // NULL string
+ ck_assert(!hasCharS(NULL, '$'));
+
+}
+
+
+void emptySFT(CuTest *tc) {
+
+ char *s;
+
+ // empty string
+ s = emptySF();
+ ck_assert(isEmptyS(s));
+ free(s);
+
+}
+
+
+void iEmptySFT(CuTest *tc) {
+
+ char *s;
+
+ // empty string
+ s = strdup("qwe");
+ iEmptySF(&s);
+ ck_assert(isEmptyS(s));
+ free(s);
+ // NULL string
+ s = NULL;
+ iEmptySF(&s);
+ ck_assert(isEmptyS(s));
+ free(s);
+ // NULL var
+ iEmptySF(NULL);
+
+}
+
+
+void isEmptyST(CuTest *tc) {
+
+ char *s;
+
+ // non empty
+ s = strdup("a");
+ ck_assert(!isEmptyS(s));
+ free(s);
+ // empty
+ emptyS(s)
+ ck_assert(isEmptyS(s));
+ free(s);
+ // NULL string
+ ck_assert(isEmptyS(NULL));
+
+}
+
+
+void isBlankST(CuTest *tc) {
+
+ char *s;
+
+ // non empty
+ s = strdup("a");
+ ck_assert(!isBlankS(s));
+ free(s);
+ // white spaces
+ ck_assert(isBlankS(" "));
+ // empty
+ emptyS(s)
+ ck_assert(isBlankS(s));
+ free(s);
+ // NULL string
+ ck_assert(isBlankS(NULL));
+
+}
+
+
+void listEmptySFT(CuTest *tc) {
+
+ char **l;
+
+ // empty list
+ l = listEmptySF();
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+
+}
+
+
+void iListEmptySFT(CuTest *tc) {
+
+ char **l;
+
+ // empty list
+ l = listCreateS("lib", "sheepy");
+ iListEmptySF(&l);
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ iListEmptySF(&l);
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL var
+ iListEmptySF(NULL);
+
+}
+
+
+void listIsEmptyST(CuTest *tc) {
+
+ char **l;
+
+ // non empty list
+ l = listCreateS("sheepy", "SHEEPY", "sheepy");
+ // check ck_assert_ptr_null not available in jessie
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert(!listIsEmptyS(l));
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ ck_assert(listIsEmptyS(NULL));
+
+}
+
+
+void listIsBlankST(CuTest *tc) {
+
+ char **l;
+
+ // non empty list
+ l = listCreateS("sheepy", "SHEEPY", "sheepy");
+ // check ck_assert_ptr_null not available in jessie
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert(!listIsBlankS(l));
+ listFreeS(l);
+ l = listCreateS("", " ");
+ ck_assert(listIsBlankS(l));
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ ck_assert(listIsBlankS(l));
+ listFreeS(l);
+ ck_assert(listIsEmptyS(NULL));
+
+}
+
+
+void listLengthST(CuTest *tc) {
+
+ char **l;
+
+ // list length
+ l = malloc(2 * sizeof(char *));
+ l[0] = (char *)1;
+ l[1] = NULL;
+ ck_assert_uint_eq(listLengthS(l),1);
+ free(l);
+ // empty list
+ listEmptyS(l)
+ ck_assert_uint_eq(listLengthS(l),0);
+ free(l);
+ // NULL list
+ ck_assert_uint_eq(listLengthS(NULL),0);
+
+
+}
+
+
+void listCreateST(CuTest *tc) {
+
+ char **l;
+
+ // create list
+ l = listCreateS("sheepy", "SHEEPY", "sheepy");
+ // check ck_assert_ptr_null not available in jessie
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert_uint_eq(listLengthS(l),3);
+ ck_assert_str_eq(l[0], "sheepy");
+ ck_assert_str_eq(l[1], "SHEEPY");
+ ck_assert_str_eq(l[2], "sheepy");
+ listFreeS(l);
+
+ // NULL first element
+ ck_assert_ptr_eq(listCreateS(NULL, "sheepy"), NULL);
+
+}
+
+
+void listFromArrayST(CuTest *tc) {
+
+ char **l = NULL;
+ char *array[] = {"1", "22", "333"};
+ char *arrayNULL[] = {"1", NULL, "333"};
+
+ // copy array to list
+ l = listFromArrayS(array, 3);
+ ck_assert_uint_eq(listLengthS(l),3);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_str_eq(l[2], "333");
+ listFreeS(l);
+ // array with NULL inside
+ l = listFromArrayS(arrayNULL, 3);
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "333");
+ listFreeS(l);
+ // empty list
+ l = listFromArrayS(array, 0);
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL pointer to list
+ ck_assert_ptr_eq(listFromArrayS(NULL, 1), NULL);
+
+}
+
+
+void listPushST(CuTest *tc) {
+
+ char **l = NULL;
+
+ // push strings and NULL list
+ listPushS(&l, "sheepy");
+ // check ck_assert_ptr_null not available in jessie
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert_str_eq(l[0], "sheepy");
+ listPushS(&l, "SHEEPY");
+ ck_assert_str_eq(l[1], "SHEEPY");
+ ck_assert_str_eq(l[0], "sheepy");
+ // push NULL
+ listPushS(&l, NULL);
+ ck_assert_ptr_eq(l[2], NULL);
+ listFreeS(l);
+ // NULL list and NULL string
+ l = NULL;
+ listPushS(&l, NULL);
+ ck_assert_ptr_eq(l, NULL);
+ // empty list
+ listEmptyS(l)
+ listPushS(&l, "sheepy");
+ ck_assert_str_eq(l[0], "sheepy");
+ ck_assert_ptr_eq(l[1], NULL);
+ listFreeS(l);
+ // NULL pointer to list
+ listPushS(NULL, NULL);
+
+}
+
+
+void iListPushST(CuTest *tc) {
+
+ char **l = NULL;
+ char *s;
+
+ // push strings and NULL list
+ s = strdup("sheepy");
+ iListPushS(&l, s);
+ // check ck_assert_ptr_null not available in jessie
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert_str_eq(l[0], "sheepy");
+ s = strdup("SHEEPY");
+ iListPushS(&l, s);
+ ck_assert_str_eq(l[0], "sheepy");
+ ck_assert_str_eq(l[1], "SHEEPY");
+ // push NULL
+ iListPushS(&l, NULL);
+ ck_assert_ptr_eq(l[2], NULL);
+ listFreeS(l);
+ // NULL list and NULL string
+ l = NULL;
+ iListPushS(&l, NULL);
+ ck_assert_ptr_eq(l, NULL);
+ // empty list
+ listEmptyS(l)
+ s = strdup("sheepy");
+ iListPushS(&l, s);
+ ck_assert_str_eq(l[0], "sheepy");
+ ck_assert_ptr_eq(l[1], NULL);
+ listFreeS(l);
+ // NULL pointer to list
+ iListPushS(NULL, NULL);
+
+}
+
+
+void listPopST(CuTest *tc) {
+
+ char **l = NULL;
+ char *s;
+
+ // pop string
+ listPushS(&l, "sheepy");
+ listPushS(&l, "SHEEPY");
+ s = listPopS(&l);
+ ck_assert_str_eq(s, "SHEEPY");
+ ck_assert_uint_eq(listLengthS(l),1);
+ free(s);
+ // last element
+ s = listPopS(&l);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ ck_assert_uint_eq(listLengthS(l),0);
+ // empty list
+ ck_assert_ptr_eq(listPopS(&l), NULL);
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ ck_assert_ptr_eq(listPopS(&l), NULL);
+ // NULL pointer to list
+ ck_assert_ptr_eq(listPopS(NULL), NULL);
+
+}
+
+
+void listPrependST(CuTest *tc) {
+
+ char **l = NULL;
+
+ // push strings and NULL list
+ listPrependS(&l, "sheepy");
+ // check ck_assert_ptr_null not available in jessie
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert_str_eq(l[0], "sheepy");
+ listPrependS(&l, "SHEEPY");
+ ck_assert_str_eq(l[0], "SHEEPY");
+ ck_assert_str_eq(l[1], "sheepy");
+ // push NULL
+ listPrependS(&l, NULL);
+ ck_assert_str_eq(l[0], "SHEEPY");
+ listFreeS(l);
+ // NULL list and NULL string`
+ l = NULL;
+ listPrependS(&l, NULL);
+ ck_assert_ptr_eq(l, NULL);
+ // empty list
+ listEmptyS(l)
+ listPrependS(&l, "sheepy");
+ ck_assert_str_eq(l[0], "sheepy");
+ ck_assert_ptr_eq(l[1], NULL);
+ listFreeS(l);
+ // NULL pointer to list
+ listPrependS(NULL, NULL);
+
+}
+
+
+void iListPrependST(CuTest *tc) {
+
+ char **l = NULL;
+ char *s;
+
+ // prepend strings and NULL list
+ s = strdup("sheepy");
+ iListPrependS(&l, s);
+ // check ck_assert_ptr_null not available in jessie
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert_str_eq(l[0], "sheepy");
+ s = strdup("SHEEPY");
+ iListPrependS(&l, s);
+ ck_assert_str_eq(l[0], "SHEEPY");
+ ck_assert_str_eq(l[1], "sheepy");
+ // prepend NULL
+ iListPrependS(&l, NULL);
+ ck_assert_str_eq(l[0], "SHEEPY");
+ listFreeS(l);
+ // NULL list and NULL string
+ l = NULL;
+ iListPrependS(&l, NULL);
+ ck_assert_ptr_eq(l, NULL);
+ // empty list
+ listEmptyS(l)
+ s = strdup("sheepy");
+ iListPrependS(&l, s);
+ ck_assert_str_eq(l[0], "sheepy");
+ ck_assert_ptr_eq(l[1], NULL);
+ listFreeS(l);
+ // NULL pointer to list
+ iListPrependS(NULL, NULL);
+
+}
+
+
+void listDequeueST(CuTest *tc) {
+
+ char **l = NULL;
+ char *s;
+
+ // dequeue string
+ listPushS(&l, "sheepy");
+ listPushS(&l, "SHEEPY");
+ s = listDequeueS(&l);
+ ck_assert_str_eq(s, "sheepy");
+ ck_assert_uint_eq(listLengthS(l),1);
+ free(s);
+ // last element
+ s = listDequeueS(&l);
+ ck_assert_str_eq(s, "SHEEPY");
+ free(s);
+ ck_assert_uint_eq(listLengthS(l),0);
+ // empty list
+ ck_assert_ptr_eq(listDequeueS(&l), NULL);
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ ck_assert_ptr_eq(listDequeueS(&l), NULL);
+ // NULL pointer to list
+ ck_assert_ptr_eq(listDequeueS(NULL), NULL);
+
+}
+
+
+void listFreeST(CuTest *tc) {
+
+ // not possible to know if a pointer is already freed
+ char **l = listCreateS("we","sd");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l);
+ listFreeS(l);
+ // NULL list
+ listFreeS(NULL);
+
+}
+
+
+void listFreeManyST(CuTest *tc) {
+
+ // not possible to know if a pointer is already freed
+ char **l1 = listCreateS("we","sd");
+ char **l2 = listEmptySF();
+ listFreeManyS(l1, l2);
+
+}
+
+
+void listPrintST(CuTest *tc) {
+
+ char **l;
+
+ // print text
+ l = readText("textTest.null");
+ // TODO check stdout
+ //listPrintS(l);
+ listFreeS(l);
+ // NULL list
+ listPrintS(NULL);
+
+}
+
+
+void listForEachT(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2 = NULL;
+
+ // for each element in list
+ listPushS(&l, "1sdfdsf");
+ listPushS(&l, "4444");
+ listPushS(&l, "3");
+ listPushS(&l, "22sdf");
+ forEachCharP(l, i)
+ //printf(*i);
+ listPushS(&l2, *i);
+ ck_assert_str_eq(l2[0], "1sdfdsf");
+ ck_assert_str_eq(l2[3], "22sdf");
+ listFreeS(l);
+ listFreeS(l2);
+
+}
+
+
+void listEnumerateT(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2 = NULL;
+
+ // enumerateCharP elements
+ listPushS(&l, "1sdfdsf");
+ listPushS(&l, "4444");
+ listPushS(&l, "3");
+ listPushS(&l, "22sdf");
+ enumerateCharP(l, i, j) {
+ listPushS(&l2, *i);
+ }
+ ck_assert_uint_eq(j, 4);
+ ck_assert_str_eq(l2[0], "1sdfdsf");
+ ck_assert_str_eq(l2[3], "22sdf");
+ listFreeS(l);
+ listFreeS(l2);
+
+}
+
+
+void listSortST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list
+ listPushS(&l, "1sdfdsf");
+ listPushS(&l, "4444");
+ listPushS(&l, "3");
+ listPushS(&l, "22sdf");
+ l2 = listSortS(l);
+ ck_assert_str_eq(l2[0], "1sdfdsf");
+ ck_assert_str_eq(l2[3], "4444");
+ listFreeS(l);
+ listFreeS(l2);
+ // one element list
+ l = NULL;
+ listPushS(&l, "1sdfdsf");
+ l2 = listSortS(l);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "1sdfdsf");
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l2)
+ l = listSortS(l2);
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ listFreeS(l);
+ listFreeS(l2);
+ // NULL list
+ ck_assert_ptr_eq(listSortS(NULL), NULL);
+
+}
+
+
+void iListSortST(CuTest *tc) {
+
+ char **l = NULL;
+
+ // list
+ listPushS(&l, "1sdfdsf");
+ listPushS(&l, "4444");
+ listPushS(&l, "3");
+ listPushS(&l, "22sdf");
+ iListSortS(&l);
+ ck_assert_str_eq(l[0], "1sdfdsf");
+ ck_assert_str_eq(l[3], "4444");
+ listFreeS(l);
+ // one element list
+ l = NULL;
+ listPushS(&l, "1sdfdsf");
+ iListSortS(&l);
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "1sdfdsf");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ iListSortS(&l);
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ iListSortS(&l);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListSortS(NULL);
+
+}
+
+
+void readTextT(CuTest *tc) {
+
+ char **l;
+
+ // text
+ l = readText("textTest.null");
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "LINE 1");
+ ck_assert_str_eq(l[1], "ANOTHER line");
+ listFreeS(l);
+ // empty text
+ l = readText("chmodTest.null");
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ listFreeS(l);
+ // NULL path
+ ck_assert_ptr_eq(readText(NULL), NULL);
+ // non existing path
+ if (fileExists("nonExistingFile"))
+ rmAll("nonExistingFile");
+ ck_assert_ptr_eq(readText("nonExistingFile"), NULL);
+
+}
+
+
+void readStreamT(CuTest *tc) {
+
+ char **l;
+ FILE *fp;
+
+ // stream
+ fp = fopen("textTest.null", "r");
+ l = readStream(fp);
+ fclose(fp);
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "LINE 1");
+ ck_assert_str_eq(l[1], "ANOTHER line");
+ listFreeS(l);
+ // empty stream
+ fp = fopen("chmodTest.null", "r");
+ l = readStream(fp);
+ fclose(fp);
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ listFreeS(l);
+ // NULL stream
+ ck_assert_ptr_eq(readStream(NULL), NULL);
+
+}
+
+
+void writeTextT(CuTest *tc) {
+
+ char **l;
+ bool r;
+
+ // write textOutTest.null
+ l = readText("textTest.null");
+ r = writeText("textOutTest.null", l);
+ ck_assert(r);
+ listFreeS(l);
+
+ // check textOutTest.null
+ l = readText("textOutTest.null");
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "LINE 1");
+ ck_assert_str_eq(l[1], "ANOTHER line");
+ // non existing file
+ // make sure the file doesnt exist
+ if (fileExists("nonExistingFile"))
+ rmAll("nonExistingFile");
+ ck_assert(writeText("nonExistingFile",l));
+ if (fileExists("nonExistingFile"))
+ rmAll("nonExistingFile");
+ // NULL path
+ ck_assert(!writeText(NULL,l));
+ listFreeS(l);
+ // NULL list
+ ck_assert(!writeText("a",NULL));
+
+}
+
+
+void writeStreamT(CuTest *tc) {
+
+ char **l;
+ FILE *fp;
+ bool r;
+
+ // write textOutTest.null
+ fp = fopen("textTest.null", "r");
+ l = readStream(fp);
+ fclose(fp);
+ fp = fopen("textOutTest.null", "w");
+ r = writeStream(fp, l);
+ ck_assert(r);
+ // NULL list
+ ck_assert(!writeStream(fp,NULL));
+ fclose(fp);
+ listFreeS(l);
+
+ // check textOutTest.null
+ fp = fopen("textOutTest.null", "r");
+ l = readStream(fp);
+ fclose(fp);
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "LINE 1");
+ ck_assert_str_eq(l[1], "ANOTHER line");
+ // NULL stream
+ ck_assert(!writeStream(NULL,l));
+ listFreeS(l);
+
+}
+
+
+void appendTextT(CuTest *tc) {
+
+ char **l;
+ bool r;
+
+ // append to textOutTest.null
+ l = readText("textTest.null");
+ r = writeText("textOutTest.null", l);
+ ck_assert(r);
+ char **c = listCreateS("A","B");
+ r = appendText("textOutTest.null", c);
+ listFreeManyS(l,c);
+
+ // check textOutTest.null
+ l = readText("textOutTest.null");
+ ck_assert_uint_eq(listLengthS(l),4);
+ ck_assert_str_eq(l[0], "LINE 1");
+ ck_assert_str_eq(l[1], "ANOTHER line");
+ ck_assert_str_eq(l[2], "A");
+ ck_assert_str_eq(l[3], "B");
+ // non existing file
+ // make sure the file doesnt exist
+ if (fileExists("nonExistingFile"))
+ rmAll("nonExistingFile");
+ ck_assert(appendText("nonExistingFile",l));
+ if (fileExists("nonExistingFile"))
+ rmAll("nonExistingFile");
+ // NULL path
+ ck_assert(!appendText(NULL,l));
+ listFreeS(l);
+ // NULL list
+ ck_assert(!appendText("a",NULL));
+
+}
+
+
+void listGetST(CuTest *tc) {
+
+ char **l = NULL;
+
+ // get string
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ char *s = listGetS(l, 0);
+ ck_assert_str_eq(s, "1");
+ free(s);
+ // negative index
+ s = listGetS(l, -1);
+ ck_assert_str_eq(s, "4444");
+ free(s);
+ // outside list
+ ck_assert_ptr_eq(listGetS(l, 10), NULL);
+ ck_assert_ptr_eq(listGetS(l, -10), NULL);
+ listFreeS(l);
+ // negative index in a one element list
+ l = NULL;
+ listPushS(&l, "ASD");
+ listPushS(&l, NULL);
+ s = listGetS(l,-1);
+ ck_assert_ptr_ne(s, NULL);
+ free(s);
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ ck_assert_ptr_eq(listGetS(l,0),NULL);
+ free(l);
+ // NULL list
+ ck_assert_ptr_eq(listGetS(NULL, 0), NULL);
+
+}
+
+
+void iListGetST(CuTest *tc) {
+
+ char **l = NULL;
+
+ // get string
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ ck_assert_str_eq(iListGetS(l, 0), "1");
+ // negative index
+ ck_assert_str_eq(iListGetS(l, -1), "4444");
+ // outside list
+ ck_assert_ptr_eq(iListGetS(l, 10), NULL);
+ ck_assert_ptr_eq(iListGetS(l, -10), NULL);
+ listFreeS(l);
+ // negative index in a one element list
+ l = NULL;
+ listPushS(&l, "ASD");
+ listPushS(&l, NULL);
+ ck_assert_ptr_ne(iListGetS(l,-1), NULL);
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ ck_assert_ptr_eq(iListGetS(l,0),NULL);
+ free(l);
+ // NULL list
+ ck_assert_ptr_eq(iListGetS(NULL, 0), NULL);
+
+}
+
+
+void listSetST(CuTest *tc) {
+
+ char **l = NULL;
+
+ // get string
+ listPushS(&l, "@@");
+ listPushS(&l, "22");
+ listPushS(&l, "|");
+ listPushS(&l, "4444");
+ listSetS(l, 0, "1");
+ char *s = listGetS(l, 0);
+ ck_assert_str_eq(s, "1");
+ free(s);
+ // negative index
+ listSetS(l, -2, "333");
+ s = listGetS(l, -2);
+ ck_assert_str_eq(s, "333");
+ free(s);
+ // outside list
+ // list is unchanged
+ listSetS(l, 10, "QWE");
+ listSetS(l, -10, "QWE");
+ // NULL s string
+ listSetS(l, -2, NULL);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_str_eq(l[2], "333");
+ ck_assert_str_eq(l[3], "4444");
+ listFreeS(l);
+ // negative index in a one element list
+ l = NULL;
+ listPushS(&l, "ASD");
+ listPushS(&l, NULL);
+ listSetS(l, -1, "QWE");
+ s = listGetS(l,-1);
+ ck_assert_str_eq(s, "QWE");
+ free(s);
+ listFreeS(l);
+ // empty list - should not crash
+ listEmptyS(l)
+ listSetS(l, 0, "QWE");
+ ck_assert_ptr_eq(listGetS(l,0),NULL);
+ free(l);
+ // NULL list
+ listSetS(NULL, 0, "QWE");
+ ck_assert_ptr_eq(listGetS(NULL, 0), NULL);
+
+}
+
+
+void iListSetST(CuTest *tc) {
+
+ char **l = NULL;
+ char *s;
+
+ // set string
+ listPushS(&l, "@@");
+ listPushS(&l, "22");
+ listPushS(&l, "|");
+ listPushS(&l, "4444");
+ s = strdup("1");
+ iListSetS(l, 0, s);
+ ck_assert_str_eq(iListGetS(l, 0), "1");
+ // negative index
+ s = strdup("333");
+ iListSetS(l, -2, s);
+ ck_assert_str_eq(iListGetS(l, -2), "333");
+ // outside list
+ // list is unchanged
+ s = strdup("QWE");
+ iListSetS(l, 10, s);
+ iListSetS(l, -10, s);
+ free(s);
+ // NULL s string
+ s = NULL;
+ iListSetS(l, -2, s);
+ // NULL s var
+ iListSetS(l, -2, NULL);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_str_eq(l[2], "333");
+ ck_assert_str_eq(l[3], "4444");
+ listFreeS(l);
+ // negative index in a one element list
+ l = NULL;
+ listPushS(&l, "ASD");
+ listPushS(&l, NULL);
+ s = strdup("QWE");
+ iListSetS(l, -1, s);
+ ck_assert_str_eq(iListGetS(l,-1), "QWE");
+ listFreeS(l);
+ // empty list - should not crash
+ listEmptyS(l)
+ s = strdup("QWE");
+ iListSetS(l, 0, s);
+ ck_assert_ptr_eq(listGetS(l,0),NULL);
+ free(s);
+ free(l);
+ // NULL list
+ s = strdup("QWE");
+ iListSetS(NULL, 0, s);
+ ck_assert_ptr_eq(listGetS(NULL, 0), NULL);
+ free(s);
+
+}
+
+
+void tokST(CuTest *tc) {
+
+ // string
+ char *s;
+ char *w;
+ s = strdup("172.16.43.0/24 dev ens32 dev proto");
+ w = s;
+ ck_assert_str_eq(tokS(s, "dev ", &w), "172.16.43.0/24 ");
+ free(s);
+ // delimiter not found
+ s = strdup("172.16.43.0/24 dev ens32 dev proto");
+ ck_assert_str_eq(tokS(s, "ANYTHING", &w), "172.16.43.0/24 dev ens32 dev proto");
+ ck_assert_ptr_eq(w, NULL);
+ free(s);
+ // same with w initialized to NULL
+ s = strdup("172.16.43.0/24 dev ens32 dev proto");
+ w = NULL;
+ ck_assert_str_eq(tokS(s, "dev ", &w), "172.16.43.0/24 ");
+ ck_assert_str_eq(w, "ens32 dev proto");
+ ck_assert_str_eq(tokS(NULL, "dev ", &w), "ens32 ");
+ ck_assert_str_eq(w, "proto");
+ ck_assert_str_eq(tokS(NULL, "dev ", &w), "proto");
+ ck_assert_ptr_eq(w, NULL);
+ free(s);
+ // NULL string
+ w = NULL;
+ ck_assert_ptr_eq(tokS(NULL, ";", &w), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(tokS("test", NULL, &w), NULL);
+
+}
+
+
+void splitT(CuTest *tc) {
+
+ char **l;
+
+ // string
+ l = split("one/two", "/");
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "one");
+ ck_assert_str_eq(l[1], "two");
+ listFreeS(l);
+ // delimiter on the edge
+ l = split("/one", "/");
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "");
+ ck_assert_str_eq(l[1], "one");
+ listFreeS(l);
+ l = split("one/", "/");
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "one");
+ ck_assert_str_eq(l[1], "");
+ listFreeS(l);
+ // delimiter not found
+ l = split("one/two", "||");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "one/two");
+ listFreeS(l);
+ // split with several delimiters after each other
+ l = split("one/two three ", " ");
+ ck_assert_uint_eq(listLengthS(l),4);
+ ck_assert_str_eq(l[0], "one/two");
+ ck_assert_str_eq(l[1], "");
+ ck_assert_str_eq(l[2], "three");
+ ck_assert_str_eq(l[3], "");
+ listFreeS(l);
+ // multiple character delimiter
+ l = split("AAe three extract", "e ");
+ ck_assert_uint_eq(listLengthS(l),3);
+ ck_assert_str_eq(l[0], "AA");
+ ck_assert_str_eq(l[1], "thre");
+ ck_assert_str_eq(l[2], "extract");
+ listFreeS(l);
+ // empty delimiter
+ l = split("AAd", "");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "AAd");
+ listFreeS(l);
+ // empty string
+ l = split("", "$");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "");
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(split(NULL, ";"), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(split("test", NULL), NULL);
+
+}
+
+
+void joinT(CuTest *tc) {
+
+ char **l;
+ char *s;
+
+ // list
+ l = split("one/two", "/");
+ s = join(l, "/");
+ ck_assert_str_eq(s, "one/two");
+ // NULL delimiter
+ ck_assert_ptr_eq(join(l, NULL), NULL);
+ listFreeS(l);
+ free(s);
+ // empty list
+ listEmptyS(l)
+ s = join(l, "/");
+ ck_assert(isEmptyS(s));
+ listFreeS(l);
+ free(s);
+ // NULL list
+ ck_assert_ptr_eq(join(NULL, ";"), NULL);
+ // list with NULL first element
+ l = NULL;
+ listPushS(&l, NULL);
+ ck_assert_ptr_eq(join(l, "/"), NULL);
+ listFreeS(l);
+
+}
+
+
+void bJoinT(CuTest *tc) {
+
+ char **l;
+ char s[100];
+
+ // list
+ l = split("one/two", "/");
+ bJoin(s, l, "/");
+ ck_assert_str_eq(s, "one/two");
+ // NULL delimiter
+ ck_assert_ptr_eq(bJoin(s, l, NULL), NULL);
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ bJoin(s, l, "/");
+ ck_assert_ptr_eq(bJoin(s, l, "/"), NULL);
+ ck_assert_str_eq(s, "one/two");
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(bJoin(s, NULL, ";"), NULL);
+ // list with NULL first element
+ l = NULL;
+ listPushS(&l, NULL);
+ ck_assert_ptr_eq(bJoin(s, l, "/"), NULL);
+ listFreeS(l);
+
+}
+
+
+void bLJoinT(CuTest *tc) {
+
+ char **l;
+ char s[100];
+
+ // list
+ l = split("one/two", "/");
+ bLJoin(s, sizeof s, l, "/");
+ ck_assert_str_eq(s, "one/two");
+ // shorter buffer
+ bLJoin(s, 5, l, "/");
+ ck_assert_str_eq(s, "one/");
+ // size 0 - no change
+ bLJoin(s, 0, l, "/");
+ ck_assert_str_eq(s, "one/");
+ // NULL delimiter
+ ck_assert_ptr_eq(bLJoin(s, sizeof s, l, NULL), NULL);
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ bLJoin(s, sizeof s, l, "/");
+ ck_assert_ptr_eq(bLJoin(s, sizeof s, l, "/"), NULL);
+ ck_assert_str_eq(s, "one/");
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(bLJoin(s, sizeof s, NULL, ";"), NULL);
+ // list with NULL first element
+ l = NULL;
+ listPushS(&l, NULL);
+ ck_assert_ptr_eq(bLJoin(s, sizeof s, l, "/"), NULL);
+ listFreeS(l);
+
+}
+
+
+void extractST(CuTest *tc) {
+
+ char **l;
+
+ // string
+ l = extractS("one/two|", "/", "|");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "two");
+ listFreeS(l);
+ // delimiter not found
+ l = extractS("one/two", "||", "/");
+ ck_assert_ptr_eq(l, NULL);
+ // extractS with several delimiters after each other
+ l = extractS("one/ two /three ", "/", " ");
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "");
+ ck_assert_str_eq(l[1], "three");
+ listFreeS(l);
+ // multiple character delimiter
+ l = extractS("AAe thre|e extract", "e ", "|");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "thre");
+ listFreeS(l);
+ // empty delimiter
+ l = extractS("AAd", "", "Ad");
+ ck_assert_ptr_eq(l, NULL);
+ l = extractS("AAd", "A", "");
+ ck_assert_ptr_eq(l, NULL);
+ // empty string
+ l = extractS("", "$", "#");
+ ck_assert_ptr_eq(l, NULL);
+ // delim1 = delim2
+ l = extractS("", "$", "$");
+ ck_assert_ptr_eq(l, NULL);
+ // NULL string
+ ck_assert_ptr_eq(extractS(NULL, ";", ","), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(extractS("test", NULL, ","), NULL);
+ ck_assert_ptr_eq(extractS("test", ",", NULL), NULL);
+
+}
+
+
+void listDupST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = listDupS(l);
+ ck_assert_uint_eq(listLengthS(l2),4);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[3], "4444");
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l)
+ l2 = listDupS(l);
+ ck_assert(listIsEmptyS(l2));
+ listFreeS(l);
+ listFreeS(l2);
+ // NULL list
+ ck_assert_ptr_eq(listDupS(NULL), NULL);
+
+}
+
+
+void iListDupST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = iListDupS(l);
+ ck_assert_uint_eq(listLengthS(l2),4);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[3], "4444");
+ free(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l);
+ l2 = iListDupS(l);
+ ck_assert(listIsEmptyS(l2));
+ free(l);
+ listFreeS(l2);
+ // NULL list
+ ck_assert_ptr_eq(iListDupS(NULL), NULL);
+
+}
+
+
+void listReverseST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = listReverseS(l);
+ ck_assert_uint_eq(listLengthS(l2),4);
+ ck_assert_str_eq(l2[0], "4444");
+ ck_assert_str_eq(l2[3], "1");
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l)
+ l2 = listReverseS(l);
+ ck_assert(listIsEmptyS(l2));
+ listFreeS(l);
+ listFreeS(l2);
+ // NULL list
+ ck_assert_ptr_eq(listReverseS(NULL), NULL);
+
+}
+
+
+void iListReverseST(CuTest *tc) {
+
+ char **l = NULL;
+
+ // list
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ iListReverseS(&l);
+ ck_assert_uint_eq(listLengthS(l),4);
+ ck_assert_str_eq(l[0], "4444");
+ ck_assert_str_eq(l[3], "1");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ iListReverseS(&l);
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ iListReverseS(&l);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListReverseS(NULL);
+
+}
+
+
+void listCatST(CuTest *tc) {
+
+ char **l;
+ char **l2;
+ char **r;
+
+ // cat lists
+ l = listCreateS("#@#","1");
+ l2 = listCreateS("lib","sheepy");
+ r = listCatS(l,l2);
+ ck_assert_str_eq(r[0], "#@#");
+ ck_assert_str_eq(r[1], "1");
+ ck_assert_str_eq(r[2], "lib");
+ ck_assert_str_eq(r[3], "sheepy");
+ listFreeManyS(l,l2,r);
+ // empty list
+ listEmptyS(l);
+ r = listCatS(l);
+ ck_assert(listIsEmptyS(r));
+ listFreeManyS(r,l);
+ // cat empty list with list
+ listEmptyS(l);
+ l2 = listCreateS("lib","sheepy");
+ r = listCatS(l, l2);
+ ck_assert_str_eq(r[0], "lib");
+ ck_assert_str_eq(r[1], "sheepy");
+ listFreeManyS(l,l2,r);
+
+}
+
+
+void listAppendST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2 = NULL;
+
+ // lists
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ listPushS(&l2, "A");
+ listPushS(&l2, "BB");
+ listPushS(&l2, "CCC");
+ listPushS(&l2, "DDDD");
+ listAppendS(&l2,l);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[0], "A");
+ ck_assert_str_eq(l2[3], "DDDD");
+ ck_assert_str_eq(l2[4],"1");
+ ck_assert_str_eq(l2[7],"4444");
+ listFreeS(l);
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ listAppendS(&l,l);
+ ck_assert_uint_eq(listLengthS(l),8);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[3], "4444");
+ ck_assert_str_eq(l[4],"1");
+ ck_assert_str_eq(l[7],"4444");
+ listFreeS(l);
+ // empty list + list
+ listEmptyS(l)
+ listAppendS(&l, l2);
+ ck_assert(listEqS(l,l2));
+ listFreeS(l);
+ // list + empty list
+ listEmptyS(l)
+ listAppendS(&l2, l);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[0], "A");
+ ck_assert_str_eq(l2[3], "DDDD");
+ ck_assert_str_eq(l2[4],"1");
+ ck_assert_str_eq(l2[7],"4444");
+ listFreeS(l);
+ // empty list + empty list
+ listEmptyS(l)
+ listAppendS(&l, l);
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL list + list = duplicate
+ l = NULL;
+ listAppendS(&l,l2);
+ ck_assert(listEqS(l,l2));
+ listFreeS(l);
+ // list + NULL list
+ listAppendS(&l2, NULL);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[0], "A");
+ ck_assert_str_eq(l2[3], "DDDD");
+ ck_assert_str_eq(l2[4],"1");
+ ck_assert_str_eq(l2[7],"4444");
+ listFreeS(l2);
+ // NULL list pointer
+ listAppendS(NULL,l2);
+ // should not crash
+
+}
+
+
+void iListAppendST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2 = NULL;
+
+ // lists
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ listPushS(&l2, "A");
+ listPushS(&l2, "BB");
+ listPushS(&l2, "CCC");
+ listPushS(&l2, "DDDD");
+ iListAppendS(&l2,l);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[0], "A");
+ ck_assert_str_eq(l2[3], "DDDD");
+ ck_assert_str_eq(l2[4],"1");
+ ck_assert_str_eq(l2[7],"4444");
+ free(l);
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ iListAppendS(&l,l);
+ ck_assert_uint_eq(listLengthS(l),4);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[3], "4444");
+ listFreeS(l);
+ // empty list + list
+ listEmptyS(l)
+ iListAppendS(&l, l2);
+ ck_assert(listEqS(l,l2));
+ free(l2);
+ listFreeS(l);
+ // list + empty list
+ l2 = NULL;
+ listPushS(&l2, "A");
+ listPushS(&l2, "BB");
+ listPushS(&l2, "CCC");
+ listPushS(&l2, "DDDD");
+ listPushS(&l2, "1");
+ listPushS(&l2, "22");
+ listPushS(&l2, "333");
+ listPushS(&l2, "4444");
+ listEmptyS(l)
+ iListAppendS(&l2, l);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[0], "A");
+ ck_assert_str_eq(l2[3], "DDDD");
+ ck_assert_str_eq(l2[4],"1");
+ ck_assert_str_eq(l2[7],"4444");
+ free(l);
+ listFreeS(l2);
+ // empty list + empty list
+ listEmptyS(l);
+ listEmptyS(l2);
+ iListAppendS(&l, l2);
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ listFreeS(l2);
+ // NULL list + list = duplicate
+ l = NULL;
+ l2 = NULL;
+ listPushS(&l2, "A");
+ listPushS(&l2, "BB");
+ listPushS(&l2, "CCC");
+ listPushS(&l2, "DDDD");
+ iListAppendS(&l,l2);
+ ck_assert(listEqS(l,l2));
+ free(l);
+ // list + NULL list
+ iListAppendS(&l2, NULL);
+ ck_assert_uint_eq(listLengthS(l2),4);
+ ck_assert_str_eq(l2[0], "A");
+ ck_assert_str_eq(l2[3], "DDDD");
+ listFreeS(l2);
+ // NULL list pointer
+ iListAppendS(NULL,l2);
+ // should not crash
+
+}
+
+
+void iListAppendNSmashST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2 = NULL;
+
+ // lists
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ listPushS(&l2, "A");
+ listPushS(&l2, "BB");
+ listPushS(&l2, "CCC");
+ listPushS(&l2, "DDDD");
+ iListAppendNSmashS(&l2,l);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[0], "A");
+ ck_assert_str_eq(l2[3], "DDDD");
+ ck_assert_str_eq(l2[4],"1");
+ ck_assert_str_eq(l2[7],"4444");
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ iListAppendNSmashS(&l,l);
+ ck_assert_uint_eq(listLengthS(l),4);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[3], "4444");
+ listFreeS(l);
+ // empty list + list
+ listEmptyS(l)
+ iListAppendNSmashS(&l, l2);
+ ck_assert_str_eq(l[0], "A");
+ ck_assert_str_eq(l[3], "DDDD");
+ ck_assert_str_eq(l[4],"1");
+ ck_assert_str_eq(l[7],"4444");
+ listFreeS(l);
+ // list + empty list
+ l2 = NULL;
+ listPushS(&l2, "A");
+ listPushS(&l2, "BB");
+ listPushS(&l2, "CCC");
+ listPushS(&l2, "DDDD");
+ listPushS(&l2, "1");
+ listPushS(&l2, "22");
+ listPushS(&l2, "333");
+ listPushS(&l2, "4444");
+ listEmptyS(l)
+ iListAppendNSmashS(&l2, l);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[0], "A");
+ ck_assert_str_eq(l2[3], "DDDD");
+ ck_assert_str_eq(l2[4],"1");
+ ck_assert_str_eq(l2[7],"4444");
+ listFreeS(l2);
+ // empty list + empty list
+ listEmptyS(l);
+ listEmptyS(l2);
+ iListAppendNSmashS(&l, l2);
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL list + list = duplicate
+ l = NULL;
+ l2 = NULL;
+ listPushS(&l2, "A");
+ listPushS(&l2, "BB");
+ listPushS(&l2, "CCC");
+ listPushS(&l2, "DDDD");
+ iListAppendNSmashS(&l,l2);
+ ck_assert_str_eq(l[0], "A");
+ ck_assert_str_eq(l[1], "BB");
+ ck_assert_str_eq(l[2], "CCC");
+ ck_assert_str_eq(l[3], "DDDD");
+ // list + NULL list
+ iListAppendNSmashS(&l, NULL);
+ ck_assert_uint_eq(listLengthS(l),4);
+ ck_assert_str_eq(l[0], "A");
+ ck_assert_str_eq(l[3], "DDDD");
+ listFreeS(l);
+ // NULL list pointer
+ iListAppendNSmashS(NULL,l);
+ // should not crash
+
+}
+
+
+void listAddST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2 = NULL;
+ char **l3;
+
+ // lists
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ listPushS(&l2, "A");
+ listPushS(&l2, "BB");
+ listPushS(&l2, "CCC");
+ listPushS(&l2, "DDDD");
+ l3 = listAddS(l2,l);
+ ck_assert_uint_eq(listLengthS(l3),8);
+ ck_assert_str_eq(l3[0], "A");
+ ck_assert_str_eq(l3[3], "DDDD");
+ ck_assert_str_eq(l3[4],"1");
+ ck_assert_str_eq(l3[7],"4444");
+ listFreeS(l3);
+ listFreeS(l);
+ // empty list + list
+ listEmptyS(l)
+ l3 = listAddS(l, l2);
+ ck_assert(listEqS(l3,l2));
+ listFreeS(l3);
+ listFreeS(l);
+ // list + empty list
+ listEmptyS(l)
+ l3 = listAddS(l2, l);
+ ck_assert(listEqS(l3,l2));
+ listFreeS(l3);
+ listFreeS(l);
+ // empty list + empty list
+ listEmptyS(l)
+ l3 = listAddS(l, l);
+ ck_assert(listIsEmptyS(l3));
+ listFreeS(l3);
+ listFreeS(l);
+ // NULL list + list
+ l3 = listAddS(NULL,l2);
+ ck_assert(listEqS(l3,l2));
+ listFreeS(l3);
+ // list + NULL list
+ l3 = listAddS(l2, NULL);
+ ck_assert(listEqS(l3,l2));
+ listFreeS(l3);
+ listFreeS(l2);
+ // NULL list + NULL list
+ ck_assert_ptr_eq(listAddS(NULL,NULL), NULL);
+
+}
+
+
+void listSliceST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list negative index
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = listSliceS(l, 1,-1);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[0], "22");
+ ck_assert_str_eq(l2[1], "333");
+ listFreeS(l2);
+ // start outside
+ ck_assert_ptr_eq(listSliceS(l, 20,-4), NULL);
+ // end outside
+ l2 = listSliceS(l, 2,40);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[0], "333");
+ ck_assert_str_eq(l2[1], "4444");
+ listFreeS(l2);
+ // end negative and outside
+ ck_assert_ptr_eq(listSliceS(l, 2,-40), NULL);
+ // end before start
+ ck_assert_ptr_eq(listSliceS(l, 3,2), NULL);
+ listFreeS(l);
+ // negative start last element
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ l2 = listSliceS(l, -1,0);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "22");
+ listFreeS(l);
+ listFreeS(l2);
+ // start = end
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ l2 = listSliceS(l, 1,1);
+ ck_assert_uint_eq(listLengthS(l2),0);
+ ck_assert_ptr_eq(l2[0], NULL);
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l)
+ ck_assert_ptr_eq(listSliceS(l, 0,0), NULL);
+ ck_assert_ptr_eq(listSliceS(l, -1,0), NULL);
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(listSliceS(NULL, 2,-4), NULL);
+
+
+}
+
+
+void iListCopyST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list negative index
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = iListCopyS(l, 1,-1);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[0], "22");
+ ck_assert_str_eq(l2[1], "333");
+ free(l2);
+ listFreeS(l);
+ // start outside
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ ck_assert_ptr_eq(iListCopyS(l, 20,-4), NULL);
+ // end outside
+ l2 = iListCopyS(l, 2,40);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[0], "333");
+ ck_assert_str_eq(l2[1], "4444");
+ free(l2);
+ listFreeS(l);
+ // end negative and outside
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ ck_assert_ptr_eq(iListCopyS(l, 2,-40), NULL);
+ // end before start
+ ck_assert_ptr_eq(iListCopyS(l, 3,2), NULL);
+ listFreeS(l);
+ // negative start last element
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ l2 = iListCopyS(l, -1,0);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "22");
+ free(l2);
+ listFreeS(l);
+ // start = end
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ l2 = iListCopyS(l, 1,1);
+ ck_assert_uint_eq(listLengthS(l2),0);
+ ck_assert_ptr_eq(l2[0], NULL);
+ free(l2);
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ ck_assert_ptr_eq(iListCopyS(l, 0,0), NULL);
+ ck_assert_ptr_eq(iListCopyS(l, -1,0), NULL);
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(iListCopyS(NULL, 2,-4), NULL);
+
+
+}
+
+
+void iListSliceST(CuTest *tc) {
+
+ char **l = NULL;
+
+ // list negative index
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ iListSliceS(&l, 1,-1);
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "22");
+ ck_assert_str_eq(l[1], "333");
+ // start outside
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ iListSliceS(&l, 20,-4);
+ ck_assert_uint_eq(listLengthS(l),0);
+ // end outside
+ iListSliceS(&l, 2,40);
+ ck_assert_uint_eq(listLengthS(l),0);
+ // end negative and outside
+ iListSliceS(&l, 2,-40);
+ ck_assert_uint_eq(listLengthS(l),0);
+ // end before start
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ iListSliceS(&l, 3,2);
+ ck_assert_uint_eq(listLengthS(l),0);
+ listFreeS(l);
+ // negative start last element
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ iListSliceS(&l, -1,0);
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "22");
+ listFreeS(l);
+ // start = end
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ iListSliceS(&l, 1,1);
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ iListSliceS(&l, 0,0);
+ ck_assert(listIsEmptyS(l));
+ iListSliceS(&l, -1,0);
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ iListSliceS(&l, 2,-4);
+ // NULL var
+ iListSliceS(NULL, 2,-4);
+
+
+}
+
+
+void listInsertST(CuTest *tc) {
+
+ char **l;
+ char **l2;
+ char **r;
+
+ // insert
+ l = listCreateS("1","22");
+ l2 = listCreateS("lib");
+ r = listInsertS(l, 0, l2);
+ ck_assert_uint_eq(listLengthS(r),3);
+ ck_assert_str_eq(r[0], "lib");
+ ck_assert_str_eq(r[1], "1");
+ ck_assert_str_eq(r[2], "22");
+ listFreeS(r);
+ // negative index
+ r = listInsertS(l, -1, l2);
+ ck_assert_uint_eq(listLengthS(r),3);
+ ck_assert_str_eq(r[0], "1");
+ ck_assert_str_eq(r[1], "22");
+ ck_assert_str_eq(r[2], "lib");
+ listFreeS(r);
+ // edge
+ r = listInsertS(l, 2, l2);
+ ck_assert_uint_eq(listLengthS(r),3);
+ ck_assert_str_eq(r[0], "1");
+ ck_assert_str_eq(r[1], "22");
+ ck_assert_str_eq(r[2], "lib");
+ listFreeS(r);
+ // outside list
+ r = listInsertS(l, 4, l2);
+ ck_assert_ptr_eq(r, NULL);
+ r = listInsertS(l, -4, l2);
+ ck_assert_ptr_eq(r, NULL);
+ listFreeS(l);
+ // negative index in a one element list
+ l = listCreateS("1");
+ r = listInsertS(l, -1, l2);
+ ck_assert_str_eq(r[0], "1");
+ ck_assert_str_eq(r[1], "lib");
+ listFreeManyS(l,r);
+ // empty list
+ listEmptyS(l);
+ r = listInsertS(l, 0, l2);
+ ck_assert_str_eq(r[0], "lib");
+ listFreeManyS(r,l);
+ listEmptyS(l);
+ r = listInsertS(l, -1, l2);
+ ck_assert_str_eq(r[0], "lib");
+ listFreeManyS(r,l, l2);
+ // empty insert list
+ l = listCreateS("1");
+ listEmptyS(l2);
+ r = listInsertS(l, 0, l2);
+ ck_assert_str_eq(r[0], "1");
+ listFreeManyS(r,l2);
+ // NULL insert string
+ r = listInsertS(l, 0, NULL);
+ ck_assert_str_eq(r[0], "1");
+ listFreeManyS(r,l);
+ // NULL list
+ r = listInsertS(NULL, 0, NULL);
+ ck_assert_ptr_eq(r, NULL);
+
+
+}
+
+
+void iListInsertST(CuTest *tc) {
+
+ char **l;
+ char **l2;
+
+ // insert
+ l = listCreateS("1","22");
+ l2 = listCreateS("lib");
+ iListInsertS(&l, 0, l2);
+ ck_assert_uint_eq(listLengthS(l),3);
+ ck_assert_str_eq(l[0], "lib");
+ ck_assert_str_eq(l[1], "1");
+ ck_assert_str_eq(l[2], "22");
+ free(l2);
+ listFreeS(l);
+ // negative index
+ l = listCreateS("1","22");
+ l2 = listCreateS("lib");
+ iListInsertS(&l, -1, l2);
+ ck_assert_uint_eq(listLengthS(l),3);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_str_eq(l[2], "lib");
+ free(l2);
+ listFreeS(l);
+ // edge
+ l = listCreateS("1","22");
+ l2 = listCreateS("lib");
+ iListInsertS(&l, 2, l2);
+ ck_assert_uint_eq(listLengthS(l),3);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_str_eq(l[2], "lib");
+ free(l2);
+ listFreeS(l);
+ // outside list
+ l = listCreateS("1","22");
+ l2 = listCreateS("lib");
+ iListInsertS(&l, 4, l2);
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ iListInsertS(&l, -4, l2);
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ listFreeS(l);
+ // negative index in a one element list
+ l = listCreateS("1");
+ iListInsertS(&l, -1, l2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "lib");
+ free(l2);
+ listFreeS(l);
+ // empty list
+ listEmptyS(l);
+ l2 = listCreateS("lib");
+ iListInsertS(&l, 0, l2);
+ ck_assert_str_eq(l[0], "lib");
+ free(l2);
+ listFreeS(l);
+ listEmptyS(l);
+ l2 = listCreateS("lib");
+ iListInsertS(&l, -1, l2);
+ ck_assert_str_eq(l[0], "lib");
+ free(l2);
+ listFreeS(l);
+ // empty insert list
+ l = listCreateS("1");
+ listEmptyS(l2);
+ iListInsertS(&l, 0, l2);
+ ck_assert_str_eq(l[0], "1");
+ listFreeS(l2);
+ // NULL insert string
+ iListInsertS(&l, 0, NULL);
+ ck_assert_str_eq(l[0], "1");
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ iListInsertS(&l, 0, NULL);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListInsertS(NULL, 0, NULL);
+
+
+}
+
+
+void iListInsertNFreeST(CuTest *tc) {
+
+ char **l, **r;
+ char **l2;
+
+ // insert
+ l = listCreateS("1","22");
+ l2 = listCreateS("lib");
+ iListInsertNFreeS(&l, 0, l2);
+ ck_assert_uint_eq(listLengthS(l),3);
+ ck_assert_str_eq(l[0], "lib");
+ ck_assert_str_eq(l[1], "1");
+ ck_assert_str_eq(l[2], "22");
+ listFreeS(l);
+ // negative index
+ l = listCreateS("1","22");
+ l2 = listCreateS("lib");
+ iListInsertNFreeS(&l, -1, l2);
+ ck_assert_uint_eq(listLengthS(l),3);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_str_eq(l[2], "lib");
+ listFreeS(l);
+ // edge
+ l = listCreateS("1","22");
+ l2 = listCreateS("lib");
+ iListInsertNFreeS(&l, 2, l2);
+ ck_assert_uint_eq(listLengthS(l),3);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_str_eq(l[2], "lib");
+ listFreeS(l);
+ // outside list
+ l = listCreateS("1","22");
+ l2 = listCreateS("lib");
+ r = iListInsertNFreeS(&l, 4, l2);
+ ck_assert_ptr_eq(r, NULL);
+ // free L2 since it is not freed because iListInsertNFreeS failed
+ listFreeS(l2);
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ l2 = listCreateS("lib");
+ r = iListInsertNFreeS(&l, -4, l2);
+ ck_assert_ptr_eq(r, NULL);
+ // free L2 since it is not freed because iListInsertNFreeS failed
+ listFreeS(l2);
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ listFreeS(l);
+ // negative index in a one element list
+ l = listCreateS("1");
+ l2 = listCreateS("lib");
+ iListInsertNFreeS(&l, -1, l2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "lib");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l);
+ l2 = listCreateS("lib");
+ iListInsertNFreeS(&l, 0, l2);
+ ck_assert_str_eq(l[0], "lib");
+ listFreeS(l);
+ listEmptyS(l);
+ l2 = listCreateS("lib");
+ iListInsertNFreeS(&l, -1, l2);
+ ck_assert_str_eq(l[0], "lib");
+ listFreeS(l);
+ // empty insert list
+ l = listCreateS("1");
+ listEmptyS(l2);
+ iListInsertNFreeS(&l, 0, l2);
+ ck_assert_str_eq(l[0], "1");
+ // NULL insert string
+ iListInsertNFreeS(&l, 0, NULL);
+ ck_assert_str_eq(l[0], "1");
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ l2 = listCreateS("lib");
+ iListInsertNFreeS(&l, 0, l2);
+ ck_assert_str_eq(l[0], "lib");
+ listFreeS(l);
+ // NULL var
+ l2 = listCreateS("lib");
+ l = iListInsertNFreeS(NULL, 0, l2);
+ ck_assert_ptr_eq(l, NULL);
+ // free L2 since it is not freed because iListInsertNFreeS failed
+ listFreeS(l2);
+
+}
+
+
+void listInjectST(CuTest *tc) {
+
+ char **l;
+ char **r;
+
+ // insert
+ l = listCreateS("1","22");
+ r = listInjectS(l, 0, "lib");
+ ck_assert_uint_eq(listLengthS(r),3);
+ ck_assert_str_eq(r[0], "lib");
+ ck_assert_str_eq(r[1], "1");
+ ck_assert_str_eq(r[2], "22");
+ listFreeS(r);
+ // negative index
+ r = listInjectS(l, -1, "lib");
+ ck_assert_uint_eq(listLengthS(r),3);
+ ck_assert_str_eq(r[0], "1");
+ ck_assert_str_eq(r[1], "22");
+ ck_assert_str_eq(r[2], "lib");
+ listFreeS(r);
+ // edge
+ r = listInjectS(l, 2, "lib");
+ ck_assert_uint_eq(listLengthS(r),3);
+ ck_assert_str_eq(r[0], "1");
+ ck_assert_str_eq(r[1], "22");
+ ck_assert_str_eq(r[2], "lib");
+ listFreeS(r);
+ // outside list
+ r = listInjectS(l, 4, "lib");
+ ck_assert_ptr_eq(r, NULL);
+ r = listInjectS(l, -4, "lib");
+ ck_assert_ptr_eq(r, NULL);
+ listFreeS(l);
+ // negative index in a one element list
+ l = listCreateS("1");
+ r = listInjectS(l, -1, "lib");
+ ck_assert_str_eq(r[0], "1");
+ ck_assert_str_eq(r[1], "lib");
+ listFreeManyS(l,r);
+ // empty list
+ listEmptyS(l);
+ r = listInjectS(l, 0, "lib");
+ ck_assert_str_eq(r[0], "lib");
+ listFreeManyS(r,l);
+ listEmptyS(l);
+ r = listInjectS(l, -1, "lib");
+ ck_assert_str_eq(r[0], "lib");
+ listFreeManyS(r,l);
+ // NULL insert string
+ l = listCreateS("1");
+ r = listInjectS(l, 0, NULL);
+ ck_assert_ptr_eq(r, NULL);
+ listFreeManyS(l,r);
+ // NULL list
+ r = listInjectS(NULL, 0, NULL);
+ ck_assert_ptr_eq(r, NULL);
+
+
+}
+
+
+void iListInjectST(CuTest *tc) {
+
+ char **l;
+
+ // insert
+ l = listCreateS("1","22");
+ iListInjectS(&l, 0, strdup("lib"));
+ ck_assert_uint_eq(listLengthS(l),3);
+ ck_assert_str_eq(l[0], "lib");
+ ck_assert_str_eq(l[1], "1");
+ ck_assert_str_eq(l[2], "22");
+ listFreeS(l);
+ // negative index
+ l = listCreateS("1","22");
+ iListInjectS(&l, -1, strdup("lib"));
+ ck_assert_uint_eq(listLengthS(l),3);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_str_eq(l[2], "lib");
+ listFreeS(l);
+ // edge
+ l = listCreateS("1","22");
+ iListInjectS(&l, 2, strdup("lib"));
+ ck_assert_uint_eq(listLengthS(l),3);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_str_eq(l[2], "lib");
+ listFreeS(l);
+ // outside list
+ l = listCreateS("1","22");
+ iListInjectS(&l, 4, "lib");
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ iListInjectS(&l, -4, "lib");
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ listFreeS(l);
+ // negative index in a one element list
+ l = listCreateS("1");
+ iListInjectS(&l, -1, strdup("lib"));
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "lib");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l);
+ iListInjectS(&l, 0, strdup("lib"));
+ ck_assert_str_eq(l[0], "lib");
+ listFreeS(l);
+ listEmptyS(l);
+ iListInjectS(&l, -1, strdup("lib"));
+ ck_assert_str_eq(l[0], "lib");
+ listFreeS(l);
+ // NULL insert string
+ l = listCreateS("1");
+ iListInjectS(&l, 0, NULL);
+ ck_assert_str_eq(l[0], "1");
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ iListInjectS(&l, 0, NULL);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListInjectS(NULL, 0, NULL);
+
+
+}
+
+
+void listDelST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list negative index
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = listDelS(l, 1,-1);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[1], "4444");
+ listFreeS(l2);
+ // start outside
+ ck_assert_ptr_eq(listDelS(l, 20,-4), NULL);
+ // end outside
+ l2 = listDelS(l, 2,40);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[1], "22");
+ listFreeS(l2);
+ // end negative and outside
+ ck_assert_ptr_eq(listDelS(l, 2,-40), NULL);
+ // end before start
+ ck_assert_ptr_eq(listDelS(l, 3,2), NULL);
+ listFreeS(l);
+ // negative start last element
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ l2 = listDelS(l, -1,0);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "1");
+ listFreeS(l);
+ listFreeS(l2);
+ // start negative and outside (delete complete list because end is 0 (=len))
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ l2 = listDelS(l, -3,0);
+ ck_assert_uint_eq(listLengthS(l2),0);
+ ck_assert_ptr_eq(l2[0], NULL);
+ listFreeS(l);
+ listFreeS(l2);
+ // start = end
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ l2 = listDelS(l, 1,1);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[1], "22");
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l)
+ ck_assert_ptr_eq(listDelS(l, 0,0), NULL);
+ ck_assert_ptr_eq(listDelS(l, -1,0), NULL);
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(listDelS(NULL, 2,-4), NULL);
+
+
+}
+
+
+void iListDelST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list negative index
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ iListDelS(&l, 1,-1);
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "4444");
+ iListEmptySF(&l);
+ // start outside
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ iListDelS(&l, 20,-4);
+ ck_assert_uint_eq(listLengthS(l),4);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[3], "4444");
+ // end outside
+ iListDelS(&l, 2,40);
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ iListEmptySF(&l);
+ // end negative and outside
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ iListDelS(&l, 2,-40);
+ ck_assert_uint_eq(listLengthS(l),4);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[3], "4444");
+ // end before start
+ iListDelS(&l, 3,2);
+ ck_assert_uint_eq(listLengthS(l),4);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[3], "4444");
+ iListEmptySF(&l);
+ // negative start last element
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ iListDelS(&l, -1,0);
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "1");
+ iListEmptySF(&l);
+ // start negative and outside (delete complete list because end is 0 (=len))
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ iListDelS(&l, -3,0);
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ // start = end
+ // (l is empty from previous test)
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ iListDelS(&l, 1,1);
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l);
+ iListDelS(&l, 0,0);
+ ck_assert(listIsEmptyS(l));
+ iListDelS(&l, -1,0);
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ iListDelS(&l, 2,-4);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListDelS(NULL, 2,-4);
+
+
+}
+
+
+void execOutT(CuTest *tc) {
+
+ char **l;
+
+ // command
+ l = execOut("ls chmodTest.null");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "chmodTest.null");
+ listFreeS(l);
+
+ // invalid command
+ l = execOut("randomComand");
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ listFreeS(l);
+ // NULL command
+ ck_assert_ptr_eq(execOut(NULL), NULL);
+
+}
+
+
+void listEqST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2;
+
+ // identical lists
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = listDupS(l);
+ ck_assert(listEqS(l,l2));
+ // NULL lists
+ ck_assert(!listEqS(NULL,l));
+ ck_assert(!listEqS(l,NULL));
+ ck_assert(!listEqS(NULL,NULL));
+ // different lists same number of elements
+ l[3][0] = 'A';
+ ck_assert(!listEqS(l,l2));
+ // different number of elements
+ char *s = listPopS(&l);
+ free(s);
+ ck_assert(!listEqS(l,l2));
+ listFreeS(l);
+ listFreeS(l2);
+
+}
+
+
+void listHasST(CuTest *tc) {
+
+ char **l = NULL;
+
+ // string
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ ck_assert(listHasS(l, "1"));
+ // NULL list
+ ck_assert(!listHasS(NULL, "1"));
+ // NULL string
+ ck_assert(!listHasS(l, NULL));
+ // non existing element
+ ck_assert(!listHasS(l, "wfe"));
+ // string in list
+ ck_assert(listHasS(l, "333"));
+ listFreeS(l);
+
+}
+
+
+void listIndexOfST(CuTest *tc) {
+
+ char **l = NULL;
+
+ // string
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ ck_assert_uint_eq(listIndexOfS(l, "1"),0);
+ // NULL list
+ ck_assert_uint_eq(listIndexOfS(NULL, "1"),-1);
+ // NULL string
+ ck_assert_uint_eq(listIndexOfS(l, NULL),-1);
+ // non existing element
+ ck_assert_uint_eq(listIndexOfS(l, "wfe"),-1);
+ // string in list
+ ck_assert_uint_eq(listIndexOfS(l, "333"),2);
+ listFreeS(l);
+
+}
+
+
+void listBinarySearchST(CuTest *tc) {
+
+ char **l = NULL;
+
+ // string
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ listPushS(&l, "5");
+ listPushS(&l, "6");
+ ck_assert_uint_eq(listBinarySearchS(l, "1"),0);
+ // NULL list
+ ck_assert_uint_eq(listBinarySearchS(NULL, "1"),-1);
+ // NULL string
+ ck_assert_uint_eq(listBinarySearchS(l, NULL),-1);
+ // non existing element
+ ck_assert_uint_eq(listBinarySearchS(l, "wfe"),-1);
+ // string in list
+ ck_assert_uint_eq(listBinarySearchS(l, "333"),2);
+ listFreeS(l);
+
+}
+
+
+void listUniqST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list with unique elements
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = listUniqS(l);
+ ck_assert(listEqS(l,l2));
+ // list with identical elements
+ l[2][0] = '2';
+ l[2][1] = '2';
+ l[2][2] = 0;
+ listFreeS(l2);
+ l2 = listUniqS(l);
+ ck_assert_uint_eq(listLengthS(l2),3);
+ ck_assert_str_eq(l2[2], "4444");
+ listFreeS(l);
+ listFreeS(l2);
+ // list with one element
+ l = NULL;
+ listPushS(&l, "1");
+ l2 = listUniqS(l);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "1");
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l)
+ l2 = listUniqS(l);
+ ck_assert_uint_eq(listLengthS(l2),0);
+ ck_assert_ptr_eq(l2[0], NULL);
+ listFreeS(l);
+ listFreeS(l2);
+ // NULL list
+ ck_assert_ptr_eq(listUniqS(NULL), NULL);
+
+}
+
+
+void iListUniqST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list with unique elements
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = listDupS(l);
+ iListUniqS(&l2);
+ ck_assert(listEqS(l,l2));
+ // list with identical elements
+ l[2][0] = '2';
+ l[2][1] = '2';
+ l[2][2] = 0;
+ listFreeS(l2);
+ l2 = listDupS(l);
+ iListUniqS(&l2);
+ ck_assert_uint_eq(listLengthS(l2),3);
+ ck_assert_str_eq(l2[2], "4444");
+ listFreeS(l);
+ listFreeS(l2);
+ // list with one element
+ l = NULL;
+ listPushS(&l, "1");
+ l2 = listDupS(l);
+ iListUniqS(&l2);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "1");
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l)
+ l2 = listDupS(l);
+ iListUniqS(&l2);
+ ck_assert_uint_eq(listLengthS(l2),0);
+ ck_assert_ptr_eq(l2[0], NULL);
+ listFreeS(l);
+ listFreeS(l2);
+ // NULL list
+ l = NULL;
+ iListUniqS(&l);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListUniqS(NULL);
+
+}
+
+
+void listCompactST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list with empty elements
+ listPushS(&l, "1");
+ listPushS(&l, "");
+ listPushS(&l, "");
+ listPushS(&l, "4444");
+ l2 = listCompactS(l);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[1], "4444");
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l)
+ l2 = listCompactS(l);
+ ck_assert_uint_eq(listLengthS(l2),0);
+ ck_assert_ptr_eq(l2[0], NULL);
+ listFreeS(l);
+ listFreeS(l2);
+ // NULL list
+ ck_assert_ptr_eq(listCompactS(NULL), NULL);
+
+}
+
+
+void iListCompactST(CuTest *tc) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list with empty elements
+ listPushS(&l, "1");
+ listPushS(&l, "");
+ listPushS(&l, "");
+ listPushS(&l, "4444");
+ l2 = listDupS(l);
+ iListCompactS(&l2);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[1], "4444");
+ listFreeS(l);
+ listFreeS(l2);
+ // list with an empty string
+ l = NULL;
+ listPushS(&l, "");
+ iListCompactS(&l);
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ l2 = listDupS(l);
+ iListCompactS(&l2);
+ ck_assert_uint_eq(listLengthS(l2),0);
+ ck_assert_ptr_eq(l2[0], NULL);
+ listFreeS(l);
+ listFreeS(l2);
+ // NULL list
+ l = NULL;
+ iListCompactS(&l);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListCompactS(NULL);
+
+}
+
+
+void listEmptyFT(CuTest *tc) {
+
+ void **l = NULL;
+
+ // empty list
+ l = listEmptyF();
+ ck_assert(listIsEmpty(l));
+ free(l);
+
+}
+
+
+void iListEmptyFT(CuTest *tc) {
+
+ void **l = NULL;
+ char *s1 = "lib";
+ char *s2 = "sheepy";
+
+ // empty list
+ listPush(&l, s1);
+ listPush(&l, s2);
+ iListEmptyF(&l);
+ ck_assert(listIsEmpty(l));
+ free(l);
+ // NULL list
+ l = NULL;
+ iListEmptyF(&l);
+ ck_assert(listIsEmpty(l));
+ free(l);
+ // NULL var
+ iListEmptyF(NULL);
+
+}
+
+
+void listIsEmptyT(CuTest *tc) {
+
+ void **l = NULL;
+ char *s1 = "lib";
+ char *s2 = "sheepy";
+
+ // non empty list
+ listPush(&l, s1);
+ listPush(&l, s2);
+ // check ck_assert_ptr_null not available in jessie
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert(!listIsEmpty(l));
+ free(l);
+ // empty list
+ listEmpty(l);
+ ck_assert(listIsEmpty(l));
+ free(l);
+ ck_assert(listIsEmpty(NULL));
+
+}
+
+
+void listCreateT(CuTest *tc) {
+
+ void **l;
+ char *s1 = "sheepy";
+ char *s2 = "SHEEPY";
+
+ // create list
+ l = listCreate((void *)s1, (void *)s2, (void *)s1);
+ // check ck_assert_ptr_null not available in jessie
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert_uint_eq(listLength(l),3);
+ ck_assert_str_eq(l[0], "sheepy");
+ ck_assert_str_eq(l[1], "SHEEPY");
+ ck_assert_str_eq(l[2], "sheepy");
+ free(l);
+
+ // NULL first element
+ ck_assert_ptr_eq(listCreate(NULL, "sheepy"), NULL);
+
+}
+
+
+void listFromArrayT(CuTest *tc) {
+
+ void **l = NULL;
+ char *array[] = {"1", "22", "333"};
+ char *arrayNULL[] = {"1", NULL, "333"};
+
+ // copy array to list
+ l = listFromArray((void *)array, 3);
+ ck_assert_uint_eq(listLength(l),3);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_str_eq(l[2], "333");
+ free(l);
+ // array with NULL inside
+ l = listFromArray((void *)arrayNULL, 3);
+ ck_assert_uint_eq(listLength(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "333");
+ free(l);
+ // empty list
+ l = listFromArray((void *)array, 0);
+ ck_assert(listIsEmpty(l));
+ free(l);
+ // NULL pointer to list
+ ck_assert_ptr_eq(listFromArray(NULL, 1), NULL);
+
+}
+
+
+void listPushT(CuTest *tc) {
+
+ void **l = NULL;
+ char *s = "sheepy";
+ char *s2 = "SHEEPY";
+
+ // push strings and NULL list
+ listPush(&l, (void *)s);
+ // check ck_assert_ptr_null not available in jessie
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert_str_eq(l[0], "sheepy");
+ listPush(&l, (void *)s2);
+ ck_assert_str_eq(l[1], "SHEEPY");
+ ck_assert_str_eq(l[0], "sheepy");
+ // push NULL
+ listPush(&l, NULL);
+ ck_assert_ptr_eq(l[2], NULL);
+ free(l);
+ // NULL list and NULL string
+ l = NULL;
+ listPush(&l, NULL);
+ ck_assert_ptr_eq(l, NULL);
+ // empty list
+ listEmpty(l);
+ listPush(&l, (void *)s);
+ ck_assert_str_eq(l[0], "sheepy");
+ ck_assert_ptr_eq(l[1], NULL);
+ free(l);
+ // NULL pointer to list
+ listPush(NULL, NULL);
+
+}
+
+
+void listPopT(CuTest *tc) {
+
+ void **l = NULL;
+ char *s1 = "sheepy";
+ char *s2 = "SHEEPY";
+ char *s;
+
+ // pop string
+ listPush(&l, (void *)s1);
+ listPush(&l, (void *)s2);
+ s = (char *)listPop(&l);
+ ck_assert_str_eq(s, "SHEEPY");
+ ck_assert_uint_eq(listLength(l),1);
+ // last element
+ s = (char *)listPop(&l);
+ ck_assert_str_eq(s, "sheepy");
+ ck_assert_uint_eq(listLength(l),0);
+ // empty list
+ ck_assert_ptr_eq(listPop(&l), NULL);
+ free(l);
+ // NULL list
+ l = NULL;
+ ck_assert_ptr_eq(listPop(&l), NULL);
+ // NULL pointer to list
+ ck_assert_ptr_eq(listPop(NULL), NULL);
+
+}
+
+
+void listPrependT(CuTest *tc) {
+
+ void **l = NULL;
+ char *s1 = "sheepy";
+ char *s2 = "SHEEPY";
+
+ // push strings and NULL list
+ listPrepend(&l, (void *)s1);
+ // check ck_assert_ptr_null not available in jessie
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert_str_eq(l[0], "sheepy");
+ listPrepend(&l, (void *)s2);
+ ck_assert_str_eq(l[0], "SHEEPY");
+ ck_assert_str_eq(l[1], "sheepy");
+ // push NULL
+ listPrepend(&l, NULL);
+ ck_assert_str_eq(l[0], "SHEEPY");
+ free(l);
+ // NULL list and NULL string`
+ l = NULL;
+ listPrepend(&l, NULL);
+ ck_assert_ptr_eq(l, NULL);
+ // empty list
+ listEmpty(l)
+ listPrepend(&l, (void *)s1);
+ ck_assert_str_eq(l[0], "sheepy");
+ ck_assert_ptr_eq(l[1], NULL);
+ free(l);
+ // NULL pointer to list
+ listPrepend(NULL, NULL);
+
+}
+
+
+void listDequeueT(CuTest *tc) {
+
+ void **l = NULL;
+ char *s1 = "sheepy";
+ char *s2 = "SHEEPY";
+ char *s;
+
+ // pop string
+ listPush(&l, (void *)s1);
+ listPush(&l, (void *)s2);
+ s = listDequeue(&l);
+ ck_assert_str_eq(s, "sheepy");
+ ck_assert_uint_eq(listLength(l),1);
+ // last element
+ s = listDequeue(&l);
+ ck_assert_str_eq(s, "SHEEPY");
+ ck_assert_uint_eq(listLength(l),0);
+ // empty list
+ ck_assert_ptr_eq(listDequeue(&l), NULL);
+ free(l);
+ // NULL list
+ l = NULL;
+ ck_assert_ptr_eq(listDequeue(&l), NULL);
+ // NULL pointer to list
+ ck_assert_ptr_eq(listDequeue(NULL), NULL);
+
+}
+
+
+void listFreeT(CuTest *tc) {
+
+ void **l = NULL;
+ char *s1 = strdup("sheepy");
+ char *s2 = strdup("SHEEPY");
+ // not possible to know if a pointer is already freed
+ listPush(&l, (void *)s1);
+ listPush(&l, (void *)s2);
+ listFree(l);
+ // empty list
+ listEmpty(l);
+ listFree(l);
+ // NULL list
+ listFree(NULL);
+
+}
+
+
+void listFreeManyT(CuTest *tc) {
+
+ void **l1 = NULL;
+ char *s1 = strdup("sheepy");
+ char *s2 = strdup("SHEEPY");
+ // not possible to know if a pointer is already freed
+ listPush(&l1, (void *)s1);
+ listPush(&l1, (void *)s2);
+ void **l2 = listEmptyF();
+ listFreeMany(l1, l2);
+
+}
+
+
+void listLengthT(CuTest *tc) {
+
+ void **l;
+
+ // list length
+ l = malloc(2 * sizeof(char *));
+ l[0] = (void *)1;
+ l[1] = NULL;
+ ck_assert_uint_eq(listLength(l),1);
+ free(l);
+ // empty list
+ listEmpty(l)
+ ck_assert_uint_eq(listLength(l),0);
+ free(l);
+ // NULL list
+ ck_assert_uint_eq(listLength(NULL),0);
+
+
+}
+
+
+void listGetT(CuTest *tc) {
+
+ void **l = NULL;
+ char *s1 = "1";
+ char *s2 = "22";
+ char *s3 = "333";
+ char *s4 = "4444";
+
+ // get string
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ ck_assert_str_eq(listGet(l, 0), "1");
+ // negative index
+ ck_assert_str_eq(listGet(l, -1), "4444");
+ // outside list
+ ck_assert_ptr_eq(listGet(l, 10), NULL);
+ ck_assert_ptr_eq(listGet(l, -10), NULL);
+ free(l);
+ // negative index in a one element list
+ l = NULL;
+ listPush(&l, (void*)s1);
+ listPush(&l, NULL);
+ ck_assert_ptr_ne(listGet(l,-1), NULL);
+ free(l);
+ // empty list
+ listEmpty(l)
+ ck_assert_ptr_eq(listGet(l,0),NULL);
+ free(l);
+ // NULL list
+ ck_assert_ptr_eq(listGet(NULL, 0), NULL);
+
+}
+
+
+void listSetT(CuTest *tc) {
+
+ void **l = NULL;
+ char *s1 = "1";
+ char *s2 = "22";
+ char *s3 = "333";
+ char *s4 = "4444";
+ char *sA = "@@";
+ char *sB = "|";
+
+ // get string
+ listPush(&l, (void*)sA);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)sB);
+ listPush(&l, (void*)s4);
+ listSet(l, 0, (void*)s1);
+ ck_assert_str_eq(listGet(l, 0), "1");
+ // negative index
+ listSet(l, -2, (void*)s3);
+ ck_assert_str_eq(listGet(l, -2), "333");
+ // outside list
+ // list is unchanged
+ listSet(l, 10, (void*)s1);
+ listSet(l, -10, (void*)s1);
+ // NULL s var
+ listSet(l, -2, NULL);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_str_eq(l[2], "333");
+ ck_assert_str_eq(l[3], "4444");
+ free(l);
+ // negative index in a one element list
+ l = NULL;
+ listPush(&l, (void*)s1);
+ listPush(&l, NULL);
+ listSet(l, -1, (void*)s1);
+ ck_assert_str_eq(listGet(l,-1), "1");
+ free(l);
+ // empty list - should not crash
+ listEmpty(l);
+ listSet(l, 0, (void*)s1);
+ ck_assert_ptr_eq(listGet(l,0),NULL);
+ free(l);
+ // NULL list
+ listSet(NULL, 0, (void*)s1);
+ ck_assert_ptr_eq(listGet(NULL, 0), NULL);
+
+}
+
+
+void listDupT(CuTest *tc) {
+
+ void **l = NULL;
+ void **l2;
+ char *s1 = "1";
+ char *s2 = "22";
+ char *s3 = "333";
+ char *s4 = "4444";
+
+ // list
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ l2 = listDup(l);
+ ck_assert_uint_eq(listLength(l2),4);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[3], "4444");
+ free(l);
+ free(l2);
+ // empty list
+ listEmpty(l);
+ l2 = listDup(l);
+ ck_assert(listIsEmpty(l2));
+ free(l);
+ free(l2);
+ // NULL list
+ ck_assert_ptr_eq(listDup(NULL), NULL);
+
+}
+
+
+void listReverseT(CuTest *tc) {
+
+ void **l = NULL;
+ void **l2;
+ char *s1 = "1";
+ char *s2 = "22";
+ char *s3 = "333";
+ char *s4 = "4444";
+
+ // list
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ l2 = listReverse(l);
+ ck_assert_uint_eq(listLength(l2),4);
+ ck_assert_str_eq(l2[0], "4444");
+ ck_assert_str_eq(l2[3], "1");
+ free(l);
+ free(l2);
+ // empty list
+ listEmpty(l);
+ l2 = listReverse(l);
+ ck_assert(listIsEmpty(l2));
+ free(l);
+ free(l2);
+ // NULL list
+ ck_assert_ptr_eq(listReverse(NULL), NULL);
+
+}
+
+
+void iListReverseT(CuTest *tc) {
+
+ void **l = NULL;
+ char *s1 = "1";
+ char *s2 = "22";
+ char *s3 = "333";
+ char *s4 = "4444";
+
+ // list
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ iListReverse(&l);
+ ck_assert_uint_eq(listLength(l),4);
+ ck_assert_str_eq(l[0], "4444");
+ ck_assert_str_eq(l[3], "1");
+ free(l);
+ /* // empty list */
+ listEmpty(l);
+ iListReverse(&l);
+ ck_assert(listIsEmpty(l));
+ free(l);
+ // NULL list
+ l = NULL;
+ iListReverse(&l);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListReverse(NULL);
+
+}
+
+
+void listCatT(CuTest *tc) {
+
+ void **l = NULL;
+ void **l2 = NULL;
+ void **r;
+ char *s1 = "1";
+ char *s2 = "#@#";
+ char *s3 = "lib";
+ char *s4 = "sheepy";
+
+ // cat lists
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s1);
+ listPush(&l2, (void*)s3);
+ listPush(&l2, (void*)s4);
+ r = listCat(l,l2);
+ ck_assert_str_eq(r[0], "#@#");
+ ck_assert_str_eq(r[1], "1");
+ ck_assert_str_eq(r[2], "lib");
+ ck_assert_str_eq(r[3], "sheepy");
+ freeManyS(l,l2,r);
+ // empty list
+ listEmpty(l);
+ r = listCat(l);
+ ck_assert(listIsEmpty(r));
+ freeManyS(r,l);
+ // cat empty list with list
+ listEmpty(l);
+ l2 = NULL;
+ listPush(&l2, (void*)s3);
+ listPush(&l2, (void*)s4);
+ r = listCat(l, l2);
+ ck_assert_str_eq(r[0], "lib");
+ ck_assert_str_eq(r[1], "sheepy");
+ freeManyS(l,l2,r);
+
+}
+
+
+void listAppendT(CuTest *tc) {
+
+ void **l = NULL;
+ void **l2 = NULL;
+ char *s1 = "1";
+ char *s2 = "22";
+ char *s3 = "333";
+ char *s4 = "4444";
+ char *sA = "A";
+ char *sB = "BB";
+ char *sC = "CCC";
+ char *sD = "DDDD";
+
+ // lists
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ listPush(&l2, (void*)sA);
+ listPush(&l2, (void*)sB);
+ listPush(&l2, (void*)sC);
+ listPush(&l2, (void*)sD);
+ listAppend(&l2,l);
+ ck_assert_uint_eq(listLength(l2),8);
+ ck_assert_str_eq(l2[0], "A");
+ ck_assert_str_eq(l2[3], "DDDD");
+ ck_assert_str_eq(l2[4],"1");
+ ck_assert_str_eq(l2[7],"4444");
+ free(l);
+ // append list to itself - no change
+ l = NULL;
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ listAppend(&l,l);
+ ck_assert_uint_eq(listLength(l),4);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[3], "4444");
+ free(l);
+ // empty list + list
+ listEmpty(l);
+ listAppend(&l, l2);
+ //ck_assert(listEqS(l,l2));
+ ck_assert_uint_eq(listLength(l),listLength(l2));
+ ck_assert_str_eq(l2[0], l[0]);
+ ck_assert_str_eq(l2[3], l[3]);
+ ck_assert_str_eq(l2[4], l[4]);
+ ck_assert_str_eq(l2[7], l[7]);
+ free(l);
+ // list + empty list
+ listEmptyS(l);
+ listAppend(&l2, l);
+ ck_assert_uint_eq(listLength(l2),8);
+ ck_assert_str_eq(l2[0], "A");
+ ck_assert_str_eq(l2[3], "DDDD");
+ ck_assert_str_eq(l2[4],"1");
+ ck_assert_str_eq(l2[7],"4444");
+ free(l);
+ free(l2);
+ // empty list + empty list
+ listEmpty(l);
+ listEmpty(l2);
+ listAppend(&l, l2);
+ ck_assert(listIsEmpty(l));
+ free(l);
+ free(l2);
+ // NULL list + list = duplicate
+ l = NULL;
+ l2 = NULL;
+ listPush(&l2, (void*)sA);
+ listPush(&l2, (void*)sB);
+ listPush(&l2, (void*)sC);
+ listPush(&l2, (void*)sD);
+ listAppend(&l,l2);
+ //ck_assert(listEqS(l,l2));
+ ck_assert_uint_eq(listLength(l),listLength(l2));
+ ck_assert_str_eq(l2[0], l[0]);
+ ck_assert_str_eq(l2[3], l[3]);
+ free(l);
+ // list + NULL list
+ listAppend(&l2, NULL);
+ ck_assert_uint_eq(listLength(l2),4);
+ ck_assert_str_eq(l2[0], "A");
+ ck_assert_str_eq(l2[3], "DDDD");
+ free(l2);
+ // NULL list pointer
+ listAppend(NULL,l2);
+ // should not crash
+
+}
+
+
+void listAddT(CuTest *tc) {
+
+ void **l = NULL;
+ void **l2 = NULL;
+ void **l3;
+ char *s1 = "1";
+ char *s2 = "22";
+ char *s3 = "333";
+ char *s4 = "4444";
+ char *sA = "A";
+ char *sB = "BB";
+ char *sC = "CCC";
+ char *sD = "DDDD";
+
+ // lists
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ listPush(&l2, (void*)sA);
+ listPush(&l2, (void*)sB);
+ listPush(&l2, (void*)sC);
+ listPush(&l2, (void*)sD);
+ l3 = listAdd(l2,l);
+ ck_assert_uint_eq(listLength(l3),8);
+ ck_assert_str_eq(l3[0], "A");
+ ck_assert_str_eq(l3[3], "DDDD");
+ ck_assert_str_eq(l3[4],"1");
+ ck_assert_str_eq(l3[7],"4444");
+ free(l3);
+ free(l);
+ // empty list + list
+ listEmpty(l);
+ l3 = listAdd(l, l2);
+ //ck_assert(listEqS(l3,l2));
+ ck_assert_uint_eq(listLength(l3),listLength(l2));
+ ck_assert_str_eq(l3[0], l2[0]);
+ ck_assert_str_eq(l3[3], l2[3]);
+ free(l3);
+ free(l);
+ // list + empty list
+ listEmpty(l)
+ l3 = listAdd(l2, l);
+ //ck_assert(listEqS(l3,l2));
+ ck_assert_uint_eq(listLength(l3),listLength(l2));
+ ck_assert_str_eq(l3[0], l2[0]);
+ ck_assert_str_eq(l3[3], l2[3]);
+ free(l3);
+ free(l);
+ // empty list + empty list
+ listEmpty(l);
+ l3 = listAdd(l, l);
+ ck_assert(listIsEmpty(l3));
+ free(l3);
+ free(l);
+ // NULL list + list
+ l3 = listAdd(NULL,l2);
+ //ck_assert(listEq(l3,l2));
+ ck_assert_uint_eq(listLength(l3),listLength(l2));
+ ck_assert_str_eq(l3[0], l2[0]);
+ ck_assert_str_eq(l3[3], l2[3]);
+ free(l3);
+ // list + NULL list
+ l3 = listAdd(l2, NULL);
+ //ck_assert(listEqS(l3,l2));
+ ck_assert_uint_eq(listLength(l3),listLength(l2));
+ ck_assert_str_eq(l3[0], l2[0]);
+ ck_assert_str_eq(l3[3], l2[3]);
+ free(l3);
+ free(l2);
+ // NULL list + NULL list
+ ck_assert_ptr_eq(listAdd(NULL,NULL), NULL);
+
+}
+
+
+void listSliceT(CuTest *tc) {
+
+ void **l = NULL;
+ void **l2;
+ char *s1 = "1";
+ char *s2 = "22";
+ char *s3 = "333";
+ char *s4 = "4444";
+
+ // list negative index
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ l2 = listSlice(l, 1,-1);
+ ck_assert_uint_eq(listLength(l2),2);
+ ck_assert_str_eq(l2[0], "22");
+ ck_assert_str_eq(l2[1], "333");
+ free(l);
+ free(l2);
+ // start outside
+ l = NULL;
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ ck_assert_ptr_eq(listSlice(l, 20,-4), NULL);
+ // end outside
+ l2 = listSlice(l, 2,40);
+ ck_assert_uint_eq(listLength(l2),2);
+ ck_assert_str_eq(l2[0], "333");
+ ck_assert_str_eq(l2[1], "4444");
+ free(l);
+ free(l2);
+ // end negative and outside
+ l = NULL;
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ ck_assert_ptr_eq(listSlice(l, 2,-40), NULL);
+ // end before start
+ ck_assert_ptr_eq(listSlice(l, 3,2), NULL);
+ free(l);
+ // negative start last element
+ l = NULL;
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ l2 = listSlice(l, -1,0);
+ ck_assert_uint_eq(listLength(l2),1);
+ ck_assert_str_eq(l2[0], "22");
+ free(l);
+ free(l2);
+ // start = end
+ l = NULL;
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ l2 = listSlice(l, 1,1);
+ ck_assert_uint_eq(listLength(l2),0);
+ ck_assert_ptr_eq(l2[0], NULL);
+ free(l);
+ free(l2);
+ // empty list
+ listEmpty(l)
+ ck_assert_ptr_eq(listSlice(l, 0,0), NULL);
+ ck_assert_ptr_eq(listSlice(l, -1,0), NULL);
+ free(l);
+ // NULL list
+ ck_assert_ptr_eq(listSlice(NULL, 2,-4), NULL);
+
+
+}
+
+
+void iListSliceT(CuTest *tc) {
+
+ void **l = NULL;
+ char *s1 = "1";
+ char *s2 = "22";
+ char *s3 = "333";
+ char *s4 = "4444";
+
+ // list negative index
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ iListSlice(&l, 1,-1);
+ ck_assert_uint_eq(listLength(l),2);
+ ck_assert_str_eq(l[0], "22");
+ ck_assert_str_eq(l[1], "333");
+ // start outside
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ iListSlice(&l, 20,-4);
+ ck_assert_uint_eq(listLength(l),0);
+ // end outside
+ iListSlice(&l, 2,40);
+ ck_assert_uint_eq(listLength(l),0);
+ // end negative and outside
+ iListSlice(&l, 2,-40);
+ ck_assert_uint_eq(listLength(l),0);
+ // end before start
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ iListSlice(&l, 3,2);
+ ck_assert_uint_eq(listLength(l),0);
+ free(l);
+ // negative start last element
+ l = NULL;
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ iListSlice(&l, -1,0);
+ ck_assert_uint_eq(listLength(l),1);
+ ck_assert_str_eq(l[0], "22");
+ free(l);
+ // start = end
+ l = NULL;
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ iListSlice(&l, 1,1);
+ ck_assert_uint_eq(listLength(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ free(l);
+ // empty list
+ listEmpty(l)
+ iListSlice(&l, 0,0);
+ ck_assert(listIsEmpty(l));
+ iListSlice(&l, -1,0);
+ ck_assert(listIsEmpty(l));
+ free(l);
+ // NULL list
+ l = NULL;
+ iListSlice(&l, 2,-4);
+ // NULL var
+ iListSlice(NULL, 2,-4);
+
+
+}
+
+
+void listInsertT(CuTest *tc) {
+
+ void **l;
+ void **l2;
+ void **r;
+ char *s1 = "1";
+ char *s2 = "22";
+ char *s3 = "lib";
+
+ // insert
+ l = listCreate((void*)s1, (void*)s2);
+ l2 = listCreate((void*)s3);
+ r = listInsert(l, 0, l2);
+ ck_assert_uint_eq(listLength(r),3);
+ ck_assert_str_eq(r[0], "lib");
+ ck_assert_str_eq(r[1], "1");
+ ck_assert_str_eq(r[2], "22");
+ free(r);
+ // negative index
+ r = listInsert(l, -1, l2);
+ ck_assert_uint_eq(listLength(r),3);
+ ck_assert_str_eq(r[0], "1");
+ ck_assert_str_eq(r[1], "22");
+ ck_assert_str_eq(r[2], "lib");
+ free(r);
+ // edge
+ r = listInsert(l, 2, l2);
+ ck_assert_uint_eq(listLength(r),3);
+ ck_assert_str_eq(r[0], "1");
+ ck_assert_str_eq(r[1], "22");
+ ck_assert_str_eq(r[2], "lib");
+ free(r);
+ // outside list
+ r = listInsert(l, 4, l2);
+ ck_assert_ptr_eq(r, NULL);
+ r = listInsert(l, -4, l2);
+ ck_assert_ptr_eq(r, NULL);
+ free(l);
+ // negative index in a one element list
+ l = listCreate((void*)s1);
+ r = listInsert(l, -1, l2);
+ ck_assert_str_eq(r[0], "1");
+ ck_assert_str_eq(r[1], "lib");
+ freeManyS(l,r);
+ // empty list
+ listEmpty(l);
+ r = listInsert(l, 0, l2);
+ ck_assert_str_eq(r[0], "lib");
+ freeManyS(r,l, l2);
+ // empty insert list
+ l = listCreate((void*)s1);
+ listEmpty(l2);
+ r = listInsert(l, 0, l2);
+ ck_assert_str_eq(r[0], "1");
+ freeManyS(r,l2);
+ // NULL insert string
+ r = listInsert(l, 0, NULL);
+ ck_assert_ptr_eq(r, NULL);
+ free(l);
+ // NULL list
+ r = listInsert(NULL, 0, NULL);
+ ck_assert_ptr_eq(r, NULL);
+
+
+}
+
+
+void iListInsertT(CuTest *tc) {
+
+ void **l;
+ void **l2;
+ char *s1 = "1";
+ char *s2 = "22";
+ char *s3 = "lib";
+
+ // insert
+ l = listCreate((void*)s1, (void*)s2);
+ l2 = listCreate((void*)s3);
+ iListInsert(&l, 0, l2);
+ ck_assert_uint_eq(listLength(l),3);
+ ck_assert_str_eq(l[0], "lib");
+ ck_assert_str_eq(l[1], "1");
+ ck_assert_str_eq(l[2], "22");
+ free(l2);
+ free(l);
+ // negative index
+ l = listCreate((void*)s1, (void*)s2);
+ l2 = listCreate((void*)s3);
+ iListInsert(&l, -1, l2);
+ ck_assert_uint_eq(listLength(l),3);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_str_eq(l[2], "lib");
+ free(l2);
+ free(l);
+ // edge
+ l = listCreate((void*)s1, (void*)s2);
+ l2 = listCreate((void*)s3);
+ iListInsert(&l, 2, l2);
+ ck_assert_uint_eq(listLength(l),3);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_str_eq(l[2], "lib");
+ free(l2);
+ free(l);
+ // outside list
+ l = listCreate((void*)s1, (void*)s2);
+ l2 = listCreate((void*)s3);
+ iListInsert(&l, 4, l2);
+ ck_assert_uint_eq(listLength(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ iListInsert(&l, -4, l2);
+ ck_assert_uint_eq(listLength(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ free(l);
+ // negative index in a one element list
+ l = listCreate((void*)s1);
+ iListInsert(&l, -1, l2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "lib");
+ free(l2);
+ free(l);
+ // empty list
+ listEmpty(l);
+ l2 = listCreate((void*)s3);
+ iListInsert(&l, 0, l2);
+ ck_assert_str_eq(l[0], "lib");
+ free(l2);
+ free(l);
+ // empty insert list
+ l = listCreate((void*)s1);
+ listEmpty(l2);
+ iListInsert(&l, 0, l2);
+ ck_assert_str_eq(l[0], "1");
+ free(l2);
+ // NULL insert string
+ iListInsert(&l, 0, NULL);
+ ck_assert_str_eq(l[0], "1");
+ free(l);
+ // NULL list
+ l = NULL;
+ iListInsert(&l, 0, NULL);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListInsert(NULL, 0, NULL);
+
+
+}
+
+
+void listDelT(CuTest *tc) {
+
+ void **l = NULL;
+ void **l2;
+ char *s1 = "1";
+ char *s2 = "22";
+ char *s3 = "333";
+ char *s4 = "4444";
+
+ // list negative index
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ l2 = listDel(l, 1,-1);
+ ck_assert_uint_eq(listLength(l2),2);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[1], "4444");
+ free(l2);
+ // start outside
+ ck_assert_ptr_eq(listDel(l, 20,-4), NULL);
+ // end outside
+ l2 = listDel(l, 2,40);
+ ck_assert_uint_eq(listLength(l2),2);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[1], "22");
+ free(l2);
+ // end negative and outside
+ ck_assert_ptr_eq(listDel(l, 2,-40), NULL);
+ // end before start
+ ck_assert_ptr_eq(listDel(l, 3,2), NULL);
+ free(l);
+ // negative start last element
+ l = NULL;
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ l2 = listDel(l, -1,0);
+ ck_assert_uint_eq(listLength(l2),1);
+ ck_assert_str_eq(l2[0], "1");
+ free(l);
+ free(l2);
+ // start negative and outside (delete complete list because end is 0 (=len))
+ l = NULL;
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ l2 = listDel(l, -3,0);
+ ck_assert_uint_eq(listLength(l2),0);
+ ck_assert_ptr_eq(l2[0], NULL);
+ free(l);
+ free(l2);
+ // start = end
+ l = NULL;
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ l2 = listDel(l, 1,1);
+ ck_assert_uint_eq(listLength(l2),2);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[1], "22");
+ free(l);
+ free(l2);
+ // empty list
+ listEmpty(l)
+ ck_assert_ptr_eq(listDel(l, 0,0), NULL);
+ ck_assert_ptr_eq(listDel(l, -1,0), NULL);
+ free(l);
+ // NULL list
+ ck_assert_ptr_eq(listDel(NULL, 2,-4), NULL);
+
+
+}
+
+
+void iListDelT(CuTest *tc) {
+
+ void **l = NULL;
+ void **l2;
+ char *s1 = "1";
+ char *s2 = "22";
+ char *s3 = "333";
+ char *s4 = "4444";
+
+ // list negative index
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ iListDel(&l, 1,-1);
+ ck_assert_uint_eq(listLength(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "4444");
+ iListEmptyF(&l);
+ // start outside
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ iListDel(&l, 20,-4);
+ ck_assert_uint_eq(listLength(l),4);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[3], "4444");
+ // end outside
+ iListDel(&l, 2,40);
+ ck_assert_uint_eq(listLength(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ iListEmptyF(&l);
+ // end negative and outside
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ listPush(&l, (void*)s3);
+ listPush(&l, (void*)s4);
+ iListDel(&l, 2,-40);
+ ck_assert_uint_eq(listLength(l),4);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[3], "4444");
+ // end before start
+ iListDel(&l, 3,2);
+ ck_assert_uint_eq(listLength(l),4);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[3], "4444");
+ iListEmptyF(&l);
+ // negative start last element
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ iListDel(&l, -1,0);
+ ck_assert_uint_eq(listLength(l),1);
+ ck_assert_str_eq(l[0], "1");
+ iListEmptyF(&l);
+ // start negative and outside (delete complete list because end is 0 (=len))
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ iListDel(&l, -3,0);
+ ck_assert_uint_eq(listLength(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ // start = end
+ // (l is empty from previous test)
+ listPush(&l, (void*)s1);
+ listPush(&l, (void*)s2);
+ iListDel(&l, 1,1);
+ ck_assert_uint_eq(listLength(l),2);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ free(l);
+ // empty list
+ listEmpty(l);
+ iListDel(&l, 0,0);
+ ck_assert(listIsEmpty(l));
+ iListDel(&l, -1,0);
+ ck_assert(listIsEmpty(l));
+ free(l);
+ // NULL list
+ l = NULL;
+ iListDel(&l, 2,-4);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListDel(NULL, 2,-4);
+
+
+}
+
+ringMake(ringTestT, int, 4);
+
+void ringInitT(CuTest *tc) {
+
+ ringTestT rg;
+
+ ck_assert_int_eq(ringInit(&rg, 4), 1);
+
+ // NULL
+ ck_assert_int_eq(ringInit(NULL, 4), 0);
+
+
+}
+
+
+void ringIsEmptyT(CuTest *tc) {
+
+ ringTestT rg;
+ ringInit(&rg, 4);
+
+ // empty
+ ck_assert_int_eq(ringIsEmpty(&rg), 1);
+
+ // not empty
+ ringPush(&rg);
+ ck_assert_int_eq(ringIsEmpty(&rg), 0);
+
+ // NULL
+ ck_assert_int_eq(ringIsEmpty(NULL), -1);
+
+
+}
+
+
+void ringIsFullT(CuTest *tc) {
+
+ ringTestT rg;
+ ringInit(&rg, 4);
+
+ // full
+ ringPush(&rg);
+ rg.last = 2;
+ rg.head = 3;
+ ck_assert_int_eq(ringIsFull(&rg), 1);
+
+ // not full
+ rg.last = 1;
+ ck_assert_int_eq(ringIsFull(&rg), 0);
+
+ // NULL
+ ck_assert_int_eq(ringIsFull(NULL), -1);
+
+}
+
+
+void ringCountT(CuTest *tc) {
+
+ ringTestT rg;
+ ringInit(&rg, 4);
+
+ // empty
+ ck_assert_int_eq(ringCount(&rg), 0);
+ // last < head
+ ringPush(&rg);
+ rg.last = 2;
+ rg.head = 3;
+ ck_assert_int_eq(ringCount(&rg), 4);
+ // cound > head
+ rg.head = 0;
+ rg.last = 2;
+ ck_assert_int_eq(ringCount(&rg), 3);
+ // NULL
+ ck_assert_int_eq(ringCount(NULL), -1);
+
+}
+
+
+void ringPushT(CuTest *tc) {
+
+ ringTestT rg;
+ ringInit(&rg, 4);
+
+ // push
+ ck_assert_int_eq(ringPush(&rg), 0);
+ ck_assert_int_eq(ringPush(&rg), 1);
+ ck_assert_int_eq(ringPush(&rg), 2);
+ ck_assert_int_eq(ringPush(&rg), 3);
+ // full
+ ck_assert_int_eq(ringPush(&rg), -1);
+ ck_assert_int_eq(ringPush(&rg), -1);
+ // NULL
+ ck_assert_int_eq(ringPush(NULL), -2);
+
+
+}
+
+
+void ringPopT(CuTest *tc) {
+
+ ringTestT rg;
+ ringInit(&rg, 4);
+
+ // empty ring
+ ck_assert_int_eq(ringPop(&rg), 0);
+ // pop
+ ringPush(&rg);
+ ringPush(&rg);
+ ck_assert_int_eq(ringPop(&rg), 1);
+ // pop last
+ ck_assert_int_eq(ringPop(&rg), 1);
+ // pop when head > last
+ rg.isEmpty = false;
+ rg.head = 3;
+ ck_assert_int_eq(ringPop(&rg), 1);
+ // NULL
+ ck_assert_int_eq(ringPop(NULL), -1);
+
+}
+
+
+void ringPrependT(CuTest *tc) {
+
+ ringTestT rg;
+ ringInit(&rg, 4);
+
+ // push
+ ck_assert_int_eq(ringPrepend(&rg), 0);
+ ck_assert_int_eq(ringPrepend(&rg), 3);
+ ck_assert_int_eq(ringPrepend(&rg), 2);
+ ck_assert_int_eq(ringPrepend(&rg), 1);
+ // full
+ ck_assert_int_eq(ringPrepend(&rg), -1);
+ ck_assert_int_eq(ringPrepend(&rg), -1);
+ // NULL
+ ck_assert_int_eq(ringPrepend(NULL), -2);
+
+}
+
+
+void ringDequeueT(CuTest *tc) {
+
+ ringTestT rg;
+ ringInit(&rg, 4);
+
+ // empty ring
+ ck_assert_int_eq(ringDequeue(&rg), 0);
+ // pop
+ ringPush(&rg);
+ ringPush(&rg);
+ ck_assert_int_eq(ringDequeue(&rg), 1);
+ // pop last
+ ck_assert_int_eq(ringDequeue(&rg), 1);
+ // pop when head > last
+ rg.isEmpty = false;
+ rg.head = 3;
+ ck_assert_int_eq(ringDequeue(&rg), 1);
+ // NULL
+ ck_assert_int_eq(ringDequeue(NULL), -1);
+
+}
+
+#define chanMax 30
+ringMake(chanT, int, chanMax);
+
+// context for fibers of type fiberA
+typedef struct {int slot; int a; chanT *c;} AArgs;
+
+// declaration of fibers type fiberA
+void fiberATest(int thisSlot) {
+ return;
+}
+
+void fiberAddT(CuTest *tc) {
+
+ staticArrayInit(fibers.L);
+ staticArrayInit(fibers.startL);
+
+ AArgs Aa;
+ chanT c;
+
+ ringInit(&c, chanMax);
+
+ Aa.c = &c;
+
+ ck_assert(fiberAdd(&Aa, 1, fiberATest));
+
+}
+
+
+void fiberPrependT(CuTest *tc) {
+
+ staticArrayInit(fibers.L);
+ staticArrayInit(fibers.startL);
+
+ AArgs Aa;
+ chanT c;
+
+ ringInit(&c, chanMax);
+
+ Aa.c = &c;
+
+ ck_assert(fiberPrepend(&Aa, 1, fiberATest));
+
+}
+
+
+void schedulerT(CuTest *tc) {
+
+ staticArrayInit(fibers.L);
+ staticArrayInit(fibers.startL);
+
+ scheduler();
+
+ AArgs Aa;
+ chanT c;
+
+ ringInit(&c, chanMax);
+
+ Aa.c = &c;
+
+ fiberAdd(&Aa, 1, fiberATest);
+
+ scheduler();
+
+ // TODO test 100%
+
+}
+
+
+void getMonotonicTimeT(CuTest *tc) {
+
+ getMonotonicTime();
+
+}
+
+
+void nanoSleepT(CuTest *tc) {
+
+ int r;
+
+ nanoSleep(100);
+ nanoSleepE(100, puts(BLD RED "nanosleep error" RST));
+ r = nanoSleepF(100);
+ ck_assert_int_eq(r, 1);
+
+}
+
+
+
+
+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, setLogFileT);
+ SUITE_ADD_TEST(suite, closeLogFilesT);
+ SUITE_ADD_TEST(suite, getLogModeT);
+ SUITE_ADD_TEST(suite, setLogModeT);
+ SUITE_ADD_TEST(suite, _pLogT);
+ SUITE_ADD_TEST(suite, initLibsheepyFT);
+ SUITE_ADD_TEST(suite, getProgPathT);
+ SUITE_ADD_TEST(suite, getRealProgPathT);
+ SUITE_ADD_TEST(suite, systemNFreeFT);
+ SUITE_ADD_TEST(suite, getModificationTimeT);
+ SUITE_ADD_TEST(suite, setModificationTimeT);
+ SUITE_ADD_TEST(suite, equalModificationTimesT);
+ SUITE_ADD_TEST(suite, shDirnameT);
+ SUITE_ADD_TEST(suite, bDirnameT);
+ SUITE_ADD_TEST(suite, bLDirnameT);
+ SUITE_ADD_TEST(suite, expandHomeT);
+ SUITE_ADD_TEST(suite, iExpandHomeT);
+ SUITE_ADD_TEST(suite, bExpandHomeT);
+ SUITE_ADD_TEST(suite, bLExpandHomeT);
+ SUITE_ADD_TEST(suite, normalizePathT);
+ SUITE_ADD_TEST(suite, iNormalizePathT);
+ SUITE_ADD_TEST(suite, bNormalizePathT);
+ SUITE_ADD_TEST(suite, bLNormalizePathT);
+ SUITE_ADD_TEST(suite, timeToST);
+ SUITE_ADD_TEST(suite, chDirT);
+ SUITE_ADD_TEST(suite, isDirT);
+ SUITE_ADD_TEST(suite, isLinkT);
+ SUITE_ADD_TEST(suite, fileExistsT);
+ SUITE_ADD_TEST(suite, fileChmodT);
+ SUITE_ADD_TEST(suite, fileSizeT);
+ SUITE_ADD_TEST(suite, readFileToST);
+ SUITE_ADD_TEST(suite, bReadFileToST);
+ SUITE_ADD_TEST(suite, bLReadFileToST);
+ SUITE_ADD_TEST(suite, readFileT);
+ SUITE_ADD_TEST(suite, bReadFileT);
+ SUITE_ADD_TEST(suite, bLReadFileT);
+ SUITE_ADD_TEST(suite, writeFileST);
+ SUITE_ADD_TEST(suite, writeFileT);
+ SUITE_ADD_TEST(suite, walkDirT);
+ SUITE_ADD_TEST(suite, walkDirDirT);
+ SUITE_ADD_TEST(suite, readDirT);
+ SUITE_ADD_TEST(suite, readDirDirT);
+ SUITE_ADD_TEST(suite, walkDirAllT);
+ SUITE_ADD_TEST(suite, readDirAllT);
+ SUITE_ADD_TEST(suite, mkdirParentsT);
+ SUITE_ADD_TEST(suite, rmAllT);
+ SUITE_ADD_TEST(suite, copyT);
+ SUITE_ADD_TEST(suite, shRenameT);
+ SUITE_ADD_TEST(suite, shMoveT);
+ SUITE_ADD_TEST(suite, setSoftwareRandomT);
+ SUITE_ADD_TEST(suite, setHardwareRandomT);
+ SUITE_ADD_TEST(suite, randomOpenCloseT);
+ SUITE_ADD_TEST(suite, randomWordT);
+ SUITE_ADD_TEST(suite, randomWordFromHWT);
+ SUITE_ADD_TEST(suite, randomChoiceT);
+ SUITE_ADD_TEST(suite, randomST);
+ SUITE_ADD_TEST(suite, bRandomST);
+ SUITE_ADD_TEST(suite, randomAlphaNumST);
+ SUITE_ADD_TEST(suite, bRandomAlphaNumST);
+ SUITE_ADD_TEST(suite, readST);
+ SUITE_ADD_TEST(suite, bLReadST);
+ SUITE_ADD_TEST(suite, readEnterT);
+ SUITE_ADD_TEST(suite, readLineT);
+ SUITE_ADD_TEST(suite, dupST);
+ SUITE_ADD_TEST(suite, shPrintfST);
+ SUITE_ADD_TEST(suite, shEprintfT);
+ SUITE_ADD_TEST(suite, freeManyST);
+ SUITE_ADD_TEST(suite, logNFreeT);
+ SUITE_ADD_TEST(suite, strCpyT);
+ SUITE_ADD_TEST(suite, strLCpyT);
+ SUITE_ADD_TEST(suite, strCatT);
+ SUITE_ADD_TEST(suite, strNCatT);
+ SUITE_ADD_TEST(suite, strLCatT);
+ SUITE_ADD_TEST(suite, strLNCatT);
+ SUITE_ADD_TEST(suite, catST);
+ SUITE_ADD_TEST(suite, iCatST);
+ SUITE_ADD_TEST(suite, bLCatST);
+ SUITE_ADD_TEST(suite, formatST);
+ SUITE_ADD_TEST(suite, appendST);
+ SUITE_ADD_TEST(suite, appendCharST);
+ SUITE_ADD_TEST(suite, appendSCharT);
+ SUITE_ADD_TEST(suite, iAppendST);
+ SUITE_ADD_TEST(suite, iAppendCharST);
+ SUITE_ADD_TEST(suite, iAppendNFreeST);
+ SUITE_ADD_TEST(suite, iAppendManyST);
+ SUITE_ADD_TEST(suite, bAppendManyST);
+ SUITE_ADD_TEST(suite, bLAppendManyST);
+ SUITE_ADD_TEST(suite, prependST);
+ SUITE_ADD_TEST(suite, prependCharST);
+ SUITE_ADD_TEST(suite, prependSCharT);
+ SUITE_ADD_TEST(suite, iPrependST);
+ SUITE_ADD_TEST(suite, iPrependCharST);
+ SUITE_ADD_TEST(suite, iPrependNFreeST);
+ SUITE_ADD_TEST(suite, bPrependST);
+ SUITE_ADD_TEST(suite, bLPrependST);
+ SUITE_ADD_TEST(suite, replaceST);
+ SUITE_ADD_TEST(suite, replaceCharSST);
+ SUITE_ADD_TEST(suite, replaceSCharST);
+ SUITE_ADD_TEST(suite, replaceCharCharST);
+ SUITE_ADD_TEST(suite, iReplaceST);
+ SUITE_ADD_TEST(suite, iReplaceCharSST);
+ SUITE_ADD_TEST(suite, iReplaceSCharST);
+ SUITE_ADD_TEST(suite, iReplaceCharCharST);
+ SUITE_ADD_TEST(suite, bReplaceST);
+ SUITE_ADD_TEST(suite, bLReplaceST);
+ SUITE_ADD_TEST(suite, replaceManyST);
+ SUITE_ADD_TEST(suite, iReplaceManyST);
+ SUITE_ADD_TEST(suite, bReplaceManyST);
+ SUITE_ADD_TEST(suite, bLReplaceManyST);
+ SUITE_ADD_TEST(suite, eqST);
+ SUITE_ADD_TEST(suite, eqCharST);
+ SUITE_ADD_TEST(suite, eqSCharT);
+ SUITE_ADD_TEST(suite, eqIST);
+ SUITE_ADD_TEST(suite, eqICharST);
+ SUITE_ADD_TEST(suite, startsWithST);
+ SUITE_ADD_TEST(suite, startsWithCharST);
+ SUITE_ADD_TEST(suite, endsWithST);
+ SUITE_ADD_TEST(suite, endsWithCharST);
+ SUITE_ADD_TEST(suite, countST);
+ SUITE_ADD_TEST(suite, countCharST);
+ SUITE_ADD_TEST(suite, isNumberT);
+ SUITE_ADD_TEST(suite, isIntT);
+ SUITE_ADD_TEST(suite, parseIntT);
+ SUITE_ADD_TEST(suite, parseIntCharT);
+ SUITE_ADD_TEST(suite, parseDoubleT);
+ SUITE_ADD_TEST(suite, intToST);
+ SUITE_ADD_TEST(suite, bIntToST);
+ SUITE_ADD_TEST(suite, doubleToST);
+ SUITE_ADD_TEST(suite, bDoubleToST);
+ SUITE_ADD_TEST(suite, lenST);
+ SUITE_ADD_TEST(suite, upperST);
+ SUITE_ADD_TEST(suite, iUpperST);
+ SUITE_ADD_TEST(suite, bUpperST);
+ SUITE_ADD_TEST(suite, lowerST);
+ SUITE_ADD_TEST(suite, iLowerST);
+ SUITE_ADD_TEST(suite, bLowerST);
+ SUITE_ADD_TEST(suite, trimST);
+ SUITE_ADD_TEST(suite, iTrimST);
+ SUITE_ADD_TEST(suite, bTrimST);
+ SUITE_ADD_TEST(suite, lTrimST);
+ SUITE_ADD_TEST(suite, iLTrimST);
+ SUITE_ADD_TEST(suite, bLTrimST);
+ SUITE_ADD_TEST(suite, rTrimST);
+ SUITE_ADD_TEST(suite, iRTrimST);
+ SUITE_ADD_TEST(suite, bRTrimST);
+ SUITE_ADD_TEST(suite, uniqST);
+ SUITE_ADD_TEST(suite, iUniqST);
+ SUITE_ADD_TEST(suite, bUniqST);
+ SUITE_ADD_TEST(suite, getST);
+ SUITE_ADD_TEST(suite, setST);
+ SUITE_ADD_TEST(suite, sliceST);
+ SUITE_ADD_TEST(suite, iSliceST);
+ SUITE_ADD_TEST(suite, bSliceST);
+ SUITE_ADD_TEST(suite, insertST);
+ SUITE_ADD_TEST(suite, insertNFreeST);
+ SUITE_ADD_TEST(suite, iInsertST);
+ SUITE_ADD_TEST(suite, iInsertNFreeST);
+ SUITE_ADD_TEST(suite, bInsertST);
+ SUITE_ADD_TEST(suite, bLInsertST);
+ SUITE_ADD_TEST(suite, injectST);
+ SUITE_ADD_TEST(suite, iInjectST);
+ SUITE_ADD_TEST(suite, bInjectST);
+ SUITE_ADD_TEST(suite, bLInjectST);
+ SUITE_ADD_TEST(suite, delST);
+ SUITE_ADD_TEST(suite, iDelST);
+ SUITE_ADD_TEST(suite, bDelST);
+ SUITE_ADD_TEST(suite, findST);
+ SUITE_ADD_TEST(suite, findCharST);
+ SUITE_ADD_TEST(suite, hasST);
+ SUITE_ADD_TEST(suite, hasCharST);
+ SUITE_ADD_TEST(suite, emptySFT);
+ SUITE_ADD_TEST(suite, iEmptySFT);
+ SUITE_ADD_TEST(suite, isEmptyST);
+ SUITE_ADD_TEST(suite, isBlankST);
+ SUITE_ADD_TEST(suite, listEmptySFT);
+ SUITE_ADD_TEST(suite, iListEmptySFT);
+ SUITE_ADD_TEST(suite, listIsEmptyST);
+ SUITE_ADD_TEST(suite, listIsBlankST);
+ SUITE_ADD_TEST(suite, listLengthST);
+ SUITE_ADD_TEST(suite, listCreateST);
+ SUITE_ADD_TEST(suite, listFromArrayST);
+ SUITE_ADD_TEST(suite, listPushST);
+ SUITE_ADD_TEST(suite, iListPushST);
+ SUITE_ADD_TEST(suite, listPopST);
+ SUITE_ADD_TEST(suite, listPrependST);
+ SUITE_ADD_TEST(suite, iListPrependST);
+ SUITE_ADD_TEST(suite, listDequeueST);
+ SUITE_ADD_TEST(suite, listFreeST);
+ SUITE_ADD_TEST(suite, listFreeManyST);
+ SUITE_ADD_TEST(suite, listPrintST);
+ SUITE_ADD_TEST(suite, listForEachT);
+ SUITE_ADD_TEST(suite, listEnumerateT);
+ SUITE_ADD_TEST(suite, listSortST);
+ SUITE_ADD_TEST(suite, iListSortST);
+ SUITE_ADD_TEST(suite, readTextT);
+ SUITE_ADD_TEST(suite, readStreamT);
+ SUITE_ADD_TEST(suite, writeTextT);
+ SUITE_ADD_TEST(suite, writeStreamT);
+ SUITE_ADD_TEST(suite, appendTextT);
+ SUITE_ADD_TEST(suite, listGetST);
+ SUITE_ADD_TEST(suite, iListGetST);
+ SUITE_ADD_TEST(suite, listSetST);
+ SUITE_ADD_TEST(suite, iListSetST);
+ SUITE_ADD_TEST(suite, tokST);
+ SUITE_ADD_TEST(suite, splitT);
+ SUITE_ADD_TEST(suite, joinT);
+ SUITE_ADD_TEST(suite, bJoinT);
+ SUITE_ADD_TEST(suite, bLJoinT);
+ SUITE_ADD_TEST(suite, extractST);
+ SUITE_ADD_TEST(suite, listDupST);
+ SUITE_ADD_TEST(suite, iListDupST);
+ SUITE_ADD_TEST(suite, listReverseST);
+ SUITE_ADD_TEST(suite, iListReverseST);
+ SUITE_ADD_TEST(suite, listCatST);
+ SUITE_ADD_TEST(suite, listAppendST);
+ SUITE_ADD_TEST(suite, iListAppendST);
+ SUITE_ADD_TEST(suite, iListAppendNSmashST);
+ SUITE_ADD_TEST(suite, listAddST);
+ SUITE_ADD_TEST(suite, listSliceST);
+ SUITE_ADD_TEST(suite, iListCopyST);
+ SUITE_ADD_TEST(suite, iListSliceST);
+ SUITE_ADD_TEST(suite, listInsertST);
+ SUITE_ADD_TEST(suite, iListInsertST);
+ SUITE_ADD_TEST(suite, iListInsertNFreeST);
+ SUITE_ADD_TEST(suite, listInjectST);
+ SUITE_ADD_TEST(suite, iListInjectST);
+ SUITE_ADD_TEST(suite, listDelST);
+ SUITE_ADD_TEST(suite, iListDelST);
+ SUITE_ADD_TEST(suite, execOutT);
+ SUITE_ADD_TEST(suite, listEqST);
+ SUITE_ADD_TEST(suite, listHasST);
+ SUITE_ADD_TEST(suite, listIndexOfST);
+ SUITE_ADD_TEST(suite, listBinarySearchST);
+ SUITE_ADD_TEST(suite, listUniqST);
+ SUITE_ADD_TEST(suite, iListUniqST);
+ SUITE_ADD_TEST(suite, listCompactST);
+ SUITE_ADD_TEST(suite, iListCompactST);
+ SUITE_ADD_TEST(suite, listEmptyFT);
+ SUITE_ADD_TEST(suite, iListEmptyFT);
+ SUITE_ADD_TEST(suite, listIsEmptyT);
+ SUITE_ADD_TEST(suite, listCreateT);
+ SUITE_ADD_TEST(suite, listFromArrayT);
+ SUITE_ADD_TEST(suite, listPushT);
+ SUITE_ADD_TEST(suite, listPopT);
+ SUITE_ADD_TEST(suite, listPrependT);
+ SUITE_ADD_TEST(suite, listDequeueT);
+ SUITE_ADD_TEST(suite, listFreeT);
+ SUITE_ADD_TEST(suite, listFreeManyT);
+ SUITE_ADD_TEST(suite, listLengthT);
+ SUITE_ADD_TEST(suite, listGetT);
+ SUITE_ADD_TEST(suite, listSetT);
+ SUITE_ADD_TEST(suite, listDupT);
+ SUITE_ADD_TEST(suite, listReverseT);
+ SUITE_ADD_TEST(suite, iListReverseT);
+ SUITE_ADD_TEST(suite, listCatT);
+ SUITE_ADD_TEST(suite, listAppendT);
+ SUITE_ADD_TEST(suite, listAddT);
+ SUITE_ADD_TEST(suite, listSliceT);
+ SUITE_ADD_TEST(suite, iListSliceT);
+ SUITE_ADD_TEST(suite, listInsertT);
+ SUITE_ADD_TEST(suite, iListInsertT);
+ SUITE_ADD_TEST(suite, listDelT);
+ SUITE_ADD_TEST(suite, iListDelT);
+ SUITE_ADD_TEST(suite, ringInitT);
+ SUITE_ADD_TEST(suite, ringIsEmptyT);
+ SUITE_ADD_TEST(suite, ringIsFullT);
+ SUITE_ADD_TEST(suite, ringCountT);
+ SUITE_ADD_TEST(suite, ringPushT);
+ SUITE_ADD_TEST(suite, ringPopT);
+ SUITE_ADD_TEST(suite, ringPrependT);
+ SUITE_ADD_TEST(suite, ringDequeueT);
+ SUITE_ADD_TEST(suite, fiberAddT);
+ SUITE_ADD_TEST(suite, fiberPrependT);
+ SUITE_ADD_TEST(suite, schedulerT);
+ SUITE_ADD_TEST(suite, getMonotonicTimeT);
+ SUITE_ADD_TEST(suite, nanoSleepT);
+
+
+ CuSuiteRun(suite);
+ CuSuiteDetails(suite, output);
+ printf ("%s\n", output->buffer);
+ return suite->failCount;
+}
diff --git a/src/runCuTest.sh b/src/runCuTest.sh
@@ -0,0 +1,9 @@
+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
+
+chmod 222 writeOnlyText.null
+./libsheepyCuTest
+gcov -b libsheepy.c
+chmod 644 writeOnlyText.null