commit 503dde2eeff3d1d7bbe082c862fcb8805edd9f57
parent 0f6cab0bf0b5f99eb364887f972e2664499932b9
Author: Remy Noulin <loader2x@gmail.com>
Date: Wed, 27 May 2020 13:12:22 +0200
add sizeS which returns strlen+1, fix bugs in libsheepy.c
Add test for the majority of libsheepy.c functions
README.md | 3 +-
example/README.template | 9 +-
release/libsheepy.c | 745 ++-
release/libsheepy.h | 21 +-
src/absLinkTest.null | 1 +
src/absLinkTest2.null | 1 +
src/libsheepy.c | 745 ++-
src/libsheepy.h | 21 +-
src/libsheepyCuTest.c | 14779 +++++++++++++++++++++++++++++++++++++---------
src/libsheepyTest.c | 14779 +++++++++++++++++++++++++++++++++++++---------
10 files changed, 25128 insertions(+), 5976 deletions(-)
Diffstat:
10 files changed, 25130 insertions(+), 5976 deletions(-)
diff --git a/README.md b/README.md
@@ -12,7 +12,7 @@ libsheepy is C library for handling text files and strings.
Status: __libsheepy and libsheepyObject implemented__
-The API in libsheepy.h and libsheepyObject.h is stable but not yet completely tested.
+The API in libsheepy.h is stable and tested, libsheepyObject.h is stable but not yet completely tested.
Current API is compatible with future version of libsheepy and will be changed only if a serious bug is found (rare).
The version number are x.Major.Minor.Patch and is updated like this:
@@ -20,6 +20,7 @@ The version number are x.Major.Minor.Patch and is updated like this:
- when Minor changes, the API is extended only (new functions, ...)
- when Major changes, the API is changed in backward compatible way (rare)
+
Future: (mainly speed improvements)
- optimize memory management
- optimize internals
diff --git a/example/README.template b/example/README.template
@@ -12,7 +12,14 @@ libsheepy is C library for handling text files and strings.
Status: __libsheepy and libsheepyObject implemented__
-The API in libsheepy.h and libsheepyObject.h is stable but not yet completely tested.
+The API in libsheepy.h is stable and tested, libsheepyObject.h is stable but not yet completely tested.
+Current API is compatible with future version of libsheepy and will be changed only if a serious bug is found (rare).
+
+The version number are x.Major.Minor.Patch and is updated like this:
+- when Patch changes for bug fixes or small changes in documentation, build scripts, ...
+- when Minor changes, the API is extended only (new functions, ...)
+- when Major changes, the API is changed in backward compatible way (rare)
+
Future: (mainly speed improvements)
- optimize memory management
diff --git a/release/libsheepy.c b/release/libsheepy.c
@@ -111,6 +111,7 @@ int setStackLimit(int64_t stackSize);
const char *getProgName(void);
bool setProgName(const char *name);
void setDefaultProgName(void);
+void freeProgName(void);
const char *getProgPath(void);
const char *getRealProgPath(void);
void freeRealProgPath(void);
@@ -228,7 +229,7 @@ char *randomAlphaNumS(uint64_t length);
char *bRandomAlphaNumS(char *dst, size_t dstSize);
char *readS(void);
char *bLReadS(char *dst, size_t dstSize);
-char *shGetpass(void);
+local char *shGetpass(void);
char *readPasswordS(void);
bool zeroS(char *string);
bool zeroBuf(void *buf, size_t len);
@@ -348,6 +349,7 @@ char *bIntToS(char *s, intmax_t n);
char *doubleToS(double n);
char *bDoubleToS(char *s, double n);
size_t lenS(const char *string);
+size_t sizeS(const char *string);
char *upperS(const char *string);
char *iUpperS(char **string);
char *bUpperS(char *string);
@@ -468,7 +470,7 @@ char *bLNextUTF8(const char *string, size_t utf8Size, const char *utf8);
char *findNextUTF8(const char *string, size_t utf8Size, const char *utf8);
char *prevUTF8(const char *utf8);
char *bPrevUTF8(const char *string, const char *utf8);
-char *bPrevUTF8Tiny(const char *string, const char *utf8);
+local char *bPrevUTF8Tiny(const char *string, const char *utf8);
char *idx2PtrUTF8(const char *utf8, intmax_t index);
char *bLIdx2PtrUTF8(const char *utf8, size_t utf8Size, intmax_t index);
intmax_t ptr2IdxUTF8(const char *utf8, const char *pos);
@@ -526,7 +528,7 @@ internal size_t _upperUTF8(char *dst, const char *utf8, localeType lcl);
char *upperUTF8(const char *utf8);
char *iUpperUTF8(char **utf8);
char *bUpperUTF8(char *utf8 UNUSED);
-int runeCombiningClass (rune uc);
+local int runeCombiningClass (rune uc);
internal bool has_more_above (const char *str);
rune tolowerUTF8(rune c);
internal size_t _lowerUTF8(char *dst, const char *utf8, localeType lcl);
@@ -868,8 +870,10 @@ void cleanUpListFree(char* **val) {
void cleanUpFileFree(FILE **val) {
- free(*val);
+ if ((*val)) {
+ fclose(*val);
}
+ }
/**
* nanosecond stopwatch
@@ -937,8 +941,13 @@ int getLogSymbols(void) {
*/
void setLogSymbols(int mode) {
- logSymbols = mode;
+ if (mode <= LOG_INVALID_MODE) {
+ logSymbols = mode;
+ }
+ else {
+ logSymbols = LOG_INVALID_MODE;
}
+ }
/**
* get current max log level
@@ -1538,10 +1547,7 @@ void initLibsheepyF(const char *progPath, initLibsheepyObjectP initF) {
*/
void finalizeLibsheepyCharAtExit(void) {
- if (defaultProgName != progName) {
- // progName has been set by the user with setProgName, free it
- free(progName);
- }
+ freeProgName();
freeRealProgPath();
randomUrandomClose();
}
@@ -1619,10 +1625,7 @@ bool setProgName(const char *name) {
return(false);
}
- if (defaultProgName != progName) {
- // progName has been set by the user with setProgName, free it
- free(progName);
- }
+ freeProgName();
progName = strdup(name);
return(true);
@@ -1643,6 +1646,18 @@ void setDefaultProgName(void) {
}
/**
+ * free ProgName
+ * if set with setProgName
+ */
+void freeProgName(void) {
+
+ if (defaultProgName != progName) {
+ // progName has been set by the user with setProgName, free it
+ freen(progName);
+}
+ }
+
+/**
* get program path
* When initLibsheepy is called before this function, it returns the given program path.
* When initLibsheepy has not been called before this function, it returns the real program path.
@@ -3326,11 +3341,27 @@ char *relPath(const char *path, const char *start) {
char *r = NULL;
+ // steps
+ // normalize path and start
+ // if start is not set, start is cwd
+ // when path and start are equal, return "."
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
+ // find first uncommon directory between npath and nstart
+ // count slashes in nstart after first uncommon directory
+ // go up directories to last common directory between npath and nstart
+
+ // normalize path and start
char *npath = expandHome(path);
iNormalizePath(&npath);
char *nstart;
char *cwd = getCwd();
+ // if start is not set, start is cwd
if (!start) {
// relative path to cwd
nstart = getCwd();
@@ -3341,60 +3372,71 @@ char *relPath(const char *path, const char *start) {
iNormalizePath(&nstart);
}
+ // when path and start are equal, return "."
if (eqS(npath, nstart)) {
r = strdup(".");
goto end;
}
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
if (npath[0] != '/' and nstart[0] == '/') {
iPrependS(&npath, "/");
- iPrependS(&npath, cwd);
+ iPrependS(&npath, nstart);
iNormalizePath(&npath);
}
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
if (npath[0] == '/' and nstart[0] != '/') {
iPrependS(&nstart, "/");
iPrependS(&nstart, cwd);
iNormalizePath(&nstart);
}
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
if (startsWithS(npath, nstart)) {
if (npath[strlen(nstart)] == '/') {
- if (!npath[strlen(nstart)+1]) {
- r = strdup(".");
- goto end;
- }
r = sliceS(npath, strlen(nstart)+1, 0);
+ goto end;
}
+ // handle case when nstart is "/" after normalize
if (npath[strlen(nstart)-1] == '/') {
r = sliceS(npath, strlen(nstart), 0);
+ goto end;
}
- goto end;
+ // fallthrough: npath starts with nstart but is a different path
+ // Example: npath = "/usr/bin" nstart = "/us"
}
+ // find first uncommon directory between npath and nstart
// lib/t
// lib/a/b
size_t i = 0;
size_t from = 0;
while (npath[i] and nstart[i]) {
if (npath[i] == '/') {
- from = i;
+ // i+1 to skip the slash
+ from = i+1;;
}
- if ((npath[i] != nstart[i])) {
+ if (npath[i] != nstart[i]) {
break;
}
i++;
}
+ // count slashes in nstart after first uncommon directory
size_t slash = 1;
rangeFrom(j, i, strlen(nstart))
if (nstart[j] == '/') {
slash++;
}
+ // go up directories to last common directory between npath and nstart
r = repeatS("../", slash);;
- iAppendS(&r, npath+from+1);
+ iAppendS(&r, npath+from);
end:
free(npath);
@@ -3426,11 +3468,27 @@ char *iRelPath(char **path, const char *start) {
char *r = NULL;
+ // steps
+ // normalize path and start
+ // if start is not set, start is cwd
+ // when path and start are equal, return "."
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
+ // find first uncommon directory between npath and nstart
+ // count slashes in nstart after first uncommon directory
+ // go up directories to last common directory between npath and nstart
+
+ // normalize path and start
char *npath = expandHome(*path);
iNormalizePath(&npath);
char *nstart;
char *cwd = getCwd();
+ // if start is not set, start is cwd
if (!start) {
// relative path to cwd
nstart = getCwd();
@@ -3441,60 +3499,72 @@ char *iRelPath(char **path, const char *start) {
iNormalizePath(&nstart);
}
+ // when path and start are equal, return "."
if (eqS(npath, nstart)) {
r = strdup(".");
goto end;
}
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
if (npath[0] != '/' and nstart[0] == '/') {
iPrependS(&npath, "/");
- iPrependS(&npath, cwd);
+ iPrependS(&npath, nstart);
iNormalizePath(&npath);
}
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
if (npath[0] == '/' and nstart[0] != '/') {
iPrependS(&nstart, "/");
iPrependS(&nstart, cwd);
iNormalizePath(&nstart);
}
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
if (startsWithS(npath, nstart)) {
if (npath[strlen(nstart)] == '/') {
- if (!npath[strlen(nstart)+1]) {
- r = strdup(".");
- goto end;
- }
r = sliceS(npath, strlen(nstart)+1, 0);
+ goto end;
}
+ // handle case when nstart is "/" after normalize
if (npath[strlen(nstart)-1] == '/') {
r = sliceS(npath, strlen(nstart), 0);
+ goto end;
}
- goto end;
+ // fallthrough: npath starts with nstart but is a different path
+ // Example: npath = "/usr/bin" nstart = "/us"
}
+
+ // find first uncommon directory between npath and nstart
// lib/t
// lib/a/b
size_t i = 0;
size_t from = 0;
while (npath[i] and nstart[i]) {
if (npath[i] == '/') {
- from = i;
+ // i+1 to skip the slash
+ from = i+1;
}
- if ((npath[i] != nstart[i])) {
+ if (npath[i] != nstart[i]) {
break;
}
i++;
}
+ // count slashes in nstart after first uncommon directory
size_t slash = 1;
rangeFrom(j, i, strlen(nstart))
if (nstart[j] == '/') {
slash++;
}
+ // go up directories to last common directory between npath and nstart
r = repeatS("../", slash);;
- iAppendS(&r, npath+from+1);
+ iAppendS(&r, npath+from);
end:
free(npath);
@@ -3529,11 +3599,27 @@ char *bRelPath(char *dest, const char *path, const char *start) {
char *r = NULL;
+ // steps
+ // normalize path and start
+ // if start is not set, start is cwd
+ // when path and start are equal, return "."
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
+ // find first uncommon directory between npath and nstart
+ // count slashes in nstart after first uncommon directory
+ // go up directories to last common directory between npath and nstart
+
+ // normalize path and start
char *npath = expandHome(path);
iNormalizePath(&npath);
char *nstart;
char *cwd = getCwd();
+ // if start is not set, start is cwd
if (!start) {
// relative path to cwd
nstart = getCwd();
@@ -3544,60 +3630,71 @@ char *bRelPath(char *dest, const char *path, const char *start) {
iNormalizePath(&nstart);
}
+ // when path and start are equal, return "."
if (eqS(npath, nstart)) {
r = strdup(".");
goto end;
}
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
if (npath[0] != '/' and nstart[0] == '/') {
iPrependS(&npath, "/");
- iPrependS(&npath, cwd);
+ iPrependS(&npath, nstart);
iNormalizePath(&npath);
}
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
if (npath[0] == '/' and nstart[0] != '/') {
iPrependS(&nstart, "/");
iPrependS(&nstart, cwd);
iNormalizePath(&nstart);
}
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
if (startsWithS(npath, nstart)) {
if (npath[strlen(nstart)] == '/') {
- if (!npath[strlen(nstart)+1]) {
- r = strdup(".");
- goto end;
- }
r = sliceS(npath, strlen(nstart)+1, 0);
+ goto end;
}
+ // handle case when nstart is "/" after normalize
if (npath[strlen(nstart)-1] == '/') {
r = sliceS(npath, strlen(nstart), 0);
+ goto end;
}
- goto end;
+ // fallthrough: npath starts with nstart but is a different path
+ // Example: npath = "/usr/bin" nstart = "/us"
}
+ // find first uncommon directory between npath and nstart
// lib/t
// lib/a/b
size_t i = 0;
size_t from = 0;
while (npath[i] and nstart[i]) {
if (npath[i] == '/') {
- from = i;
+ // i+1 to skip the slash
+ from = i+1;
}
- if ((npath[i] != nstart[i])) {
+ if (npath[i] != nstart[i]) {
break;
}
i++;
}
+ // count slashes in nstart after first uncommon directory
size_t slash = 1;
rangeFrom(j, i, strlen(nstart))
if (nstart[j] == '/') {
slash++;
}
+ // go up directories to last common directory between npath and nstart
r = repeatS("../", slash);;
- iAppendS(&r, npath+from+1);
+ iAppendS(&r, npath+from);
end:
free(npath);
@@ -3632,11 +3729,27 @@ char *bLRelPath(char *dest, size_t destSize, char *path, const char *start) {
char *r = NULL;
+ // steps
+ // normalize path and start
+ // if start is not set, start is cwd
+ // when path and start are equal, return "."
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
+ // find first uncommon directory between npath and nstart
+ // count slashes in nstart after first uncommon directory
+ // go up directories to last common directory between npath and nstart
+
+ // normalize path and start
char *npath = expandHome(path);
iNormalizePath(&npath);
char *nstart;
char *cwd = getCwd();
+ // if start is not set, start is cwd
if (!start) {
// relative path to cwd
nstart = getCwd();
@@ -3647,60 +3760,70 @@ char *bLRelPath(char *dest, size_t destSize, char *path, const char *start) {
iNormalizePath(&nstart);
}
+ // when path and start are equal, return "."
if (eqS(npath, nstart)) {
r = strdup(".");
goto end;
}
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
if (npath[0] != '/' and nstart[0] == '/') {
iPrependS(&npath, "/");
- iPrependS(&npath, cwd);
+ iPrependS(&npath, nstart);
iNormalizePath(&npath);
}
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
if (npath[0] == '/' and nstart[0] != '/') {
iPrependS(&nstart, "/");
iPrependS(&nstart, cwd);
iNormalizePath(&nstart);
}
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
if (startsWithS(npath, nstart)) {
if (npath[strlen(nstart)] == '/') {
- if (!npath[strlen(nstart)+1]) {
- r = strdup(".");
- goto end;
- }
r = sliceS(npath, strlen(nstart)+1, 0);
+ goto end;
}
+ // handle case when nstart is "/" after normalize
if (npath[strlen(nstart)-1] == '/') {
r = sliceS(npath, strlen(nstart), 0);
+ goto end;
}
- goto end;
+ // fallthrough: npath starts with nstart but is a different path
+ // Example: npath = "/usr/bin" nstart = "/us"
}
+ // find first uncommon directory between npath and nstart
// lib/t
// lib/a/b
size_t i = 0;
size_t from = 0;
while (npath[i] and nstart[i]) {
if (npath[i] == '/') {
- from = i;
+ from = i+1;
}
- if ((npath[i] != nstart[i])) {
+ if (npath[i] != nstart[i]) {
break;
}
i++;
}
+ // count slashes in nstart after first uncommon directory
size_t slash = 1;
rangeFrom(j, i, strlen(nstart))
if (nstart[j] == '/') {
slash++;
}
+ // go up directories to last common directory between npath and nstart
r = repeatS("../", slash);;
- iAppendS(&r, npath+from+1);
+ iAppendS(&r, npath+from);
end:
free(npath);
@@ -3754,6 +3877,9 @@ char *bGetHomePath(char *path) {
char *bLGetHomePath(char *path, size_t pathSize) {
struct passwd *pw = getpwuid(getuid());;
+ if (strlen(pw->pw_dir)+1 > pathSize) {
+ return(NULL);
+ }
strLCpy(path, pathSize, pw->pw_dir);
return(path);
}
@@ -6044,8 +6170,10 @@ char *bLReadS(char *dst, size_t dstSize) {
*
* currently used in Termux because getpass is missging
*/
-char *shGetpass(void) {
+local char *shGetpass(void) {
char *r = NULL;
+
+ #ifndef unitTest
struct termios old;
struct termios new;
@@ -6071,6 +6199,9 @@ char *shGetpass(void) {
/* Restore terminal. */
(void) tcsetattr (fileno (stream), TCSAFLUSH, &old);
fclose(stream);
+ #else
+ r = strdup("*****");;
+ #endif
return(r);
}
@@ -6083,7 +6214,7 @@ char *shGetpass(void) {
*/
char *readPasswordS(void) {
- #if (__TERMUX__ || __HAIKU__)
+ #if (__TERMUX__ || __HAIKU__ || unitTest)
char *r = shGetpass();
#else
char *p = getpass("");
@@ -6433,9 +6564,10 @@ char *toHexHeadSepS(const void *buf, size_t len, const char *head, const char *s
return(NULL);
}
- size_t sepLen = strlen(separator);;
+ size_t headLen = strlen(head);;
+ size_t sepLen = strlen(separator);;
- r = MALLOC(sizeof(char) * ((4+sepLen)*len-sepLen+1));;
+ r = MALLOC(sizeof(char) * ((2+headLen+sepLen)*len-sepLen+1));;
if (!r) {
return(NULL);
}
@@ -6446,7 +6578,7 @@ char *toHexHeadSepS(const void *buf, size_t len, const char *head, const char *s
b = buf;
for (size_t i = 0; i < len-1; i++) {
sprintf(c, "%s%02x%s", head, b[i], separator);
- c += 4+sepLen;;
+ c += 2+headLen+sepLen;;
}
sprintf(c, "%s%02x", head, b[len-1]);
@@ -9130,8 +9262,7 @@ bool icStartsWithCharS(const char *string1, char c) {
if (!string1) {
return(false);
}
- charToS(s,c);
- return(icStartsWithS(string1, s));
+ return(toupper(*string1) == toupper(c));;
}
/**
@@ -9171,8 +9302,7 @@ bool icEndsWithCharS(const char *string1, char c) {
if (!strlen(string1)) {
return(false);
}
- charToS(s,c);
- return(icEndsWithS(string1, s));
+ return(toupper(*(string1+strlen(string1)-1)) == toupper(c));;
}
/**
@@ -9272,7 +9402,7 @@ char *stripCtrlS(const char *string) {
return(NULL);
}
- size_t len = strlen(string);
+ size_t len = strlen(string)+1;
r = MALLOC(len);
if (!r) {
return(NULL);
@@ -9303,7 +9433,7 @@ char *iStripCtrlS(char **string) {
return(NULL);
}
- size_t i, j = 0;
+ size_t i = 0, j = 0;
while ((*string)[i]) {
if (!iscntrl((*string)[i])) {
@@ -9312,6 +9442,7 @@ char *iStripCtrlS(char **string) {
i++;
}
+ (*string)[j] = 0;;
return(*string);
}
@@ -9330,7 +9461,7 @@ char *bStripCtrlS(char *string) {
return(NULL);
}
- size_t i, j = 0;
+ size_t i = 0, j = 0;
while (string[i]) {
if (!iscntrl(string[i])) {
@@ -9339,6 +9470,7 @@ char *bStripCtrlS(char *string) {
i++;
}
+ string[j] = 0;;
return(string);
}
@@ -9661,6 +9793,25 @@ size_t lenS(const char *string) {
}
/**
+ * string buffer size
+ *
+ * return strlen+1 when possible
+ *
+ * \param
+ * string
+ * \return
+ * strlen+1 value
+ * 0 when string is NULL
+ */
+size_t sizeS(const char *string) {
+
+ if (!string) {
+ return(0);
+ }
+ return(strlen(string)+1);
+}
+
+/**
* upper case String
* duplicate string
*
@@ -10695,6 +10846,10 @@ char *ellipsisStartS(const char *string, size_t targetLength, const char *ellips
return(NULL);
}
+ if (!targetLength) {
+ return(strdup(""));
+ }
+
size_t len = strlen(string);
if (len <= targetLength) {
@@ -10737,6 +10892,11 @@ char *iEllipsisStartS(char **string, size_t targetLength, const char *ellipsisSt
return(NULL);
}
+ if (!targetLength) {
+ (*string)[0] = 0;
+ return(*string);
+ }
+
size_t len = strlen(*string);
if (len > targetLength) {
@@ -10777,6 +10937,11 @@ char *bEllipsisStartS(char *dest, const char *string, size_t targetLength, const
return(NULL);
}
+ if (!targetLength) {
+ dest[0] = 0;
+ return(dest);
+ }
+
size_t len = strlen(string);
if (len <= targetLength) {
@@ -10789,7 +10954,7 @@ char *bEllipsisStartS(char *dest, const char *string, size_t targetLength, const
iAppendS(&ellip, string);
// make sure the result is target length
iSliceS(&ellip, 0, targetLength);
- strncpy(dest, ellip, targetLength);
+ strncpy(dest, ellip, targetLength+1);
free(ellip);
}
return(dest);
@@ -10820,6 +10985,15 @@ char *bLEllipsisStartS(char *dest, size_t destSize, const char *string, size_t t
return(NULL);
}
+ if (!destSize) {
+ return(dest);
+ }
+
+ if (!targetLength) {
+ dest[0] = 0;;
+ return(dest);
+ }
+
targetLength = destSize > targetLength ? targetLength : destSize;;
size_t len = strlen(string);
@@ -10865,6 +11039,10 @@ char *ellipsisStartCharS(const char *string, size_t targetLength, char ellipsisC
return(NULL);
}
+ if (!targetLength) {
+ return(strdup(""));
+ }
+
charToS(ellipsisString, ellipsisChar);
size_t len = strlen(string);
@@ -10908,6 +11086,11 @@ char *iEllipsisStartCharS(char **string, size_t targetLength, char ellipsisChar)
return(NULL);
}
+ if (!targetLength) {
+ (*string)[0] = 0;
+ return(*string);
+ }
+
charToS(ellipsisString, ellipsisChar);
size_t len = strlen(*string);
@@ -10950,6 +11133,11 @@ char *bEllipsisStartCharS(char *dest, const char *string, size_t targetLength, c
return(NULL);
}
+ if (!targetLength) {
+ dest[0] = 0;
+ return(dest);
+ }
+
charToS(ellipsisString, ellipsisChar);
size_t len = strlen(string);
@@ -10964,7 +11152,7 @@ char *bEllipsisStartCharS(char *dest, const char *string, size_t targetLength, c
iAppendS(&ellip, string);
// make sure the result is target length
iSliceS(&ellip, 0, targetLength);
- strncpy(dest, ellip, targetLength);
+ strncpy(dest, ellip, targetLength+1);
free(ellip);
}
return(dest);
@@ -10995,6 +11183,15 @@ char *bLEllipsisStartCharS(char *dest, size_t destSize, const char *string, size
return(NULL);
}
+ if (!destSize) {
+ return(dest);
+ }
+
+ if (!targetLength) {
+ dest[0] = 0;
+ return(dest);
+ }
+
charToS(ellipsisString, ellipsisChar);
targetLength = destSize > targetLength ? targetLength : destSize;;
@@ -11069,6 +11266,10 @@ char *ellipsisEndS(const char *string, size_t targetLength, const char *ellipsis
return(NULL);
}
+ if (!targetLength) {
+ return(strdup(""));
+ }
+
size_t len = strlen(string);
if (len <= targetLength) {
@@ -11114,6 +11315,11 @@ char *iEllipsisEndS(char **string, size_t targetLength, const char *ellipsisStri
return(NULL);
}
+ if (!targetLength) {
+ (*string)[0] = 0;
+ return(*string);
+ }
+
size_t len = strlen(*string);
if (len > targetLength) {
@@ -11158,6 +11364,11 @@ char *bEllipsisEndS(char *dest, const char *string, size_t targetLength, const c
return(NULL);
}
+ if (!targetLength) {
+ dest[0] = 0;
+ return(dest);
+ }
+
size_t len = strlen(string);
if (len <= targetLength) {
@@ -11174,7 +11385,8 @@ char *bEllipsisEndS(char *dest, const char *string, size_t targetLength, const c
// ellipsisString is longer than targetLength
ellip = sliceS(ellipsisString, 0, targetLength);
}
- strncpy(dest, ellip, targetLength);
+ strncpy(dest, ellip, targetLength+1);
+ free(ellip);
}
return(dest);
}
@@ -11204,6 +11416,15 @@ char *bLEllipsisEndS(char *dest, size_t destSize, const char *string, size_t tar
return(NULL);
}
+ if (!destSize) {
+ return(dest);
+ }
+
+ if (!targetLength) {
+ dest[0] = 0;
+ return(dest);
+ }
+
targetLength = destSize > targetLength ? targetLength : destSize;;
size_t len = strlen(string);
@@ -11223,6 +11444,7 @@ char *bLEllipsisEndS(char *dest, size_t destSize, const char *string, size_t tar
ellip = sliceS(ellipsisString, 0, targetLength);
}
strLCpy(dest, destSize, ellip);
+ free(ellip);
}
return(dest);
}
@@ -11252,6 +11474,10 @@ char *ellipsisEndCharS(const char *string, size_t targetLength, char ellipsisCha
return(NULL);
}
+ if (!targetLength) {
+ return(strdup(""));
+ }
+
charToS(ellipsisString, ellipsisChar);
size_t len = strlen(string);
@@ -11262,14 +11488,8 @@ char *ellipsisEndCharS(const char *string, size_t targetLength, char ellipsisCha
else {
// truncate string
char *ellip;
- if ( strlen(ellipsisString) < targetLength) {
- ellip = sliceS(string, 0, targetLength - strlen(ellipsisString));
- iAppendS(&ellip, ellipsisString);
- }
- else {
- // ellipsisString is longer than targetLength
- ellip = sliceS(ellipsisString, 0, targetLength);
- }
+ ellip = sliceS(string, 0, targetLength - strlen(ellipsisString));
+ iAppendS(&ellip, ellipsisString);
return(ellip);
}
}
@@ -11299,6 +11519,11 @@ char *iEllipsisEndCharS(char **string, size_t targetLength, char ellipsisChar) {
return(NULL);
}
+ if (!targetLength) {
+ (*string)[0] = 0;
+ return(*string);
+ }
+
charToS(ellipsisString, ellipsisChar);
size_t len = strlen(*string);
@@ -11306,14 +11531,8 @@ char *iEllipsisEndCharS(char **string, size_t targetLength, char ellipsisChar) {
if (len > targetLength) {
// truncate string
char *ellip;
- if ( strlen(ellipsisString) < targetLength) {
- ellip = sliceS(*string, 0, targetLength - strlen(ellipsisString));
- iAppendS(&ellip, ellipsisString);
- }
- else {
- // ellipsisString is longer than targetLength
- ellip = sliceS(ellipsisString, 0, targetLength);
- }
+ ellip = sliceS(*string, 0, targetLength - strlen(ellipsisString));
+ iAppendS(&ellip, ellipsisString);
free(*string);
*string = ellip;
}
@@ -11345,6 +11564,11 @@ char *bEllipsisEndCharS(char *dest, const char *string, size_t targetLength, cha
return(NULL);
}
+ if (!targetLength) {
+ dest[0] = 0;
+ return(dest);
+ }
+
charToS(ellipsisString, ellipsisChar);
size_t len = strlen(string);
@@ -11355,15 +11579,10 @@ char *bEllipsisEndCharS(char *dest, const char *string, size_t targetLength, cha
else {
// truncate string
char *ellip;
- if ( strlen(ellipsisString) < targetLength) {
- ellip = sliceS(string, 0, targetLength - strlen(ellipsisString));
- iAppendS(&ellip, ellipsisString);
- }
- else {
- // ellipsisString is longer than targetLength
- ellip = sliceS(ellipsisString, 0, targetLength);
- }
- strncpy(dest, ellip, targetLength);
+ ellip = sliceS(string, 0, targetLength - strlen(ellipsisString));
+ iAppendS(&ellip, ellipsisString);
+ strncpy(dest, ellip, targetLength+1);
+ free(ellip);
}
return(dest);
}
@@ -11393,6 +11612,15 @@ char *bLEllipsisEndCharS(char *dest, size_t destSize, const char *string, size_t
return(NULL);
}
+ if (!destSize) {
+ return(dest);
+ }
+
+ if (!targetLength) {
+ dest[0] = 0;
+ return(dest);
+ }
+
charToS(ellipsisString, ellipsisChar);
targetLength = destSize > targetLength ? targetLength : destSize;;
@@ -11405,15 +11633,10 @@ char *bLEllipsisEndCharS(char *dest, size_t destSize, const char *string, size_t
else {
// truncate string
char *ellip;
- if ( strlen(ellipsisString) < targetLength) {
- ellip = sliceS(string, 0, targetLength - strlen(ellipsisString));
- iAppendS(&ellip, ellipsisString);
- }
- else {
- // ellipsisString is longer than targetLength
- ellip = sliceS(ellipsisString, 0, targetLength);
- }
+ ellip = sliceS(string, 0, targetLength - strlen(ellipsisString));
+ iAppendS(&ellip, ellipsisString);
strLCpy(dest, destSize, ellip);
+ free(ellip);
}
return(dest);
}
@@ -12501,7 +12724,7 @@ char *bSwapS(char *string, intmax_t index1, intmax_t index2) {
* \return
* string with characters swapped at index1 and index2
* NULL when string is NULL or when index1 or index2 are outside the string
- */
+ */
char *bLSwapS(char *string, size_t size, intmax_t index1, intmax_t index2) {
intmax_t len;
@@ -12509,10 +12732,14 @@ char *bLSwapS(char *string, size_t size, intmax_t index1, intmax_t index2) {
return(NULL);
}
+ if (!size) {
+ return(string);
+ }
+
len = strlen(string);
- if ((size_t)len > size) {
- len = size+1;
+ if ((size_t)len+1 > size) {
+ len = size-1;
}
if (index1 >= len) {
@@ -12739,7 +12966,9 @@ char *bSliceS(char *string, intmax_t start, intmax_t end) {
// copy range to a new string
intmax_t n;
n = end - start;
- strncpy(string, string+start, n);
+ if (start) {
+ strncpy(string, string+start, n);
+ }
string[n] = 0;
}
@@ -12765,33 +12994,38 @@ char *bSliceS(char *string, intmax_t start, intmax_t end) {
* NULL unchanged string when start and end are not set correctly
*/
char *bLSliceS(char *string, size_t stringSize, intmax_t start, intmax_t end) {
+ intmax_t len;
// sanity checks
if (!string || !stringSize) {
return(NULL);
}
+ len = strlen(string);
+ if ((size_t)len+1 > stringSize) {
+ len = stringSize - 1;
+ }
+
// compute string length without NUL
- stringSize--;
- if (start > (intmax_t)stringSize) {
+ if (start > len) {
bEmptyS(string);
return(NULL);
}
- if (end > (intmax_t)stringSize) {
- end = stringSize;
+ if (end > len) {
+ end = len;
}
- if (start <= -(intmax_t)stringSize) {
- start = -stringSize;
+ if (start <= -len) {
+ start = -len;
}
- if (end <= -(intmax_t)stringSize) {
+ if (end <= -len) {
bEmptyS(string);
return(NULL);
}
if (start < 0) {
- start = stringSize + start;
+ start = len + start;
}
if (end <= 0) {
- end = stringSize + end;
+ end = len + end;
}
if (end < start) {
bEmptyS(string);
@@ -12802,11 +13036,13 @@ char *bLSliceS(char *string, size_t stringSize, intmax_t start, intmax_t end) {
bEmptyS(string);
}
else {
- // start < end < stringSize
+ // start < end < len
// copy range to a new string
intmax_t n;
n = end - start;
- strncpy(string, string+start, n);
+ if (start) {
+ strncpy(string, string+start, n);
+ }
string[n] = 0;
}
@@ -12876,6 +13112,10 @@ char *cropS(char *string, intmax_t start, intmax_t end) {
strLCpy(l, (n+1) * sizeof(char), string+start);
strLCpy(string+start, len-end+1, string+end);
}
+ else {
+ // start = end, return empty string
+ l = strdup("");
+ }
return(l);
}
@@ -12943,6 +13183,10 @@ char *iCropS(char **string, intmax_t start, intmax_t end) {
strLCpy(l, (n+1) * sizeof(char), *string+start);
strLCpy(*string+start, len-end+1, *string+end);
}
+ else {
+ // start = end, return empty string
+ l = strdup("");
+ }
return(l);
}
@@ -12971,7 +13215,7 @@ char cropElemS(char *string, intmax_t index) {
string[len-1] = 0;
}
else {
- strLCpy(string+index, len-1, string+index+1);
+ strLCpy(string+index, len, string+index+1);
}
return(r);
@@ -13948,32 +14192,36 @@ char *bDelS(char *string, intmax_t start, intmax_t end) {
* or when input string is NULL or when malloc failed or when end is under start
*/
char *bLDelS(char *string, size_t stringSize, intmax_t start, intmax_t end) {
+ intmax_t len;
// sanity checks
if (!string || !stringSize) {
return(NULL);
}
- // compute string length without NUL
- stringSize--;
+ len = strlen(string);
+ if ((size_t)len+1 > stringSize) {
+ len = stringSize - 1;
+ }
- if (start >= (intmax_t)stringSize) {
- start = stringSize;
+ // compute string length without NUL
+ if (start >= (intmax_t)len) {
+ start = len;
}
- if (end > (intmax_t)stringSize) {
- end = stringSize;
+ if (end > (intmax_t)len) {
+ end = len;
}
- if (start <= -(intmax_t)stringSize) {
- start = -stringSize;
+ if (start <= -(intmax_t)len) {
+ start = -len;
}
- if (end <= -(intmax_t)stringSize) {
- end = -stringSize;
+ if (end <= -(intmax_t)len) {
+ end = -len;
}
if (start < 0) {
- start = stringSize + start;
+ start = len + start;
}
if (end <= 0) {
- end = stringSize + end;
+ end = len + end;
}
if (end < start) {
return(NULL);
@@ -13983,12 +14231,12 @@ char *bLDelS(char *string, size_t stringSize, intmax_t start, intmax_t end) {
return(string);
}
- // start < end < stringSize
+ // start < end < len
// copy range to a new string
intmax_t n;
n = end - start;
- strncpy(string+start, string+start+n, stringSize-n-start);
- string[stringSize-n] = 0;
+ strncpy(string+start, string+start+n, len-n-start);
+ string[len-n] = 0;
return(string);
}
@@ -14139,27 +14387,31 @@ char *bDelElemS(char *string, intmax_t index) {
* NULL when input string is NULL or when malloc failed
*/
char *bLDelElemS(char *string, size_t stringSize, intmax_t index) {
+ intmax_t len;
// sanity checks
if (!string || !stringSize) {
return(NULL);
}
- // compute string length without NUL
- stringSize--;
+ len = strlen(string);
+ if ((size_t)len+1 > stringSize) {
+ len = stringSize - 1;
+ }
- if (index >= (intmax_t)stringSize) {
+ // compute string length without NUL
+ if (index >= (intmax_t)len) {
return(NULL);
}
- if (index < -(intmax_t)stringSize) {
+ if (index < -(intmax_t)len) {
return(NULL);
}
if (index < 0) {
- index = (intmax_t)stringSize + index;
+ index = (intmax_t)len + index;
}
- strncpy(string+index, string+index+1, stringSize-1-index);
- string[stringSize-1] = 0;
+ strncpy(string+index, string+index+1, len-1-index);
+ string[len-1] = 0;
return(string);
}
@@ -14289,6 +14541,11 @@ char *icFindCharS(const char *string, char c) {
if (!string) {
return(NULL);
}
+ if (c == 0) {
+ // include terminating '\0' in comparison
+ // like findCharS
+ return(strchr(string, c));
+ }
charToS(s, c);
return(icFindS(string, s));
}
@@ -14484,7 +14741,7 @@ size_t bLLenUTF8(const char *s, size_t maxSize) {
}
const char *t = s;
- while (*s && ((size_t)(s-t) < maxSize)) {
+ while (*s && ((size_t)(s-t)+1 < maxSize)) {
r += (*s++ & 0xC0) != 0x80;
}
return(r);
@@ -14567,20 +14824,23 @@ bool bLIsUTF8(const char * string, size_t stringSize) {
const unsigned char * bytes = (const unsigned char *)string;
while (*bytes) {
- if ((size_t)(bytes - (const unsigned char *)string) >= stringSize) {
- return(false);
- }
// ASCII
// use bytes[0] <= 0x7F to allow ASCII control characters
if (bytes[0] == 0x09 || bytes[0] == 0x0A || bytes[0] == 0x0D || (0x20 <= bytes[0] && bytes[0] <= 0x7E)) {
bytes += 1;
+ if ((size_t)(bytes - (const unsigned char *)string)+1 > stringSize) {
+ return(false);
+ }
continue;
}
// non-overlong 2-byte
if ((0xC2 <= bytes[0] && bytes[0] <= 0xDF) && (0x80 <= bytes[1] && bytes[1] <= 0xBF)) {
bytes += 2;
+ if ((size_t)(bytes - (const unsigned char *)string)+1 > stringSize) {
+ return(false);
+ }
continue;
}
@@ -14589,6 +14849,9 @@ bool bLIsUTF8(const char * string, size_t stringSize) {
// excluding surrogates
if ((bytes[0] == 0xE0 && (0xA0 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF)) || (((0xE1 <= bytes[0] && bytes[0] <= 0xEC) || bytes[0] == 0xEE || bytes[0] == 0xEF) && (0x80 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF)) || (bytes[0] == 0xED && (0x80 <= bytes[1] && bytes[1] <= 0x9F) && (0x80 <= bytes[2] && bytes[2] <= 0xBF))) {
bytes += 3;
+ if ((size_t)(bytes - (const unsigned char *)string)+1 > stringSize) {
+ return(false);
+ }
continue;
}
@@ -14597,6 +14860,9 @@ bool bLIsUTF8(const char * string, size_t stringSize) {
// plane 16
if ((bytes[0] == 0xF0 && (0x90 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF)) || ((0xF1 <= bytes[0] && bytes[0] <= 0xF3) && (0x80 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF)) || (bytes[0] == 0xF4 && (0x80 <= bytes[1] && bytes[1] <= 0x8F) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF))) {
bytes += 4;
+ if ((size_t)(bytes - (const unsigned char *)string)+1 > stringSize) {
+ return(false);
+ }
continue;
}
@@ -14621,6 +14887,9 @@ bool bLIsUTF8(const char * string, size_t stringSize) {
*/
bool isCodeUTF8(const char *code) {
+ if (!code) {
+ return(false);
+ }
const unsigned char * bytes = (const unsigned char *)code;
// ASCII
// use bytes[0] <= 0x7F to allow ASCII control characters
@@ -44435,7 +44704,7 @@ char *nextUTF8(const char *utf8) {
* \param
* utf8 pointer to a code point in string
* \param
- * ut8Size string buffer size (including NUL, strlen(string) +1 when the buffer is full)
+ * utf8Size string buffer size (including NUL, strlen(string) +1 when the buffer is full)
* \return
* pointer to next UTF-8 code point
* NULL when the end string is reached or utf8 is NULL or the start of the next code point is outside the string
@@ -44543,7 +44812,7 @@ char *bPrevUTF8(const char *string, const char *utf8) {
return(bPrevUTF8Tiny(string, utf8));
}
-char *bPrevUTF8Tiny(const char *string, const char *utf8) {
+local char *bPrevUTF8Tiny(const char *string, const char *utf8) {
while (utf8 > string) {
utf8--;
@@ -44587,7 +44856,7 @@ char *idx2PtrUTF8(const char *utf8, intmax_t index) {
intmax_t i = 0;;
while (i != index) {
nxCodeUTF8(utf8);
- if (utf8 >= end) {
+ if (utf8 > end) {
return(NULL);
}
i++;
@@ -44640,9 +44909,16 @@ char *bLIdx2PtrUTF8(const char *utf8, size_t utf8Size, intmax_t index) {
return(NULL);
}
+ // find string end
+ size_t len;
+ len = strlen(utf8);
+ if (len+1 > utf8Size) {
+ len = utf8Size - 1;
+ }
+
// go from the end
char *start = (char *)utf8;;
- utf8 += utf8Size;;
+ utf8 += len;;
intmax_t i = 0;;
while (i != index) {
utf8 = bPrevUTF8Tiny(start, utf8);;
@@ -44681,10 +44957,19 @@ intmax_t ptr2IdxUTF8(const char *utf8, const char *pos) {
// there is at least one code point
// find next code point, works even when utf8 points inside a code point
while (*utf8) {
- if ((*utf8++ & 0xC0) != 0x80) {
+ if ((*utf8 & 0xC0) != 0x80) {
+ // check utf8 is in a multibyte code point
+ // if it is, find the end of the code point
+ if ((*utf8 & 0xC0) == 0xC0) {
+ nxCodeUTF8(utf8);
+ }
+ else {
+ utf8++;
+ }
break;
- }
}
+ utf8++;
+ }
r++;
while (*utf8 && (utf8 < pos)) {
nxCodeUTF8(utf8);
@@ -44749,6 +45034,7 @@ intmax_t bPtr2IdxUTF8(const char *start, const char *utf8, const char *pos) {
break;
}
}
+ nxCodeUTF8(utf8);
r++;
while (*utf8 && (utf8 < pos)) {
nxCodeUTF8(utf8);
@@ -44811,6 +45097,7 @@ intmax_t bLPtr2IdxUTF8(const char *utf8, size_t utf8Size, const char *pos) {
break;
}
}
+ nxCodeUTF8(utf8);
r++;
while ((utf8 < end) && *utf8 && (utf8 < pos)) {
nxCodeUTF8(utf8);
@@ -45013,7 +45300,7 @@ char *nMakeValidUTF8(const char *utf8, size_t utf8Len) {
*/
char *bNMakeValidUTF8(char *dst, const char *utf8, size_t utf8Len) {
- if (!!dst || !utf8 || !utf8Len) {
+ if (!dst || !utf8 || !utf8Len) {
return(NULL);
}
@@ -45062,7 +45349,7 @@ char *bNMakeValidUTF8(char *dst, const char *utf8, size_t utf8Len) {
*/
char *bLMakeValidUTF8(char *dst, size_t dstSize, const char *utf8) {
- if (!!dst || !utf8 || !dstSize) {
+ if (!dst || !utf8 || !dstSize) {
return(NULL);
}
@@ -45114,7 +45401,7 @@ char *bLMakeValidUTF8(char *dst, size_t dstSize, const char *utf8) {
*/
char *bLNMakeValidUTF8(char *dst, size_t dstSize, const char *utf8, size_t utf8Len) {
- if (!!dst || !dstSize || !utf8 || !utf8Len) {
+ if (!dst || !dstSize || !utf8 || !utf8Len) {
return(NULL);
}
@@ -45169,7 +45456,6 @@ char *strNCpyUTF8(char *dst, const char *src, size_t srcLen) {
}
if (!srcLen) {
- *dst = 0;
return(dst);
}
@@ -45769,17 +46055,19 @@ bool icEndsWithUTF8(const char *string1, const char *string2) {
* -1 when there is an error
*/
ssize_t icCountUTF8(const char *s, const char *needle) {
+ char *lower = NULL;
// sanity checks
if (!s || !needle) {
return(-1);
}
- s = casefoldUTF8(s);
+ lower = casefoldUTF8(s);
needle = casefoldUTF8(needle);
ssize_t r = 0;
size_t len = strlen(needle);
+ s = lower;
while (s != NULL) {
s = strstr(s, needle);
if (s != NULL) {
@@ -45791,7 +46079,7 @@ ssize_t icCountUTF8(const char *s, const char *needle) {
}
}
- freeManyS(s, needle);
+ freeManyS(lower, needle);
return(r);
}
@@ -46322,7 +46610,7 @@ char *bUpperUTF8(char *utf8 UNUSED) {
*
* Returns: the combining class of the character
**/
-int runeCombiningClass (rune uc) {
+local int runeCombiningClass (rune uc) {
return(COMBINING_CLASS(uc));
}
@@ -46611,10 +46899,10 @@ char *casefoldUTF8(const char *utf8) {
char code[8] = {0, 0, 0, 0, 0, 0, 0, 0};
bRune2CodeUTF8(code, tolowerUTF8(ch));
iAppendS(&r, code);
- }
- next:
- nxCodeUTF8(utf8);
+ next:
+ nxCodeUTF8(utf8);
+ }
return(r);
}
@@ -46895,6 +47183,7 @@ char *setUTF8(char *string, intmax_t index, rune c) {
char *p = idx2PtrUTF8(string, index);
bRune2CodeUTF8(p, c);
+ // TODO check code point length and shift string end when necessary
return(string);
}
@@ -47139,12 +47428,43 @@ char *bSliceUTF8(char *string, intmax_t start, intmax_t end) {
* NULL unchanged string when start and end are not set correctly
*/
char *bLSliceUTF8(char *string, size_t stringSize, intmax_t start, intmax_t end) {
+ intmax_t len;
// sanity checks
if (!string || !stringSize) {
return(NULL);
}
+ len = strlen(string);
+ if ((size_t)len+1 > stringSize) {
+ len = stringSize - 1;
+ }
+
+ if (start > len) {
+ bEmptyS(string);
+ return(NULL);
+ }
+ if (end > len) {
+ end = len;
+ }
+ if (start <= -len) {
+ start = -len;
+ }
+ if (end <= -len) {
+ bEmptyS(string);
+ return(NULL);
+ }
+ if (start < 0) {
+ start = len + start;
+ }
+ if (end <= 0) {
+ end = len + end;
+ }
+ if (end < start) {
+ bEmptyS(string);
+ return(NULL);
+ }
+
char *startp = bLIdx2PtrUTF8(string, stringSize, start);
char *endp = bLIdx2PtrUTF8(string, stringSize, end);
@@ -47893,14 +48213,40 @@ char *bDelUTF8(char *string, intmax_t start, intmax_t end) {
* or when input string is NULL or when malloc failed or when end is under start
*/
char *bLDelUTF8(char *string, size_t stringSize, intmax_t start, intmax_t end) {
+ intmax_t len;
// sanity checks
if (!string || !stringSize) {
return(NULL);
}
+ len = strlen(string);
+ if ((size_t)len+1 > stringSize) {
+ len = stringSize - 1;
+ }
+
// compute string length without NUL
- stringSize--;
+ if (start >= len) {
+ start = len;
+ }
+ if (end > len) {
+ end = len;
+ }
+ if (start <= -len) {
+ start = -len;
+ }
+ if (end <= -len) {
+ end = -len;
+ }
+ if (start < 0) {
+ start = len + start;
+ }
+ if (end <= 0) {
+ end = len + end;
+ }
+ if (end < start) {
+ return(NULL);
+ }
char *startp = bLIdx2PtrUTF8(string, stringSize, start);
char *endp = bLIdx2PtrUTF8(string, stringSize, end);
@@ -47925,12 +48271,12 @@ char *bLDelUTF8(char *string, size_t stringSize, intmax_t start, intmax_t end) {
return(string);
}
- // start < end < stringSize
+ // start < end < len
// copy range to a new string
intmax_t n;
n = endp - startp;
- strncpy(string+starto, string+starto+n, stringSize-n-starto);
- string[stringSize-n] = 0;
+ strncpy(string+starto, string+starto+n, len-n-starto);
+ string[len-n] = 0;
return(string);
}
@@ -48329,9 +48675,15 @@ char **icListUniqUTF8(char **list) {
return(NULL);
}
+ size_t len = listLengthS(list);
+
+ if (!len) {
+ listEmptyS(r);
+ return(r);
+ }
listPushS(&r, list[0]);
// one element list
- if (listLengthS(list) == 1) {
+ if (len == 1) {
return(r);
}
// push element to new list if it is not already in new list
@@ -48364,7 +48716,12 @@ char **iicListUniqUTF8(char ***list) {
return(NULL);
}
- if (listLengthS(*list) < 2) {
+ size_t len = listLengthS(*list);
+
+ if (len < 1) {
+ return(*list);
+ }
+ else if (len < 2) {
// one element list
iListPushS(&r, (*list)[0]);
}
@@ -49005,7 +49362,7 @@ size_t listLengthS(char **list) {
* -1 when list is NULL
*/
ssize_t listStrLengthS(char **list) {
- ssize_t r;
+ ssize_t r = 0;;
// sanity checks
if (!list) {
@@ -49492,7 +49849,7 @@ char **icSplitChar(const char *string, char delim) {
* -1 when list is NULL
*/
ssize_t joinLength(char **list, const char* delim) {
- ssize_t r;
+ ssize_t r = 0;;
// sanity checks
if (!list || !delim) {
@@ -49503,10 +49860,11 @@ ssize_t joinLength(char **list, const char* delim) {
bool isFirstElem = true;
forEachS(list, i) {
if (isFirstElem) {
- r += strlen(i);
+ r += strlen(i);
+ isFirstElem = no;
}
else {
- r += strlen(i) + delimLen;
+ r += strlen(i) + delimLen;
}
}
@@ -50151,9 +50509,13 @@ char **iListAppendNSmashS(char ***list1, char **list2) {
*/
char **listShiftS(char ***list1, char **list2) {
+ if (!list1) {
+ return(NULL);
+ }
+
char **r = listInsertS(*list1, 0, list2);
if (r) {
- free(*list1);
+ listFreeS(*list1);
*list1 = r;
}
return(r);
@@ -50546,7 +50908,12 @@ char **listCropS(char **list, intmax_t start, intmax_t end) {
return(NULL);
}
- if (start < end) {
+ if (start == end) {
+ // empty list
+ listEmptyS(l);
+ return(l);
+ }
+ else {
// start < end < len
intmax_t n;
n = end - start;
@@ -50623,7 +50990,12 @@ char **iListCropS(char ***list, intmax_t start, intmax_t end) {
return(NULL);
}
- if (start < end) {
+ if (start == end) {
+ // empty list
+ listEmptyS(l);
+ return(l);
+ }
+ else {
// start < end < len
intmax_t n;
n = end - start;
@@ -50858,7 +51230,17 @@ char **iListInsertS(char ***list, intmax_t index, char **toInsert) {
if (index) {
return(NULL);
}
- r = listDupS(toInsert);
+ len = listLengthS(toInsert);
+ r = MALLOC((len+1) * sizeof(char *));
+ if (!r) {
+ return(NULL);//LCOV_EXCL_LINE
+ }
+ // last element is NULL
+ r[len] = NULL;
+ // copy each element
+ enumerateCharP(toInsert, e, i) {
+ r[i] = *e;
+ }
*list = r;
return(r);
}
@@ -50892,6 +51274,12 @@ char **iListInsertS(char ***list, intmax_t index, char **toInsert) {
return(*list);
}
+ if ((*list) == toInsert) {
+ // list1 and list2 identical, cancel this operations
+ // to avoid double free undefined behavior in listFreeS
+ return(NULL);
+ }
+
if (index == 0) {
// insert at beginning
iListAppendS(&r, toInsert);
@@ -50979,6 +51367,12 @@ char **iListInsertNFreeS(char ***list, intmax_t index, char **toInsert) {
return(*list);
}
+ if ((*list) == toInsert) {
+ // list1 and list2 identical, cancel this operations
+ // to avoid double free undefined behavior in listFreeS
+ return(NULL);
+ }
+
if (index == 0) {
// insert at beginning
iListAppendS(&r, toInsert);
@@ -52462,6 +52856,12 @@ char **icListUniqS(char **list) {
return(NULL);
}
+ size_t len = listLengthS(list);
+
+ if (!len) {
+ listEmptyS(r);
+ return(r);
+ }
listPushS(&r, list[0]);
// one element list
if (listLengthS(list) == 1) {
@@ -52496,7 +52896,12 @@ char **iicListUniqS(char ***list) {
return(NULL);
}
- if (listLengthS(*list) < 2) {
+ size_t len = listLengthS(*list);
+
+ if (!len) {
+ listEmptyS(r);
+ }
+ else if (len == 1) {
// one element list
iListPushS(&r, (*list)[0]);
}
diff --git a/release/libsheepy.h b/release/libsheepy.h
@@ -96,7 +96,7 @@
// version accoring to the version package: Release.Major.minor.patch
// https://noulin.net/version/file/README.md.html
-#define LIBSHEEPY_VERSION "1.1.1"
+#define LIBSHEEPY_VERSION "1.1.2"
#ifndef SH_PREFIX
#define SH_PREFIX(NAME) NAME
@@ -850,6 +850,17 @@ uint64_t shStopwatch(uint8_t op);
/**
* LOG LEVELS
+ * TODO:
+ * add levels:
+ * EMERGENCY
+ * ALERT
+ * CRITICAL
+ * ERROR
+ * WARNING
+ * NOTICE
+ * PASS
+ * INFO
+ * DEBUG
*/
#define LOG_CRITICAL 0
#define LOG_ERROR 1
@@ -863,6 +874,7 @@ uint64_t shStopwatch(uint8_t op);
#define LOG_PASS 3
#define LOG_INFO 4
#define LOG_INVALID 5
+#define LOG_MAX_LEVEL LOG_INVALID
/** getMaxLogLevel and setMaxLogLevel value disabling all logs */
#define LOG_DISABLE -1
@@ -1416,6 +1428,9 @@ bool setProgName(const char *name);
// set default program name
void setDefaultProgName(void);
+// free ProgName
+void freeProgName(void);
+
// get program path as given in the shell
const char *getProgPath(void);
@@ -1871,6 +1886,8 @@ char *bDoubleToS(char *s, double n);
// length
size_t lenS(const char *string);
+// string buffer size: strlen+1
+size_t sizeS(const char *string);
/**
* upper case and store the result in c and return the result
@@ -2818,7 +2835,7 @@ int systemf(const char *fmt, ...);
// run command and return exit code from command (not system return value like system, systemf and systemNFree)
#define command(cmd) commandF(cmd, __LINE__, __func__, __FILE__)
int commandF(const char *cmd, int line, const char *thisFunc, const char *thisFileName);
-#define commandf(cmd, ...) commandfF(__LINE__, __func__, __FILE__, cmd, __VA_ARGS__)
+#define commandf(...) commandfF(__LINE__, __func__, __FILE__, __VA_ARGS__)
int commandfF(int line, const char *thisFunc, const char *thisFileName, const char *fmt, ...);
#define commandNFree(cmd) commandNFreeF(cmd, __LINE__, __func__, __FILE__)
int commandNFreeF(char *cmd, int line, const char *thisFunc, const char *thisFileName);
diff --git a/src/absLinkTest.null b/src/absLinkTest.null
@@ -0,0 +1 @@
+absLinkTest2.null+
\ No newline at end of file
diff --git a/src/absLinkTest2.null b/src/absLinkTest2.null
@@ -0,0 +1 @@
+/usr/local/bin/sheepy+
\ No newline at end of file
diff --git a/src/libsheepy.c b/src/libsheepy.c
@@ -113,6 +113,7 @@ int setStackLimit(int64_t stackSize);
const char *getProgName(void);
bool setProgName(const char *name);
void setDefaultProgName(void);
+void freeProgName(void);
const char *getProgPath(void);
const char *getRealProgPath(void);
void freeRealProgPath(void);
@@ -230,7 +231,7 @@ char *randomAlphaNumS(uint64_t length);
char *bRandomAlphaNumS(char *dst, size_t dstSize);
char *readS(void);
char *bLReadS(char *dst, size_t dstSize);
-char *shGetpass(void);
+local char *shGetpass(void);
char *readPasswordS(void);
bool zeroS(char *string);
bool zeroBuf(void *buf, size_t len);
@@ -350,6 +351,7 @@ char *bIntToS(char *s, intmax_t n);
char *doubleToS(double n);
char *bDoubleToS(char *s, double n);
size_t lenS(const char *string);
+size_t sizeS(const char *string);
char *upperS(const char *string);
char *iUpperS(char **string);
char *bUpperS(char *string);
@@ -470,7 +472,7 @@ char *bLNextUTF8(const char *string, size_t utf8Size, const char *utf8);
char *findNextUTF8(const char *string, size_t utf8Size, const char *utf8);
char *prevUTF8(const char *utf8);
char *bPrevUTF8(const char *string, const char *utf8);
-char *bPrevUTF8Tiny(const char *string, const char *utf8);
+local char *bPrevUTF8Tiny(const char *string, const char *utf8);
char *idx2PtrUTF8(const char *utf8, intmax_t index);
char *bLIdx2PtrUTF8(const char *utf8, size_t utf8Size, intmax_t index);
intmax_t ptr2IdxUTF8(const char *utf8, const char *pos);
@@ -528,7 +530,7 @@ internal size_t _upperUTF8(char *dst, const char *utf8, localeType lcl);
char *upperUTF8(const char *utf8);
char *iUpperUTF8(char **utf8);
char *bUpperUTF8(char *utf8 UNUSED);
-int runeCombiningClass (rune uc);
+local int runeCombiningClass (rune uc);
internal bool has_more_above (const char *str);
rune tolowerUTF8(rune c);
internal size_t _lowerUTF8(char *dst, const char *utf8, localeType lcl);
@@ -924,8 +926,10 @@ void cleanUpListFree(char* **val) {
void cleanUpFileFree(FILE **val) {
- free(*val);
+ if ((*val)) {
+ fclose(*val);
}
+ }
/**
* nanosecond stopwatch
@@ -993,8 +997,13 @@ int getLogSymbols(void) {
*/
void setLogSymbols(int mode) {
- logSymbols = mode;
+ if (mode <= LOG_INVALID_MODE) {
+ logSymbols = mode;
+ }
+ else {
+ logSymbols = LOG_INVALID_MODE;
}
+ }
/**
* get current max log level
@@ -1594,10 +1603,7 @@ void initLibsheepyF(const char *progPath, initLibsheepyObjectP initF) {
*/
void finalizeLibsheepyCharAtExit(void) {
- if (defaultProgName != progName) {
- // progName has been set by the user with setProgName, free it
- free(progName);
- }
+ freeProgName();
freeRealProgPath();
randomUrandomClose();
}
@@ -1675,10 +1681,7 @@ bool setProgName(const char *name) {
return(false);
}
- if (defaultProgName != progName) {
- // progName has been set by the user with setProgName, free it
- free(progName);
- }
+ freeProgName();
progName = strdup(name);
return(true);
@@ -1699,6 +1702,18 @@ void setDefaultProgName(void) {
}
/**
+ * free ProgName
+ * if set with setProgName
+ */
+void freeProgName(void) {
+
+ if (defaultProgName != progName) {
+ // progName has been set by the user with setProgName, free it
+ freen(progName);
+}
+ }
+
+/**
* get program path
* When initLibsheepy is called before this function, it returns the given program path.
* When initLibsheepy has not been called before this function, it returns the real program path.
@@ -3382,11 +3397,27 @@ char *relPath(const char *path, const char *start) {
char *r = NULL;
+ // steps
+ // normalize path and start
+ // if start is not set, start is cwd
+ // when path and start are equal, return "."
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
+ // find first uncommon directory between npath and nstart
+ // count slashes in nstart after first uncommon directory
+ // go up directories to last common directory between npath and nstart
+
+ // normalize path and start
char *npath = expandHome(path);
iNormalizePath(&npath);
char *nstart;
char *cwd = getCwd();
+ // if start is not set, start is cwd
if (!start) {
// relative path to cwd
nstart = getCwd();
@@ -3397,60 +3428,71 @@ char *relPath(const char *path, const char *start) {
iNormalizePath(&nstart);
}
+ // when path and start are equal, return "."
if (eqS(npath, nstart)) {
r = strdup(".");
goto end;
}
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
if (npath[0] != '/' and nstart[0] == '/') {
iPrependS(&npath, "/");
- iPrependS(&npath, cwd);
+ iPrependS(&npath, nstart);
iNormalizePath(&npath);
}
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
if (npath[0] == '/' and nstart[0] != '/') {
iPrependS(&nstart, "/");
iPrependS(&nstart, cwd);
iNormalizePath(&nstart);
}
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
if (startsWithS(npath, nstart)) {
if (npath[strlen(nstart)] == '/') {
- if (!npath[strlen(nstart)+1]) {
- r = strdup(".");
- goto end;
- }
r = sliceS(npath, strlen(nstart)+1, 0);
+ goto end;
}
+ // handle case when nstart is "/" after normalize
if (npath[strlen(nstart)-1] == '/') {
r = sliceS(npath, strlen(nstart), 0);
+ goto end;
}
- goto end;
+ // fallthrough: npath starts with nstart but is a different path
+ // Example: npath = "/usr/bin" nstart = "/us"
}
+ // find first uncommon directory between npath and nstart
// lib/t
// lib/a/b
size_t i = 0;
size_t from = 0;
while (npath[i] and nstart[i]) {
if (npath[i] == '/') {
- from = i;
+ // i+1 to skip the slash
+ from = i+1;;
}
- if ((npath[i] != nstart[i])) {
+ if (npath[i] != nstart[i]) {
break;
}
i++;
}
+ // count slashes in nstart after first uncommon directory
size_t slash = 1;
rangeFrom(j, i, strlen(nstart))
if (nstart[j] == '/') {
slash++;
}
+ // go up directories to last common directory between npath and nstart
r = repeatS("../", slash);;
- iAppendS(&r, npath+from+1);
+ iAppendS(&r, npath+from);
end:
free(npath);
@@ -3482,11 +3524,27 @@ char *iRelPath(char **path, const char *start) {
char *r = NULL;
+ // steps
+ // normalize path and start
+ // if start is not set, start is cwd
+ // when path and start are equal, return "."
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
+ // find first uncommon directory between npath and nstart
+ // count slashes in nstart after first uncommon directory
+ // go up directories to last common directory between npath and nstart
+
+ // normalize path and start
char *npath = expandHome(*path);
iNormalizePath(&npath);
char *nstart;
char *cwd = getCwd();
+ // if start is not set, start is cwd
if (!start) {
// relative path to cwd
nstart = getCwd();
@@ -3497,60 +3555,72 @@ char *iRelPath(char **path, const char *start) {
iNormalizePath(&nstart);
}
+ // when path and start are equal, return "."
if (eqS(npath, nstart)) {
r = strdup(".");
goto end;
}
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
if (npath[0] != '/' and nstart[0] == '/') {
iPrependS(&npath, "/");
- iPrependS(&npath, cwd);
+ iPrependS(&npath, nstart);
iNormalizePath(&npath);
}
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
if (npath[0] == '/' and nstart[0] != '/') {
iPrependS(&nstart, "/");
iPrependS(&nstart, cwd);
iNormalizePath(&nstart);
}
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
if (startsWithS(npath, nstart)) {
if (npath[strlen(nstart)] == '/') {
- if (!npath[strlen(nstart)+1]) {
- r = strdup(".");
- goto end;
- }
r = sliceS(npath, strlen(nstart)+1, 0);
+ goto end;
}
+ // handle case when nstart is "/" after normalize
if (npath[strlen(nstart)-1] == '/') {
r = sliceS(npath, strlen(nstart), 0);
+ goto end;
}
- goto end;
+ // fallthrough: npath starts with nstart but is a different path
+ // Example: npath = "/usr/bin" nstart = "/us"
}
+
+ // find first uncommon directory between npath and nstart
// lib/t
// lib/a/b
size_t i = 0;
size_t from = 0;
while (npath[i] and nstart[i]) {
if (npath[i] == '/') {
- from = i;
+ // i+1 to skip the slash
+ from = i+1;
}
- if ((npath[i] != nstart[i])) {
+ if (npath[i] != nstart[i]) {
break;
}
i++;
}
+ // count slashes in nstart after first uncommon directory
size_t slash = 1;
rangeFrom(j, i, strlen(nstart))
if (nstart[j] == '/') {
slash++;
}
+ // go up directories to last common directory between npath and nstart
r = repeatS("../", slash);;
- iAppendS(&r, npath+from+1);
+ iAppendS(&r, npath+from);
end:
free(npath);
@@ -3585,11 +3655,27 @@ char *bRelPath(char *dest, const char *path, const char *start) {
char *r = NULL;
+ // steps
+ // normalize path and start
+ // if start is not set, start is cwd
+ // when path and start are equal, return "."
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
+ // find first uncommon directory between npath and nstart
+ // count slashes in nstart after first uncommon directory
+ // go up directories to last common directory between npath and nstart
+
+ // normalize path and start
char *npath = expandHome(path);
iNormalizePath(&npath);
char *nstart;
char *cwd = getCwd();
+ // if start is not set, start is cwd
if (!start) {
// relative path to cwd
nstart = getCwd();
@@ -3600,60 +3686,71 @@ char *bRelPath(char *dest, const char *path, const char *start) {
iNormalizePath(&nstart);
}
+ // when path and start are equal, return "."
if (eqS(npath, nstart)) {
r = strdup(".");
goto end;
}
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
if (npath[0] != '/' and nstart[0] == '/') {
iPrependS(&npath, "/");
- iPrependS(&npath, cwd);
+ iPrependS(&npath, nstart);
iNormalizePath(&npath);
}
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
if (npath[0] == '/' and nstart[0] != '/') {
iPrependS(&nstart, "/");
iPrependS(&nstart, cwd);
iNormalizePath(&nstart);
}
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
if (startsWithS(npath, nstart)) {
if (npath[strlen(nstart)] == '/') {
- if (!npath[strlen(nstart)+1]) {
- r = strdup(".");
- goto end;
- }
r = sliceS(npath, strlen(nstart)+1, 0);
+ goto end;
}
+ // handle case when nstart is "/" after normalize
if (npath[strlen(nstart)-1] == '/') {
r = sliceS(npath, strlen(nstart), 0);
+ goto end;
}
- goto end;
+ // fallthrough: npath starts with nstart but is a different path
+ // Example: npath = "/usr/bin" nstart = "/us"
}
+ // find first uncommon directory between npath and nstart
// lib/t
// lib/a/b
size_t i = 0;
size_t from = 0;
while (npath[i] and nstart[i]) {
if (npath[i] == '/') {
- from = i;
+ // i+1 to skip the slash
+ from = i+1;
}
- if ((npath[i] != nstart[i])) {
+ if (npath[i] != nstart[i]) {
break;
}
i++;
}
+ // count slashes in nstart after first uncommon directory
size_t slash = 1;
rangeFrom(j, i, strlen(nstart))
if (nstart[j] == '/') {
slash++;
}
+ // go up directories to last common directory between npath and nstart
r = repeatS("../", slash);;
- iAppendS(&r, npath+from+1);
+ iAppendS(&r, npath+from);
end:
free(npath);
@@ -3688,11 +3785,27 @@ char *bLRelPath(char *dest, size_t destSize, char *path, const char *start) {
char *r = NULL;
+ // steps
+ // normalize path and start
+ // if start is not set, start is cwd
+ // when path and start are equal, return "."
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
+ // find first uncommon directory between npath and nstart
+ // count slashes in nstart after first uncommon directory
+ // go up directories to last common directory between npath and nstart
+
+ // normalize path and start
char *npath = expandHome(path);
iNormalizePath(&npath);
char *nstart;
char *cwd = getCwd();
+ // if start is not set, start is cwd
if (!start) {
// relative path to cwd
nstart = getCwd();
@@ -3703,60 +3816,70 @@ char *bLRelPath(char *dest, size_t destSize, char *path, const char *start) {
iNormalizePath(&nstart);
}
+ // when path and start are equal, return "."
if (eqS(npath, nstart)) {
r = strdup(".");
goto end;
}
+ // if path is relative path and start is absolute path
+ // then path is relative to nstart
if (npath[0] != '/' and nstart[0] == '/') {
iPrependS(&npath, "/");
- iPrependS(&npath, cwd);
+ iPrependS(&npath, nstart);
iNormalizePath(&npath);
}
+ // if path is absolute path and start is relative path
+ // then start is relative to cwd
if (npath[0] == '/' and nstart[0] != '/') {
iPrependS(&nstart, "/");
iPrependS(&nstart, cwd);
iNormalizePath(&nstart);
}
+ // when path starts with nstart, slice path to only keep the string
+ // after the end of nstart
if (startsWithS(npath, nstart)) {
if (npath[strlen(nstart)] == '/') {
- if (!npath[strlen(nstart)+1]) {
- r = strdup(".");
- goto end;
- }
r = sliceS(npath, strlen(nstart)+1, 0);
+ goto end;
}
+ // handle case when nstart is "/" after normalize
if (npath[strlen(nstart)-1] == '/') {
r = sliceS(npath, strlen(nstart), 0);
+ goto end;
}
- goto end;
+ // fallthrough: npath starts with nstart but is a different path
+ // Example: npath = "/usr/bin" nstart = "/us"
}
+ // find first uncommon directory between npath and nstart
// lib/t
// lib/a/b
size_t i = 0;
size_t from = 0;
while (npath[i] and nstart[i]) {
if (npath[i] == '/') {
- from = i;
+ from = i+1;
}
- if ((npath[i] != nstart[i])) {
+ if (npath[i] != nstart[i]) {
break;
}
i++;
}
+ // count slashes in nstart after first uncommon directory
size_t slash = 1;
rangeFrom(j, i, strlen(nstart))
if (nstart[j] == '/') {
slash++;
}
+ // go up directories to last common directory between npath and nstart
r = repeatS("../", slash);;
- iAppendS(&r, npath+from+1);
+ iAppendS(&r, npath+from);
end:
free(npath);
@@ -3810,6 +3933,9 @@ char *bGetHomePath(char *path) {
char *bLGetHomePath(char *path, size_t pathSize) {
struct passwd *pw = getpwuid(getuid());;
+ if (strlen(pw->pw_dir)+1 > pathSize) {
+ return(NULL);
+ }
strLCpy(path, pathSize, pw->pw_dir);
return(path);
}
@@ -6100,8 +6226,10 @@ char *bLReadS(char *dst, size_t dstSize) {
*
* currently used in Termux because getpass is missging
*/
-char *shGetpass(void) {
+local char *shGetpass(void) {
char *r = NULL;
+
+ #ifndef unitTest
struct termios old;
struct termios new;
@@ -6127,6 +6255,9 @@ char *shGetpass(void) {
/* Restore terminal. */
(void) tcsetattr (fileno (stream), TCSAFLUSH, &old);
fclose(stream);
+ #else
+ r = strdup("*****");;
+ #endif
return(r);
}
@@ -6139,7 +6270,7 @@ char *shGetpass(void) {
*/
char *readPasswordS(void) {
- #if (__TERMUX__ || __HAIKU__)
+ #if (__TERMUX__ || __HAIKU__ || unitTest)
char *r = shGetpass();
#else
char *p = getpass("");
@@ -6489,9 +6620,10 @@ char *toHexHeadSepS(const void *buf, size_t len, const char *head, const char *s
return(NULL);
}
- size_t sepLen = strlen(separator);;
+ size_t headLen = strlen(head);;
+ size_t sepLen = strlen(separator);;
- r = MALLOC(sizeof(char) * ((4+sepLen)*len-sepLen+1));;
+ r = MALLOC(sizeof(char) * ((2+headLen+sepLen)*len-sepLen+1));;
if (!r) {
return(NULL);
}
@@ -6502,7 +6634,7 @@ char *toHexHeadSepS(const void *buf, size_t len, const char *head, const char *s
b = buf;
for (size_t i = 0; i < len-1; i++) {
sprintf(c, "%s%02x%s", head, b[i], separator);
- c += 4+sepLen;;
+ c += 2+headLen+sepLen;;
}
sprintf(c, "%s%02x", head, b[len-1]);
@@ -9186,8 +9318,7 @@ bool icStartsWithCharS(const char *string1, char c) {
if (!string1) {
return(false);
}
- charToS(s,c);
- return(icStartsWithS(string1, s));
+ return(toupper(*string1) == toupper(c));;
}
/**
@@ -9227,8 +9358,7 @@ bool icEndsWithCharS(const char *string1, char c) {
if (!strlen(string1)) {
return(false);
}
- charToS(s,c);
- return(icEndsWithS(string1, s));
+ return(toupper(*(string1+strlen(string1)-1)) == toupper(c));;
}
/**
@@ -9328,7 +9458,7 @@ char *stripCtrlS(const char *string) {
return(NULL);
}
- size_t len = strlen(string);
+ size_t len = strlen(string)+1;
r = MALLOC(len);
if (!r) {
return(NULL);
@@ -9359,7 +9489,7 @@ char *iStripCtrlS(char **string) {
return(NULL);
}
- size_t i, j = 0;
+ size_t i = 0, j = 0;
while ((*string)[i]) {
if (!iscntrl((*string)[i])) {
@@ -9368,6 +9498,7 @@ char *iStripCtrlS(char **string) {
i++;
}
+ (*string)[j] = 0;;
return(*string);
}
@@ -9386,7 +9517,7 @@ char *bStripCtrlS(char *string) {
return(NULL);
}
- size_t i, j = 0;
+ size_t i = 0, j = 0;
while (string[i]) {
if (!iscntrl(string[i])) {
@@ -9395,6 +9526,7 @@ char *bStripCtrlS(char *string) {
i++;
}
+ string[j] = 0;;
return(string);
}
@@ -9717,6 +9849,25 @@ size_t lenS(const char *string) {
}
/**
+ * string buffer size
+ *
+ * return strlen+1 when possible
+ *
+ * \param
+ * string
+ * \return
+ * strlen+1 value
+ * 0 when string is NULL
+ */
+size_t sizeS(const char *string) {
+
+ if (!string) {
+ return(0);
+ }
+ return(strlen(string)+1);
+}
+
+/**
* upper case String
* duplicate string
*
@@ -10751,6 +10902,10 @@ char *ellipsisStartS(const char *string, size_t targetLength, const char *ellips
return(NULL);
}
+ if (!targetLength) {
+ return(strdup(""));
+ }
+
size_t len = strlen(string);
if (len <= targetLength) {
@@ -10793,6 +10948,11 @@ char *iEllipsisStartS(char **string, size_t targetLength, const char *ellipsisSt
return(NULL);
}
+ if (!targetLength) {
+ (*string)[0] = 0;
+ return(*string);
+ }
+
size_t len = strlen(*string);
if (len > targetLength) {
@@ -10833,6 +10993,11 @@ char *bEllipsisStartS(char *dest, const char *string, size_t targetLength, const
return(NULL);
}
+ if (!targetLength) {
+ dest[0] = 0;
+ return(dest);
+ }
+
size_t len = strlen(string);
if (len <= targetLength) {
@@ -10845,7 +11010,7 @@ char *bEllipsisStartS(char *dest, const char *string, size_t targetLength, const
iAppendS(&ellip, string);
// make sure the result is target length
iSliceS(&ellip, 0, targetLength);
- strncpy(dest, ellip, targetLength);
+ strncpy(dest, ellip, targetLength+1);
free(ellip);
}
return(dest);
@@ -10876,6 +11041,15 @@ char *bLEllipsisStartS(char *dest, size_t destSize, const char *string, size_t t
return(NULL);
}
+ if (!destSize) {
+ return(dest);
+ }
+
+ if (!targetLength) {
+ dest[0] = 0;;
+ return(dest);
+ }
+
targetLength = destSize > targetLength ? targetLength : destSize;;
size_t len = strlen(string);
@@ -10921,6 +11095,10 @@ char *ellipsisStartCharS(const char *string, size_t targetLength, char ellipsisC
return(NULL);
}
+ if (!targetLength) {
+ return(strdup(""));
+ }
+
charToS(ellipsisString, ellipsisChar);
size_t len = strlen(string);
@@ -10964,6 +11142,11 @@ char *iEllipsisStartCharS(char **string, size_t targetLength, char ellipsisChar)
return(NULL);
}
+ if (!targetLength) {
+ (*string)[0] = 0;
+ return(*string);
+ }
+
charToS(ellipsisString, ellipsisChar);
size_t len = strlen(*string);
@@ -11006,6 +11189,11 @@ char *bEllipsisStartCharS(char *dest, const char *string, size_t targetLength, c
return(NULL);
}
+ if (!targetLength) {
+ dest[0] = 0;
+ return(dest);
+ }
+
charToS(ellipsisString, ellipsisChar);
size_t len = strlen(string);
@@ -11020,7 +11208,7 @@ char *bEllipsisStartCharS(char *dest, const char *string, size_t targetLength, c
iAppendS(&ellip, string);
// make sure the result is target length
iSliceS(&ellip, 0, targetLength);
- strncpy(dest, ellip, targetLength);
+ strncpy(dest, ellip, targetLength+1);
free(ellip);
}
return(dest);
@@ -11051,6 +11239,15 @@ char *bLEllipsisStartCharS(char *dest, size_t destSize, const char *string, size
return(NULL);
}
+ if (!destSize) {
+ return(dest);
+ }
+
+ if (!targetLength) {
+ dest[0] = 0;
+ return(dest);
+ }
+
charToS(ellipsisString, ellipsisChar);
targetLength = destSize > targetLength ? targetLength : destSize;;
@@ -11125,6 +11322,10 @@ char *ellipsisEndS(const char *string, size_t targetLength, const char *ellipsis
return(NULL);
}
+ if (!targetLength) {
+ return(strdup(""));
+ }
+
size_t len = strlen(string);
if (len <= targetLength) {
@@ -11170,6 +11371,11 @@ char *iEllipsisEndS(char **string, size_t targetLength, const char *ellipsisStri
return(NULL);
}
+ if (!targetLength) {
+ (*string)[0] = 0;
+ return(*string);
+ }
+
size_t len = strlen(*string);
if (len > targetLength) {
@@ -11214,6 +11420,11 @@ char *bEllipsisEndS(char *dest, const char *string, size_t targetLength, const c
return(NULL);
}
+ if (!targetLength) {
+ dest[0] = 0;
+ return(dest);
+ }
+
size_t len = strlen(string);
if (len <= targetLength) {
@@ -11230,7 +11441,8 @@ char *bEllipsisEndS(char *dest, const char *string, size_t targetLength, const c
// ellipsisString is longer than targetLength
ellip = sliceS(ellipsisString, 0, targetLength);
}
- strncpy(dest, ellip, targetLength);
+ strncpy(dest, ellip, targetLength+1);
+ free(ellip);
}
return(dest);
}
@@ -11260,6 +11472,15 @@ char *bLEllipsisEndS(char *dest, size_t destSize, const char *string, size_t tar
return(NULL);
}
+ if (!destSize) {
+ return(dest);
+ }
+
+ if (!targetLength) {
+ dest[0] = 0;
+ return(dest);
+ }
+
targetLength = destSize > targetLength ? targetLength : destSize;;
size_t len = strlen(string);
@@ -11279,6 +11500,7 @@ char *bLEllipsisEndS(char *dest, size_t destSize, const char *string, size_t tar
ellip = sliceS(ellipsisString, 0, targetLength);
}
strLCpy(dest, destSize, ellip);
+ free(ellip);
}
return(dest);
}
@@ -11308,6 +11530,10 @@ char *ellipsisEndCharS(const char *string, size_t targetLength, char ellipsisCha
return(NULL);
}
+ if (!targetLength) {
+ return(strdup(""));
+ }
+
charToS(ellipsisString, ellipsisChar);
size_t len = strlen(string);
@@ -11318,14 +11544,8 @@ char *ellipsisEndCharS(const char *string, size_t targetLength, char ellipsisCha
else {
// truncate string
char *ellip;
- if ( strlen(ellipsisString) < targetLength) {
- ellip = sliceS(string, 0, targetLength - strlen(ellipsisString));
- iAppendS(&ellip, ellipsisString);
- }
- else {
- // ellipsisString is longer than targetLength
- ellip = sliceS(ellipsisString, 0, targetLength);
- }
+ ellip = sliceS(string, 0, targetLength - strlen(ellipsisString));
+ iAppendS(&ellip, ellipsisString);
return(ellip);
}
}
@@ -11355,6 +11575,11 @@ char *iEllipsisEndCharS(char **string, size_t targetLength, char ellipsisChar) {
return(NULL);
}
+ if (!targetLength) {
+ (*string)[0] = 0;
+ return(*string);
+ }
+
charToS(ellipsisString, ellipsisChar);
size_t len = strlen(*string);
@@ -11362,14 +11587,8 @@ char *iEllipsisEndCharS(char **string, size_t targetLength, char ellipsisChar) {
if (len > targetLength) {
// truncate string
char *ellip;
- if ( strlen(ellipsisString) < targetLength) {
- ellip = sliceS(*string, 0, targetLength - strlen(ellipsisString));
- iAppendS(&ellip, ellipsisString);
- }
- else {
- // ellipsisString is longer than targetLength
- ellip = sliceS(ellipsisString, 0, targetLength);
- }
+ ellip = sliceS(*string, 0, targetLength - strlen(ellipsisString));
+ iAppendS(&ellip, ellipsisString);
free(*string);
*string = ellip;
}
@@ -11401,6 +11620,11 @@ char *bEllipsisEndCharS(char *dest, const char *string, size_t targetLength, cha
return(NULL);
}
+ if (!targetLength) {
+ dest[0] = 0;
+ return(dest);
+ }
+
charToS(ellipsisString, ellipsisChar);
size_t len = strlen(string);
@@ -11411,15 +11635,10 @@ char *bEllipsisEndCharS(char *dest, const char *string, size_t targetLength, cha
else {
// truncate string
char *ellip;
- if ( strlen(ellipsisString) < targetLength) {
- ellip = sliceS(string, 0, targetLength - strlen(ellipsisString));
- iAppendS(&ellip, ellipsisString);
- }
- else {
- // ellipsisString is longer than targetLength
- ellip = sliceS(ellipsisString, 0, targetLength);
- }
- strncpy(dest, ellip, targetLength);
+ ellip = sliceS(string, 0, targetLength - strlen(ellipsisString));
+ iAppendS(&ellip, ellipsisString);
+ strncpy(dest, ellip, targetLength+1);
+ free(ellip);
}
return(dest);
}
@@ -11449,6 +11668,15 @@ char *bLEllipsisEndCharS(char *dest, size_t destSize, const char *string, size_t
return(NULL);
}
+ if (!destSize) {
+ return(dest);
+ }
+
+ if (!targetLength) {
+ dest[0] = 0;
+ return(dest);
+ }
+
charToS(ellipsisString, ellipsisChar);
targetLength = destSize > targetLength ? targetLength : destSize;;
@@ -11461,15 +11689,10 @@ char *bLEllipsisEndCharS(char *dest, size_t destSize, const char *string, size_t
else {
// truncate string
char *ellip;
- if ( strlen(ellipsisString) < targetLength) {
- ellip = sliceS(string, 0, targetLength - strlen(ellipsisString));
- iAppendS(&ellip, ellipsisString);
- }
- else {
- // ellipsisString is longer than targetLength
- ellip = sliceS(ellipsisString, 0, targetLength);
- }
+ ellip = sliceS(string, 0, targetLength - strlen(ellipsisString));
+ iAppendS(&ellip, ellipsisString);
strLCpy(dest, destSize, ellip);
+ free(ellip);
}
return(dest);
}
@@ -12557,7 +12780,7 @@ char *bSwapS(char *string, intmax_t index1, intmax_t index2) {
* \return
* string with characters swapped at index1 and index2
* NULL when string is NULL or when index1 or index2 are outside the string
- */
+ */
char *bLSwapS(char *string, size_t size, intmax_t index1, intmax_t index2) {
intmax_t len;
@@ -12565,10 +12788,14 @@ char *bLSwapS(char *string, size_t size, intmax_t index1, intmax_t index2) {
return(NULL);
}
+ if (!size) {
+ return(string);
+ }
+
len = strlen(string);
- if ((size_t)len > size) {
- len = size+1;
+ if ((size_t)len+1 > size) {
+ len = size-1;
}
if (index1 >= len) {
@@ -12795,7 +13022,9 @@ char *bSliceS(char *string, intmax_t start, intmax_t end) {
// copy range to a new string
intmax_t n;
n = end - start;
- strncpy(string, string+start, n);
+ if (start) {
+ strncpy(string, string+start, n);
+ }
string[n] = 0;
}
@@ -12821,33 +13050,38 @@ char *bSliceS(char *string, intmax_t start, intmax_t end) {
* NULL unchanged string when start and end are not set correctly
*/
char *bLSliceS(char *string, size_t stringSize, intmax_t start, intmax_t end) {
+ intmax_t len;
// sanity checks
if (!string || !stringSize) {
return(NULL);
}
+ len = strlen(string);
+ if ((size_t)len+1 > stringSize) {
+ len = stringSize - 1;
+ }
+
// compute string length without NUL
- stringSize--;
- if (start > (intmax_t)stringSize) {
+ if (start > len) {
bEmptyS(string);
return(NULL);
}
- if (end > (intmax_t)stringSize) {
- end = stringSize;
+ if (end > len) {
+ end = len;
}
- if (start <= -(intmax_t)stringSize) {
- start = -stringSize;
+ if (start <= -len) {
+ start = -len;
}
- if (end <= -(intmax_t)stringSize) {
+ if (end <= -len) {
bEmptyS(string);
return(NULL);
}
if (start < 0) {
- start = stringSize + start;
+ start = len + start;
}
if (end <= 0) {
- end = stringSize + end;
+ end = len + end;
}
if (end < start) {
bEmptyS(string);
@@ -12858,11 +13092,13 @@ char *bLSliceS(char *string, size_t stringSize, intmax_t start, intmax_t end) {
bEmptyS(string);
}
else {
- // start < end < stringSize
+ // start < end < len
// copy range to a new string
intmax_t n;
n = end - start;
- strncpy(string, string+start, n);
+ if (start) {
+ strncpy(string, string+start, n);
+ }
string[n] = 0;
}
@@ -12932,6 +13168,10 @@ char *cropS(char *string, intmax_t start, intmax_t end) {
strLCpy(l, (n+1) * sizeof(char), string+start);
strLCpy(string+start, len-end+1, string+end);
}
+ else {
+ // start = end, return empty string
+ l = strdup("");
+ }
return(l);
}
@@ -12999,6 +13239,10 @@ char *iCropS(char **string, intmax_t start, intmax_t end) {
strLCpy(l, (n+1) * sizeof(char), *string+start);
strLCpy(*string+start, len-end+1, *string+end);
}
+ else {
+ // start = end, return empty string
+ l = strdup("");
+ }
return(l);
}
@@ -13027,7 +13271,7 @@ char cropElemS(char *string, intmax_t index) {
string[len-1] = 0;
}
else {
- strLCpy(string+index, len-1, string+index+1);
+ strLCpy(string+index, len, string+index+1);
}
return(r);
@@ -14004,32 +14248,36 @@ char *bDelS(char *string, intmax_t start, intmax_t end) {
* or when input string is NULL or when malloc failed or when end is under start
*/
char *bLDelS(char *string, size_t stringSize, intmax_t start, intmax_t end) {
+ intmax_t len;
// sanity checks
if (!string || !stringSize) {
return(NULL);
}
- // compute string length without NUL
- stringSize--;
+ len = strlen(string);
+ if ((size_t)len+1 > stringSize) {
+ len = stringSize - 1;
+ }
- if (start >= (intmax_t)stringSize) {
- start = stringSize;
+ // compute string length without NUL
+ if (start >= (intmax_t)len) {
+ start = len;
}
- if (end > (intmax_t)stringSize) {
- end = stringSize;
+ if (end > (intmax_t)len) {
+ end = len;
}
- if (start <= -(intmax_t)stringSize) {
- start = -stringSize;
+ if (start <= -(intmax_t)len) {
+ start = -len;
}
- if (end <= -(intmax_t)stringSize) {
- end = -stringSize;
+ if (end <= -(intmax_t)len) {
+ end = -len;
}
if (start < 0) {
- start = stringSize + start;
+ start = len + start;
}
if (end <= 0) {
- end = stringSize + end;
+ end = len + end;
}
if (end < start) {
return(NULL);
@@ -14039,12 +14287,12 @@ char *bLDelS(char *string, size_t stringSize, intmax_t start, intmax_t end) {
return(string);
}
- // start < end < stringSize
+ // start < end < len
// copy range to a new string
intmax_t n;
n = end - start;
- strncpy(string+start, string+start+n, stringSize-n-start);
- string[stringSize-n] = 0;
+ strncpy(string+start, string+start+n, len-n-start);
+ string[len-n] = 0;
return(string);
}
@@ -14195,27 +14443,31 @@ char *bDelElemS(char *string, intmax_t index) {
* NULL when input string is NULL or when malloc failed
*/
char *bLDelElemS(char *string, size_t stringSize, intmax_t index) {
+ intmax_t len;
// sanity checks
if (!string || !stringSize) {
return(NULL);
}
- // compute string length without NUL
- stringSize--;
+ len = strlen(string);
+ if ((size_t)len+1 > stringSize) {
+ len = stringSize - 1;
+ }
- if (index >= (intmax_t)stringSize) {
+ // compute string length without NUL
+ if (index >= (intmax_t)len) {
return(NULL);
}
- if (index < -(intmax_t)stringSize) {
+ if (index < -(intmax_t)len) {
return(NULL);
}
if (index < 0) {
- index = (intmax_t)stringSize + index;
+ index = (intmax_t)len + index;
}
- strncpy(string+index, string+index+1, stringSize-1-index);
- string[stringSize-1] = 0;
+ strncpy(string+index, string+index+1, len-1-index);
+ string[len-1] = 0;
return(string);
}
@@ -14345,6 +14597,11 @@ char *icFindCharS(const char *string, char c) {
if (!string) {
return(NULL);
}
+ if (c == 0) {
+ // include terminating '\0' in comparison
+ // like findCharS
+ return(strchr(string, c));
+ }
charToS(s, c);
return(icFindS(string, s));
}
@@ -14540,7 +14797,7 @@ size_t bLLenUTF8(const char *s, size_t maxSize) {
}
const char *t = s;
- while (*s && ((size_t)(s-t) < maxSize)) {
+ while (*s && ((size_t)(s-t)+1 < maxSize)) {
r += (*s++ & 0xC0) != 0x80;
}
return(r);
@@ -14623,20 +14880,23 @@ bool bLIsUTF8(const char * string, size_t stringSize) {
const unsigned char * bytes = (const unsigned char *)string;
while (*bytes) {
- if ((size_t)(bytes - (const unsigned char *)string) >= stringSize) {
- return(false);
- }
// ASCII
// use bytes[0] <= 0x7F to allow ASCII control characters
if (bytes[0] == 0x09 || bytes[0] == 0x0A || bytes[0] == 0x0D || (0x20 <= bytes[0] && bytes[0] <= 0x7E)) {
bytes += 1;
+ if ((size_t)(bytes - (const unsigned char *)string)+1 > stringSize) {
+ return(false);
+ }
continue;
}
// non-overlong 2-byte
if ((0xC2 <= bytes[0] && bytes[0] <= 0xDF) && (0x80 <= bytes[1] && bytes[1] <= 0xBF)) {
bytes += 2;
+ if ((size_t)(bytes - (const unsigned char *)string)+1 > stringSize) {
+ return(false);
+ }
continue;
}
@@ -14645,6 +14905,9 @@ bool bLIsUTF8(const char * string, size_t stringSize) {
// excluding surrogates
if ((bytes[0] == 0xE0 && (0xA0 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF)) || (((0xE1 <= bytes[0] && bytes[0] <= 0xEC) || bytes[0] == 0xEE || bytes[0] == 0xEF) && (0x80 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF)) || (bytes[0] == 0xED && (0x80 <= bytes[1] && bytes[1] <= 0x9F) && (0x80 <= bytes[2] && bytes[2] <= 0xBF))) {
bytes += 3;
+ if ((size_t)(bytes - (const unsigned char *)string)+1 > stringSize) {
+ return(false);
+ }
continue;
}
@@ -14653,6 +14916,9 @@ bool bLIsUTF8(const char * string, size_t stringSize) {
// plane 16
if ((bytes[0] == 0xF0 && (0x90 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF)) || ((0xF1 <= bytes[0] && bytes[0] <= 0xF3) && (0x80 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF)) || (bytes[0] == 0xF4 && (0x80 <= bytes[1] && bytes[1] <= 0x8F) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF))) {
bytes += 4;
+ if ((size_t)(bytes - (const unsigned char *)string)+1 > stringSize) {
+ return(false);
+ }
continue;
}
@@ -14677,6 +14943,9 @@ bool bLIsUTF8(const char * string, size_t stringSize) {
*/
bool isCodeUTF8(const char *code) {
+ if (!code) {
+ return(false);
+ }
const unsigned char * bytes = (const unsigned char *)code;
// ASCII
// use bytes[0] <= 0x7F to allow ASCII control characters
@@ -44491,7 +44760,7 @@ char *nextUTF8(const char *utf8) {
* \param
* utf8 pointer to a code point in string
* \param
- * ut8Size string buffer size (including NUL, strlen(string) +1 when the buffer is full)
+ * utf8Size string buffer size (including NUL, strlen(string) +1 when the buffer is full)
* \return
* pointer to next UTF-8 code point
* NULL when the end string is reached or utf8 is NULL or the start of the next code point is outside the string
@@ -44599,7 +44868,7 @@ char *bPrevUTF8(const char *string, const char *utf8) {
return(bPrevUTF8Tiny(string, utf8));
}
-char *bPrevUTF8Tiny(const char *string, const char *utf8) {
+local char *bPrevUTF8Tiny(const char *string, const char *utf8) {
while (utf8 > string) {
utf8--;
@@ -44643,7 +44912,7 @@ char *idx2PtrUTF8(const char *utf8, intmax_t index) {
intmax_t i = 0;;
while (i != index) {
nxCodeUTF8(utf8);
- if (utf8 >= end) {
+ if (utf8 > end) {
return(NULL);
}
i++;
@@ -44696,9 +44965,16 @@ char *bLIdx2PtrUTF8(const char *utf8, size_t utf8Size, intmax_t index) {
return(NULL);
}
+ // find string end
+ size_t len;
+ len = strlen(utf8);
+ if (len+1 > utf8Size) {
+ len = utf8Size - 1;
+ }
+
// go from the end
char *start = (char *)utf8;;
- utf8 += utf8Size;;
+ utf8 += len;;
intmax_t i = 0;;
while (i != index) {
utf8 = bPrevUTF8Tiny(start, utf8);;
@@ -44737,10 +45013,19 @@ intmax_t ptr2IdxUTF8(const char *utf8, const char *pos) {
// there is at least one code point
// find next code point, works even when utf8 points inside a code point
while (*utf8) {
- if ((*utf8++ & 0xC0) != 0x80) {
+ if ((*utf8 & 0xC0) != 0x80) {
+ // check utf8 is in a multibyte code point
+ // if it is, find the end of the code point
+ if ((*utf8 & 0xC0) == 0xC0) {
+ nxCodeUTF8(utf8);
+ }
+ else {
+ utf8++;
+ }
break;
- }
}
+ utf8++;
+ }
r++;
while (*utf8 && (utf8 < pos)) {
nxCodeUTF8(utf8);
@@ -44805,6 +45090,7 @@ intmax_t bPtr2IdxUTF8(const char *start, const char *utf8, const char *pos) {
break;
}
}
+ nxCodeUTF8(utf8);
r++;
while (*utf8 && (utf8 < pos)) {
nxCodeUTF8(utf8);
@@ -44867,6 +45153,7 @@ intmax_t bLPtr2IdxUTF8(const char *utf8, size_t utf8Size, const char *pos) {
break;
}
}
+ nxCodeUTF8(utf8);
r++;
while ((utf8 < end) && *utf8 && (utf8 < pos)) {
nxCodeUTF8(utf8);
@@ -45069,7 +45356,7 @@ char *nMakeValidUTF8(const char *utf8, size_t utf8Len) {
*/
char *bNMakeValidUTF8(char *dst, const char *utf8, size_t utf8Len) {
- if (!!dst || !utf8 || !utf8Len) {
+ if (!dst || !utf8 || !utf8Len) {
return(NULL);
}
@@ -45118,7 +45405,7 @@ char *bNMakeValidUTF8(char *dst, const char *utf8, size_t utf8Len) {
*/
char *bLMakeValidUTF8(char *dst, size_t dstSize, const char *utf8) {
- if (!!dst || !utf8 || !dstSize) {
+ if (!dst || !utf8 || !dstSize) {
return(NULL);
}
@@ -45170,7 +45457,7 @@ char *bLMakeValidUTF8(char *dst, size_t dstSize, const char *utf8) {
*/
char *bLNMakeValidUTF8(char *dst, size_t dstSize, const char *utf8, size_t utf8Len) {
- if (!!dst || !dstSize || !utf8 || !utf8Len) {
+ if (!dst || !dstSize || !utf8 || !utf8Len) {
return(NULL);
}
@@ -45225,7 +45512,6 @@ char *strNCpyUTF8(char *dst, const char *src, size_t srcLen) {
}
if (!srcLen) {
- *dst = 0;
return(dst);
}
@@ -45825,17 +46111,19 @@ bool icEndsWithUTF8(const char *string1, const char *string2) {
* -1 when there is an error
*/
ssize_t icCountUTF8(const char *s, const char *needle) {
+ char *lower = NULL;
// sanity checks
if (!s || !needle) {
return(-1);
}
- s = casefoldUTF8(s);
+ lower = casefoldUTF8(s);
needle = casefoldUTF8(needle);
ssize_t r = 0;
size_t len = strlen(needle);
+ s = lower;
while (s != NULL) {
s = strstr(s, needle);
if (s != NULL) {
@@ -45847,7 +46135,7 @@ ssize_t icCountUTF8(const char *s, const char *needle) {
}
}
- freeManyS(s, needle);
+ freeManyS(lower, needle);
return(r);
}
@@ -46378,7 +46666,7 @@ char *bUpperUTF8(char *utf8 UNUSED) {
*
* Returns: the combining class of the character
**/
-int runeCombiningClass (rune uc) {
+local int runeCombiningClass (rune uc) {
return(COMBINING_CLASS(uc));
}
@@ -46667,10 +46955,10 @@ char *casefoldUTF8(const char *utf8) {
char code[8] = {0, 0, 0, 0, 0, 0, 0, 0};
bRune2CodeUTF8(code, tolowerUTF8(ch));
iAppendS(&r, code);
- }
- next:
- nxCodeUTF8(utf8);
+ next:
+ nxCodeUTF8(utf8);
+ }
return(r);
}
@@ -46951,6 +47239,7 @@ char *setUTF8(char *string, intmax_t index, rune c) {
char *p = idx2PtrUTF8(string, index);
bRune2CodeUTF8(p, c);
+ // TODO check code point length and shift string end when necessary
return(string);
}
@@ -47195,12 +47484,43 @@ char *bSliceUTF8(char *string, intmax_t start, intmax_t end) {
* NULL unchanged string when start and end are not set correctly
*/
char *bLSliceUTF8(char *string, size_t stringSize, intmax_t start, intmax_t end) {
+ intmax_t len;
// sanity checks
if (!string || !stringSize) {
return(NULL);
}
+ len = strlen(string);
+ if ((size_t)len+1 > stringSize) {
+ len = stringSize - 1;
+ }
+
+ if (start > len) {
+ bEmptyS(string);
+ return(NULL);
+ }
+ if (end > len) {
+ end = len;
+ }
+ if (start <= -len) {
+ start = -len;
+ }
+ if (end <= -len) {
+ bEmptyS(string);
+ return(NULL);
+ }
+ if (start < 0) {
+ start = len + start;
+ }
+ if (end <= 0) {
+ end = len + end;
+ }
+ if (end < start) {
+ bEmptyS(string);
+ return(NULL);
+ }
+
char *startp = bLIdx2PtrUTF8(string, stringSize, start);
char *endp = bLIdx2PtrUTF8(string, stringSize, end);
@@ -47949,14 +48269,40 @@ char *bDelUTF8(char *string, intmax_t start, intmax_t end) {
* or when input string is NULL or when malloc failed or when end is under start
*/
char *bLDelUTF8(char *string, size_t stringSize, intmax_t start, intmax_t end) {
+ intmax_t len;
// sanity checks
if (!string || !stringSize) {
return(NULL);
}
+ len = strlen(string);
+ if ((size_t)len+1 > stringSize) {
+ len = stringSize - 1;
+ }
+
// compute string length without NUL
- stringSize--;
+ if (start >= len) {
+ start = len;
+ }
+ if (end > len) {
+ end = len;
+ }
+ if (start <= -len) {
+ start = -len;
+ }
+ if (end <= -len) {
+ end = -len;
+ }
+ if (start < 0) {
+ start = len + start;
+ }
+ if (end <= 0) {
+ end = len + end;
+ }
+ if (end < start) {
+ return(NULL);
+ }
char *startp = bLIdx2PtrUTF8(string, stringSize, start);
char *endp = bLIdx2PtrUTF8(string, stringSize, end);
@@ -47981,12 +48327,12 @@ char *bLDelUTF8(char *string, size_t stringSize, intmax_t start, intmax_t end) {
return(string);
}
- // start < end < stringSize
+ // start < end < len
// copy range to a new string
intmax_t n;
n = endp - startp;
- strncpy(string+starto, string+starto+n, stringSize-n-starto);
- string[stringSize-n] = 0;
+ strncpy(string+starto, string+starto+n, len-n-starto);
+ string[len-n] = 0;
return(string);
}
@@ -48385,9 +48731,15 @@ char **icListUniqUTF8(char **list) {
return(NULL);
}
+ size_t len = listLengthS(list);
+
+ if (!len) {
+ listEmptyS(r);
+ return(r);
+ }
listPushS(&r, list[0]);
// one element list
- if (listLengthS(list) == 1) {
+ if (len == 1) {
return(r);
}
// push element to new list if it is not already in new list
@@ -48420,7 +48772,12 @@ char **iicListUniqUTF8(char ***list) {
return(NULL);
}
- if (listLengthS(*list) < 2) {
+ size_t len = listLengthS(*list);
+
+ if (len < 1) {
+ return(*list);
+ }
+ else if (len < 2) {
// one element list
iListPushS(&r, (*list)[0]);
}
@@ -49061,7 +49418,7 @@ size_t listLengthS(char **list) {
* -1 when list is NULL
*/
ssize_t listStrLengthS(char **list) {
- ssize_t r;
+ ssize_t r = 0;;
// sanity checks
if (!list) {
@@ -49548,7 +49905,7 @@ char **icSplitChar(const char *string, char delim) {
* -1 when list is NULL
*/
ssize_t joinLength(char **list, const char* delim) {
- ssize_t r;
+ ssize_t r = 0;;
// sanity checks
if (!list || !delim) {
@@ -49559,10 +49916,11 @@ ssize_t joinLength(char **list, const char* delim) {
bool isFirstElem = true;
forEachS(list, i) {
if (isFirstElem) {
- r += strlen(i);
+ r += strlen(i);
+ isFirstElem = no;
}
else {
- r += strlen(i) + delimLen;
+ r += strlen(i) + delimLen;
}
}
@@ -50207,9 +50565,13 @@ char **iListAppendNSmashS(char ***list1, char **list2) {
*/
char **listShiftS(char ***list1, char **list2) {
+ if (!list1) {
+ return(NULL);
+ }
+
char **r = listInsertS(*list1, 0, list2);
if (r) {
- free(*list1);
+ listFreeS(*list1);
*list1 = r;
}
return(r);
@@ -50602,7 +50964,12 @@ char **listCropS(char **list, intmax_t start, intmax_t end) {
return(NULL);
}
- if (start < end) {
+ if (start == end) {
+ // empty list
+ listEmptyS(l);
+ return(l);
+ }
+ else {
// start < end < len
intmax_t n;
n = end - start;
@@ -50679,7 +51046,12 @@ char **iListCropS(char ***list, intmax_t start, intmax_t end) {
return(NULL);
}
- if (start < end) {
+ if (start == end) {
+ // empty list
+ listEmptyS(l);
+ return(l);
+ }
+ else {
// start < end < len
intmax_t n;
n = end - start;
@@ -50914,7 +51286,17 @@ char **iListInsertS(char ***list, intmax_t index, char **toInsert) {
if (index) {
return(NULL);
}
- r = listDupS(toInsert);
+ len = listLengthS(toInsert);
+ r = MALLOC((len+1) * sizeof(char *));
+ if (!r) {
+ return(NULL);//LCOV_EXCL_LINE
+ }
+ // last element is NULL
+ r[len] = NULL;
+ // copy each element
+ enumerateCharP(toInsert, e, i) {
+ r[i] = *e;
+ }
*list = r;
return(r);
}
@@ -50948,6 +51330,12 @@ char **iListInsertS(char ***list, intmax_t index, char **toInsert) {
return(*list);
}
+ if ((*list) == toInsert) {
+ // list1 and list2 identical, cancel this operations
+ // to avoid double free undefined behavior in listFreeS
+ return(NULL);
+ }
+
if (index == 0) {
// insert at beginning
iListAppendS(&r, toInsert);
@@ -51035,6 +51423,12 @@ char **iListInsertNFreeS(char ***list, intmax_t index, char **toInsert) {
return(*list);
}
+ if ((*list) == toInsert) {
+ // list1 and list2 identical, cancel this operations
+ // to avoid double free undefined behavior in listFreeS
+ return(NULL);
+ }
+
if (index == 0) {
// insert at beginning
iListAppendS(&r, toInsert);
@@ -52518,6 +52912,12 @@ char **icListUniqS(char **list) {
return(NULL);
}
+ size_t len = listLengthS(list);
+
+ if (!len) {
+ listEmptyS(r);
+ return(r);
+ }
listPushS(&r, list[0]);
// one element list
if (listLengthS(list) == 1) {
@@ -52552,7 +52952,12 @@ char **iicListUniqS(char ***list) {
return(NULL);
}
- if (listLengthS(*list) < 2) {
+ size_t len = listLengthS(*list);
+
+ if (!len) {
+ listEmptyS(r);
+ }
+ else if (len == 1) {
// one element list
iListPushS(&r, (*list)[0]);
}
diff --git a/src/libsheepy.h b/src/libsheepy.h
@@ -96,7 +96,7 @@
// version accoring to the version package: Release.Major.minor.patch
// https://noulin.net/version/file/README.md.html
-#define LIBSHEEPY_VERSION "1.1.1"
+#define LIBSHEEPY_VERSION "1.1.2"
#ifndef SH_PREFIX
#define SH_PREFIX(NAME) NAME
@@ -850,6 +850,17 @@ uint64_t shStopwatch(uint8_t op);
/**
* LOG LEVELS
+ * TODO:
+ * add levels:
+ * EMERGENCY
+ * ALERT
+ * CRITICAL
+ * ERROR
+ * WARNING
+ * NOTICE
+ * PASS
+ * INFO
+ * DEBUG
*/
#define LOG_CRITICAL 0
#define LOG_ERROR 1
@@ -863,6 +874,7 @@ uint64_t shStopwatch(uint8_t op);
#define LOG_PASS 3
#define LOG_INFO 4
#define LOG_INVALID 5
+#define LOG_MAX_LEVEL LOG_INVALID
/** getMaxLogLevel and setMaxLogLevel value disabling all logs */
#define LOG_DISABLE -1
@@ -1416,6 +1428,9 @@ bool setProgName(const char *name);
// set default program name
void setDefaultProgName(void);
+// free ProgName
+void freeProgName(void);
+
// get program path as given in the shell
const char *getProgPath(void);
@@ -1871,6 +1886,8 @@ char *bDoubleToS(char *s, double n);
// length
size_t lenS(const char *string);
+// string buffer size: strlen+1
+size_t sizeS(const char *string);
/**
* upper case and store the result in c and return the result
@@ -2818,7 +2835,7 @@ int systemf(const char *fmt, ...);
// run command and return exit code from command (not system return value like system, systemf and systemNFree)
#define command(cmd) commandF(cmd, __LINE__, __func__, __FILE__)
int commandF(const char *cmd, int line, const char *thisFunc, const char *thisFileName);
-#define commandf(cmd, ...) commandfF(__LINE__, __func__, __FILE__, cmd, __VA_ARGS__)
+#define commandf(...) commandfF(__LINE__, __func__, __FILE__, __VA_ARGS__)
int commandfF(int line, const char *thisFunc, const char *thisFileName, const char *fmt, ...);
#define commandNFree(cmd) commandNFreeF(cmd, __LINE__, __func__, __FILE__)
int commandNFreeF(char *cmd, int line, const char *thisFunc, const char *thisFileName);
diff --git a/src/libsheepyCuTest.c b/src/libsheepyCuTest.c
@@ -19,6 +19,153 @@
// TODO redirect stderr
+void cleanUpCharFreeT(CuTest *tc UNUSED) {
+
+ cleanCharP(s) = strdup("test");
+
+}
+
+
+void cleanUpListFreeT(CuTest *tc UNUSED) {
+
+ cleanListP(l) = listCreateS("a","b");
+
+}
+
+
+void cleanUpFileFreeT(CuTest *tc UNUSED) {
+
+ cleanFileP(f) = fopen("renameTest.null", "r");
+
+}
+
+
+void cleanUpCharFreeNullT(CuTest *tc UNUSED) {
+
+ cleanCharP(s) = null;
+
+}
+
+
+void cleanUpListFreeNullT(CuTest *tc UNUSED) {
+
+ cleanListP(l) = null;
+
+}
+
+
+void cleanUpFileFreeNullT(CuTest *tc UNUSED) {
+
+ cleanFileP(f) = null;
+
+}
+
+
+void shStopwatchT(CuTest *tc UNUSED) {
+
+ stopwatchStart;
+ stopwatchLog;
+
+}
+
+
+void setLogSymbolsT(CuTest *tc UNUSED) {
+
+ int m;
+
+ // set mode utf8
+ setLogSymbols(LOG_UTF8);
+ m = getLogSymbols();
+ ck_assert_int_eq(m, LOG_UTF8);
+
+ // set invalid mode
+ setLogSymbols(LOG_INVALID_MODE);
+ m = getLogSymbols();
+ ck_assert_int_eq(m, LOG_INVALID_MODE);
+
+ setLogSymbols(LOG_UTF8);
+ setLogSymbols(LOG_INVALID_MODE+10);
+ m = getLogSymbols();
+ ck_assert_int_eq(m, LOG_INVALID_MODE);
+
+}
+
+
+void setMaxLogLevelT(CuTest *tc UNUSED) {
+
+ int lv;
+
+ // set max level
+ setMaxLogLevel(LOG_DISABLE);
+ lv = getMaxLogLevel();
+ ck_assert_int_eq(lv, LOG_DISABLE);
+
+ // set invalid max level (all levels)
+ setMaxLogLevel(LOG_INVALID);
+ lv = getMaxLogLevel();
+ ck_assert_int_eq(lv, LOG_MAX_LEVEL);
+
+
+}
+
+
+void setLogShortPathT(CuTest *tc UNUSED) {
+
+ bool sp;
+
+ // set long path
+ setLogShortPath(no);
+ sp = getLogShortPath();
+ ck_assert(!sp);
+
+ // set short path
+ setLogShortPath(yes);
+ sp = getLogShortPath();
+ ck_assert(sp);
+
+}
+
+
+void setLogStdoutT(CuTest *tc UNUSED) {
+
+ bool std;
+
+ // set long path
+ setLogStdout(no);
+ std = getLogStdout();
+ ck_assert(!std);
+
+ // set short path
+ setLogStdout(yes);
+ std = getLogStdout();
+ ck_assert(std);
+
+}
+
+
+void openProgLogFileT(CuTest *tc UNUSED) {
+
+ const char *pn;
+ bool r;
+
+ // check that prog name is not set
+ pn = getProgName();
+ ck_assert_ptr_eq(pn, null);
+ r = openProgLogFile();
+ ck_assert(!r);
+
+ // set progname and open file
+ setProgName("openProgLogFileT");
+ r = openProgLogFile();
+ ck_assert(r);
+
+ freeProgName();
+ closeLogFiles();
+ rmAll("openProgLogFileT.log");
+
+}
+
+
void setLogFileT(CuTest *tc UNUSED) {
FILE *f;
@@ -261,6 +408,35 @@ void _pLogT(CuTest *tc UNUSED) {
}
+void setProgNameT(CuTest *tc UNUSED) {
+
+ bool r;
+
+ // set default prog name (null since init is not called yet)
+ setDefaultProgName();
+ ck_assert_ptr_eq(getProgName(), null);
+
+ // set prog name
+ r = setProgName("name");
+ ck_assert(r);
+
+ // set null prog name
+ r = setProgName(NULL);
+ ck_assert(!r);
+ ck_assert_ptr_ne(getProgName(), null);
+ ck_assert_str_eq(getProgName(), "name");
+
+ freeProgName();
+
+ // set prog name and then set default prog name
+ // no memory leak should happen
+ r = setProgName("name");
+ ck_assert(r);
+ setDefaultProgName();
+
+}
+
+
void initTest(void) { }
@@ -275,6 +451,24 @@ void initLibsheepyFT(CuTest *tc UNUSED) {
}
+void setStackLimitT(CuTest *tc UNUSED) {
+
+ int r;
+ i64 stackSize;
+
+ // set bigger stack
+ r = setStackLimit(16 * 1024 * 1024);
+ ck_assert(r!=0);
+ stackSize = getStackLimit();
+ ck_assert_int_eq(stackSize, 16 * 1024 * 1024);
+
+ // set unlimited stack
+ r = setStackLimit(-1);
+ ck_assert(r!=0);
+
+}
+
+
void getProgPathT(CuTest *tc UNUSED) {
const char *s;
@@ -362,6 +556,75 @@ void setModificationTimeT(CuTest *tc UNUSED) {
}
+void isReadableT(CuTest *tc UNUSED) {
+
+ bool r;
+
+ // check readable file
+ r = isReadable("sizeTest.null");
+ ck_assert(r);
+
+ // non readable file
+ r = isReadable("writeOnlyText.null");
+ ck_assert(!r);
+
+ // non existing file
+ r = isReadable("random.null");
+ ck_assert(!r);
+
+ // null
+ r = isReadable(null);
+ ck_assert(!r);
+
+}
+
+
+void isWritableT(CuTest *tc UNUSED) {
+
+ bool r;
+
+ // check writable file
+ r = isWritable("writeOnlyText.null");
+ ck_assert(r);
+
+ // non writable file
+ r = isWritable("sizeTest.null");
+ ck_assert(!r);
+
+ // non existing file
+ r = isWritable("random.null");
+ ck_assert(!r);
+
+ // null
+ r = isWritable(null);
+ ck_assert(!r);
+
+}
+
+
+void isExecutableT(CuTest *tc UNUSED) {
+
+ bool r;
+
+ // check executable file
+ r = isExecutable("runCuTest.sh");
+ ck_assert(r);
+
+ // non executable file
+ r = isExecutable("sizeTest.null");
+ ck_assert(!r);
+
+ // non existing file
+ r = isExecutable("random.null");
+ ck_assert(!r);
+
+ // null
+ r = isExecutable(null);
+ ck_assert(!r);
+
+}
+
+
void equalModificationTimesT(CuTest *tc UNUSED) {
// equal time
@@ -381,6 +644,147 @@ void equalModificationTimesT(CuTest *tc UNUSED) {
}
+void getCurrentUnixTimeT(CuTest *tc UNUSED) {
+
+ time_t t = getCurrentUnixTime();
+ ck_assert_int_ne(t, 0);
+
+}
+
+
+void strToUnixTimeT(CuTest *tc UNUSED) {
+
+ time_t t;
+
+ // convert
+ t = strToUnixTime("2020-05-15 13:59:58", "%Y-%m-%d %H:%M");
+ ck_assert_int_ne(t, -1);
+ // depends on local settings - ck_assert_int_eq(t, 1589547540);
+
+
+ // bad date or format
+ t = strToUnixTime("", "%Y-%m-%d %H:%M");
+ ck_assert_int_eq(t, -1);
+
+ // null date
+ t = strToUnixTime(null, "%Y-%m-%d %H:%M");
+ ck_assert_int_eq(t, -1);
+
+ // null format
+ t = strToUnixTime("", null);
+ ck_assert_int_eq(t, -1);
+
+}
+
+
+void timeToST(CuTest *tc UNUSED) {
+
+ char *s;
+
+ s = timeToS(0);
+ ck_assert_str_eq(s, "Thu Jan 1 01:00:00 1970");
+ free(s);
+
+ // bTimeToS
+ char b[80] = init0Var;
+ s = bTimeToS(b, 0);
+ ck_assert_ptr_ne(s, null);
+ ck_assert_str_eq(b, "Thu Jan 1 01:00:00 1970");
+
+ // bLTimeToS
+ char bL[50] = init0Var;
+ s = bLTimeToS(bL, sizeof(bL), 0);
+ ck_assert_ptr_ne(s, null);
+ ck_assert_str_eq(bL, "Thu Jan 1 01:00:00 1970");
+
+ // null parameter
+ s = bTimeToS(null, 0);
+ ck_assert_ptr_eq(s, null);
+ s = bLTimeToS(null, sizeof(bL), 0);
+ ck_assert_ptr_eq(s, null);
+
+}
+
+
+void timeToYMDST(CuTest *tc UNUSED) {
+
+ char *s;
+
+ s = timeToYMDS(0);
+ ck_assert_str_eq(s, "1970-01-01 01:00:00");
+ free(s);
+
+ // bTimeToYMDS
+ char b[80] = init0Var;
+ s = bTimeToYMDS(b, 0);
+ ck_assert_ptr_ne(s, null);
+ ck_assert_str_eq(b, "1970-01-01 01:00:00");
+
+ // bLTimeToYMDS
+ char bL[50] = init0Var;
+ s = bLTimeToYMDS(bL, sizeof(bL), 0);
+ ck_assert_ptr_ne(s, null);
+ ck_assert_str_eq(bL, "1970-01-01 01:00:00");
+
+ // null parameter
+ s = bTimeToYMDS(null, 0);
+ ck_assert_ptr_eq(s, null);
+ s = bLTimeToYMDS(null, sizeof(bL), 0);
+ ck_assert_ptr_eq(s, null);
+
+}
+
+
+void getCurrentDateT(CuTest *tc UNUSED) {
+
+ char *s;
+
+ s = getCurrentDate();
+ ck_assert_ptr_ne(s, null);
+ free(s);
+
+ char b[80] = init0Var;
+ s = bGetCurrentDate(b);
+ ck_assert_ptr_ne(s, null);
+
+ char bL[50] = init0Var;
+ s = bLGetCurrentDate(bL, sizeof(bL));
+ ck_assert_ptr_ne(s, null);
+
+ // null parameter
+ s = bGetCurrentDate(null);
+ ck_assert_ptr_eq(s, null);
+ s = bLGetCurrentDate(null, sizeof(bL));
+ ck_assert_ptr_eq(s, null);
+
+}
+
+
+void getCurrentDateYMDT(CuTest *tc UNUSED) {
+
+ char *s;
+
+ s = getCurrentDateYMD();
+ ck_assert_ptr_ne(s, null);
+ free(s);
+
+ char b[80] = init0Var;
+ s = bGetCurrentDateYMD(b);
+ ck_assert_ptr_ne(s, null);
+
+ char bL[50] = init0Var;
+ s = bLGetCurrentDateYMD(bL, sizeof(bL));
+ ck_assert_ptr_ne(s, null);
+
+ // null parameter
+ s = bGetCurrentDateYMD(null);
+ ck_assert_ptr_eq(s, null);
+ s = bLGetCurrentDateYMD(null, sizeof(bL));
+ ck_assert_ptr_eq(s, null);
+
+}
+
+
void shDirnameT(CuTest *tc UNUSED) {
char *s;
@@ -885,73 +1289,512 @@ void bLNormalizePathT(CuTest *tc UNUSED) {
}
-void timeToST(CuTest *tc UNUSED) {
+void relPathT(CuTest *tc UNUSED) {
- char *s = timeToS(0);
- ck_assert_str_eq(s, "Thu Jan 1 01:00:00 1970");
- free(s);
+ char *r;
+ char *cwd;
-}
+ // relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = relPath(cwd, null);
+ ck_assert_str_eq(r, "../sheepy");
+ free(r);
+ free(cwd);
+
+ // relative to cwd and path starts with cwd but is a different path
+ // (no slash between cwd and "../sheepy")
+ cwd = getCwd();
+ iAppendS(&cwd, "../sheepy");
+ r = relPath(cwd, null);
+ ck_assert_str_eq(r, "../src../sheepy");
+ free(r);
+ free(cwd);
+ // subdirectory to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ r = relPath(cwd, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ free(cwd);
-void chDirT(CuTest *tc UNUSED) {
+ // path = start
+ cwd = getCwd();
+ r = relPath(cwd, null);
+ ck_assert_str_eq(r, ".");
+ free(r);
+ free(cwd);
- // 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));
+ // start = root
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ r = relPath(cwd, "/../");
+ ck_assert_str_eq(r, cwd+1);
+ free(r);
+ free(cwd);
-}
+ // relative to start
+ r = relPath("/home/sheepy", "/home/test");
+ ck_assert_str_eq(r, "../sheepy");
+ free(r);
+ // path is relative (no leading slash), start is cwd
+ r = relPath("../src/sheepy", null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
-void isDirT(CuTest *tc UNUSED) {
+ // path is relative (no leading slash)
+ r = relPath("../test/sheepy", "/home/test");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
- // dir
- ck_assert(isDir("dirTest.null"));
+ // start is relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = relPath(cwd, "test/");
+ ck_assert_str_eq(r, "../../sheepy");
+ free(r);
+ free(cwd);
- // non existing dir
- ck_assert(!isDir("RandomNonExistingDir"));
+ // all relative paths
+ // the reference for path and start parameters is an arbitrary directory
+ r = relPath("sheepy", "shefjf/test/src/");
+ ck_assert_str_eq(r, "../../../sheepy");
+ free(r);
- // blank
- ck_assert(!isDir(" "));
+ r = relPath("sheepy", "shee");
+ ck_assert_str_eq(r, "../sheepy");
+ free(r);
- // NULL path
- ck_assert(!isDir(NULL));
+ // null path
+ r = relPath(null, null);
+ ck_assert_ptr_eq(r, null);
}
-void isLinkT(CuTest *tc UNUSED) {
+void iRelPathT(CuTest *tc UNUSED) {
- // link
- ck_assert(isLink("linkTest.null"));
+ char *r;
+ char *cwd;
- // not link
- ck_assert(!isLink("textTest.null"));
+ // relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = iRelPath(&cwd, null);
+ ck_assert_str_eq(r, "../sheepy");
+ free(r);
- // non existing link
- ck_assert(!isLink("RandomNonExistingDir"));
+ // relative to cwd and path starts with cwd but is a different path
+ // (no slash between cwd and "../sheepy")
+ cwd = getCwd();
+ iAppendS(&cwd, "../sheepy");
+ r = iRelPath(&cwd, null);
+ ck_assert_str_eq(r, "../src../sheepy");
+ free(r);
- // blank
- ck_assert(!isLink(" "));
+ // subdirectory to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ r = iRelPath(&cwd, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
- // NULL path
- ck_assert(!isLink(NULL));
+ // path = start
+ cwd = getCwd();
+ r = iRelPath(&cwd, null);
+ ck_assert_str_eq(r, ".");
+ free(r);
-}
+ // start = root
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ char *expected = strdup(cwd+1);
+ r = iRelPath(&cwd, "/../");
+ ck_assert_str_eq(r, expected);
+ free(r);
+ free(expected);
+ // relative to start
+ cwd = strdup("/home/sheepy");
+ r = iRelPath(&cwd, "/home/test");
+ ck_assert_str_eq(r, "../sheepy");
+ free(r);
-void fileExistsT(CuTest *tc UNUSED) {
+ // path is relative (no leading slash), start is cwd
+ cwd = strdup("../src/sheepy");
+ r = iRelPath(&cwd, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
- // detect existing file
- ck_assert(fileExists("libsheepyTest.c"));
+ // path is relative (no leading slash)
+ cwd = strdup("../test/sheepy");
+ r = iRelPath(&cwd, "/home/test");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // start is relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = iRelPath(&cwd, "test/");
+ ck_assert_str_eq(r, "../../sheepy");
+ free(r);
+
+ // all relative paths
+ // the reference for path and start parameters is an arbitrary directory
+ cwd = strdup("sheepy");
+ r = iRelPath(&cwd, "shefjf/test/src/");
+ ck_assert_str_eq(r, "../../../sheepy");
+ free(r);
+
+ cwd = strdup("sheepy");
+ r = iRelPath(&cwd, "shee");
+ ck_assert_str_eq(r, "../sheepy");
+ free(r);
+
+ // null path
+ cwd = null;
+ r = iRelPath(&cwd, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null var
+ r = iRelPath(null, null);
+ ck_assert_ptr_eq(r, null);
+
+}
+
+
+void bRelPathT(CuTest *tc UNUSED) {
+
+ char b[8192] = init0Var;
+ char *r;
+ char *cwd;
+
+ // relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = bRelPath(b, cwd, null);
+ ck_assert_str_eq(r, "../sheepy");
+ free(cwd);
+
+ // relative to cwd and path starts with cwd but is a different path
+ // (no slash between cwd and "../sheepy")
+ cwd = getCwd();
+ iAppendS(&cwd, "../sheepy");
+ r = bRelPath(b, cwd, null);
+ ck_assert_str_eq(r, "../src../sheepy");
+ free(cwd);
+
+ // subdirectory to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ r = bRelPath(b, cwd, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(cwd);
+
+ // path = start
+ cwd = getCwd();
+ r = bRelPath(b, cwd, null);
+ ck_assert_str_eq(r, ".");
+ free(cwd);
+
+ // start = root
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ r = bRelPath(b, cwd, "/../");
+ ck_assert_str_eq(r, cwd+1);
+ free(cwd);
+
+ // relative to start
+ r = bRelPath(b, "/home/sheepy", "/home/test");
+ ck_assert_str_eq(r, "../sheepy");
+
+ // path is relative (no leading slash), start is cwd
+ r = bRelPath(b, "../src/sheepy", null);
+ ck_assert_str_eq(r, "sheepy");
+
+ // path is relative (no leading slash)
+ r = bRelPath(b, "../test/sheepy", "/home/test");
+ ck_assert_str_eq(r, "sheepy");
+
+ // start is relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = bRelPath(b, cwd, "test/");
+ ck_assert_str_eq(r, "../../sheepy");
+ free(cwd);
+
+ // all relative paths
+ // the reference for path and start parameters is an arbitrary directory
+ r = bRelPath(b, "sheepy", "shefjf/test/src/");
+ ck_assert_str_eq(r, "../../../sheepy");
+
+ r = bRelPath(b, "sheepy", "shee");
+ ck_assert_str_eq(r, "../sheepy");
+
+ // null path
+ r = bRelPath(b, null, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bRelPath(null, "", null);
+ ck_assert_ptr_eq(r, null);
+
+
+}
+
+
+void bLRelPathT(CuTest *tc UNUSED) {
+
+ char b[8192] = init0Var;
+ char *r;
+ char *cwd;
+
+ // relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = bLRelPath(b, sizeof(b), cwd, null);
+ ck_assert_str_eq(r, "../sheepy");
+ free(cwd);
+
+ // relative to cwd and path starts with cwd but is a different path
+ // (no slash between cwd and "../sheepy")
+ cwd = getCwd();
+ iAppendS(&cwd, "../sheepy");
+ r = bLRelPath(b, sizeof(b), cwd, null);
+ ck_assert_str_eq(r, "../src../sheepy");
+ free(cwd);
+
+ // subdirectory to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ r = bLRelPath(b, sizeof(b), cwd, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(cwd);
+
+ // path = start
+ cwd = getCwd();
+ r = bLRelPath(b, sizeof(b), cwd, null);
+ ck_assert_str_eq(r, ".");
+ free(cwd);
+
+ // start = root
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ r = bLRelPath(b, sizeof(b), cwd, "/../");
+ ck_assert_str_eq(r, cwd+1);
+ free(cwd);
+
+ // relative to start
+ r = bLRelPath(b, sizeof(b), "/home/sheepy", "/home/test");
+ ck_assert_str_eq(r, "../sheepy");
+
+ // path is relative (no leading slash), start is cwd
+ r = bLRelPath(b, sizeof(b), "../src/sheepy", null);
+ ck_assert_str_eq(r, "sheepy");
+
+ // path is relative (no leading slash)
+ r = bLRelPath(b, sizeof(b), "../test/sheepy", "/home/test");
+ ck_assert_str_eq(r, "sheepy");
+
+ // start is relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = bLRelPath(b, sizeof(b), cwd, "test/");
+ ck_assert_str_eq(r, "../../sheepy");
+ free(cwd);
+
+ // all relative paths
+ // the reference for path and start parameters is an arbitrary directory
+ r = bLRelPath(b, sizeof(b), "sheepy", "shefjf/test/src/");
+ ck_assert_str_eq(r, "../../../sheepy");
+
+ r = bLRelPath(b, sizeof(b), "sheepy", "shee");
+ ck_assert_str_eq(r, "../sheepy");
+
+ // null path
+ r = bLRelPath(b, sizeof(b), null, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bLRelPath(null, sizeof(b), "", null);
+ ck_assert_ptr_eq(r, null);
+
+}
+
+
+void getHomePathT(CuTest *tc UNUSED) {
+
+ char *r = getHomePath();
+ ck_assert_ptr_ne(r, null);
+ ck_assert_int_eq(r[0], '/');
+ free(r);
+
+ char b[8192] = init0Var;
+ r = bGetHomePath(b);
+ ck_assert_ptr_ne(r, null);
+ ck_assert_int_eq(r[0], '/');
+
+ r = bLGetHomePath(b, sizeof(b));
+ ck_assert_ptr_ne(r, null);
+ ck_assert_int_eq(r[0], '/');
+
+ // buffer too short
+ char bL[2] = init0Var;
+ r = bLGetHomePath(bL, sizeof(bL));
+ ck_assert_ptr_eq(r, null);
+
+ const char *cR = getCHomePath();
+ ck_assert_ptr_ne(cR, null);
+ ck_assert_int_eq(cR[0], '/');
+
+}
+
+
+void getCwdT(CuTest *tc UNUSED) {
+
+ char *r = getCwd();
+ ck_assert_ptr_ne(r, null);
+ ck_assert_int_eq(r[0], '/');
+ free(r);
+
+ // buffer
+ char b[8192] = init0Var;
+ r = bLGetCwd(b, sizeof(b));
+ ck_assert_ptr_ne(r, null);
+ ck_assert_int_eq(r[0], '/');
+
+ // buffer too short
+ char bL[2] = init0Var;
+ r = bLGetCwd(bL, sizeof(bL));
+ ck_assert_ptr_eq(r, null);
+
+}
+
+
+void chDirT(CuTest *tc UNUSED) {
+
+ // 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 UNUSED) {
+
+ // dir
+ ck_assert(isDir("dirTest.null"));
+
+ // non existing dir
+ ck_assert(!isDir("RandomNonExistingDir"));
+
+ // blank
+ ck_assert(!isDir(" "));
+
+ // NULL path
+ ck_assert(!isDir(NULL));
+
+}
+
+
+void shReadlinkT(CuTest *tc UNUSED) {
+
+ char *r;
+
+ // read a link
+ r = shReadlink("linkTest.null");
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(r, "textTest.null");
+ free(r);
+
+ // not a link, regular file
+ r = shReadlink("textTest.null");
+ ck_assert_ptr_eq(r, null);
+
+ // non existing path
+ r = shReadlink("random");
+ ck_assert_ptr_eq(r, null);
+
+ // blank path
+ r = shReadlink(" ");
+ ck_assert_ptr_eq(r, null);
+
+ // null path
+ r = shReadlink(null);
+ ck_assert_ptr_eq(r, null);
+
+}
+
+
+void endlinkT(CuTest *tc UNUSED) {
+
+ char *r;
+
+ // read a link
+ r = endlink("linkTest.null");
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(r, "textTest.null");
+ free(r);
+
+ // read a link to absolute path
+ r = endlink("absLinkTest.null");
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(r, "/usr/local/bin/sheepy");
+ free(r);
+
+ // not a link, regular file
+ r = endlink("textTest.null");
+ ck_assert_ptr_eq(r, null);
+
+ // non existing path
+ r = endlink("random");
+ ck_assert_ptr_eq(r, null);
+
+ // blank path
+ r = endlink(" ");
+ ck_assert_ptr_eq(r, null);
+
+ // null path
+ r = endlink(null);
+ ck_assert_ptr_eq(r, null);
+
+}
+
+
+void isLinkT(CuTest *tc UNUSED) {
+
+ // 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 UNUSED) {
+
+ // detect existing file
+ ck_assert(fileExists("libsheepyTest.c"));
// non existing file
ck_assert(!fileExists("wefwepfk34.c"));
// folder
@@ -995,6 +1838,26 @@ void fileSizeT(CuTest *tc UNUSED) {
}
+void fileSizeFPT(CuTest *tc UNUSED) {
+
+ FILE *f;
+
+ // existing file
+ f = fopen("sizeTest.null", "r");
+ ck_assert_int_eq(fileSizeFP(f), 743);
+ fclose(f);
+
+ // empty file
+ f = fopen("chmodTest.null", "r");
+ ck_assert_int_eq(fileSizeFP(f), 0);
+ fclose(f);
+
+ // null file
+ ck_assert_int_eq(fileSizeFP(null), -1);
+
+}
+
+
void readFileToST(CuTest *tc UNUSED) {
char *l;
@@ -1026,6 +1889,31 @@ void readFileToST(CuTest *tc UNUSED) {
}
+void readStreamToST(CuTest *tc UNUSED) {
+
+ FILE *f;
+ char *l;
+
+ // text
+ f = fopen("textTest.null", "r");
+ l = readStreamToS(f);
+ ck_assert_str_eq(l, "LINE 1\nANOTHER line\n");
+ free(l);
+ fclose(f);
+
+ // empty text
+ f = fopen("chmodTest.null", "r");
+ l = readStreamToS(f);
+ ck_assert_str_eq(l, "");
+ free(l);
+ fclose(f);
+
+ // null file
+ ck_assert_ptr_eq(readStreamToS(null), null);
+
+}
+
+
void bReadFileToST(CuTest *tc UNUSED) {
char l[100];
@@ -1058,6 +1946,34 @@ void bReadFileToST(CuTest *tc UNUSED) {
}
+void bReadStreamToST(CuTest *tc UNUSED) {
+
+ FILE *f;
+ char l[1024] = init0Var;
+ char *r;
+
+ // text
+ f = fopen("textTest.null", "r");
+ r = bReadStreamToS(f, l);
+ ck_assert_str_eq(r, "LINE 1\nANOTHER line\n");
+ fclose(f);
+
+ // empty text
+ f = fopen("chmodTest.null", "r");
+ r = bReadStreamToS(f, l);
+ ck_assert_str_eq(r, "");
+ fclose(f);
+
+ // null dst
+ ck_assert_ptr_eq(bReadStreamToS(f, null), null);
+
+ // null file
+ ck_assert_ptr_eq(bReadStreamToS(null, l), null);
+
+
+}
+
+
void bLReadFileToST(CuTest *tc UNUSED) {
char l[100];
@@ -1099,6 +2015,45 @@ void bLReadFileToST(CuTest *tc UNUSED) {
}
+void bLReadStreamToST(CuTest *tc UNUSED) {
+
+ FILE *f;
+ char l[1024] = init0Var;
+ char *r;
+
+ // text
+ f = fopen("textTest.null", "r");
+ r = bLReadStreamToS(f, l, sizeof(l));
+ ck_assert_str_eq(r, "LINE 1\nANOTHER line\n");
+ fclose(f);
+
+ // shorter buffer
+ l[0] = 'a';
+ l[1] = 'a';
+ f = fopen("textTest.null", "r");
+ r = bLReadStreamToS(f, l, 2);
+ ck_assert_str_eq(r, "L");
+ fclose(f);
+
+ // empty text
+ f = fopen("chmodTest.null", "r");
+ r = bLReadStreamToS(f, l, sizeof(l));
+ ck_assert_str_eq(r, "");
+ fclose(f);
+
+ // dst size 0, no changes
+ r = bLReadStreamToS(f, l, 0);
+ ck_assert_str_eq(r, "");
+
+ // null dst
+ ck_assert_ptr_eq(bLReadStreamToS(f, null, sizeof(l)), null);
+
+ // null file
+ ck_assert_ptr_eq(bLReadStreamToS(null, l, sizeof(l)), null);
+
+}
+
+
void readFileT(CuTest *tc UNUSED) {
char *l;
@@ -1294,58 +2249,182 @@ void writeFileT(CuTest *tc UNUSED) {
}
-void walkDirT(CuTest *tc UNUSED) {
-
- 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 writeStreamST(CuTest *tc UNUSED) {
-}
+ char *l;
+ int r;
+ FILE *f;
+ // write textOutTest.null
+ l = readFileToS("textTest.null");
+ f = fopen("textOutTest.null", "w");
+ r = writeStreamS(f, l);
+ ck_assert(r);
+ free(l);
+ fclose(f);
-void walkDirDirT(CuTest *tc UNUSED) {
+ // check textOutTest.null
+ l = readFileToS("textOutTest.null");
+ ck_assert_uint_eq(strlen(l),20);
+ ck_assert_str_eq(l, "LINE 1\nANOTHER line\n");
- char **l;
+ // NULL file
+ ck_assert(!writeStreamS(NULL,l));
+ free(l);
+ // NULL string
+ ck_assert(!writeStreamS(f,NULL));
- // 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 UNUSED) {
+void writeLStreamT(CuTest *tc UNUSED) {
- char **l;
+ char *l;
+ int r;
+ FILE *f;
- // existing directory
- l = readDir("dirTest.null");
- ck_assert_uint_eq(listLengthS(l),1);
+ // write textOutTest.null
+ l = readFileToS("textTest.null");
+ f = fopen("textOutTest.null", "w");
+ r = writeLStream(f, l, strlen(l));
+ ck_assert(r);
+ free(l);
+ fclose(f);
+
+ // check textOutTest.null
+ l = readFileToS("textOutTest.null");
+ ck_assert_uint_eq(strlen(l),20);
+ ck_assert_str_eq(l, "LINE 1\nANOTHER line\n");
+
+ // NULL file
+ ck_assert(!writeLStream(NULL,l, strlen(l)));
+ free(l);
+ // NULL string
+ ck_assert(!writeLStream(f,NULL, 10));
+
+
+}
+
+
+void appendFileST(CuTest *tc UNUSED) {
+
+ char *l;
+ int r;
+
+ // write textOutTest.null
+ l = "appended line\n";
+ r = appendFileS("appendTextOutTest.null", l);
+ ck_assert(r);
+ l = "appended line 2\n";
+ r = appendFileS("appendTextOutTest.null", l);
+ ck_assert(r);
+
+ // check textOutTest.null
+ l = readFileToS("appendTextOutTest.null");
+ ck_assert_uint_eq(strlen(l),30);
+ ck_assert_str_eq(l, "appended line\nappended line 2\n");
+ if (fileExists("appendTextOutTest.null"))
+ rmAll("appendTextOutTest.null");
+ // blank file name
+ ck_assert(!appendFileS(" ",l));
+ // read only path
+ ck_assert(!appendFileS("/nonExistingFile",l));
+ // NULL path
+ ck_assert(!appendFileS(NULL,l));
+ free(l);
+ // NULL string
+ ck_assert(!appendFileS("a",NULL));
+
+
+}
+
+
+void appendFileT(CuTest *tc UNUSED) {
+
+ char *l;
+ int r;
+
+ // write textOutTest.null
+ l = "appended line\n";
+ r = appendFile("appendTextOutTest.null", l, strlen(l));
+ ck_assert(r);
+ l = "appended line 2\n";
+ r = appendFile("appendTextOutTest.null", l, strlen(l));
+ ck_assert(r);
+
+ // check textOutTest.null
+ l = readFileToS("appendTextOutTest.null");
+ ck_assert_uint_eq(strlen(l),30);
+ ck_assert_str_eq(l, "appended line\nappended line 2\n");
+ if (fileExists("appendTextOutTest.null"))
+ rmAll("appendTextOutTest.null");
+ // blank file name
+ ck_assert(!appendFile(" ",l, strlen(l)));
+ // read only path
+ ck_assert(!appendFile("/nonExistingFile",l, strlen(l)));
+ // NULL path
+ ck_assert(!appendFile(NULL,l, strlen(l)));
+ free(l);
+ // NULL string
+ ck_assert(!appendFile("a",NULL, 0));
+
+
+}
+
+
+void walkDirT(CuTest *tc UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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
@@ -1716,6 +2795,75 @@ void bLReadST(CuTest *tc UNUSED) {
}
+void readPasswordST(CuTest *tc UNUSED) {
+
+ char *r = readPasswordS();
+ ck_assert_str_eq(r, "*****");
+ free(r);
+
+}
+
+
+void zeroST(CuTest *tc UNUSED) {
+
+ bool r;
+
+ // clear string
+ char *s = strdup("zero");
+ r = zeroS(s);
+ ck_assert_str_eq(s, "");
+ ck_assert(r);
+ free(s);
+
+ // null string
+ r = zeroS(null);
+ ck_assert(!r);
+
+}
+
+
+void zeroBufT(CuTest *tc UNUSED) {
+
+ bool r;
+
+ // clear string
+ char *s = strdup("zero");
+ r = zeroBuf(s, strlen(s));
+ ck_assert_str_eq(s, "");
+ ck_assert(r);
+ free(s);
+
+ // 0 length
+ r = zeroBuf(s, 0);
+ ck_assert(!r);
+
+ // null string
+ r = zeroBuf(null, 1);
+ ck_assert(!r);
+
+}
+
+
+void memdupT(CuTest *tc UNUSED) {
+
+ char *r;
+
+ // clear string
+ r = memdup("memdup", sizeof("memdup"));
+ ck_assert_str_eq(r, "memdup");
+ free(r);
+
+ // 0 length
+ r = memdup("wef", 0);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = memdup(null, 1);
+ ck_assert_ptr_eq(r, null);
+
+}
+
+
void readEnterT(CuTest *tc UNUSED) {
readEnter();
@@ -1794,22 +2942,142 @@ void logNFreeT(CuTest *tc UNUSED) {
}
+void loghexT(CuTest *tc UNUSED) {
+
+ char *b = "abc";
+
+ // print hex
+ loghex(b, strlen(b)+1);
+
+ // size zero
+ loghex(b, 0);
+
+ // null buf
+ loghex(null, 1);
+
+}
+
+
+void toHexST(CuTest *tc UNUSED) {
+
+ char *b = "abc";
+ char *r;
+
+ // print hex
+ r = toHexS(b, strlen(b)+1);
+ ck_assert_str_eq(r, "0x61, 0x62, 0x63, 0x00");
+ free(r);
+
+ // size zero
+ r = toHexS(b, 0);
+ ck_assert_ptr_eq(r, null);
+
+ // null buf
+ r = toHexS(null, 1);
+ ck_assert_ptr_eq(r, null);
+
+
+}
+
+
+void toHexSepST(CuTest *tc UNUSED) {
+
+ char *b = "abc";
+ char *r;
+
+ // print hex
+ r = toHexSepS(b, strlen(b)+1, ",");
+ ck_assert_str_eq(r, "0x61,0x62,0x63,0x00");
+ free(r);
+
+ // size zero
+ r = toHexSepS(b, 0, "");
+ ck_assert_ptr_eq(r, null);
+
+ // null sep
+ r = toHexSepS(b, 1, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null buf
+ r = toHexSepS(null, 1, "");
+ ck_assert_ptr_eq(r, null);
+
+}
+
+
+void toHexHeadSepST(CuTest *tc UNUSED) {
+
+ char *b = "abc";
+ char *r;
+
+ // print hex
+ r = toHexHeadSepS(b, strlen(b)+1, "x", ",");
+ ck_assert_str_eq(r, "x61,x62,x63,x00");
+ free(r);
+
+ // size zero
+ r = toHexHeadSepS(b, 0, "", "");
+ ck_assert_ptr_eq(r, null);
+
+ // null head
+ r = toHexHeadSepS(b, 1, null, "");
+ ck_assert_ptr_eq(r, null);
+
+ // null sep
+ r = toHexHeadSepS(b, 1, "", null);
+ ck_assert_ptr_eq(r, null);
+
+ // null buf
+ r = toHexHeadSepS(null, 1, "", "");
+ ck_assert_ptr_eq(r, null);
+
+}
+
+
void strCpyT(CuTest *tc UNUSED) {
- char s[1024];
+ char s[1024] = init0Var;
+ char *r;
// copy string
- strCpy(s, "lib");
+ r = strCpy(s, "lib");
+ ck_assert_ptr_ne(r, null);
ck_assert_str_eq(s, "lib");
// NULL
s[0] = 0;
- strCpy(s, NULL);
+ r = strCpy(s, NULL);
+ ck_assert_ptr_eq(r, null);
ck_assert_str_eq(s, "");
ck_assert_ptr_eq(strCpy(NULL, "lib"), NULL);
}
+void strNCpyT(CuTest *tc UNUSED) {
+
+ char s[1024] = init0Var;
+ char *r;
+
+ // copy string
+ r = strNCpy(s, "lib", 4);
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(s, "lib");
+
+ // size 0
+ r = strNCpy(s, "AAA", 0);
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(s, "lib");
+
+ // NULL
+ s[0] = 0;
+ r = strNCpy(s, NULL, 10);
+ ck_assert_ptr_eq(r, null);
+ ck_assert_str_eq(s, "");
+ ck_assert_ptr_eq(strNCpy(NULL, "lib", 1), NULL);
+
+}
+
+
void strLCpyT(CuTest *tc UNUSED) {
char s[1024];
@@ -2047,6 +3315,7 @@ void bLCatST(CuTest *tc UNUSED) {
void formatST(CuTest *tc UNUSED) {
char *s;
+ char r[128] = init0Var;
// format
s = formatS("sheepy is num %d", 1);
@@ -2055,6 +3324,26 @@ void formatST(CuTest *tc UNUSED) {
// NULL
ck_assert_ptr_eq(formatS(NULL), NULL);
+ // bFormatS
+ s = bFormatS(r, "sheepy is num %d", 1);
+ ck_assert_str_eq(s, "sheepy is num 1");
+ // NULL
+ ck_assert_ptr_eq(bFormatS(r,NULL), NULL);
+ ck_assert_ptr_eq(bFormatS(NULL,"ojoi"), NULL);
+
+ // bLFormatS
+ s = bLFormatS(r, sizeof(r), "sheepy is num %d", 1);
+ ck_assert_str_eq(s, "sheepy is num 1");
+ // shorter buffer
+ s = bLFormatS(r, 7, "sheepy is num %d", 1);
+ ck_assert_str_eq(s, "sheepy");
+ // buffer size 0
+ s = bLFormatS(r, 0, "sheepy is num %d", 1);
+ ck_assert_str_eq(s, "sheepy");
+ // NULL
+ ck_assert_ptr_eq(bLFormatS(r,1,NULL), NULL);
+ ck_assert_ptr_eq(bLFormatS(NULL,1,"ojoi"), NULL);
+
}
@@ -2842,42 +4131,256 @@ void bLReplaceST(CuTest *tc UNUSED) {
}
-void replaceManyST(CuTest *tc UNUSED) {
+void icReplaceST(CuTest *tc UNUSED) {
+
+ char *s;
// replace string, multiple character new delimeter
- char *s = replaceManyS("#ee#ee#ad", "#","^^","ad","AD");
- ck_assert_str_eq(s, "^^ee^^ee^^AD");
+ s = icReplaceS("#EE#ee#ad", "ee","VV", 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
free(s);
- // replace string, empty new delimeter
- s = replaceManyS("#ee#ee#ad", "#","","ad","AD");
- ck_assert_str_eq(s, "eeeeAD");
+ // icReplaceCharSS
+ s = icReplaceCharSS("#EE#ee#ad", 'e',"V", 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
free(s);
- // not enough olds:news pairs
- s = replaceManyS("#ee#ee#ad", "#","","ad");
- ck_assert_str_eq(s, "eeeead");
+ // icReplaceSCharS
+ s = icReplaceSCharS("#EE#ee#ad", "e",'V', 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
free(s);
- // only 2 parameters
- s = replaceManyS("#ee#ee#ad", "#");
- ck_assert_ptr_eq(s, NULL);
+ // icReplaceCharCharS
+ s = icReplaceCharCharS("#EE#ee#ad", 'e','V', 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
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);
+
+ // replace string, multiple character old delimeter
+ s = icReplaceS("AA##ee##ee#", "##","|", 0);
+ ck_assert_str_eq(s, "AA|ee|ee#");
free(s);
- // empty string
- s = replaceManyS("", "##", "");
- ck_assert_str_eq(s, "");
+ // replace one time at the start of string
+ s = icReplaceS("#ee#ee#ad", "#","^^",1);
+ ck_assert_str_eq(s, "^^ee#ee#ad");
free(s);
- // empty string many pairs
- s = replaceManyS("", "##", "", "$$", "");
- ck_assert_str_eq(s, "");
+ // replace one time
+ s = icReplaceS("AA##ee##ee#", "##","|",1);
+ ck_assert_str_eq(s, "AA|ee##ee#");
free(s);
- // empty string many pairs empty olds
- s = replaceManyS("", "##", "", "", "");
- ck_assert_str_eq(s, "");
+ // NULL new delimiter, one time: same as empty delimiter
+ s = icReplaceS("AA##ee##ee#", "##",NULL,1);
+ ck_assert_str_eq(s, "AAee##ee#");
free(s);
- // empty string and NULL old delimiter
- s = replaceManyS("", NULL,"|");
+ // empty string
+ s = icReplaceS("", "##",NULL,1);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty old delimiter
+ ck_assert_ptr_eq(icReplaceS("qwe", "","|",1), NULL);
+ // NULL old delimiter
+ ck_assert_ptr_eq(icReplaceS("qwe", NULL,"|",1), NULL);
+ // NULL string
+ ck_assert_ptr_eq(icReplaceS(NULL, "##","|",1), NULL);
+ // empty old delimiter
+ ck_assert_ptr_eq(icReplaceS("AA##ee##ee#", "","|",1), NULL);
+
+
+}
+
+
+void iicReplaceST(CuTest *tc UNUSED) {
+
+ char *s;
+ // replace string, multiple character new delimeter
+ s = strdup("#EE#ee#ad");
+ iicReplaceS(&s, "EE","VV", 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
+ free(s);
+ // iicReplaceCharSS
+ s = strdup("#EE#ee#ad");
+ s = iicReplaceCharSS(&s, 'e',"V", 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
+ free(s);
+ // iicReplaceSCharS
+ s = strdup("#EE#ee#ad");
+ s = iicReplaceSCharS(&s, "e",'V', 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
+ free(s);
+ // iicReplaceCharCharS
+ s = strdup("#EE#ee#ad");
+ s = iicReplaceCharCharS(&s, 'e','V', 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
+ free(s);
+ // replace string, multiple character old delimeter
+ s = strdup("AA##ee##ee#");
+ iicReplaceS(&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");
+ iicReplaceS(&s, "#","^^",1);
+ ck_assert_str_eq(s, "^^ee#ee#ad");
+ free(s);
+ // replace one time
+ s = strdup("AA##ee##ee#");
+ iicReplaceS(&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#");
+ iicReplaceS(&s, "##",NULL,1);
+ ck_assert_str_eq(s, "AAee##ee#");
+ free(s);
+ // empty string
+ emptyS(s);
+ iicReplaceS(&s, "##",NULL,1);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty old delimiter
+ s = strdup("qwe");
+ iicReplaceS(&s, "","|",1);
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // NULL old delimiter
+ s = strdup("qwe");
+ iicReplaceS(&s, NULL,"|",1);
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // NULL string
+ s = NULL;
+ iicReplaceS(&s, "##","|",1);
+ // NULL var
+ iicReplaceS(NULL, "##","|",1);
+
+
+}
+
+
+void bicReplaceST(CuTest *tc UNUSED) {
+
+ char s[100];
+ // replace string, multiple character new delimeter
+ strcpy(s, "#EE#ee#ad");
+ bicReplaceS(s, "ee","VV", 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
+ // replace string, multiple character old delimeter
+ strcpy(s, "AA##ee##ee#");
+ bicReplaceS(s, "##","|", 0);
+ ck_assert_str_eq(s, "AA|ee|ee#");
+ // replace one time at the start of string
+ strcpy(s, "#ee#ee#ad");
+ bicReplaceS(s, "#","^^",1);
+ ck_assert_str_eq(s, "^^ee#ee#ad");
+ // replace one time
+ strcpy(s, "AA##ee##ee#");
+ bicReplaceS(s, "##","|",1);
+ ck_assert_str_eq(s, "AA|ee##ee#");
+ // NULL new delimiter, one time: same as empty delimiter
+ strcpy(s, "AA##ee##ee#");
+ bicReplaceS(s, "##",NULL,1);
+ ck_assert_str_eq(s, "AAee##ee#");
+ // empty string
+ bEmptyS(s);
+ bicReplaceS(s, "##",NULL,1);
+ ck_assert_str_eq(s, "");
+ // empty old delimiter
+ strcpy(s, "qwe");
+ bicReplaceS(s, "","|",1);
+ ck_assert_str_eq(s, "qwe");
+ // NULL old delimiter
+ strcpy(s, "qwe");
+ bicReplaceS(s, NULL,"|",1);
+ ck_assert_str_eq(s, "qwe");
+ // NULL var
+ ck_assert_ptr_eq(bicReplaceS(NULL, "##","|",1), NULL);
+
+
+}
+
+
+void bLicReplaceST(CuTest *tc UNUSED) {
+
+ char s[100];
+ // replace string, multiple character new delimeter
+ strcpy(s, "#ee#EE#ad");
+ bLicReplaceS(s, sizeof s, "ee","vv", 0);
+ ck_assert_str_eq(s, "#vv#vv#ad");
+ // shorter buffer
+ strcpy(s, "#ee#ee#ad");
+ bLicReplaceS(s, 5, "#","^^", 0);
+ ck_assert_str_eq(s, "^^ee");
+ // replace string, multiple character old delimeter
+ strcpy(s, "AA##ee##ee#");
+ bLicReplaceS(s, sizeof s, "##","|", 0);
+ 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 UNUSED) {
+
+ // 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
@@ -3096,75 +4599,333 @@ void bLReplaceManyST(CuTest *tc UNUSED) {
}
-void eqST(CuTest *tc UNUSED) {
-
- // 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 UNUSED) {
+void icReplaceManyST(CuTest *tc UNUSED) {
- // 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, ""));
+ // replace string, multiple character new delimeter
+ char *s = icReplaceManyS("#ee#ee#ad", "#","^^","AD","vv");
+ ck_assert_str_eq(s, "^^ee^^ee^^vv");
+ free(s);
+ // replace string, empty new delimeter
+ s = icReplaceManyS("#ee#ee#ad", "#","","ad","AD");
+ ck_assert_str_eq(s, "eeeeAD");
+ free(s);
+ // not enough olds:news pairs
+ s = icReplaceManyS("#ee#ee#ad", "#","","ad");
+ ck_assert_str_eq(s, "eeeead");
+ free(s);
+ // only 2 parameters
+ s = icReplaceManyS("#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 = icReplaceManyS("AA##ee##ee#", "##",NULL);
+ ck_assert_ptr_eq(s, NULL);
+ free(s);
+ // empty string
+ s = icReplaceManyS("", "##", "");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty string many pairs
+ s = icReplaceManyS("", "##", "", "$$", "");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty string many pairs empty olds
+ s = icReplaceManyS("", "##", "", "", "");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty string and NULL old delimiter
+ s = icReplaceManyS("", NULL,"|");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty string and NULL old delimiter not first - same as replace empty string
+ s = icReplaceManyS("","##","|", NULL,"|");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty old delimiter
+ ck_assert_ptr_eq(icReplaceManyS("AA##ee##ee#", "","|", "AA", "BB"), NULL);
+ // empty old delimiter not first
+ ck_assert_ptr_eq(icReplaceManyS("AA##ee##ee#", "##","|", "", "BB"), NULL);
// NULL string
- ck_assert(!eqCharS(0,"a"));
- ck_assert(!eqCharS('a', NULL));
-
-}
-
-
-void eqSCharT(CuTest *tc UNUSED) {
+ ck_assert_ptr_eq(icReplaceManyS(NULL, "##","|"), NULL);
+ // NULL string many pairs
+ ck_assert_ptr_eq(icReplaceManyS(NULL, "##","|", "$$", ""), NULL);
- // 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 UNUSED) {
+void iicReplaceManyST(CuTest *tc UNUSED) {
- // 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));
+ char *s;
+ // replace string, multiple character new delimeter
+ s = strdup("#ee#ee#ad");
+ iicReplaceManyS(&s, "#","^^","ad","vv");
+ ck_assert_str_eq(s, "^^ee^^ee^^vv");
+ free(s);
+ // replace string, empty new delimeter
+ s = strdup("#ee#ee#ad");
+ iicReplaceManyS(&s, "#","","ad","AD");
+ ck_assert_str_eq(s, "eeeeAD");
+ free(s);
+ // not enough olds:news pairs
+ s = strdup("#ee#ee#ad");
+ iicReplaceManyS(&s, "#","","ad");
+ ck_assert_str_eq(s, "eeeead");
+ free(s);
+ // only 2 parameters
+ // doesn't compile
+ /* s = strdup("#ee#ee#ad"); */
+ /* iicReplaceManyS(&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");
+ iicReplaceManyS(&s, "#", NULL);
+ ck_assert_str_eq(s, "#ee#ee#ad");
+ free(s);
+ // empty string
+ emptyS(s);
+ iicReplaceManyS(&s, "#", "");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty string many pairs
+ emptyS(s);
+ iicReplaceManyS(&s, "#", "", "%", "");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // many pairs empty olds
+ s = strdup("qw#e");
+ iicReplaceManyS(&s, "#", "", "", "");
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // NULL old delimiter
+ s = strdup("qw#e");
+ iicReplaceManyS(&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");
+ iicReplaceManyS(&s, "#","|", NULL, "");
+ ck_assert_str_eq(s, "qw|e");
+ free(s);
+ // empty old delimiter
+ s = strdup("qw#e");
+ iicReplaceManyS(&s, "","|", NULL, "");
+ ck_assert_str_eq(s, "qw#e");
+ free(s);
+ // empty old delimiter not first
+ s = strdup("qw#e");
+ iicReplaceManyS(&s, "#","|", "", "*");
+ ck_assert_str_eq(s, "qw|e");
+ free(s);
+ // NULL string
+ s = NULL;
+ iicReplaceManyS(&s, "#","|", "$", "*");
+ ck_assert_ptr_eq(s, NULL);
+ free(s);
+ // NULL var
+ iicReplaceManyS(NULL, "#","|", "$", "*");
+
+
+}
+
+
+void bicReplaceManyST(CuTest *tc UNUSED) {
+
+ char s[100];
+ // replace string, multiple character new delimeter
+ strcpy(s, "#ee#ee#ad");
+ bicReplaceManyS(s, "#","^^","AD","vv");
+ ck_assert_str_eq(s, "^^ee^^ee^^vv");
+ // replace string, empty new delimeter
+ strcpy(s, "#ee#ee#ad");
+ bicReplaceManyS(s, "#","","ad","AD");
+ ck_assert_str_eq(s, "eeeeAD");
+ // not enough olds:news pairs
+ strcpy(s, "#ee#ee#ad");
+ bicReplaceManyS(s, "#","","ad");
+ ck_assert_str_eq(s, "eeeead");
+ // only 2 parameters
+ // doesn't compile
+ /* strcpy(s, "#ee#ee#ad"); */
+ /* bicReplaceManyS(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");
+ bicReplaceManyS(s, "#", NULL);
+ ck_assert_str_eq(s, "#ee#ee#ad");
+ // empty string
+ bEmptyS(s);
+ bicReplaceManyS(s, "#", "");
+ ck_assert_str_eq(s, "");
+ // empty string many pairs
+ bEmptyS(s);
+ bicReplaceManyS(s, "#", "", "%", "");
+ ck_assert_str_eq(s, "");
+ // many pairs empty olds
+ strcpy(s, "qw#e");
+ bicReplaceManyS(s, "#", "", "", "");
+ ck_assert_str_eq(s, "qwe");
+ // NULL old delimiter
+ strcpy(s, "qw#e");
+ bicReplaceManyS(s, NULL, "");
+ ck_assert_str_eq(s, "qw#e");
+ // NULL old delimiter not first - same as replace empty string
+ strcpy(s, "qw#e");
+ bicReplaceManyS(s, "#","|", NULL, "");
+ ck_assert_str_eq(s, "qw|e");
+ // empty old delimiter
+ strcpy(s, "qw#e");
+ bicReplaceManyS(s, "","|", NULL, "");
+ ck_assert_str_eq(s, "qw#e");
+ // empty old delimiter not first
+ strcpy(s, "qw#e");
+ bicReplaceManyS(s, "#","|", "", "*");
+ ck_assert_str_eq(s, "qw|e");
+ // NULL var
+ ck_assert_ptr_eq(bicReplaceManyS(NULL, "#","|", "$", "*"), NULL);
+
+
+}
+
+
+void bLicReplaceManyST(CuTest *tc UNUSED) {
+
+ char s[100];
+ // replace string, multiple character new delimeter
+ strcpy(s, "#ee#ee#ad");
+ bLicReplaceManyS(s, sizeof s, "#","^^","AD","vv");
+ ck_assert_str_eq(s, "^^ee^^ee^^vv");
+ // shorter buffer
+ strcpy(s, "#ee#ee#ad");
+ bLicReplaceManyS(s, 5, "#","^^","ad","AD");
+ ck_assert_str_eq(s, "^^ee");
+ // replace string, empty new delimeter
+ strcpy(s, "#ee#ee#ad");
+ bLicReplaceManyS(s, sizeof s, "#","","ad","AD");
+ ck_assert_str_eq(s, "eeeeAD");
+ // not enough olds:news pairs
+ strcpy(s, "#ee#ee#ad");
+ bLicReplaceManyS(s, sizeof s, "#","","ad");
+ ck_assert_str_eq(s, "eeeead");
+ // only 2 parameters
+ // doesn't compile
+ /* strcpy(s, "#ee#ee#ad"); */
+ /* bLicReplaceManyS(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");
+ bLicReplaceManyS(s, sizeof s, "#", NULL);
+ ck_assert_str_eq(s, "#ee#ee#ad");
+ // empty string
+ bEmptyS(s);
+ bLicReplaceManyS(s, sizeof s, "#", "");
+ ck_assert_str_eq(s, "");
+ // empty string many pairs
+ bEmptyS(s);
+ bLicReplaceManyS(s, sizeof s, "#", "", "%", "");
+ ck_assert_str_eq(s, "");
+ // many pairs empty olds
+ strcpy(s, "qw#e");
+ bLicReplaceManyS(s, sizeof s, "#", "", "", "");
+ ck_assert_str_eq(s, "qwe");
+ // NULL old delimiter
+ strcpy(s, "qw#e");
+ bLicReplaceManyS(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");
+ bLicReplaceManyS(s, sizeof s, "#","|", NULL, "");
+ ck_assert_str_eq(s, "qw|e");
+ // empty old delimiter
+ strcpy(s, "qw#e");
+ bLicReplaceManyS(s, sizeof s, "","|", NULL, "");
+ ck_assert_str_eq(s, "qw#e");
+ // empty old delimiter not first
+ strcpy(s, "qw#e");
+ bLicReplaceManyS(s, sizeof s, "#","|", "", "*");
+ ck_assert_str_eq(s, "qw|e");
+ // size 0 - no change
+ bLicReplaceManyS(s, 0, "#","|", "", "*");
+ ck_assert_str_eq(s, "qw|e");
+ // NULL var
+ ck_assert_ptr_eq(bLicReplaceManyS(NULL, sizeof s, "#","|", "$", "*"), NULL);
+
+
+}
+
+
+void eqST(CuTest *tc UNUSED) {
+
+ // 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 UNUSED) {
+
+ // 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 UNUSED) {
+
+ // 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 UNUSED) {
+
+ // 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));
@@ -3300,41 +5061,335 @@ void countCharST(CuTest *tc UNUSED) {
}
-void isNumberT(CuTest *tc UNUSED) {
+void icEqST(CuTest *tc UNUSED) {
- // 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(""));
+ // identical strings
+ ck_assert(icEqS("SHEE", "shee"));
+ // different strings
+ ck_assert(!icEqS("shee", "SH"));
+ // empty strings
+ ck_assert(!icEqS("shee", ""));
+ ck_assert(!icEqS("", "SH"));
+ ck_assert(icEqS("", ""));
+ // NULL string
+ ck_assert(!icEqS(NULL,"a"));
+ ck_assert(!icEqS("a", NULL));
+
+
+}
+
+
+void icEqCharST(CuTest *tc UNUSED) {
+
+ // identical strings
+ ck_assert(icEqCharS('S', "s"));
+ // different strings
+ ck_assert(!icEqCharS('s', "SH"));
+ // empty strings
+ ck_assert(!icEqCharS('s', ""));
+ ck_assert(!icEqCharS(0, "SH"));
+ ck_assert(icEqCharS(0, ""));
+ // NULL string
+ ck_assert(!icEqCharS(0,"a"));
+ ck_assert(!icEqCharS('a', NULL));
+
+
+}
+
+
+void icEqSCharT(CuTest *tc UNUSED) {
+
+ // identical strings
+ ck_assert(icEqSChar("S", 's'));
+ // different strings
+ ck_assert(!icEqSChar("shee", 'S'));
+ // empty strings
+ ck_assert(!icEqSChar("shee", 0));
+ ck_assert(!icEqSChar("", 'S'));
+ ck_assert(icEqSChar("", 0));
+ // NULL string
+ ck_assert(!icEqSChar(NULL,'a'));
+ ck_assert(!eqS("a", 0));
+
+
+}
+
+
+void icEqIST(CuTest *tc UNUSED) {
+
+ // identical strings
+ ck_assert(icEqIS("AshEe|", "shee", 1));
+ ck_assert(icEqIS("AshEE", "shee", -4));
+ // string at index shorter than string2
+ ck_assert(!icEqIS("Ashee", "shee", 2));
+ // empty string
+ ck_assert(!icEqIS("", "shee", 0));
+ ck_assert(!icEqIS("Ashee", "", 0));
+ ck_assert(icEqIS("", "", 0));
+ // index mismatch
+ ck_assert(!icEqIS("Ashee", "shee", 0));
+ // index outside
+ ck_assert(!icEqIS("Ashee", "shee", 10));
+ ck_assert(!icEqIS("Ashee", "shee", -10));
+ // different strings
+ ck_assert(!icEqIS("shee", "Sg",0));
+ // NULL string
+ ck_assert(!icEqIS(NULL,"a", 0));
+ ck_assert(!icEqIS("a", NULL, 0));
+
+
+}
+
+
+void icEqICharST(CuTest *tc UNUSED) {
+
+ // identical strings
+ ck_assert(icEqICharS("ASHEE", 's', 1));
+ ck_assert(icEqICharS("Ashee", 's', -4));
+ // string at index shorter than string2
+ ck_assert(!icEqICharS("Ashee", 's', 2));
+ // empty string
+ ck_assert(!icEqICharS("", 's', 0));
+ ck_assert(!icEqICharS("Ashee", 0, 0));
+ ck_assert(icEqICharS("", 0, 0));
+ // index mismatch
+ ck_assert(!icEqICharS("Ashee", 's', 0));
+ // index outside
+ ck_assert(!icEqICharS("Ashee", 's', 10));
+ ck_assert(!icEqICharS("Ashee", 's', -10));
+ // different strings
+ ck_assert(!icEqICharS("shee", 'd',0));
+ // NULL string
+ ck_assert(!icEqICharS(NULL,'a', 0));
+ ck_assert(!icEqICharS("a", 0, 0));
+
+
+}
+
+
+void icStartsWithST(CuTest *tc UNUSED) {
+
+ // identical strings
+ ck_assert(icStartsWithS("SHEE", "shee"));
+ ck_assert(icStartsWithS("SHEEPY", "shee"));
+ // different strings
+ ck_assert(!icStartsWithS("shee", "aH"));
+ ck_assert(!icStartsWithS("shee", "sheep"));
+ ck_assert(!icStartsWithS("-shee", "shee"));
+ // NULL string
+ ck_assert(!icStartsWithS(NULL,"a"));
+ ck_assert(!icStartsWithS("a", NULL));
+
+
+}
+
+
+void icStartsWithCharST(CuTest *tc UNUSED) {
+
+ // identical strings
+ ck_assert(icStartsWithCharS("Shee", 's'));
+ ck_assert(icStartsWithCharS("Sheepy", 's'));
+ ck_assert(icStartsWithCharS("", 0));
+ // different strings
+ ck_assert(!icStartsWithCharS("shee", 'a'));
+ ck_assert(!icStartsWithCharS("-shee", 's'));
+ ck_assert(!icStartsWithCharS("", '0'));
+ // NULL string
+ ck_assert(!icStartsWithCharS(NULL,'a'));
+ ck_assert(!icStartsWithCharS("a", 0));
+
+
+}
+
+
+void icEndsWithST(CuTest *tc UNUSED) {
+
+ // identical strings
+ ck_assert(icEndsWithS("SHEE", "shee"));
+ ck_assert(icEndsWithS("SHEEPY", "eepy"));
+ // different strings
+ ck_assert(!icEndsWithS("shee", "SH"));
+ ck_assert(!icEndsWithS("shee", "sheep"));
+ ck_assert(!icEndsWithS("shee-", "shee"));
+ // NULL string
+ ck_assert(!icEndsWithS(NULL,"a"));
+ ck_assert(!icEndsWithS("a", NULL));
+
+
+}
+
+
+void icEndsWithCharST(CuTest *tc UNUSED) {
+
+ // identical strings
+ ck_assert(icEndsWithCharS("sheE", 'e'));
+ ck_assert(icEndsWithCharS("sheepY", 'y'));
+ ck_assert(icEndsWithCharS("", 0));
+ // different strings
+ ck_assert(!icEndsWithCharS("shee", 'R'));
+ ck_assert(!icEndsWithCharS("shee", 'p'));
+ ck_assert(!icEndsWithCharS("shee-", 'e'));
+ ck_assert(!icEndsWithCharS("", '0'));
+ // NULL string
+ ck_assert(!icEndsWithCharS(NULL,'a'));
+ ck_assert(!icEndsWithCharS("a", 0));
+
+
+}
+
+
+void icCountST(CuTest *tc UNUSED) {
+
+ // positive count
+ ck_assert_int_eq(icCountS("SHEE", "shee"), 1);
+ ck_assert_int_eq(icCountS("AAA AAA", "a"), 6);
+ ck_assert_int_eq(icCountS("AAA AAA", "aa"), 2);
+ // 0 count
+ ck_assert_int_eq(icCountS("shee", "eSH"), 0);
+ ck_assert_int_eq(icCountS("shee", "sheepy"), 0);
+ ck_assert_int_eq(icCountS("aaa aaa", "ab"), 0);
+ // NULL string
+ ck_assert_int_eq(icCountS(NULL,"a"), -1);
+ ck_assert_int_eq(icCountS("a", NULL), -1);
+
+
+}
+
+
+void icCountCharST(CuTest *tc UNUSED) {
+
+ // positive count
+ ck_assert_int_eq(icCountCharS("Shee", 's'), 1);
+ ck_assert_int_eq(icCountCharS("AAA aaa", 'a'), 6);
+ // 0 count
+ ck_assert_int_eq(icCountCharS("shee", '0'), 0);
+ ck_assert_int_eq(icCountCharS("shee", 'y'), 0);
+ ck_assert_int_eq(icCountCharS("aaa aaa", 'b'), 0);
+ // empty string
+ ck_assert_int_eq(icCountCharS("", 'a'), 0);
+ ck_assert_int_eq(icCountCharS("", 0), -1);
+ // NULL string
+ ck_assert_int_eq(icCountCharS(NULL,'a'), -1);
+ ck_assert_int_eq(icCountCharS("a", 0), -1);
+
+
+}
+
+
+void hasCtrlCharT(CuTest *tc UNUSED) {
+
+ // string with control char
+ ck_assert(hasCtrlChar("\tsheepy\n"));
+ // no control char
+ ck_assert(!hasCtrlChar("sheepy"));
+ // null string
+ ck_assert(!hasCtrlChar(null));
+
+
+}
+
+
+void stripCtrlST(CuTest *tc UNUSED) {
+
+ char *r;
+
+ // string with control char
+ r = stripCtrlS("\tsheepy\n");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ // no control char
+ r = stripCtrlS("sheepy");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ // null string
+ r = stripCtrlS(null);
+ ck_assert_ptr_eq(r, null);
+
+
+}
+
+
+void iStripCtrlST(CuTest *tc UNUSED) {
+
+ char *r, *s;
+
+ // string with control char
+ s = strdup("\tsheepy\n");
+ r = iStripCtrlS(&s);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ // no control char
+ s = strdup("sheepy");
+ r = iStripCtrlS(&s);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ // null string
+ s = null;
+ r = iStripCtrlS(&s);
+ ck_assert_ptr_eq(r, null);
+ r = iStripCtrlS(null);
+ ck_assert_ptr_eq(r, null);
+
+
+}
+
+
+void bStripCtrlST(CuTest *tc UNUSED) {
+
+ char *r;
+ char s[40];
+
+ // string with control char
+ strLCpy(s, sizeof(s), "\tsheepy\n");
+ r = bStripCtrlS(s);
+ ck_assert_str_eq(r, "sheepy");
+ // no control char
+ strLCpy(s, sizeof(s), "sheepy");
+ r = bStripCtrlS(s);
+ ck_assert_str_eq(r, "sheepy");
+ // null string
+ r = bStripCtrlS(null);
+ ck_assert_ptr_eq(r, null);
+
+
+}
+
+
+void isNumberT(CuTest *tc UNUSED) {
+
+ // 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));
@@ -3402,6 +5457,37 @@ void parseIntCharT(CuTest *tc UNUSED) {
}
+void parseI64T(CuTest *tc UNUSED) {
+
+ // number
+ ck_assert_int_eq(parseI64("123sheepy"), 123);
+ ck_assert_int_eq(parseI64("lib123sheepy"), 123);
+ ck_assert_int_eq(parseI64("-123"), -123);
+ // out of range - TODO check stderr
+ parseI64("999999999999999999999999999999999999999");
+ // string without number
+ ck_assert_int_eq(parseI64("sheepy"), 0);
+ // NULL string
+ ck_assert_int_eq(parseI64(NULL), 0);
+
+
+}
+
+
+void parseI64CharT(CuTest *tc UNUSED) {
+
+ // number
+ ck_assert_int_eq(parseI64Char('1'),1);
+ ck_assert_int_eq(parseI64Char('0'),0);
+ ck_assert_int_eq(parseI64Char('9'),9);
+ // not a number
+ ck_assert_int_eq(parseI64Char('a'),-1);
+ ck_assert_int_eq(parseI64Char(0),-1);
+
+
+}
+
+
void parseDoubleT(CuTest *tc UNUSED) {
// number
@@ -3418,6 +5504,36 @@ void parseDoubleT(CuTest *tc UNUSED) {
}
+void parseDoubleCharT(CuTest *tc UNUSED) {
+
+ // number
+ ck_assert_int_eq(parseDoubleChar('1'),1);
+ ck_assert_int_eq(parseDoubleChar('0'),0);
+ ck_assert_int_eq(parseDoubleChar('9'),9);
+ // not a number
+ ck_assert_int_eq(parseDoubleChar('a'),-1);
+ ck_assert_int_eq(parseDoubleChar(0),-1);
+
+}
+
+
+void parseHexT(CuTest *tc UNUSED) {
+
+ u64 r;
+
+ // hex to int
+ r = parseHex("0x04");
+ ck_assert_int_eq(r, 4);
+ r = parseHex("aoij0xaa");
+ ck_assert_int_eq(r, 170);
+ // null string
+ r = parseHex(null);
+ ck_assert_int_eq(r, 0);
+
+
+}
+
+
void intToST(CuTest *tc UNUSED) {
// number
@@ -3482,6 +5598,16 @@ void lenST(CuTest *tc UNUSED) {
}
+void sizeST(CuTest *tc UNUSED) {
+
+ // string
+ ck_assert_uint_eq(sizeS("sheepy"), 7);
+ // NULL string
+ ck_assert_uint_eq(sizeS(NULL), 0);
+
+}
+
+
void upperST(CuTest *tc UNUSED) {
// string
@@ -3908,3353 +6034,10057 @@ void bUniqST(CuTest *tc UNUSED) {
}
-void getST(CuTest *tc UNUSED) {
+void icUniqST(CuTest *tc UNUSED) {
+
+ char *s;
+
+ // uniquify
+ s = icUniqS("/qQqwd///", 'q');
+ ck_assert_str_eq(s, "/qwd///");
+ free(s);
+ // short string
+ s = icUniqS("?", '/');
+ ck_assert_str_eq(s, "?");
+ free(s);
+ // NULL
+ ck_assert_ptr_eq(icUniqS(NULL, '/'), NULL);
- // 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 UNUSED) {
+void iicUniqST(CuTest *tc UNUSED) {
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");
+ // uniquify
+ s = strdup("/qQqwd///");
+ ck_assert_str_eq(iicUniqS(&s, 'Q'), "/qwd///");
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, "");
+ // short string
+ s = strdup("?");
+ ck_assert_str_eq(iicUniqS(&s, '/'), "?");
free(s);
// NULL string
- setS(NULL, 0, 's');
+ s = NULL;
+ ck_assert_ptr_eq(iicUniqS(&s, '/'), NULL);
+ // NULL
+ ck_assert_ptr_eq(iicUniqS(NULL, '/'), NULL);
}
-void sliceST(CuTest *tc UNUSED) {
+void bicUniqST(CuTest *tc UNUSED) {
+
+ char s[100];
+
+ // uniquify
+ strcpy(s, "/qQqwd///");
+ ck_assert_str_eq(bicUniqS(s, 'q'), "/qwd///");
+ // short string
+ strcpy(s, "?");
+ ck_assert_str_eq(bicUniqS(s, '/'), "?");
+ // NULL
+ ck_assert_ptr_eq(bicUniqS(NULL, '/'), NULL);
- // 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 UNUSED) {
+void repeatST(CuTest *tc UNUSED) {
- 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);
+ char *r;
+
+ // repeat
+ r = repeatS("abc", 2);
+ ck_assert_str_eq(r, "abcabc");
+ free(r);
+
+ // empty string
+ r = repeatS("", 2);
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // once
+ r = repeatS("ab", 1);
+ ck_assert_str_eq(r, "ab");
+ free(r);
+
+ // 0 times
+ r = repeatS("jhgjgh", 0);
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // null string
+ r = repeatS(null, 2);
+ ck_assert_ptr_eq(r, null);
}
-void bSliceST(CuTest *tc UNUSED) {
+void iRepeatST(CuTest *tc UNUSED) {
- 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);
+ char *s, *r;
+
+ // repeat
+ s = strdup("abc");
+ r = iRepeatS(&s, 2);
+ ck_assert_ptr_eq(r, s);
+ ck_assert_str_eq(r, "abcabc");
+ free(r);
+
+ // empty string
+ s = strdup("");
+ r = iRepeatS(&s, 2);
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // once
+ s = strdup("ab");
+ r = iRepeatS(&s, 1);
+ ck_assert_str_eq(r, "ab");
+ free(r);
+
+ // 0 times
+ s = strdup("jhgjgh");
+ r = iRepeatS(&s, 0);
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // null string
+ s = null;
+ r = iRepeatS(&s, 2);
+ ck_assert_ptr_eq(r, null);
+
+ r = iRepeatS(null, 2);
+ ck_assert_ptr_eq(r, null);
}
-void insertST(CuTest *tc UNUSED) {
+void bRepeatST(CuTest *tc UNUSED) {
- char *s;
+ char s[128] = init0Var;
+ char *r;
+
+ // repeat
+ r = bRepeatS(s, "abc", 2);
+ ck_assert_str_eq(r, "abcabc");
- // 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);
+ r = bRepeatS(s, "", 2);
+ ck_assert_str_eq(r, "");
+ // once
+ r = bRepeatS(s, "ab", 1);
+ ck_assert_str_eq(r, "ab");
+
+ // 0 times
+ r = bRepeatS(s, "adsad", 0);
+ ck_assert_str_eq(r, "");
+
+ // null string
+ r = bRepeatS(s, null, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bRepeatS(null, "asd", 2);
+ ck_assert_ptr_eq(r, null);
}
-void insertNFreeST(CuTest *tc UNUSED) {
+void bLRepeatST(CuTest *tc UNUSED) {
- char *s, *a;
+ char s[6] = init0Var;
+ char *r;
+
+ // repeat
+ r = bLRepeatS(s, sizeof(s), "ab", 2);
+ ck_assert_str_eq(r, "abab");
- // 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);
+ r = bLRepeatS(s, sizeof(s), "", 2);
+ ck_assert_str_eq(r, "");
+
+ // once
+ r = bLRepeatS(s, sizeof(s), "ab", 1);
+ ck_assert_str_eq(r, "ab");
+
+ // 0 times
+ r = bLRepeatS(s, sizeof(s), "asdasd", 0);
+ ck_assert_str_eq(r, "");
+
+ // once bigger than buffer
+ r = bLRepeatS(s, sizeof(s), "123456", 1);
+ ck_assert_ptr_eq(r, null);
+
+ // dest size 0
+ r = bLRepeatS(s, 0, "123", 2);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = bLRepeatS(s, sizeof(s), null, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bLRepeatS(null, sizeof(s), "asd", 2);
+ ck_assert_ptr_eq(r, null);
}
-void iInsertST(CuTest *tc UNUSED) {
+void repeatCharST(CuTest *tc UNUSED) {
- char *s;
+ char *r;
- // 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");
+ // repeat
+ r = repeatCharS('$', 2);
+ ck_assert_str_eq(r, "$$");
+ free(r);
+
+ // once
+ r = repeatCharS('!', 1);
+ ck_assert_str_eq(r, "!");
+ free(r);
+
+ // 0 times
+ r = repeatCharS('0', 0);
+ ck_assert_str_eq(r, "");
+ free(r);
}
-void iInsertNFreeST(CuTest *tc UNUSED) {
+void bRepeatCharST(CuTest *tc UNUSED) {
- char *s, *a, *r;
+ char s[128] = init0Var;
+ char *r;
+
+ // repeat
+ r = bRepeatCharS(s, 'a', 2);
+ ck_assert_str_eq(r, "aa");
+
+ // once
+ r = bRepeatCharS(s, 'a', 1);
+ ck_assert_str_eq(r, "a");
+
+ // 0 times
+ r = bRepeatCharS(s, '0', 0);
+ ck_assert_str_eq(r, "");
+
+ // null dest
+ r = bRepeatCharS(null, 'd', 2);
+ ck_assert_ptr_eq(r, null);
- // 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 UNUSED) {
+void bLRepeatCharST(CuTest *tc UNUSED) {
- char s[100];
+ char s[6] = init0Var;
+ char *r;
+
+ // repeat
+ r = bLRepeatCharS(s, sizeof(s), '$', 4);
+ ck_assert_str_eq(r, "$$$$");
+
+ // once
+ r = bLRepeatCharS(s, sizeof(s), '+', 1);
+ ck_assert_str_eq(r, "+");
+
+ // 0 times
+ r = bLRepeatCharS(s, sizeof(s), '1', 0);
+ ck_assert_str_eq(r, "");
+
+ // once bigger than buffer
+ r = bLRepeatCharS(s, sizeof(s), '=', 6);
+ ck_assert_ptr_eq(r, null);
+
+ // dest size 0
+ r = bLRepeatCharS(s, 0, '/', 2);
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bLRepeatCharS(null, sizeof(s), '\'', 2);
+ ck_assert_ptr_eq(r, null);
- // 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 UNUSED) {
+void repeatLenST(CuTest *tc UNUSED) {
- char s[100];
+ ssize_t r;
+
+ r = repeatLenS("asd", 3);
+ ck_assert_int_eq(r, 9);
+
+ // 0 times
+ r = repeatLenS("asd", 0);
+ ck_assert_int_eq(r, 0);
- // 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);
+ r = repeatLenS("", 3);
+ ck_assert_int_eq(r, 0);
+
+ // null string
+ r = repeatLenS(null, 3);
+ ck_assert_int_eq(r, -1);
}
-void injectST(CuTest *tc UNUSED) {
+void ellipsisStartST(CuTest *tc UNUSED) {
- char *s;
+ char *r;
- // 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);
+ // no ellipsis
+ r = ellipsisStartS("sheepy", 10, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ r = ellipsisStartS("sheepy", 6, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // ellipsis
+ r = ellipsisStartS("sheepy", 5, "...");
+ ck_assert_str_eq(r, "...py");
+ free(r);
+
+ // ellipsis longer than target length
+ r = ellipsisStartS("sheepy", 5, "......");
+ ck_assert_str_eq(r, ".....");
+ free(r);
+
+ // empty ellipsis
+ r = ellipsisStartS("sheepy", 5, "");
+ ck_assert_str_eq(r, "heepy");
+ free(r);
+
+ // target length 0
+ r = ellipsisStartS("sheepy", 0, "...");
+ ck_assert_str_eq(r, "");
+ free(r);
+ // null string
+ ck_assert_ptr_eq(ellipsisStartS(null,4,""), null);
+ // null ellipsis
+ ck_assert_ptr_eq(ellipsisStartS("",4,null), null);
}
-void iInjectST(CuTest *tc UNUSED) {
+void iEllipsisStartST(CuTest *tc UNUSED) {
- char *s;
+ char *s, *r;
- // insert
+ // no ellipsis
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");
+ r = iEllipsisStartS(&s, 10, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ s = strdup("sheepy");
+ r = iEllipsisStartS(&s, 6, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // ellipsis
+ s = strdup("sheepy");
+ r = iEllipsisStartS(&s, 5, "...");
+ ck_assert_str_eq(r, "...py");
+ free(r);
+
+ // ellipsis longer than target length
+ s = strdup("sheepy");
+ r = iEllipsisStartS(&s, 5, "......");
+ ck_assert_str_eq(r, ".....");
+ free(r);
+
+ // empty ellipsis
+ s = strdup("sheepy");
+ r = iEllipsisStartS(&s, 5, "");
+ ck_assert_str_eq(r, "heepy");
+ free(r);
+
+ // target length 0
+ s = strdup("sheepy");
+ r = iEllipsisStartS(&s, 0, "...");
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // null string
+ s = null;
+ ck_assert_ptr_eq(iEllipsisStartS(&s,4,""), null);
+ ck_assert_ptr_eq(iEllipsisStartS(null,4,""), null);
+ // null ellipsis
+ s = strdup("sd");
+ ck_assert_ptr_eq(iEllipsisStartS(&s,4,null), null);
free(s);
- // NULL var
- iInjectS(NULL, 0, 's');
+
}
-void bInjectST(CuTest *tc UNUSED) {
+void bEllipsisStartST(CuTest *tc UNUSED) {
- char s[100];
+ char *r;
+ char dest[48];
+
+ // no ellipsis
+ r = bEllipsisStartS(dest, "sheepy", 10, "...");
+ ck_assert_str_eq(r, "sheepy");
+ r = bEllipsisStartS(dest, "sheepy", 6, "...");
+ ck_assert_str_eq(r, "sheepy");
+
+ // ellipsis
+ r = bEllipsisStartS(dest, "sheepy", 5, "...");
+ ck_assert_str_eq(r, "...py");
+
+ // ellipsis longer than target length
+ r = bEllipsisStartS(dest, "sheepy", 5, "......");
+ ck_assert_str_eq(r, ".....");
+
+ // empty ellipsis
+ r = bEllipsisStartS(dest, "sheepy", 5, "");
+ ck_assert_str_eq(r, "heepy");
+
+ // target length 0
+ r = bEllipsisStartS(dest, "sheepy", 0, "...");
+ ck_assert_str_eq(r, "");
+
+ // null string
+ ck_assert_ptr_eq(bEllipsisStartS(dest, null,4,""), null);
+ // null ellipsis
+ ck_assert_ptr_eq(bEllipsisStartS(dest, "",4,null), null);
+ // null dest
+ ck_assert_ptr_eq(bEllipsisStartS(null, "",4,""), null);
- // 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 UNUSED) {
+void bLEllipsisStartST(CuTest *tc UNUSED) {
- char s[100];
+ char *r;
+ char dest[6];
+
+ // no ellipsis
+ r = bLEllipsisStartS(dest, sizeof(dest), "sheepy", 10, "...");
+ ck_assert_str_eq(r, "sheep");
+ r = bLEllipsisStartS(dest, sizeof(dest), "sheepy", 6, "...");
+ ck_assert_str_eq(r, "sheep");
+
+ // ellipsis
+ r = bLEllipsisStartS(dest, sizeof(dest), "sheepy", 5, "...");
+ ck_assert_str_eq(r, "...py");
+
+ // ellipsis longer than target length
+ r = bLEllipsisStartS(dest, sizeof(dest), "sheepy", 5, "......");
+ ck_assert_str_eq(r, ".....");
+
+ // empty ellipsis
+ r = bLEllipsisStartS(dest, sizeof(dest), "sheepy", 5, "");
+ ck_assert_str_eq(r, "heepy");
+
+ // target length 0
+ r = bLEllipsisStartS(dest, sizeof(dest), "sheepy", 0, "...");
+ ck_assert_str_eq(r, "");
+
+ // dest size 0, dest unchanged
+ dest[0] = 'a';
+ dest[1] = 0;
+ r = bLEllipsisStartS(dest, 0, "sheepy", 5, "");
+ ck_assert_str_eq(r, "a");
+
+ // null string
+ ck_assert_ptr_eq(bLEllipsisStartS(dest, sizeof(dest), null,4,""), null);
+ // null ellipsis
+ ck_assert_ptr_eq(bLEllipsisStartS(dest, sizeof(dest), "",4,null), null);
+ // null dest
+ ck_assert_ptr_eq(bLEllipsisStartS(null, sizeof(dest), "",4,""), null);
- // 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 UNUSED) {
+void ellipsisStartCharST(CuTest *tc UNUSED) {
+
+ char *r;
+
+ // no ellipsis
+ r = ellipsisStartCharS("sheepy", 10, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ r = ellipsisStartCharS("sheepy", 6, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // ellipsis
+ r = ellipsisStartCharS("sheepy", 5, '-');
+ ck_assert_str_eq(r, "-eepy");
+ free(r);
+
+ // target length 0
+ r = ellipsisStartCharS("sheepy", 0, '-');
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // null string
+ ck_assert_ptr_eq(ellipsisStartCharS(null,4,'-'), null);
- // 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 UNUSED) {
+void iEllipsisStartCharST(CuTest *tc UNUSED) {
- char *s;
- // del
+ char *s, *r;
+
+ // no ellipsis
s = strdup("sheepy");
- iDelS(&s, 0,2);
- ck_assert_str_eq(s, "eepy");
- free(s);
- // negative index
+ r = iEllipsisStartCharS(&s, 10, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
s = strdup("sheepy");
- iDelS(&s, -2,0);
- ck_assert_str_eq(s, "shee");
- free(s);
- // positive and negative indexes
+ r = iEllipsisStartCharS(&s, 6, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // ellipsis
s = strdup("sheepy");
- iDelS(&s, 2,-2);
- ck_assert_str_eq(s, "shpy");
- free(s);
- // start = end
+ r = iEllipsisStartCharS(&s, 5, '-');
+ ck_assert_str_eq(r, "-eepy");
+ free(r);
+
+ // target length 0
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);
+ r = iEllipsisStartCharS(&s, 0, '-');
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // null string
+ s = null;
+ ck_assert_ptr_eq(iEllipsisStartCharS(&s,4,'-'), null);
+ ck_assert_ptr_eq(iEllipsisStartCharS(null,4,'-'), null);
+
}
-void bDelST(CuTest *tc UNUSED) {
+void bEllipsisStartCharST(CuTest *tc UNUSED) {
- 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);
+ char *r;
+ char dest[48];
-}
+ // no ellipsis
+ r = bEllipsisStartCharS(dest, "sheepy", 10, '-');
+ ck_assert_str_eq(r, "sheepy");
+ r = bEllipsisStartCharS(dest, "sheepy", 6, '-');
+ ck_assert_str_eq(r, "sheepy");
+ // ellipsis
+ r = bEllipsisStartCharS(dest, "sheepy", 5, '-');
+ ck_assert_str_eq(r, "-eepy");
-void findST(CuTest *tc UNUSED) {
+ // target length 0
+ r = bEllipsisStartCharS(dest, "sheepy", 0, '-');
+ ck_assert_str_eq(r, "");
+
+ // null string
+ ck_assert_ptr_eq(bEllipsisStartCharS(dest, null,4,'-'), null);
+ // null dest
+ ck_assert_ptr_eq(bEllipsisStartCharS(null, "",4,'-'), null);
- // 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 UNUSED) {
+void bLEllipsisStartCharST(CuTest *tc UNUSED) {
- // 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);
+ char *r;
+ char dest[6];
-}
+ // no ellipsis
+ r = bLEllipsisStartCharS(dest, sizeof(dest), "sheepy", 10, '-');
+ ck_assert_str_eq(r, "sheep");
+ r = bLEllipsisStartCharS(dest, sizeof(dest), "sheepy", 6, '-');
+ ck_assert_str_eq(r, "sheep");
+ // ellipsis
+ r = bLEllipsisStartCharS(dest, sizeof(dest), "sheepy", 5, '-');
+ ck_assert_str_eq(r, "-eepy");
-void hasST(CuTest *tc UNUSED) {
+ // target length 0
+ r = bLEllipsisStartCharS(dest, sizeof(dest), "sheepy", 0, '-');
+ ck_assert_str_eq(r, "");
+
+ // dest size 0, dest unchanged
+ dest[0] = 'a';
+ dest[1] = 0;
+ r = bLEllipsisStartCharS(dest, 0, "sheepy", 5, '-');
+ ck_assert_str_eq(r, "a");
+
+ // null string
+ ck_assert_ptr_eq(bLEllipsisStartCharS(dest, sizeof(dest), null,4,'-'), null);
+ // null dest
+ ck_assert_ptr_eq(bLEllipsisStartCharS(null, sizeof(dest), "",4,'-'), null);
- // 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 UNUSED) {
+void ellipsisLenST(CuTest *tc UNUSED) {
- // 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, '$'));
+ ssize_t r;
-}
+ // no ellipsis
+ r = ellipsisLenS("sheepy", 10, "...");
+ ck_assert_int_eq(r, 6);
+ r = ellipsisLenS("sheepy", 6, "...");
+ ck_assert_int_eq(r, 6);
+ // ellipsis
+ r = ellipsisLenS("sheepy", 5, "...");
+ ck_assert_int_eq(r, 5);
-void emptySFT(CuTest *tc UNUSED) {
+ // ellipsis longer than target length
+ r = ellipsisLenS("sheepy", 5, "......");
+ ck_assert_int_eq(r, 5);
- char *s;
+ // empty ellipsis
+ r = ellipsisLenS("sheepy", 5, "");
+ ck_assert_int_eq(r, 5);
+
+ // target length 0
+ r = ellipsisLenS("sheepy", 0, "...");
+ ck_assert_int_eq(r, 0);
+
+ // null string
+ ck_assert_int_eq(ellipsisLenS(null,4,""), -1);
+ // null ellipsis
+ ck_assert_int_eq(ellipsisLenS("",4,null), -1);
- // empty string
- s = emptySF();
- ck_assert(isEmptyS(s));
- free(s);
}
-void iEmptySFT(CuTest *tc UNUSED) {
+void ellipsisEndST(CuTest *tc UNUSED) {
- char *s;
+ char *r;
- // 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);
+ // no ellipsis
+ r = ellipsisEndS("sheepy", 10, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ r = ellipsisEndS("sheepy", 6, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
-}
+ // ellipsis
+ r = ellipsisEndS("sheepy", 5, "...");
+ ck_assert_str_eq(r, "sh...");
+ free(r);
+ // ellipsis longer than target length
+ r = ellipsisEndS("sheepy", 5, "......");
+ ck_assert_str_eq(r, ".....");
+ free(r);
-void isEmptyST(CuTest *tc UNUSED) {
+ // empty ellipsis
+ r = ellipsisEndS("sheepy", 5, "");
+ ck_assert_str_eq(r, "sheep");
+ free(r);
- char *s;
+ // target length 0
+ r = ellipsisEndS("sheepy", 0, "...");
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // null string
+ ck_assert_ptr_eq(ellipsisEndS(null,4,""), null);
+ // null ellipsis
+ ck_assert_ptr_eq(ellipsisEndS("",4,null), null);
- // 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 UNUSED) {
+void iEllipsisEndST(CuTest *tc UNUSED) {
- char *s;
+ char *s, *r;
- // 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));
+ // no ellipsis
+ s = strdup("sheepy");
+ r = iEllipsisEndS(&s, 10, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ s = strdup("sheepy");
+ r = iEllipsisEndS(&s, 6, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
-}
+ // ellipsis
+ s = strdup("sheepy");
+ r = iEllipsisEndS(&s, 5, "...");
+ ck_assert_str_eq(r, "sh...");
+ free(r);
+ // ellipsis longer than target length
+ s = strdup("sheepy");
+ r = iEllipsisEndS(&s, 5, "......");
+ ck_assert_str_eq(r, ".....");
+ free(r);
-void listEmptySFT(CuTest *tc UNUSED) {
+ // empty ellipsis
+ s = strdup("sheepy");
+ r = iEllipsisEndS(&s, 5, "");
+ ck_assert_str_eq(r, "sheep");
+ free(r);
- char **l;
+ // target length 0
+ s = strdup("sheepy");
+ r = iEllipsisEndS(&s, 0, "...");
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // null string
+ s = null;
+ ck_assert_ptr_eq(iEllipsisEndS(&s,4,""), null);
+ ck_assert_ptr_eq(iEllipsisEndS(null,4,""), null);
+ // null ellipsis
+ s = strdup("sd");
+ ck_assert_ptr_eq(iEllipsisEndS(&s,4,null), null);
+ free(s);
- // empty list
- l = listEmptySF();
- ck_assert(listIsEmptyS(l));
- listFreeS(l);
}
-void iListEmptySFT(CuTest *tc UNUSED) {
+void bEllipsisEndST(CuTest *tc UNUSED) {
- char **l;
+ char *r;
+ char dest[48];
- // 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);
+ // no ellipsis
+ r = bEllipsisEndS(dest, "sheepy", 10, "...");
+ ck_assert_str_eq(r, "sheepy");
+ r = bEllipsisEndS(dest, "sheepy", 6, "...");
+ ck_assert_str_eq(r, "sheepy");
-}
+ // ellipsis
+ r = bEllipsisEndS(dest, "sheepy", 5, "...");
+ ck_assert_str_eq(r, "sh...");
+ // ellipsis longer than target length
+ r = bEllipsisEndS(dest, "sheepy", 5, "......");
+ ck_assert_str_eq(r, ".....");
-void listIsEmptyST(CuTest *tc UNUSED) {
+ // empty ellipsis
+ r = bEllipsisEndS(dest, "sheepy", 5, "");
+ ck_assert_str_eq(r, "sheep");
- char **l;
+ // target length 0
+ r = bEllipsisEndS(dest, "sheepy", 0, "...");
+ ck_assert_str_eq(r, "");
+
+ // null string
+ ck_assert_ptr_eq(bEllipsisEndS(dest, null,4,""), null);
+ // null ellipsis
+ ck_assert_ptr_eq(bEllipsisEndS(dest, "",4,null), null);
+ // null dest
+ ck_assert_ptr_eq(bEllipsisEndS(null, "",4,""), null);
- // 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 UNUSED) {
+void bLEllipsisEndST(CuTest *tc UNUSED) {
- char **l;
+ char *r;
+ char dest[6];
- // 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));
+ // no ellipsis
+ r = bLEllipsisEndS(dest, sizeof(dest), "sheepy", 10, "...");
+ ck_assert_str_eq(r, "sheep");
+ r = bLEllipsisEndS(dest, sizeof(dest), "sheepy", 6, "...");
+ ck_assert_str_eq(r, "sheep");
-}
+ // ellipsis
+ r = bLEllipsisEndS(dest, sizeof(dest), "sheepy", 5, "...");
+ ck_assert_str_eq(r, "sh...");
+ // ellipsis longer than target length
+ r = bLEllipsisEndS(dest, sizeof(dest), "sheepy", 5, "......");
+ ck_assert_str_eq(r, ".....");
-void listLengthST(CuTest *tc UNUSED) {
-
- char **l;
+ // empty ellipsis
+ r = bLEllipsisEndS(dest, sizeof(dest), "sheepy", 4, "");
+ ck_assert_str_eq(r, "shee");
- // 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);
+ // target length 0
+ r = bLEllipsisEndS(dest, sizeof(dest), "sheepy", 0, "...");
+ ck_assert_str_eq(r, "");
+ // dest size 0, dest unchanged
+ dest[0] = 'a';
+ dest[1] = 0;
+ r = bLEllipsisEndS(dest, 0, "sheepy", 5, "");
+ ck_assert_str_eq(r, "a");
-}
+ // null string
+ ck_assert_ptr_eq(bLEllipsisEndS(dest, sizeof(dest), null,4,""), null);
+ // null ellipsis
+ ck_assert_ptr_eq(bLEllipsisEndS(dest, sizeof(dest), "",4,null), null);
+ // null dest
+ ck_assert_ptr_eq(bLEllipsisEndS(null, sizeof(dest), "",4,""), null);
-void listCreateST(CuTest *tc UNUSED) {
+}
- 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);
+void ellipsisEndCharST(CuTest *tc UNUSED) {
- // NULL first element
- ck_assert_ptr_eq(listCreateS(NULL, "sheepy"), NULL);
+ char *r;
-}
+ // no ellipsis
+ r = ellipsisEndCharS("sheepy", 10, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ r = ellipsisEndCharS("sheepy", 6, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ // ellipsis
+ r = ellipsisEndCharS("sheepy", 5, '-');
+ ck_assert_str_eq(r, "shee-");
+ free(r);
-void listFromArrayST(CuTest *tc UNUSED) {
+ // target length 0
+ r = ellipsisEndCharS("sheepy", 0, '-');
+ ck_assert_str_eq(r, "");
+ free(r);
- char **l = NULL;
- char *array[] = {"1", "22", "333"};
- char *arrayNULL[] = {"1", NULL, "333"};
+ // null string
+ ck_assert_ptr_eq(ellipsisEndCharS(null,4,'-'), null);
- // 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 UNUSED) {
-
- char **l = NULL;
+void iEllipsisEndCharST(CuTest *tc UNUSED) {
- // 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);
+ char *s, *r;
-}
+ // no ellipsis
+ s = strdup("sheepy");
+ r = iEllipsisEndCharS(&s, 10, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ s = strdup("sheepy");
+ r = iEllipsisEndCharS(&s, 6, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ // ellipsis
+ s = strdup("sheepy");
+ r = iEllipsisEndCharS(&s, 5, '-');
+ ck_assert_str_eq(r, "shee-");
+ free(r);
-void iListPushST(CuTest *tc UNUSED) {
+ // target length 0
+ s = strdup("sheepy");
+ r = iEllipsisEndCharS(&s, 0, '-');
+ ck_assert_str_eq(r, "");
+ free(r);
- char **l = NULL;
- char *s;
+ // null string
+ s = null;
+ ck_assert_ptr_eq(iEllipsisEndCharS(&s,4,'-'), null);
+ ck_assert_ptr_eq(iEllipsisEndCharS(null,4,'-'), null);
- // 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 UNUSED) {
-
- char **l = NULL;
- char *s;
+void bEllipsisEndCharST(CuTest *tc UNUSED) {
- // 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);
+ char *r;
+ char dest[48];
-}
+ // no ellipsis
+ r = bEllipsisEndCharS(dest, "sheepy", 10, '-');
+ ck_assert_str_eq(r, "sheepy");
+ r = bEllipsisEndCharS(dest, "sheepy", 6, '-');
+ ck_assert_str_eq(r, "sheepy");
+ // ellipsis
+ r = bEllipsisEndCharS(dest, "sheepy", 5, '-');
+ ck_assert_str_eq(r, "shee-");
-void listPrependST(CuTest *tc UNUSED) {
+ // target length 0
+ r = bEllipsisEndCharS(dest, "sheepy", 0, '-');
+ ck_assert_str_eq(r, "");
- char **l = NULL;
+ // null string
+ ck_assert_ptr_eq(bEllipsisEndCharS(dest, null,4,'-'), null);
+ // null dest
+ ck_assert_ptr_eq(bEllipsisEndCharS(null, "",4,'-'), 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 UNUSED) {
+void bLEllipsisEndCharST(CuTest *tc UNUSED) {
- char **l = NULL;
- char *s;
+ char *r;
+ char dest[6];
- // 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);
+ // no ellipsis
+ r = bLEllipsisEndCharS(dest, sizeof(dest), "sheepy", 10, '-');
+ ck_assert_str_eq(r, "sheep");
+ r = bLEllipsisEndCharS(dest, sizeof(dest), "sheepy", 6, '-');
+ ck_assert_str_eq(r, "sheep");
-}
+ // ellipsis
+ r = bLEllipsisEndCharS(dest, sizeof(dest), "sheepy", 5, '-');
+ ck_assert_str_eq(r, "shee-");
+ // target length 0
+ r = bLEllipsisEndCharS(dest, sizeof(dest), "sheepy", 0, '-');
+ ck_assert_str_eq(r, "");
-void listDequeueST(CuTest *tc UNUSED) {
+ // dest size 0, dest unchanged
+ dest[0] = 'a';
+ dest[1] = 0;
+ r = bLEllipsisEndCharS(dest, 0, "sheepy", 5, '-');
+ ck_assert_str_eq(r, "a");
- char **l = NULL;
- char *s;
+ // null string
+ ck_assert_ptr_eq(bLEllipsisEndCharS(dest, sizeof(dest), null,4,'-'), null);
+ // null dest
+ ck_assert_ptr_eq(bLEllipsisEndCharS(null, sizeof(dest), "",4,'-'), null);
- // 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 UNUSED) {
+void padStartST(CuTest *tc UNUSED) {
- // 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);
+ char *r;
-}
+ // pad string
+ r = padStartS("sheepy", 10, ">>>");
+ ck_assert_str_eq(r, ">>>>sheepy");
+ free(r);
+ r = padStartS("sheepy", 7, ">>>");
+ ck_assert_str_eq(r, ">sheepy");
+ free(r);
-void listFreeManyST(CuTest *tc UNUSED) {
+ // string bigger than target length
+ r = padStartS("sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
- // not possible to know if a pointer is already freed
- char **l1 = listCreateS("we","sd");
- char **l2 = listEmptySF();
- listFreeManyS(l1, l2);
+ // empty pad string
+ r = padStartS("sheepy", 10, "");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // null pad string
+ r = padStartS("sheepy", 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ r = padStartS("sheepy", 10, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = padStartS(null, 4, "q");
+ ck_assert_ptr_eq(r, null);
}
-void listPrintST(CuTest *tc UNUSED) {
+void iPadStartST(CuTest *tc UNUSED) {
- char **l;
+ char *s, *r;
- // print text
- l = readText("textTest.null");
- // TODO check stdout
- //listPrintS(l);
- listFreeS(l);
- // NULL list
- listPrintS(NULL);
+ // pad string
+ s = strdup("sheepy");
+ r = iPadStartS(&s, 10, ">>>");
+ ck_assert_str_eq(r, ">>>>sheepy");
+ free(r);
-}
+ s = strdup("sheepy");
+ r = iPadStartS(&s, 7, ">>>");
+ ck_assert_str_eq(r, ">sheepy");
+ free(r);
+ // string bigger than target length
+ s = strdup("sheepy");
+ r = iPadStartS(&s, 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
-void listForEachT(CuTest *tc UNUSED) {
+ // empty pad string
+ s = strdup("sheepy");
+ r = iPadStartS(&s, 10, "");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
- char **l = NULL;
- char **l2 = NULL;
+ // null pad string
+ s = strdup("sheepy");
+ r = iPadStartS(&s, 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ s = strdup("sheepy");
+ r = iPadStartS(&s, 10, null);
+ ck_assert_ptr_eq(r, null);
+ free(s);
+
+ // null string
+ s = null;
+ r = iPadStartS(&s, 4, "q");
+ ck_assert_ptr_eq(r, null);
+ r = iPadStartS(null, 4, "q");
+ ck_assert_ptr_eq(r, 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 UNUSED) {
+void bPadStartST(CuTest *tc UNUSED) {
- char **l = NULL;
- char **l2 = NULL;
+ char *r;
+ char b[48];
- // 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);
+ // pad string
+ r = bPadStartS(b, "sheepy", 10, ">>>");
+ ck_assert_str_eq(r, ">>>>sheepy");
-}
+ r = bPadStartS(b, "sheepy", 7, ">>>");
+ ck_assert_str_eq(r, ">sheepy");
+ // string bigger than target length
+ r = bPadStartS(b, "sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
-void listSortST(CuTest *tc UNUSED) {
+ // empty pad string
+ r = bPadStartS(b, "sheepy", 10, "");
+ ck_assert_str_eq(r, "sheepy");
- char **l = NULL;
- char **l2;
+ // null pad string
+ r = bPadStartS(b, "sheepy", 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ r = bPadStartS(b, "sheepy", 10, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = bPadStartS(b, null, 4, "q");
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bPadStartS(null, "d", 4, "q");
+ ck_assert_ptr_eq(r, null);
- // 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 UNUSED) {
+void bLPadStartST(CuTest *tc UNUSED) {
- char **l = NULL;
+ char *r;
+ char b[48];
- // 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);
+ // pad string
+ r = bLPadStartS(b, sizeof(b), "sheepy", 10, ">>>");
+ ck_assert_str_eq(r, ">>>>sheepy");
+ r = bLPadStartS(b, sizeof(b), "sheepy", 7, ">>>");
+ ck_assert_str_eq(r, ">sheepy");
+ // smaller dest size
+ r = bLPadStartS(b, 4, "sheepy", 7, ">>>");
+ ck_assert_str_eq(r, ">sh");
-}
+ // string bigger than target length
+ r = bLPadStartS(b, sizeof(b), "sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
+ // smaller dest size
+ r = bLPadStartS(b, 4, "sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "she");
+ // empty pad string
+ r = bLPadStartS(b, sizeof(b), "sheepy", 10, "");
+ ck_assert_str_eq(r, "sheepy");
+ // smaller dest size
+ r = bLPadStartS(b, 4, "sheepy", 10, "");
+ ck_assert_str_eq(r, "she");
-void readTextT(CuTest *tc UNUSED) {
- char **l;
+ // null pad string
+ r = bLPadStartS(b, sizeof(b), "sheepy", 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ r = bLPadStartS(b, sizeof(b), "sheepy", 10, null);
+ ck_assert_ptr_eq(r, null);
- // 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);
+ // null string
+ r = bLPadStartS(b, sizeof(b), null, 4, "q");
+ ck_assert_ptr_eq(r, null);
-}
+ // null dest
+ r = bLPadStartS(null, sizeof(b), "d", 4, "q");
+ ck_assert_ptr_eq(r, null);
-void readStreamT(CuTest *tc UNUSED) {
+}
- 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 padStartCharST(CuTest *tc UNUSED) {
-}
+ char *r;
+ // pad string
+ r = padStartCharS("sheepy", 10, '>');
+ ck_assert_str_eq(r, ">>>>sheepy");
+ free(r);
-void writeTextT(CuTest *tc UNUSED) {
+ r = padStartCharS("sheepy", 7, '>');
+ ck_assert_str_eq(r, ">sheepy");
+ free(r);
- char **l;
- bool r;
+ // string bigger than target length
+ r = padStartCharS("sheepy", 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
- // write textOutTest.null
- l = readText("textTest.null");
- r = writeText("textOutTest.null", l);
- ck_assert(r);
- listFreeS(l);
+ // null string
+ r = padStartCharS(null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
- // 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 UNUSED) {
+void iPadStartCharST(CuTest *tc UNUSED) {
- char **l;
- FILE *fp;
- bool r;
+ char *s, *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);
+ // pad string
+ s = strdup("sheepy");
+ r = iPadStartCharS(&s, 10, '>');
+ ck_assert_str_eq(r, ">>>>sheepy");
+ free(r);
- // 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);
+ s = strdup("sheepy");
+ r = iPadStartCharS(&s, 7, '>');
+ ck_assert_str_eq(r, ">sheepy");
+ free(r);
-}
+ // string bigger than target length
+ s = strdup("sheepy");
+ r = iPadStartCharS(&s, 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ // null string
+ s = null;
+ r = iPadStartCharS(&s, 4, 'q');
+ ck_assert_ptr_eq(r, null);
+ r = iPadStartCharS(null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
-void appendTextT(CuTest *tc UNUSED) {
- 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 bPadStartCharST(CuTest *tc UNUSED) {
-}
+ char *r;
+ char b[48];
+ // pad string
+ r = bPadStartCharS(b, "sheepy", 10, '>');
+ ck_assert_str_eq(r, ">>>>sheepy");
-void listGetST(CuTest *tc UNUSED) {
+ r = bPadStartCharS(b, "sheepy", 7, '>');
+ ck_assert_str_eq(r, ">sheepy");
- char **l = NULL;
+ // string bigger than target length
+ r = bPadStartCharS(b, "sheepy", 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+
+ // null string
+ r = bPadStartCharS(b, null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bPadStartCharS(null, "d", 4, 'q');
+ ck_assert_ptr_eq(r, 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 UNUSED) {
+void bLPadStartCharST(CuTest *tc UNUSED) {
- char **l = NULL;
+ char *r;
+ char b[48];
+
+ // pad string
+ r = bLPadStartCharS(b, sizeof(b), "sheepy", 10, '>');
+ ck_assert_str_eq(r, ">>>>sheepy");
+ r = bLPadStartCharS(b, sizeof(b), "sheepy", 7, '>');
+ ck_assert_str_eq(r, ">sheepy");
+ // smaller dest size
+ r = bLPadStartCharS(b, 4, "sheepy", 7, '>');
+ ck_assert_str_eq(r, ">sh");
+
+ // string bigger than target length
+ r = bLPadStartCharS(b, sizeof(b), "sheepy", 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+ // smaller dest size
+ r = bLPadStartCharS(b, 4, "sheepy", 4, '>');
+ ck_assert_str_eq(r, "she");
+
+ // null string
+ r = bLPadStartCharS(b, sizeof(b), null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bLPadStartCharS(null, sizeof(b), "d", 4, 'q');
+ ck_assert_ptr_eq(r, 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 UNUSED) {
+void padStartLenST(CuTest *tc UNUSED) {
- char **l = NULL;
+ ssize_t r;
- // 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);
+ // pad string
+ r = padStartLenS("sheepy", 10, ">>>");
+ ck_assert_int_eq(r, 10);
-}
+ r = padStartLenS("sheepy", 7, ">>>");
+ ck_assert_int_eq(r, 7);
+ // string bigger than target length
+ r = padStartLenS("sheepy", 4, ">>>");
+ ck_assert_int_eq(r, 6);
-void iListSetST(CuTest *tc UNUSED) {
+ // empty pad string
+ r = padStartLenS("sheepy", 10, "");
+ ck_assert_int_eq(r, 6);
- char **l = NULL;
- char *s;
+ // null pad string
+ r = padStartLenS("sheepy", 4, null);
+ ck_assert_int_eq(r, 6);
+ r = padStartLenS("sheepy", 10, null);
+ ck_assert_int_eq(r, -1);
+
+ // null string
+ r = padStartLenS(null, 4, "q");
+ ck_assert_int_eq(r, -1);
- // 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 UNUSED) {
+void padEndST(CuTest *tc UNUSED) {
- // 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);
+ char *r;
-}
+ // pad string
+ r = padEndS("sheepy", 10, ">>>");
+ ck_assert_str_eq(r, "sheepy>>>>");
+ free(r);
+
+ r = padEndS("sheepy", 7, ">>>");
+ ck_assert_str_eq(r, "sheepy>");
+ free(r);
+ // string bigger than target length
+ r = padEndS("sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
-void splitT(CuTest *tc UNUSED) {
+ // empty pad string
+ r = padEndS("sheepy", 10, "");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
- char **l;
+ // null pad string
+ r = padEndS("sheepy", 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ r = padEndS("sheepy", 10, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = padEndS(null, 4, "q");
+ ck_assert_ptr_eq(r, null);
- // 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 UNUSED) {
+void iPadEndST(CuTest *tc UNUSED) {
- char **l;
- char *s;
+ char *s, *r;
- // 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);
+ // pad string
+ s = strdup("sheepy");
+ r = iPadEndS(&s, 10, ">>>");
+ ck_assert_str_eq(r, "sheepy>>>>");
+ free(r);
+
+ s = strdup("sheepy");
+ r = iPadEndS(&s, 7, ">>>");
+ ck_assert_str_eq(r, "sheepy>");
+ free(r);
+
+ // string bigger than target length
+ s = strdup("sheepy");
+ r = iPadEndS(&s, 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // empty pad string
+ s = strdup("sheepy");
+ r = iPadEndS(&s, 10, "");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // null pad string
+ s = strdup("sheepy");
+ r = iPadEndS(&s, 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ s = strdup("sheepy");
+ r = iPadEndS(&s, 10, null);
+ ck_assert_ptr_eq(r, null);
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);
+
+ // null string
+ s = null;
+ r = iPadEndS(&s, 4, "q");
+ ck_assert_ptr_eq(r, null);
+ r = iPadEndS(null, 4, "q");
+ ck_assert_ptr_eq(r, null);
+
}
-void bJoinT(CuTest *tc UNUSED) {
+void bPadEndST(CuTest *tc UNUSED) {
- char **l;
- char s[100];
+ char *r;
+ char b[48];
- // 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);
+ // pad string
+ r = bPadEndS(b, "sheepy", 10, ">>>");
+ ck_assert_str_eq(r, "sheepy>>>>");
-}
+ r = bPadEndS(b, "sheepy", 7, ">>>");
+ ck_assert_str_eq(r, "sheepy>");
+ // string bigger than target length
+ r = bPadEndS(b, "sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
-void bLJoinT(CuTest *tc UNUSED) {
+ // empty pad string
+ r = bPadEndS(b, "sheepy", 10, "");
+ ck_assert_str_eq(r, "sheepy");
- char **l;
- char s[100];
+ // null pad string
+ r = bPadEndS(b, "sheepy", 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ r = bPadEndS(b, "sheepy", 10, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = bPadEndS(b, null, 4, "q");
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bPadEndS(null, "d", 4, "q");
+ ck_assert_ptr_eq(r, null);
- // 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 UNUSED) {
+void bLPadEndST(CuTest *tc UNUSED) {
- char **l;
+ char *r;
+ char b[48];
- // 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);
+ // pad string
+ r = bLPadEndS(b, sizeof(b), "sheepy", 10, ">>>");
+ ck_assert_str_eq(r, "sheepy>>>>");
+ r = bLPadEndS(b, sizeof(b), "sheepy", 7, ">>>");
+ ck_assert_str_eq(r, "sheepy>");
+ // smaller dest size
+ r = bLPadEndS(b, 4, "sheepy", 7, ">>>");
+ ck_assert_str_eq(r, "she");
-}
+ // string bigger than target length
+ r = bLPadEndS(b, sizeof(b), "sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
+ // smaller dest size
+ r = bLPadEndS(b, 4, "sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "she");
+ // empty pad string
+ r = bLPadEndS(b, sizeof(b), "sheepy", 10, "");
+ ck_assert_str_eq(r, "sheepy");
+ // smaller dest size
+ r = bLPadEndS(b, 4, "sheepy", 10, "");
+ ck_assert_str_eq(r, "she");
-void listDupST(CuTest *tc UNUSED) {
- char **l = NULL;
- char **l2;
+ // null pad string
+ r = bLPadEndS(b, sizeof(b), "sheepy", 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ r = bLPadEndS(b, sizeof(b), "sheepy", 10, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = bLPadEndS(b, sizeof(b), null, 4, "q");
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bLPadEndS(null, sizeof(b), "d", 4, "q");
+ ck_assert_ptr_eq(r, null);
- // 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 UNUSED) {
+void padEndCharST(CuTest *tc UNUSED) {
- char **l = NULL;
- char **l2;
+ char *r;
+
+ // pad string
+ r = padEndCharS("sheepy", 10, '>');
+ ck_assert_str_eq(r, "sheepy>>>>");
+ free(r);
+
+ r = padEndCharS("sheepy", 7, '>');
+ ck_assert_str_eq(r, "sheepy>");
+ free(r);
+
+ // string bigger than target length
+ r = padEndCharS("sheepy", 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // null string
+ r = padEndCharS(null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
- // 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 UNUSED) {
+void iPadEndCharST(CuTest *tc UNUSED) {
- char **l = NULL;
- char **l2;
+ char *s, *r;
+
+ // pad string
+ s = strdup("sheepy");
+ r = iPadEndCharS(&s, 10, '>');
+ ck_assert_str_eq(r, "sheepy>>>>");
+ free(r);
+
+ s = strdup("sheepy");
+ r = iPadEndCharS(&s, 7, '>');
+ ck_assert_str_eq(r, "sheepy>");
+ free(r);
+
+ // string bigger than target length
+ s = strdup("sheepy");
+ r = iPadEndCharS(&s, 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // null string
+ s = null;
+ r = iPadEndCharS(&s, 4, 'q');
+ ck_assert_ptr_eq(r, null);
+ r = iPadEndCharS(null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
- // 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 UNUSED) {
+void bPadEndCharST(CuTest *tc UNUSED) {
- char **l = NULL;
+ char *r;
+ char b[48];
+
+ // pad string
+ r = bPadEndCharS(b, "sheepy", 10, '>');
+ ck_assert_str_eq(r, "sheepy>>>>");
+
+ r = bPadEndCharS(b, "sheepy", 7, '>');
+ ck_assert_str_eq(r, "sheepy>");
+
+ // string bigger than target length
+ r = bPadEndCharS(b, "sheepy", 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+
+ // null string
+ r = bPadEndCharS(b, null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bPadEndCharS(null, "d", 4, 'q');
+ ck_assert_ptr_eq(r, 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 UNUSED) {
+void bLPadEndCharST(CuTest *tc UNUSED) {
- char **l;
- char **l2;
- char **r;
+ char *r;
+ char b[48];
- // 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");
+ // pad string
+ r = bLPadEndCharS(b, sizeof(b), "sheepy", 10, '>');
+ ck_assert_str_eq(r, "sheepy>>>>");
+ r = bLPadEndCharS(b, sizeof(b), "sheepy", 7, '>');
+ ck_assert_str_eq(r, "sheepy>");
+ // smaller dest size
+ r = bLPadEndCharS(b, 4, "sheepy", 7, '>');
+ ck_assert_str_eq(r, "she");
+
+ // string bigger than target length
+ r = bLPadEndCharS(b, sizeof(b), "sheepy", 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+ // smaller dest size
+ r = bLPadEndCharS(b, 4, "sheepy", 4, '>');
+ ck_assert_str_eq(r, "she");
+
+ // null string
+ r = bLPadEndCharS(b, sizeof(b), null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bLPadEndCharS(null, sizeof(b), "d", 4, 'q');
+ ck_assert_ptr_eq(r, null);
+
+
+}
+
+
+void padEndLenST(CuTest *tc UNUSED) {
+
+ ssize_t r;
+
+ // pad string
+ r = padEndLenS("sheepy", 10, ">>>");
+ ck_assert_int_eq(r, 10);
+
+ r = padEndLenS("sheepy", 7, ">>>");
+ ck_assert_int_eq(r, 7);
+
+ // string bigger than target length
+ r = padEndLenS("sheepy", 4, ">>>");
+ ck_assert_int_eq(r, 6);
+
+ // empty pad string
+ r = padEndLenS("sheepy", 10, "");
+ ck_assert_int_eq(r, 6);
+
+ // null pad string
+ r = padEndLenS("sheepy", 4, null);
+ ck_assert_int_eq(r, 6);
+ r = padEndLenS("sheepy", 10, null);
+ ck_assert_int_eq(r, -1);
+
+ // null string
+ r = padEndLenS(null, 4, "q");
+ ck_assert_int_eq(r, -1);
+
+
+}
+
+
+void getST(CuTest *tc UNUSED) {
+
+ // 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 UNUSED) {
+
+ 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 swapST(CuTest *tc UNUSED) {
+
+ char *r;
+
+ // swap
+ r = swapS("sheepy", 0, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+ r = swapS("sheepy", -6, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+ r = swapS("sheepy", 2, 0);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+ r = swapS("sheepy", 2, -6);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+
+ // index1 >= len
+ r = swapS("sheepy", 6, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 >= len
+ r = swapS("sheepy", 2, 6);
+ ck_assert_ptr_eq(r, null);
+
+ // index1 < -len
+ r = swapS("sheepy", -10, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 < -len
+ r = swapS("sheepy", 2, -7);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = swapS(null, 0, 2);
+ ck_assert_ptr_eq(r, null);
+
+}
+
+
+void iSwapST(CuTest *tc UNUSED) {
+
+ char *b;
+ char *r;
+
+ // swap
+ b = strdup("sheepy");
+ r = iSwapS(&b, 0, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+ b = strdup("sheepy");
+ r = iSwapS(&b, -6, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+ b = strdup("sheepy");
+ r = iSwapS(&b, 2, 0);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+ b = strdup("sheepy");
+ r = iSwapS(&b, 2, -6);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+
+ b = strdup("sheepy");
+
+ // index1 >= len
+ r = iSwapS(&b, 6, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 >= len
+ r = iSwapS(&b, 2, 6);
+ ck_assert_ptr_eq(r, null);
+
+ // index1 < -len
+ r = iSwapS(&b, -10, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 < -len
+ r = iSwapS(&b, 2, -7);
+ ck_assert_ptr_eq(r, null);
+
+ free(b);
+
+ // null string
+ b = null;
+ r = iSwapS(&b, 0, 2);
+ ck_assert_ptr_eq(r, null);
+ r = iSwapS(null, 0, 2);
+ ck_assert_ptr_eq(r, null);
+
+
+}
+
+
+void bSwapST(CuTest *tc UNUSED) {
+
+ char b[20];
+ char *r;
+
+ // swap
+ strcpy(b, "sheepy");
+ r = bSwapS(b, 0, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ strcpy(b, "sheepy");
+ r = bSwapS(b, -6, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ strcpy(b, "sheepy");
+ r = bSwapS(b, 2, 0);
+ ck_assert_str_eq(r, "ehsepy");
+ strcpy(b, "sheepy");
+ r = bSwapS(b, 2, -6);
+ ck_assert_str_eq(r, "ehsepy");
+
+ // index1 >= len
+ r = bSwapS("sheepy", 6, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 >= len
+ r = bSwapS("sheepy", 2, 6);
+ ck_assert_ptr_eq(r, null);
+
+ // index1 < -len
+ r = bSwapS("sheepy", -10, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 < -len
+ r = bSwapS("sheepy", 2, -7);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = bSwapS(null, 0, 2);
+ ck_assert_ptr_eq(r, null);
+
+
+}
+
+
+void bLSwapST(CuTest *tc UNUSED) {
+
+ char b[20];
+ char *r;
+
+ // swap
+ strcpy(b, "sheepy");
+ r = bLSwapS(b, sizeof(b), 0, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ strcpy(b, "sheepy");
+ r = bLSwapS(b, sizeof(b), -6, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ strcpy(b, "sheepy");
+ r = bLSwapS(b, sizeof(b), 2, 0);
+ ck_assert_str_eq(r, "ehsepy");
+ strcpy(b, "sheepy");
+ r = bLSwapS(b, sizeof(b), 2, -6);
+ ck_assert_str_eq(r, "ehsepy");
+
+ // buffer = strlen+1
+ strcpy(b, "sheepy");
+ r = bLSwapS(b, 7, -1, 0);
+ ck_assert_str_eq(r, "yheeps");
+ // buffer shorter than strlen
+ strcpy(b, "sheepy");
+ r = bLSwapS(b, 6, -1, 0);
+ ck_assert_str_eq(r, "pheesy");
+
+ // size 0
+ strcpy(b, "sheepy");
+ r = bLSwapS(b, 0, -1, 0);
+ ck_assert_str_eq(r, "sheepy");
+
+ // index1 >= len
+ r = bLSwapS("sheepy", sizeof(b), 6, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 >= len
+ r = bLSwapS("sheepy", sizeof(b), 2, 6);
+ ck_assert_ptr_eq(r, null);
+
+ // index1 < -len
+ r = bLSwapS("sheepy", sizeof(b), -10, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 < -len
+ r = bLSwapS("sheepy", sizeof(b), 2, -7);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = bLSwapS(null, sizeof(b), 0, 2);
+ ck_assert_ptr_eq(r, null);
+
+
+}
+
+
+void sliceST(CuTest *tc UNUSED) {
+
+ // 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 bLSliceST(CuTest *tc UNUSED) {
+
+ char s[100];
+ // slice
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 0,2);
+ ck_assert_str_eq(s, "sh");
+ // buffer shorter than string
+ strcpy(s, "sheepy");
+ bLSliceS(s, 5, 0,2);
+ ck_assert_str_eq(s, "sh");
+ // negative index
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), -2,0);
+ ck_assert_str_eq(s, "py");
+ // positive and negative indexes
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 2,-2);
+ ck_assert_str_eq(s, "ee");
+ // start = end
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 2,-4);
+ ck_assert_str_eq(s, "");
+ // end of string
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 2,6);
+ ck_assert_str_eq(s, "eepy");
+ // start outside string
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 20,-4);
+ ck_assert_str_eq(s, "");
+ // end outside string
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 2,40);
+ ck_assert_str_eq(s, "eepy");
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), -22,3);
+ ck_assert_str_eq(s, "she");
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 2,-40);
+ ck_assert_str_eq(s, "");
+ // end before start
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 4,2);
+ ck_assert_str_eq(s, "");
+ // size 0
+ ck_assert_ptr_eq(bLSliceS(s, 0, 0, 0), NULL);
+ // NULL var
+ ck_assert_ptr_eq(bLSliceS(NULL, sizeof(s), 0, 0), NULL);
+
+
+}
+
+
+void cropST(CuTest *tc UNUSED) {
+
+ char b[20];
+ char *s;
+
+ // crop
+ strcpy(b, "sheepy");
+ s = cropS(b, 0,2);
+ ck_assert_str_eq(s, "sh");
+ ck_assert_str_eq(b, "eepy");
+ free(s);
+ // negative index
+ strcpy(b, "sheepy");
+ s = cropS(b, -2,0);
+ ck_assert_str_eq(s, "py");
+ ck_assert_str_eq(b, "shee");
+ free(s);
+ // positive and negative indexes
+ strcpy(b, "sheepy");
+ s = cropS(b, 2,-2);
+ ck_assert_str_eq(s, "ee");
+ ck_assert_str_eq(b, "shpy");
+ free(s);
+ // start = end
+ strcpy(b, "sheepy");
+ s = cropS(b, 2,-4);
+ ck_assert_str_eq(s, "");
+ ck_assert_str_eq(b, "sheepy");
+ free(s);
+ // end of string
+ strcpy(b, "sheepy");
+ s = cropS(b, 2,6);
+ ck_assert_str_eq(s, "eepy");
+ ck_assert_str_eq(b, "sh");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(cropS(NULL, 2,-4), NULL);
+ // start outside string
+ ck_assert_ptr_eq(cropS("sheepy", 20,-4), NULL);
+ // end outside string
+ strcpy(b, "sheepy");
+ s = cropS(b, 2,40);
+ ck_assert_str_eq(s, "eepy");
+ ck_assert_str_eq(b, "sh");
+ free(s);
+ strcpy(b, "sheepy");
+ s = cropS(b, -22,3);
+ ck_assert_str_eq(s, "she");
+ ck_assert_str_eq(b, "epy");
+ free(s);
+ ck_assert_ptr_eq(cropS("sheepy", 2,-40), NULL);
+ // end before start
+ ck_assert_ptr_eq(cropS("sheepy", 4,2), NULL);
+
+
+}
+
+
+void iCropST(CuTest *tc UNUSED) {
+
+ char *b;
+ char *s;
+
+ // crop
+ b = strdup("sheepy");
+ s = iCropS(&b, 0,2);
+ ck_assert_str_eq(s, "sh");
+ ck_assert_str_eq(b, "eepy");
+ free(s);
+ free(b);
+ // negative index
+ b = strdup("sheepy");
+ s = iCropS(&b, -2,0);
+ ck_assert_str_eq(s, "py");
+ ck_assert_str_eq(b, "shee");
+ free(s);
+ free(b);
+ // positive and negative indexes
+ b = strdup("sheepy");
+ s = iCropS(&b, 2,-2);
+ ck_assert_str_eq(s, "ee");
+ ck_assert_str_eq(b, "shpy");
+ free(s);
+ free(b);
+ // start = end
+ b = strdup("sheepy");
+ s = iCropS(&b, 2,-4);
+ ck_assert_str_eq(s, "");
+ ck_assert_str_eq(b, "sheepy");
+ free(s);
+ free(b);
+ // end of string
+ b = strdup("sheepy");
+ s = iCropS(&b, 2,6);
+ ck_assert_str_eq(s, "eepy");
+ ck_assert_str_eq(b, "sh");
+ free(s);
+ free(b);
+ // NULL string
+ b = null;
+ ck_assert_ptr_eq(iCropS(&b, 2,-4), NULL);
+ ck_assert_ptr_eq(iCropS(NULL, 2,-4), NULL);
+ // start outside string
+ b = strdup("sheepy");
+ ck_assert_ptr_eq(iCropS(&b, 20,-4), NULL);
+ free(b);
+ // end outside string
+ b = strdup("sheepy");
+ s = iCropS(&b, 2,40);
+ ck_assert_str_eq(s, "eepy");
+ ck_assert_str_eq(b, "sh");
+ free(s);
+ free(b);
+ b = strdup("sheepy");
+ s = iCropS(&b, -22,3);
+ ck_assert_str_eq(s, "she");
+ ck_assert_str_eq(b, "epy");
+ free(s);
+ free(b);
+ b = strdup("sheepy");
+ ck_assert_ptr_eq(iCropS(&b, 2,-40), NULL);
+ free(b);
+ // end before start
+ b = strdup("sheepy");
+ ck_assert_ptr_eq(iCropS(&b, 4,2), NULL);
+ free(b);
+
+
+}
+
+
+void cropElemST(CuTest *tc UNUSED) {
+
+ char b[20];
+ char r;
+
+ // crop
+ strcpy(b, "sheepy");
+ r = cropElemS(b, 0);
+ ck_assert_int_eq(r, 's');
+ ck_assert_str_eq(b, "heepy");
+ strcpy(b, "sheepy");
+ r = cropElemS(b, 5);
+ ck_assert_int_eq(r, 'y');
+ ck_assert_str_eq(b, "sheep");
+ // negative index
+ strcpy(b, "sheepy");
+ r = cropElemS(b, -1);
+ ck_assert_int_eq(r, 'y');
+ ck_assert_str_eq(b, "sheep");
+ strcpy(b, "sheepy");
+ r = cropElemS(b, -6);
+ ck_assert_int_eq(r, 's');
+ ck_assert_str_eq(b, "heepy");
+ // index outside string
+ strcpy(b, "sheepy");
+ r = cropElemS(b, 6);
+ ck_assert_int_eq(r, 0);
+ ck_assert_str_eq(b, "sheepy");
+ strcpy(b, "sheepy");
+ r = cropElemS(b, -7);
+ ck_assert_int_eq(r, 0);
+ ck_assert_str_eq(b, "sheepy");
+ // null string
+ ck_assert_int_eq(cropElemS(null, 0), 0);
+
+}
+
+
+void iCropElemST(CuTest *tc UNUSED) {
+
+ char *b;
+ char r;
+
+ // crop
+ b = strdup("sheepy");
+ r = iCropElemS(&b, 0);
+ ck_assert_int_eq(r, 's');
+ ck_assert_str_eq(b, "heepy");
+ free(b);
+ b = strdup("sheepy");
+ r = iCropElemS(&b, 5);
+ ck_assert_int_eq(r, 'y');
+ ck_assert_str_eq(b, "sheep");
+ free(b);
+ // negative index
+ b = strdup("sheepy");
+ r = iCropElemS(&b, -1);
+ ck_assert_int_eq(r, 'y');
+ ck_assert_str_eq(b, "sheep");
+ free(b);
+ b = strdup("sheepy");
+ r = iCropElemS(&b, -6);
+ ck_assert_int_eq(r, 's');
+ ck_assert_str_eq(b, "heepy");
+ free(b);
+ // index outside string
+ b = strdup("sheepy");
+ r = iCropElemS(&b, 6);
+ ck_assert_int_eq(r, 0);
+ ck_assert_str_eq(b, "sheepy");
+ free(b);
+ b = strdup("sheepy");
+ r = iCropElemS(&b, -7);
+ ck_assert_int_eq(r, 0);
+ ck_assert_str_eq(b, "sheepy");
+ free(b);
+ // null string
+ b = null;
+ ck_assert_int_eq(iCropElemS(&b, 0), 0);
+ ck_assert_int_eq(iCropElemS(null, 0), 0);
+
+
+}
+
+
+void insertST(CuTest *tc UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ // 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 bLDelST(CuTest *tc UNUSED) {
+
+ char s[100];
+ // del
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 0,2);
+ ck_assert_str_eq(s, "eepy");
+ // buffer shorter than string
+ strcpy(s, "sheepy");
+ bLDelS(s, 5, 0,2);
+ ck_assert_str_eq(s, "ee");
+ // negative index
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), -2,0);
+ ck_assert_str_eq(s, "shee");
+ // positive and negative indexes
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 2,-2);
+ ck_assert_str_eq(s, "shpy");
+ // start = end
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 2,-4);
+ ck_assert_str_eq(s, "sheepy");
+ // end of string
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 2,6);
+ ck_assert_str_eq(s, "sh");
+ // start outside string
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 20,-4);
+ ck_assert_str_eq(s, "sheepy");
+ // end outside string
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 2,40);
+ ck_assert_str_eq(s, "sh");
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), -22,3);
+ ck_assert_str_eq(s, "epy");
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 2,-40);
+ ck_assert_str_eq(s, "sheepy");
+ // end before start
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 4,2);
+ ck_assert_str_eq(s, "sheepy");
+ // size 0
+ ck_assert_ptr_eq(bLDelS(s, 0, 0, 0), NULL);
+ // NULL var
+ ck_assert_ptr_eq(bLDelS(NULL, sizeof(s), 0, 0), NULL);
+
+
+}
+
+
+void delElemST(CuTest *tc UNUSED) {
+
+ char b[20];
+ char *r;
+
+ // del
+ strcpy(b, "sheepy");
+ r = delElemS(b, 0);
+ ck_assert_str_eq(r, "heepy");
+ free(r);
+ strcpy(b, "sheepy");
+ r = delElemS(b, 5);
+ ck_assert_str_eq(r, "sheep");
+ free(r);
+ // negative index
+ strcpy(b, "sheepy");
+ r = delElemS(b, -1);
+ ck_assert_str_eq(r, "sheep");
+ free(r);
+ strcpy(b, "sheepy");
+ r = delElemS(b, -6);
+ ck_assert_str_eq(r, "heepy");
+ free(r);
+ // index outside string
+ strcpy(b, "sheepy");
+ r = delElemS(b, 6);
+ ck_assert_ptr_eq(r, null);
+ free(r);
+ strcpy(b, "sheepy");
+ r = delElemS(b, -7);
+ ck_assert_ptr_eq(r, null);
+ free(r);
+ // null string
+ ck_assert_ptr_eq(delElemS(null, 0), null);
+
+
+}
+
+
+void iDelElemST(CuTest *tc UNUSED) {
+
+ char *b;
+ char *r;
+
+ // del
+ b = strdup("sheepy");
+ r = iDelElemS(&b, 0);
+ ck_assert_str_eq(r, "heepy");
+ free(r);
+ b = strdup("sheepy");
+ r = iDelElemS(&b, 5);
+ ck_assert_str_eq(r, "sheep");
+ free(r);
+ // negative index
+ b = strdup("sheepy");
+ r = iDelElemS(&b, -1);
+ ck_assert_str_eq(r, "sheep");
+ free(r);
+ b = strdup("sheepy");
+ r = iDelElemS(&b, -6);
+ ck_assert_str_eq(r, "heepy");
+ free(r);
+ // index outside string
+ b = strdup("sheepy");
+ r = iDelElemS(&b, 6);
+ ck_assert_ptr_eq(r, null);
+ free(b);
+ b = strdup("sheepy");
+ r = iDelElemS(&b, -7);
+ ck_assert_ptr_eq(r, null);
+ free(b);
+ // null string
+ ck_assert_ptr_eq(iDelElemS(null, 0), null);
+
+
+}
+
+
+void bDelElemST(CuTest *tc UNUSED) {
+
+ char b[20];
+ char *r;
+
+ // del
+ strcpy(b, "sheepy");
+ r = bDelElemS(b, 0);
+ ck_assert_str_eq(r, "heepy");
+ strcpy(b, "sheepy");
+ r = bDelElemS(b, 5);
+ ck_assert_str_eq(r, "sheep");
+ // negative index
+ strcpy(b, "sheepy");
+ r = bDelElemS(b, -1);
+ ck_assert_str_eq(r, "sheep");
+ strcpy(b, "sheepy");
+ r = bDelElemS(b, -6);
+ ck_assert_str_eq(r, "heepy");
+ // index outside string
+ strcpy(b, "sheepy");
+ r = bDelElemS(b, 6);
+ ck_assert_ptr_eq(r, null);
+ strcpy(b, "sheepy");
+ r = bDelElemS(b, -7);
+ ck_assert_ptr_eq(r, null);
+ // null string
+ ck_assert_ptr_eq(bDelElemS(null, 0), null);
+
+
+}
+
+
+void bLDelElemST(CuTest *tc UNUSED) {
+
+ char b[20];
+ char *r;
+
+ // del
+ strcpy(b, "sheepy");
+ r = bLDelElemS(b, sizeof(b), 0);
+ ck_assert_str_eq(r, "heepy");
+ strcpy(b, "sheepy");
+ r = bLDelElemS(b, sizeof(b), 5);
+ ck_assert_str_eq(r, "sheep");
+ // negative index
+ strcpy(b, "sheepy");
+ r = bLDelElemS(b, sizeof(b), -1);
+ ck_assert_str_eq(r, "sheep");
+ strcpy(b, "sheepy");
+ r = bLDelElemS(b, sizeof(b), -6);
+ ck_assert_str_eq(r, "heepy");
+ // dest size shorter than strlen
+ strcpy(b, "sheepy");
+ r = bLDelElemS(b, 4, -1);
+ ck_assert_str_eq(r, "sh");
+ // index outside string
+ strcpy(b, "sheepy");
+ r = bLDelElemS(b, sizeof(b), 6);
+ ck_assert_ptr_eq(r, null);
+ strcpy(b, "sheepy");
+ r = bLDelElemS(b, sizeof(b), -7);
+ ck_assert_ptr_eq(r, null);
+ r = bLDelElemS(b, sizeof(b), -8);
+ ck_assert_ptr_eq(r, null);
+ // size 0
+ ck_assert_ptr_eq(bLDelElemS(b, 0, 0), null);
+ // null string
+ ck_assert_ptr_eq(bLDelElemS(null, sizeof(b), 0), null);
+
+
+}
+
+
+void findST(CuTest *tc UNUSED) {
+
+ // 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 UNUSED) {
+
+ // 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 indexOfST(CuTest *tc UNUSED) {
+
+ // indexOf string in the middle
+ ck_assert_int_eq(indexOfS("sheepy", "ee"), 2);
+ // indexOf non existing string
+ ck_assert_int_eq(indexOfS("sheepy", "$"), -1);
+ // indexOf NULL
+ ck_assert_int_eq(indexOfS("sheepy", NULL), -1);
+ // NULL string
+ ck_assert_int_eq(indexOfS(NULL, "$"), -1);
+
+
+}
+
+
+void indexOfCharST(CuTest *tc UNUSED) {
+
+ // indexOf string in the middle
+ ck_assert_int_eq(indexOfCharS("sheepy", 'e'), 2);
+ // indexOf non existing string
+ ck_assert_int_eq(indexOfCharS("sheepy", '$'), -1);
+ // indexOf 0
+ ck_assert_int_eq(indexOfCharS("sheepy", 0), 6);
+ // NULL string
+ ck_assert_int_eq(indexOfCharS(NULL, '$'), -1);
+
+
+}
+
+
+void hasST(CuTest *tc UNUSED) {
+
+ // 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 UNUSED) {
+
+ // 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 icFindST(CuTest *tc UNUSED) {
+
+ // find string in the middle
+ ck_assert_str_eq(icFindS("shEepy", "eE"), "Eepy");
+ // find non existing string
+ ck_assert_ptr_eq(icFindS("sheepy", "$"), NULL);
+ // find NULL
+ ck_assert_ptr_eq(icFindS("sheepy", NULL), NULL);
+ // NULL string
+ ck_assert_ptr_eq(icFindS(NULL, "$"), NULL);
+
+
+}
+
+
+void icFindCharST(CuTest *tc UNUSED) {
+
+ // find string in the middle
+ ck_assert_str_eq(icFindCharS("shEEpy", 'e'), "EEpy");
+ // find non existing string
+ ck_assert_ptr_eq(icFindCharS("sheepy", '$'), NULL);
+ // find 0
+ ck_assert_str_eq(icFindCharS("sheepy", 0), "");
+ // NULL string
+ ck_assert_ptr_eq(icFindCharS(NULL, '$'), NULL);
+
+
+}
+
+
+void icIndexOfST(CuTest *tc UNUSED) {
+
+ // indexOf string in the middle
+ ck_assert_int_eq(icIndexOfS("sheepy", "EE"), 2);
+ // indexOf non existing string
+ ck_assert_int_eq(icIndexOfS("sheepy", "$"), -1);
+ // indexOf NULL
+ ck_assert_int_eq(icIndexOfS("sheepy", NULL), -1);
+ // NULL string
+ ck_assert_int_eq(icIndexOfS(NULL, "$"), -1);
+
+
+}
+
+
+void icIndexOfCharST(CuTest *tc UNUSED) {
+
+ // indexOf string in the middle
+ ck_assert_int_eq(icIndexOfCharS("sheepy", 'E'), 2);
+ // indexOf non existing string
+ ck_assert_int_eq(icIndexOfCharS("sheepy", '$'), -1);
+ // indexOf 0
+ ck_assert_int_eq(icIndexOfCharS("sheepy", 0), 6);
+ // NULL string
+ ck_assert_int_eq(icIndexOfCharS(NULL, '$'), -1);
+
+
+}
+
+
+void icHasST(CuTest *tc UNUSED) {
+
+ // find string in the middle
+ ck_assert(icHasS("sheepy", "EE"));
+ // find non existing string
+ ck_assert(!icHasS("sheepy", "$"));
+ // find NULL
+ ck_assert(!icHasS("sheepy", NULL));
+ // NULL string
+ ck_assert(!icHasS(NULL, "$"));
+
+
+}
+
+
+void icHasCharST(CuTest *tc UNUSED) {
+
+ // find string in the middle
+ ck_assert(icHasCharS("shEepy", 'e'));
+ // find non existing string
+ ck_assert(!icHasCharS("sheepy", '$'));
+ // find 0
+ ck_assert(icHasCharS("sheepy", 0));
+ // NULL string
+ ck_assert(!icHasCharS(NULL, '$'));
+
+
+}
+
+
+void tokST(CuTest *tc UNUSED) {
+
+ // 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 icTokST(CuTest *tc UNUSED) {
+
+ // string
+ char *s;
+ char *w;
+ s = strdup("172.16.43.0/24 dev ens32 dev proto");
+ w = s;
+ ck_assert_str_eq(icTokS(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(icTokS(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(icTokS(s, "dev ", &w), "172.16.43.0/24 ");
+ ck_assert_str_eq(w, "ens32 dev proto");
+ ck_assert_str_eq(icTokS(NULL, "dev ", &w), "ens32 ");
+ ck_assert_str_eq(w, "proto");
+ ck_assert_str_eq(icTokS(NULL, "dev ", &w), "proto");
+ ck_assert_ptr_eq(w, NULL);
+ free(s);
+ // NULL string
+ w = NULL;
+ ck_assert_ptr_eq(icTokS(NULL, ";", &w), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(icTokS("test", NULL, &w), NULL);
+
+
+}
+
+
+void lenUTF8T(CuTest *tc UNUSED) {
+
+ // string
+ ck_assert_uint_eq(lenUTF8("sheepy"), 6);
+ // UTF8
+ ck_assert_uint_eq(lenUTF8("sheepy£"), 7);
+ ck_assert_uint_eq(lenS("sheepy£"), 8);
+ // NULL string
+ ck_assert_uint_eq(lenUTF8(NULL), 0);
+
+
+}
+
+
+void bLLenUTF8T(CuTest *tc UNUSED) {
+
+ // string
+ ck_assert_uint_eq(bLLenUTF8("sheepy", 7), 6);
+ // UTF8
+ ck_assert_uint_eq(bLLenUTF8("sheepy£",9), 7);
+ ck_assert_uint_eq(bLLenUTF8("sheepy£", 6), 5);
+ ck_assert_uint_eq(lenS("sheepy£"), 8);
+ // size 0
+ ck_assert_uint_eq(bLLenUTF8("sheepy£", 0), 0);
+ // NULL string
+ ck_assert_uint_eq(bLLenUTF8(NULL, 1), 0);
+
+
+}
+
+
+void isUTF8T(CuTest *tc UNUSED) {
+
+ char b[8];
+
+ // string
+ ck_assert(isUTF8("sheepy"));
+ // UTF8
+ ck_assert(isUTF8("sheepy£"));
+ // invalid UTF8
+ strLCpy(b, sizeof(b), "sheepy£");
+ ck_assert(!isUTF8(b));
+ // null string
+ ck_assert(!isUTF8(null));
+
+
+}
+
+
+void bLIsUTF8T(CuTest *tc UNUSED) {
+
+ // string
+ ck_assert(bLIsUTF8("sheepy", 7));
+ // UTF8
+ ck_assert(bLIsUTF8("sheepy£", 9));
+ // buffer shorter than string (string is not nul terminated)
+ ck_assert(!bLIsUTF8("sheepy", 6));
+ // invalid UTF8
+ ck_assert(!bLIsUTF8("sheepy£", 8));
+ // size 0
+ ck_assert(!bLIsUTF8("sheepy£", 0));
+ // null string
+ ck_assert(!bLIsUTF8(null, 1));
+
+
+}
+
+
+void isCodeUTF8T(CuTest *tc UNUSED) {
+
+ // valid
+ ck_assert(isCodeUTF8("as"));
+ ck_assert(isCodeUTF8("£s"));
+ // invalid
+ u8 b[3] = init0Var;
+ b[0] = 128;
+ ck_assert(!isCodeUTF8((char*)b));
+ // null string
+ ck_assert(!isCodeUTF8(null));
+
+
+}
+
+
+void nextUTF8T(CuTest *tc UNUSED) {
+
+ char *r;
+
+ // next
+ r = nextUTF8("£sheepy");
+ ck_assert_str_eq(r, "sheepy");
+ // empty string
+ r = nextUTF8("");
+ ck_assert_ptr_eq(r, null);
+ // null string
+ r = nextUTF8(null);
+ ck_assert_ptr_eq(r, null);
+
+
+}
+
+
+void bLNextUTF8T(CuTest *tc UNUSED) {
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // next
+ r = bLNextUTF8(b, sizeof(b), &b[3]);
+ ck_assert_str_eq(r, "eepy");
+ // last char
+ r = bLNextUTF8(b, sizeof(b), &b[7]);
+ ck_assert_ptr_eq(r, null);
+ // empty string
+ r = bLNextUTF8(b, sizeof(b), &b[10]);
+ ck_assert_ptr_eq(r, null);
+ // string longer than buffer
+ r = bLNextUTF8(b, 6, &b[7]);
+ ck_assert_ptr_eq(r, null);
+ r = bLNextUTF8(b, 6, &b[5]);
+ ck_assert_ptr_eq(r, null);
+ // size 0
+ r = bLNextUTF8(b, 0, b);
+ ck_assert_ptr_eq(r, null);
+ // null string
+ r = bLNextUTF8(null, 1, b);
+ ck_assert_ptr_eq(r, null);
+ r = bLNextUTF8(b, 1, null);
+ ck_assert_ptr_eq(r, null);
+
+
+}
+
+
+void findNextUTF8T(CuTest *tc UNUSED) {
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // next
+ r = findNextUTF8(b, sizeof(b), &b[3]);
+ ck_assert_str_eq(r, "eepy");
+ // in a code point, find first valid code point in utf8 parameter
+ // same as findNextUTF8(b, sizeof(b), &b[2])
+ r = findNextUTF8(b, sizeof(b), &b[1]);
+ ck_assert_str_eq(r, "heepy");
+ // last char
+ r = findNextUTF8(b, sizeof(b), &b[7]);
+ ck_assert_ptr_eq(r, null);
+ // empty string
+ r = findNextUTF8(b, sizeof(b), &b[10]);
+ ck_assert_ptr_eq(r, null);
+ // string longer than buffer
+ r = findNextUTF8(b, 6, &b[7]);
+ ck_assert_ptr_eq(r, null);
+ r = findNextUTF8(b, 6, &b[5]);
+ ck_assert_ptr_eq(r, null);
+ // size 0
+ r = findNextUTF8(b, 0, b);
+ ck_assert_ptr_eq(r, null);
+ // null string
+ r = findNextUTF8(null, 1, b);
+ ck_assert_ptr_eq(r, null);
+ r = findNextUTF8(b, 1, null);
+ ck_assert_ptr_eq(r, null);
+
+
+}
+
+
+void prevUTF8T(CuTest *tc UNUSED) {
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // prev
+ r = prevUTF8(&b[2]);
+ ck_assert_str_eq(r, "£sheepy");
+ // null string
+ r = prevUTF8(null);
+ ck_assert_ptr_eq(r, null);
+
+
+}
+
+
+void bPrevUTF8T(CuTest *tc UNUSED) {
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // prev
+ r = bPrevUTF8(b, &b[2]);
+ ck_assert_str_eq(r, "£sheepy");
+ // string start
+ r = bPrevUTF8(b, b);
+ ck_assert_ptr_eq(r, null);
+ // null string
+ r = bPrevUTF8(null, b);
+ ck_assert_ptr_eq(r, null);
+ r = bPrevUTF8(b, null);
+ ck_assert_ptr_eq(r, null);
+
+}
+
+
+void idx2PtrUTF8T(CuTest *tc UNUSED) {
+
+ char *emptys = "";
+ char *r;
+
+ // index
+ r = idx2PtrUTF8("£sheepy", 1);
+ ck_assert_str_eq(r, "sheepy");
+ r = idx2PtrUTF8("£sheepy", 2);
+ ck_assert_str_eq(r, "heepy");
+ r = idx2PtrUTF8("£sheepy", 0);
+ ck_assert_str_eq(r, "£sheepy");
+ // NUL byte index
+ r = idx2PtrUTF8("£sheepy", strlen("£sheepy")-1);
+ ck_assert_str_eq(r, "");
+ // negative index
+ r = idx2PtrUTF8("£sheepy", -1);
+ ck_assert_str_eq(r, "y");
+ // empty string
+ r = idx2PtrUTF8(emptys, -1);
+ ck_assert_ptr_eq(r, emptys);
+ // index outside buffer
+ r = idx2PtrUTF8("£sheepy", 8);
+ ck_assert_ptr_eq(r, null);
+ r = idx2PtrUTF8("£sheepy", 9);
+ ck_assert_ptr_eq(r, null);
+ r = idx2PtrUTF8("£sheepy", -9);
+ ck_assert_ptr_eq(r, null);
+ // null string
+ r = idx2PtrUTF8(null, 1);
+ ck_assert_ptr_eq(r, null);
+
+}
+
+
+void bLIdx2PtrUTF8T(CuTest *tc UNUSED) {
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // index
+ r = bLIdx2PtrUTF8(b, sizeof(b), 3);
+ ck_assert_str_eq(r, "eepy");
+ r = bLIdx2PtrUTF8(b, sizeof(b), 0);
+ ck_assert_str_eq(r, b);
+ // NUL byte index
+ r = bLIdx2PtrUTF8(b, sizeS(b), strlen(b)-1);
+ ck_assert_str_eq(r, "");
+ // negative index
+ r = bLIdx2PtrUTF8(b, sizeof(b), -2);
+ ck_assert_str_eq(r, "py");
+ r = bLIdx2PtrUTF8(b, sizeof(b), -1);
+ ck_assert_str_eq(r, "y");
+ // string longer than buffer and negative index
+ r = bLIdx2PtrUTF8(b, 8, -1);
+ ck_assert_str_eq(r, "py");
+ // last char
+ r = bLIdx2PtrUTF8(b, sizeof(b), 7);
+ ck_assert_str_eq(r, "");
+ // empty string
+ r = bLIdx2PtrUTF8(&b[10], 2, 1);
+ ck_assert_str_eq(r, &b[10]);
+ // index outside string
+ r = bLIdx2PtrUTF8(b, 6, 7);
+ ck_assert_ptr_eq(r, null);
+ r = bLIdx2PtrUTF8(b, 6, 5);
+ ck_assert_ptr_eq(r, null);
+ r = bLIdx2PtrUTF8(b, 6, -7);
+ ck_assert_ptr_eq(r, null);
+ // size 0
+ r = bLIdx2PtrUTF8(b, 0, 0);
+ ck_assert_ptr_eq(r, b);
+ // null string
+ r = bLIdx2PtrUTF8(null, 1, 0);
+ ck_assert_ptr_eq(r, null);
+
+
+}
+
+
+void ptr2IdxUTF8T(CuTest *tc UNUSED) {
+
+ char b[20] = init0Var;
+ intmax_t r;
+ strcpy(b, "£sheepy");
+
+ // pointer to index
+ r = ptr2IdxUTF8(b, &b[1]);
+ ck_assert_int_eq(r, 0);
+ r = ptr2IdxUTF8(b, &b[2]);
+ ck_assert_int_eq(r, 1);
+ r = ptr2IdxUTF8(&b[2], &b[4]);
+ ck_assert_int_eq(r, 2);
+ r = ptr2IdxUTF8(b, &b[7]);
+ ck_assert_int_eq(r, 6);
+ // negative index
+ r = ptr2IdxUTF8(&b[8], &b[7]);
+ ck_assert_int_eq(r, -1);
+ r = ptr2IdxUTF8(&b[8], &b[6]);
+ ck_assert_int_eq(r, -2);
+ r = ptr2IdxUTF8(&b[8], b);
+ ck_assert_int_eq(r, -7);
+ // string start
+ r = ptr2IdxUTF8(b, b);
+ ck_assert_int_eq(r, 0);
+ // null pos
+ r = ptr2IdxUTF8(b, null);
+ ck_assert_int_eq(r, 0);
+ // null string
+ r = ptr2IdxUTF8(null, b);
+ ck_assert_int_eq(r, 0);
+
+}
+
+
+void bPtr2IdxUTF8T(CuTest *tc UNUSED) {
+
+ char b[20] = init0Var;
+ intmax_t r;
+ strcpy(b, "£sheepy");
+
+ // pointer to index
+ r = bPtr2IdxUTF8(b, b, &b[1]);
+ ck_assert_int_eq(r, 0);
+ r = bPtr2IdxUTF8(b, b, &b[2]);
+ ck_assert_int_eq(r, 1);
+ r = bPtr2IdxUTF8(b, b, &b[7]);
+ ck_assert_int_eq(r, 6);
+ // negative index
+ r = bPtr2IdxUTF8(b, &b[8], &b[7]);
+ ck_assert_int_eq(r, -1);
+ r = bPtr2IdxUTF8(b, &b[8], &b[6]);
+ ck_assert_int_eq(r, -2);
+ r = bPtr2IdxUTF8(b, &b[8], b);
+ ck_assert_int_eq(r, -7);
+ // string start
+ r = bPtr2IdxUTF8(b, b, b);
+ ck_assert_int_eq(r, 0);
+ // null pos
+ r = bPtr2IdxUTF8(b, b, null);
+ ck_assert_int_eq(r, 0);
+ // null string
+ r = bPtr2IdxUTF8(b, null, b);
+ ck_assert_int_eq(r, 0);
+ r = bPtr2IdxUTF8(null, b, b);
+ ck_assert_int_eq(r, 0);
+
+
+}
+
+
+void bLPtr2IdxUTF8T(CuTest *tc UNUSED) {
+
+ char b[20] = init0Var;
+ intmax_t r;
+ strcpy(b, "£sheepy");
+
+ // pointer to index
+ r = bLPtr2IdxUTF8(b, sizeof(b), &b[1]);
+ ck_assert_int_eq(r, 0);
+ r = bLPtr2IdxUTF8(b, sizeof(b), &b[2]);
+ ck_assert_int_eq(r, 1);
+ r = bLPtr2IdxUTF8(b, sizeof(b), &b[7]);
+ ck_assert_int_eq(r, 6);
+ // string start
+ r = bLPtr2IdxUTF8(b, sizeof(b), b);
+ ck_assert_int_eq(r, 0);
+ // null pos
+ r = bLPtr2IdxUTF8(b, sizeof(b), null);
+ ck_assert_int_eq(r, -1);
+ // pos outside buffer
+ r = bLPtr2IdxUTF8(b, 8, &b[10]);
+ ck_assert_int_eq(r, -1);
+ // pos before buffer start
+ r = bLPtr2IdxUTF8(&b[1], 8, b);
+ ck_assert_int_eq(r, -1);
+ // size 0 buffer
+ r = bLPtr2IdxUTF8(b, 0, b);
+ ck_assert_int_eq(r, -1);
+ r = bLPtr2IdxUTF8(null, sizeof(b), b);
+ ck_assert_int_eq(r, -1);
+
+
+}
+
+
+void bLPtr2NegIdxUTF8T(CuTest *tc UNUSED) {
+
+ char b[20] = init0Var;
+ intmax_t r;
+ strcpy(b, "£sheepy");
+
+ // negative index
+ r = bLPtr2NegIdxUTF8(b, 9, &b[7]);
+ ck_assert_int_eq(r, -1);
+ r = bLPtr2NegIdxUTF8(b, 9, &b[6]);
+ ck_assert_int_eq(r, -2);
+ r = bLPtr2NegIdxUTF8(b, 9, b);
+ ck_assert_int_eq(r, -7);
+ // null pos
+ r = bLPtr2NegIdxUTF8(b, sizeof(b), null);
+ ck_assert_int_eq(r, 0);
+ // pos outside buffer
+ r = bLPtr2NegIdxUTF8(b, 9, &b[10]);
+ ck_assert_int_eq(r, 0);
+ // pos before buffer start
+ r = bLPtr2NegIdxUTF8(&b[1], 9, b);
+ ck_assert_int_eq(r, 0);
+ // size 0 buffer
+ r = bLPtr2NegIdxUTF8(b, 0, b);
+ ck_assert_int_eq(r, 0);
+ r = bLPtr2NegIdxUTF8(null, sizeof(b), b);
+ ck_assert_int_eq(r, 0);
+
+}
+
+
+void makeValidUTF8T(CuTest *tc UNUSED) {
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // valid utf8, no change
+ r = makeValidUTF8(b);
+ ck_assert_str_eq(r, b);
+ free(r);
+ // invalid utf8 string
+ r = makeValidUTF8(&b[1]);
+ ck_assert_str_eq(r, "?sheepy");
+ free(r);
+ // null string
+ ck_assert_ptr_eq(makeValidUTF8(null), null);
+
+
+}
+
+
+void bMakeValidUTF8T(CuTest *tc UNUSED) {
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // valid utf8, no change
+ r = bMakeValidUTF8(b);
+ ck_assert_str_eq(r, "£sheepy");
+ // invalid utf8 string
+ r = bMakeValidUTF8(&b[1]);
+ ck_assert_str_eq(r, "?sheepy");
+ // null string
+ ck_assert_ptr_eq(bMakeValidUTF8(null), null);
+
+
+}
+
+
+void nMakeValidUTF8T(CuTest *tc UNUSED) {
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // valid utf8, no change
+ r = nMakeValidUTF8(b, 4);
+ ck_assert_str_eq(r, "£sh");
+ free(r);
+ // invalid utf8 string
+ r = nMakeValidUTF8(&b[1], 4);
+ ck_assert_str_eq(r, "?she");
+ free(r);
+ // len 0
+ ck_assert_ptr_eq(nMakeValidUTF8(b, 0), null);
+ // null string
+ ck_assert_ptr_eq(nMakeValidUTF8(null, 1), null);
+
+
+}
+
+
+void bNMakeValidUTF8T(CuTest *tc UNUSED) {
+
+ char b[20] = init0Var;
+ char s[20] = init0Var;
+ char *r;
+
+ // valid utf8, no change
+ strcpy(b, "£sheepy");
+ r = bNMakeValidUTF8(s, b, 4);
+ ck_assert_str_eq(r, "£sh");
+ // invalid utf8 string
+ strcpy(b, "£sheepy");
+ r = bNMakeValidUTF8(s, &b[1], 4);
+ ck_assert_str_eq(r, "?she");
+ // len 0
+ ck_assert_ptr_eq(bNMakeValidUTF8(s, b, 0), null);
+ // null string
+ ck_assert_ptr_eq(bNMakeValidUTF8(s, null, 1), null);
+ // null dest
+ ck_assert_ptr_eq(bNMakeValidUTF8(null, b, 1), null);
+
+
+}
+
+
+void bLMakeValidUTF8T(CuTest *tc UNUSED) {
+
+ char b[20] = init0Var;
+ char s[20] = init0Var;
+ char *r;
+
+ // valid utf8, no change
+ strcpy(b, "£sheepy");
+ r = bLMakeValidUTF8(s, 5, b);
+ ck_assert_str_eq(r, "£sh");
+ // invalid utf8 string
+ strcpy(b, "£sheepy");
+ r = bLMakeValidUTF8(s, 5, &b[1]);
+ ck_assert_str_eq(r, "?she");
+ // len 0
+ ck_assert_ptr_eq(bLMakeValidUTF8(s, 0, b), null);
+ // null string
+ ck_assert_ptr_eq(bLMakeValidUTF8(s, 1, null), null);
+ // null dest
+ ck_assert_ptr_eq(bLMakeValidUTF8(null, 1, b), null);
+
+
+}
+
+
+void bLNMakeValidUTF8T(CuTest *tc UNUSED) {
+
+ char b[20] = init0Var;
+ char s[20] = init0Var;
+ char *r;
+
+ // valid utf8, no change
+ strcpy(b, "£sheepy");
+ r = bLNMakeValidUTF8(s, 5, b, 4);
+ ck_assert_str_eq(r, "£sh");
+ r = bLNMakeValidUTF8(s, 5, b, 3);
+ ck_assert_str_eq(r, "£s");
+ r = bLNMakeValidUTF8(s, 5, b, 6);
+ ck_assert_str_eq(r, "£sh");
+ // invalid utf8 string
+ strcpy(b, "£sheepy");
+ r = bLNMakeValidUTF8(s, 5, &b[1],4);
+ ck_assert_str_eq(r, "?she");
+ // len 0
+ ck_assert_ptr_eq(bLNMakeValidUTF8(s, 0, b, 1), null);
+ ck_assert_ptr_eq(bLNMakeValidUTF8(s, 2, b, 0), null);
+ // null string
+ ck_assert_ptr_eq(bLNMakeValidUTF8(s, 1, null, 1), null);
+ // null dest
+ ck_assert_ptr_eq(bLNMakeValidUTF8(null, 1, b, 1), null);
+
+
+}
+
+
+void strNCpyUTF8T(CuTest *tc UNUSED) {
+
+ char s[1024] = init0Var;
+ char *r;
+
+ // copy string
+ r = strNCpyUTF8(s, "lib", 4);
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(s, "lib");
+
+ // size 0
+ r = strNCpyUTF8(s, "AAA", 0);
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(s, "lib");
+
+ // NULL
+ s[0] = 0;
+ r = strNCpyUTF8(s, NULL, 10);
+ ck_assert_ptr_eq(r, null);
+ ck_assert_str_eq(s, "");
+ ck_assert_ptr_eq(strNCpyUTF8(NULL, "lib", 1), NULL);
+
+
+}
+
+
+void strLCpyUTF8T(CuTest *tc UNUSED) {
+
+ char s[1024];
+
+ // copy string
+ strLCpyUTF8(s, 100, "lib");
+ ck_assert_str_eq(s, "lib");
+ // truncate src
+ s[0] = 0;
+ s[1] = 0;
+ s[2] = 0;
+ strLCpyUTF8(s, 3, "lib");
+ ck_assert_str_eq(s, "li");
+ s[0] = 'a';
+ s[1] = 'a';
+ s[2] = 'a';
+ s[3] = 0;
+ strLCpyUTF8(s, 3, "lib");
+ ck_assert_str_eq(s, "li");
+ // size 0 - no change in s
+ strLCpyUTF8(s, 0, "libsheepy");
+ ck_assert_str_eq(s, "li");
+ // NULL
+ s[0] = 0;
+ strLCpyUTF8(s, 1, NULL);
+ ck_assert_str_eq(s, "");
+ ck_assert_ptr_eq(strLCpyUTF8(NULL,1, "lib"), NULL);
+
+
+}
+
+
+void strNCatUTF8T(CuTest *tc UNUSED) {
+
+ char s[1024];
+
+ // append string
+ strCpy(s, "lib");
+ strNCatUTF8(s, "sheepy", 100);
+ ck_assert_str_eq(s, "libsheepy");
+ // empty string2
+ strNCatUTF8(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");
+ strNCatUTF8(s, "sheepy", 2);
+ ck_assert_str_eq(s, "libsh");
+ // length 0
+ strNCatUTF8(s, "sheepy", 0);
+ ck_assert_str_eq(s, "libsh");
+ // NULL string2
+ strNCatUTF8(s, NULL, 1);
+ ck_assert_str_eq(s, "libsh");
+ // NULL parameter
+ ck_assert_ptr_eq(strNCatUTF8(NULL, "ad", 1), NULL);
+
+
+}
+
+
+void strLCatUTF8T(CuTest *tc UNUSED) {
+
+ char s[1024];
+
+ // append string
+ strCpy(s, "lib");
+ strLCatUTF8(s, 100, "sheepy");
+ ck_assert_str_eq(s, "libsheepy");
+ // empty string2
+ strLCatUTF8(s, 20, "");
+ ck_assert_str_eq(s, "libsheepy");
+ // s strlen bigger than s size - keep s as it is
+ strLCatUTF8(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");
+ strLCatUTF8(s, 6, "sheepy");
+ ck_assert_str_eq(s, "libsh");
+ // NULL string2
+ strLCatUTF8(s, 1, NULL);
+ ck_assert_str_eq(s, "libsh");
+ // NULL parameter
+ ck_assert_ptr_eq(strLCatUTF8(NULL, 1, "ad"), NULL);
+
+
+}
+
+
+void strLNCatUTF8T(CuTest *tc UNUSED) {
+
+ char s[1024];
+
+ // append string
+ strCpy(s, "lib");
+ strLNCatUTF8(s, 100, "sheepy", 100);
+ ck_assert_str_eq(s, "libsheepy");
+ // empty string2
+ strLNCatUTF8(s, 20, "", 10);
+ ck_assert_str_eq(s, "libsheepy");
+ // s strlen bigger than s size - keep s as it is
+ strLNCatUTF8(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");
+ strLNCatUTF8(s, 6, "sheepy", 4);
+ ck_assert_str_eq(s, "libsh");
+ // 0 source length
+ strLNCatUTF8(s, 6, "sheepy", 0);
+ ck_assert_str_eq(s, "libsh");
+ // NULL string2
+ strLNCatUTF8(s, 1, NULL, 1);
+ ck_assert_str_eq(s, "libsh");
+ // NULL parameter
+ ck_assert_ptr_eq(strLNCatUTF8(NULL, 1, "ad", 1), NULL);
+
+
+}
+
+
+void eqIUTF8T(CuTest *tc UNUSED) {
+
+ // identical strings
+ ck_assert(eqIUTF8("Ashee|", "shee", 1));
+ ck_assert(eqIUTF8("Ashee", "shee", -4));
+ // string at index shorter than string2
+ ck_assert(!eqIUTF8("Ashee", "shee", 2));
+ // empty string
+ ck_assert(!eqIUTF8("", "shee", 0));
+ ck_assert(!eqIUTF8("Ashee", "", 0));
+ ck_assert(eqIUTF8("", "", 0));
+ // index mismatch
+ ck_assert(!eqIUTF8("Ashee", "shee", 0));
+ // index outside
+ ck_assert(!eqIUTF8("Ashee", "shee", 10));
+ ck_assert(!eqIUTF8("Ashee", "shee", -10));
+ // different strings
+ ck_assert(!eqIUTF8("shee", "SH",0));
+ // NULL string
+ ck_assert(!eqIUTF8(NULL,"a", 0));
+ ck_assert(!eqIUTF8("a", NULL, 0));
+
+
+}
+
+
+void eqICharUTF8T(CuTest *tc UNUSED) {
+
+ // identical strings
+ ck_assert(eqICharUTF8("Ashee", 's', 1));
+ ck_assert(eqICharUTF8("Ashee", 's', -4));
+ // string at index shorter than string2
+ ck_assert(!eqICharUTF8("Ashee", 's', 2));
+ // empty string
+ ck_assert(!eqICharUTF8("", 's', 0));
+ ck_assert(!eqICharUTF8("Ashee", 0, 0));
+ ck_assert(eqICharUTF8("", 0, 0));
+ // index mismatch
+ ck_assert(!eqICharUTF8("Ashee", 's', 0));
+ // index outside
+ ck_assert(!eqICharUTF8("Ashee", 's', 10));
+ ck_assert(!eqICharUTF8("Ashee", 's', -10));
+ // different strings
+ ck_assert(!eqICharUTF8("shee", 'S',0));
+ // NULL string
+ ck_assert(!eqICharUTF8(NULL,'a', 0));
+ ck_assert(!eqICharUTF8("a", 0, 0));
+
+
+}
+
+
+void icEqUTF8T(CuTest *tc UNUSED) {
+
+ // identical strings
+ ck_assert(icEqUTF8("SHEE", "shee"));
+ // different strings
+ ck_assert(!icEqUTF8("shee", "SH"));
+ // empty strings
+ ck_assert(!icEqUTF8("shee", ""));
+ ck_assert(!icEqUTF8("", "SH"));
+ ck_assert(icEqUTF8("", ""));
+ // NULL string
+ ck_assert(!icEqUTF8(NULL,"a"));
+ ck_assert(!icEqUTF8("a", NULL));
+
+
+}
+
+
+void icEqCharUTF8T(CuTest *tc UNUSED) {
+
+ // identical strings
+ ck_assert(icEqCharUTF8('S', "s"));
+ // different strings
+ ck_assert(!icEqCharUTF8('s', "SH"));
+ // empty strings
+ ck_assert(!icEqCharUTF8('s', ""));
+ ck_assert(!icEqCharUTF8(0, "SH"));
+ ck_assert(icEqCharUTF8(0, ""));
+ // NULL string
+ ck_assert(!icEqCharUTF8(0,"a"));
+ ck_assert(!icEqCharUTF8('a', NULL));
+
+
+}
+
+
+void icEqUTF8CharT(CuTest *tc UNUSED) {
+
+ // identical strings
+ ck_assert(icEqUTF8Char("S", 's'));
+ // different strings
+ ck_assert(!icEqUTF8Char("shee", 'S'));
+ // empty strings
+ ck_assert(!icEqUTF8Char("shee", 0));
+ ck_assert(!icEqUTF8Char("", 'S'));
+ ck_assert(icEqUTF8Char("", 0));
+ // NULL string
+ ck_assert(!icEqUTF8Char(NULL,'a'));
+ ck_assert(!icEqUTF8Char("a", 0));
+
+
+}
+
+
+void icStartsWithUTF8T(CuTest *tc UNUSED) {
+
+ // identical strings
+ ck_assert(icStartsWithUTF8("SHEE", "shee"));
+ ck_assert(icStartsWithUTF8("SHEEPY", "shee"));
+ // different strings
+ ck_assert(!icStartsWithUTF8("shee", "aH"));
+ ck_assert(!icStartsWithUTF8("shee", "sheep"));
+ ck_assert(!icStartsWithUTF8("-shee", "shee"));
+ // NULL string
+ ck_assert(!icStartsWithUTF8(NULL,"a"));
+ ck_assert(!icStartsWithUTF8("a", NULL));
+
+
+}
+
+
+void icEndsWithUTF8T(CuTest *tc UNUSED) {
+
+ // identical strings
+ ck_assert(icEndsWithUTF8("SHEE", "shee"));
+ ck_assert(icEndsWithUTF8("SHEEPY", "eepy"));
+ // different strings
+ ck_assert(!icEndsWithUTF8("shee", "SH"));
+ ck_assert(!icEndsWithUTF8("shee", "sheep"));
+ ck_assert(!icEndsWithUTF8("shee-", "shee"));
+ // NULL string
+ ck_assert(!icEndsWithUTF8(NULL,"a"));
+ ck_assert(!icEndsWithUTF8("a", NULL));
+
+
+}
+
+
+void icCountUTF8T(CuTest *tc UNUSED) {
+
+ // positive count
+ ck_assert_int_eq(icCountUTF8("SHEE", "shee"), 1);
+ ck_assert_int_eq(icCountUTF8("AAA AAA", "a"), 6);
+ ck_assert_int_eq(icCountUTF8("AAA AAA", "aa"), 2);
+ // 0 count
+ ck_assert_int_eq(icCountUTF8("shee", "eSH"), 0);
+ ck_assert_int_eq(icCountUTF8("shee", "sheepy"), 0);
+ ck_assert_int_eq(icCountUTF8("aaa aaa", "ab"), 0);
+ // NULL string
+ ck_assert_int_eq(icCountUTF8(NULL,"a"), -1);
+ ck_assert_int_eq(icCountUTF8("a", NULL), -1);
+
+
+}
+
+
+void code2RuneUTF8T(CuTest *tc UNUSED) {
+
+ u32 r;
+
+ r = code2RuneUTF8("£");
+ ck_assert_int_eq(r, 163);
+
+}
+
+
+void code2RuneLUTF8T(CuTest *tc UNUSED) {
+
+ u8 n;
+ u32 r;
+
+ r = code2RuneLUTF8("£", &n);
+ ck_assert_int_eq(r, 163);
+ ck_assert_int_eq(n, 2);
+ // empty string
+ r = code2RuneLUTF8("", &n);
+ ck_assert_int_eq(r, 0);
+ // null length
+ r = code2RuneLUTF8("£", null);
+ ck_assert_int_eq(r, 0);
+ // null string
+ r = code2RuneLUTF8(null, &n);
+ ck_assert_int_eq(r, 0);
+
+
+}
+
+
+void bRune2CodeUTF8T(CuTest *tc UNUSED) {
+
+ u8 n;
+ char r[20] = init0Var;
+
+ // pound
+ n = bRune2CodeUTF8(r, 163);
+ ck_assert_str_eq(r, "£");
+ ck_assert_int_eq(n, 2);
+
+ // null dst
+ n = 0;
+ n = bRune2CodeUTF8(null, 163);
+ ck_assert_int_eq(n, 2);
+
+}
+
+
+void runeLenUTF8T(CuTest *tc UNUSED) {
+
+ u8 r;
+
+ r = runeLenUTF8(163);
+ ck_assert_int_eq(r, 2);
+
+
+}
+
+
+void toupperUTF8T(CuTest *tc UNUSED) {
+
+ rune r;
+ char dst[20] = init0Var;
+
+ r = toupperUTF8(163);
+ ck_assert_int_eq(r, 163);
+
+ r = code2RuneUTF8("Ã¥");
+ r = toupperUTF8(r);
+ bRune2CodeUTF8(dst,r);
+ ck_assert_str_eq(dst, "Ã…");
+
+}
+
+
+void upperUTF8T(CuTest *tc UNUSED) {
+
+ // string
+ char *s = upperUTF8("sheepyå");
+ ck_assert_str_eq(s, "SHEEPYÃ…");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(upperUTF8(NULL), NULL);
+
+
+}
+
+
+void iUpperUTF8T(CuTest *tc UNUSED) {
+
+ char *s;
+ // string
+ s = strdup("sheepy");
+ iUpperUTF8(&s);
+ ck_assert_str_eq(s, "SHEEPY");
+ free(s);
+ // NULL string
+ s = NULL;
+ iUpperUTF8(&s);
+ ck_assert_ptr_eq(s, NULL);
+ // NULL var
+ iUpperUTF8(NULL);
+
+
+}
+
+
+void tolowerUTF8T(CuTest *tc UNUSED) {
+
+ rune r;
+ char dst[20] = init0Var;
+
+ r = tolowerUTF8(163);
+ ck_assert_int_eq(r, 163);
+
+ r = code2RuneUTF8("Ã…");
+ r = tolowerUTF8(r);
+ bRune2CodeUTF8(dst,r);
+ ck_assert_str_eq(dst, "Ã¥");
+
+
+}
+
+
+void lowerUTF8T(CuTest *tc UNUSED) {
+
+ // string
+ char *s = lowerUTF8("SHeePY");
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(lowerUTF8(NULL), NULL);
+
+
+}
+
+
+void iLowerUTF8T(CuTest *tc UNUSED) {
+
+ char *s;
+ // string
+ s = strdup("SHEEPY");
+ iLowerUTF8(&s);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // NULL string
+ s = NULL;
+ iLowerUTF8(&s);
+ ck_assert_ptr_eq(s, NULL);
+ // NULL var
+ iLowerUTF8(NULL);
+
+
+}
+
+
+void uniqUTF8T(CuTest *tc UNUSED) {
+
+ char *s;
+
+ // uniquify
+ s = uniqUTF8("∑qwd∑∑∑", "∑");
+ ck_assert_str_eq(s, "∑qwd∑");
+ free(s);
+ // short string
+ s = uniqUTF8("?", "/");
+ ck_assert_str_eq(s, "?");
+ free(s);
+ // NULL
+ ck_assert_ptr_eq(uniqUTF8(NULL, "/"), NULL);
+ ck_assert_ptr_eq(uniqUTF8("sd", null), NULL);
+
+
+}
+
+
+void iUniqUTF8T(CuTest *tc UNUSED) {
+
+ char *s;
+
+ // uniquify
+ s = strdup("/qwd///");
+ ck_assert_str_eq(iUniqUTF8(&s, "/"), "/qwd/");
+ free(s);
+ // short string
+ s = strdup("?");
+ ck_assert_str_eq(iUniqUTF8(&s, "/"), "?");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(iUniqUTF8(&s, null), NULL);
+ s = NULL;
+ ck_assert_ptr_eq(iUniqUTF8(&s, "/"), NULL);
+ // NULL
+ ck_assert_ptr_eq(iUniqUTF8(NULL, "/"), NULL);
+
+
+}
+
+
+void bUniqUTF8T(CuTest *tc UNUSED) {
+
+ char s[100];
+
+ // uniquify
+ strcpy(s, "/qwd///");
+ ck_assert_str_eq(bUniqUTF8(s, "/"), "/qwd/");
+ // short string
+ strcpy(s, "?");
+ ck_assert_str_eq(bUniqUTF8(s, "/"), "?");
+ // NULL
+ ck_assert_ptr_eq(bUniqUTF8(s, null), NULL);
+ ck_assert_ptr_eq(bUniqUTF8(NULL, "/"), NULL);
+
+
+}
+
+
+void getUTF8T(CuTest *tc UNUSED) {
+
+ // get char
+ ck_assert_uint_eq(getUTF8("sheepy", 0), 's');
+ // negative index
+ ck_assert_uint_eq(getUTF8("sheepy", -1), 'y');
+ // outside string
+ ck_assert_uint_eq(getUTF8("sheepy", 10), 0);
+ ck_assert_uint_eq(getUTF8("sheepy", -10), 0);
+ // negative index in a one char string
+ ck_assert_uint_eq(getUTF8("z", -1), 'z');
+ // empty string
+ ck_assert_uint_eq(getUTF8("", 0), 0);
+ // NULL string
+ ck_assert_uint_eq(getUTF8(NULL, 0), 0);
+
+
+}
+
+
+void setUTF8T(CuTest *tc UNUSED) {
+
+ char *s;
+ s = strdup("sheepy");
+
+ // set char
+ setUTF8(s, 0, 'S');
+ ck_assert_uint_eq(s[0], 'S');
+ // negative index
+ setUTF8(s, -2, 'P');
+ ck_assert_uint_eq(s[4], 'P');
+ // outside string
+ setUTF8(s, 20, 'Y');
+ setUTF8(s, -20, 'Y');
+ ck_assert_str_eq(s, "SheePy");
+ free(s);
+ // negative index in a one char string
+ s = strdup("s");
+ setUTF8(s, -1, 'S');
+ ck_assert_uint_eq(s[0], 'S');
+ free(s);
+ // empty string
+ emptyS(s);
+ setUTF8(s, -1, 'S');
+ ck_assert_str_eq(s, "");
+ free(s);
+ // NULL string
+ setUTF8(NULL, 0, 's');
+
+
+}
+
+
+void sliceUTF8T(CuTest *tc UNUSED) {
+
+ // slice
+ char *s = sliceUTF8("sheepy", 0,2);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ // negative index
+ s = sliceUTF8("sheepy", -2,0);
+ ck_assert_str_eq(s, "py");
+ free(s);
+ // positive and negative indexes
+ s = sliceUTF8("sheepy", 2,-2);
+ ck_assert_str_eq(s, "ee");
+ free(s);
+ // start = end
+ s = sliceUTF8("sheepy", 2,-4);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end of string
+ s = sliceUTF8("sheepy", 2,6);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(sliceUTF8(NULL, 2,-4), NULL);
+ // start outside string
+ ck_assert_ptr_eq(sliceUTF8("sheepy", 20,-4), NULL);
+ // end outside string
+ s = sliceUTF8("sheepy", 2,40);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ s = sliceUTF8("sheepy", -22,3);
+ ck_assert_str_eq(s, "she");
+ free(s);
+ ck_assert_ptr_eq(sliceUTF8("sheepy", 2,-40), NULL);
+ // end before start
+ ck_assert_ptr_eq(sliceUTF8("sheepy", 4,2), NULL);
+
+
+}
+
+
+void iSliceUTF8T(CuTest *tc UNUSED) {
+
+ char *s;
+ // slice
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 0,2);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ // negative index
+ s = strdup("sheepy");
+ iSliceUTF8(&s, -2,0);
+ ck_assert_str_eq(s, "py");
+ free(s);
+ // positive and negative indexes
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 2,-2);
+ ck_assert_str_eq(s, "ee");
+ free(s);
+ // start = end
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 2,-4);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end of string
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 2,6);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // NULL string
+ s = NULL;
+ iSliceUTF8(&s, 2,-4);
+ ck_assert_ptr_eq(s, NULL);
+ // start outside string
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 20,-4);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end outside string
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 2,40);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ s = strdup("sheepy");
+ iSliceUTF8(&s, -22,3);
+ ck_assert_str_eq(s, "she");
+ free(s);
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 2,-40);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end before start
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 4,2);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // NULL var
+ iSliceUTF8(NULL, 0, 0);
+
+
+}
+
+
+void bSliceUTF8T(CuTest *tc UNUSED) {
+
+ char s[100];
+ // slice
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 0,2);
+ ck_assert_str_eq(s, "sh");
+ // negative index
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, -2,0);
+ ck_assert_str_eq(s, "py");
+ // positive and negative indexes
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 2,-2);
+ ck_assert_str_eq(s, "ee");
+ // start = end
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 2,-4);
+ ck_assert_str_eq(s, "");
+ // end of string
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 2,6);
+ ck_assert_str_eq(s, "eepy");
+ // start outside string
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 20,-4);
+ ck_assert_str_eq(s, "");
+ // end outside string
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 2,40);
+ ck_assert_str_eq(s, "eepy");
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, -22,3);
+ ck_assert_str_eq(s, "she");
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 2,-40);
+ ck_assert_str_eq(s, "");
+ // end before start
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 4,2);
+ ck_assert_str_eq(s, "");
+ // NULL var
+ ck_assert_ptr_eq(bSliceUTF8(NULL, 0, 0), NULL);
+
+
+}
+
+
+void bLSliceUTF8T(CuTest *tc UNUSED) {
+
+ char s[100];
+ // slice
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 0,2);
+ ck_assert_str_eq(s, "sh");
+ // buffer shorter than string
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, 5, 0,2);
+ ck_assert_str_eq(s, "sh");
+ // negative index
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), -2,0);
+ ck_assert_str_eq(s, "py");
+ // positive and negative indexes
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 2,-2);
+ ck_assert_str_eq(s, "ee");
+ // start = end
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 2,-4);
+ ck_assert_str_eq(s, "");
+ // end of string
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 2,6);
+ ck_assert_str_eq(s, "eepy");
+ // start outside string
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 20,-4);
+ ck_assert_str_eq(s, "");
+ // end outside string
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 2,40);
+ ck_assert_str_eq(s, "eepy");
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), -22,3);
+ ck_assert_str_eq(s, "she");
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 2,-40);
+ ck_assert_str_eq(s, "");
+ // end before start
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 4,2);
+ ck_assert_str_eq(s, "");
+ // size 0
+ ck_assert_ptr_eq(bLSliceUTF8(s, 0, 0, 0), NULL);
+ // NULL var
+ ck_assert_ptr_eq(bLSliceUTF8(NULL, sizeof(s), 0, 0), NULL);
+
+
+}
+
+
+void insertUTF8T(CuTest *tc UNUSED) {
+
+ char *s;
+
+ // insert
+ s = insertUTF8("sheepy", 0, "lib");
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // negative index
+ s = insertUTF8("libsheepy", -2, "P");
+ ck_assert_str_eq(s, "libsheepPy");
+ free(s);
+ // edge
+ s = insertUTF8("qwe", 3, "C");
+ ck_assert_str_eq(s, "qweC");
+ free(s);
+ // outside string
+ s = insertUTF8("qwe", 4, "C");
+ ck_assert_ptr_eq(s, NULL);
+ s = insertUTF8("qwe", -5, "C");
+ ck_assert_ptr_eq(s, NULL);
+ // negative index in a one char string
+ s = insertUTF8("s", -1, "S");
+ ck_assert_str_eq(s, "sS");
+ free(s);
+ // empty string
+ s = insertUTF8("", 0, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+ s = insertUTF8("", -1, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // empty insert string
+ s = insertUTF8("a", 0, "");
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL insert string
+ s = insertUTF8("a", 0, NULL);
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL string
+ s = insertUTF8(NULL, 0, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+
+
+}
+
+
+void insertNFreeUTF8T(CuTest *tc UNUSED) {
+
+ char *s, *a;
+
+ // insert
+ s = insertNFreeUTF8("sheepy", 0, strdup("lib"));
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // negative index
+ s = insertNFreeUTF8("libsheepy", -2, strdup("P"));
+ ck_assert_str_eq(s, "libsheepPy");
+ free(s);
+ // edge
+ s = insertNFreeUTF8("qwe", 3, strdup("C"));
+ ck_assert_str_eq(s, "qweC");
+ free(s);
+ // outside string
+ a = strdup("C");
+ s = insertNFreeUTF8("qwe", 4, a);
+ ck_assert_ptr_eq(s, NULL);
+ s = insertNFreeUTF8("qwe", -5, a);
+ ck_assert_ptr_eq(s, NULL);
+ free(a);
+ // negative index in a one char string
+ s = insertNFreeUTF8("s", -1, strdup("S"));
+ ck_assert_str_eq(s, "sS");
+ free(s);
+ // empty string
+ s = insertNFreeUTF8("", 0, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+ s = insertNFreeUTF8("", -1, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // empty insert string
+ s = insertNFreeUTF8("a", 0, strdup(""));
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL insert string
+ s = insertNFreeUTF8("a", 0, NULL);
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL string
+ s = insertNFreeUTF8(NULL, 0, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+
+
+}
+
+
+void iInsertUTF8T(CuTest *tc UNUSED) {
+
+ char *s;
+
+ // insert
+ s = strdup("sheepy");
+ iInsertUTF8(&s, 0, "lib");
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // negative index
+ s = strdup("libsheepy");
+ iInsertUTF8(&s, -2, "P");
+ ck_assert_str_eq(s, "libsheepPy");
+ free(s);
+ // edge
+ s = strdup("qwe");
+ iInsertUTF8(&s, 3, "C");
+ ck_assert_str_eq(s, "qweC");
+ free(s);
+ // outside string
+ s = strdup("qwe");
+ iInsertUTF8(&s, 4, "C");
+ ck_assert_str_eq(s, "qwe");
+ iInsertUTF8(&s, -5, "C");
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // negative index in a one char string
+ s = strdup("s");
+ iInsertUTF8(&s, -1, "S");
+ ck_assert_str_eq(s, "sS");
+ free(s);
+ // empty string
+ emptyS(s);
+ iInsertUTF8(&s, 0, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+ emptyS(s);
+ iInsertUTF8(&s, -1, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // empty insert string
+ s = strdup("a");
+ iInsertUTF8(&s, 0, "");
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL insert string
+ s = strdup("a");
+ iInsertUTF8(&s, 0, NULL);
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL string
+ s = NULL;
+ iInsertUTF8(&s, 0, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // NULL var
+ iInsertUTF8(NULL, 0, "s");
+
+
+}
+
+
+void iInsertNFreeUTF8T(CuTest *tc UNUSED) {
+
+ char *s, *a, *r;
+
+ // insert
+ s = strdup("sheepy");
+ iInsertNFreeUTF8(&s, 0, strdup("lib"));
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // negative index
+ s = strdup("libsheepy");
+ iInsertNFreeUTF8(&s, -2, strdup("P"));
+ ck_assert_str_eq(s, "libsheepPy");
+ free(s);
+ // edge
+ s = strdup("qwe");
+ iInsertNFreeUTF8(&s, 3, strdup("C"));
+ ck_assert_str_eq(s, "qweC");
+ free(s);
+ // outside string
+ s = strdup("qwe");
+ a = strdup("C");
+ r = iInsertNFreeUTF8(&s, 4, a);
+ ck_assert_ptr_eq(r, NULL);
+ ck_assert_str_eq(s, "qwe");
+ r = iInsertNFreeUTF8(&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");
+ iInsertNFreeUTF8(&s, -1, strdup("S"));
+ ck_assert_str_eq(s, "sS");
+ free(s);
+ // empty string
+ emptyS(s);
+ iInsertNFreeUTF8(&s, 0, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+ emptyS(s);
+ iInsertNFreeUTF8(&s, -1, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // empty insert string
+ s = strdup("a");
+ iInsertNFreeUTF8(&s, 0, strdup(""));
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL insert string
+ s = strdup("a");
+ iInsertNFreeUTF8(&s, 0, NULL);
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL string
+ s = NULL;
+ iInsertNFreeUTF8(&s, 0, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // NULL var
+ s = strdup("s");
+ r = iInsertNFreeUTF8(NULL, 0, s);
+ ck_assert_ptr_eq(r, NULL);
+ free(s);
+
+
+}
+
+
+void bInsertUTF8T(CuTest *tc UNUSED) {
+
+ char s[100];
+
+ // insert
+ strcpy(s, "sheepy");
+ bInsertUTF8(s, 0, "lib");
+ ck_assert_str_eq(s, "libsheepy");
+ // negative index
+ strcpy(s, "libsheepy");
+ bInsertUTF8(s, -2, "P");
+ ck_assert_str_eq(s, "libsheepPy");
+ // edge
+ strcpy(s, "qwe");
+ bInsertUTF8(s, 3, "C");
+ ck_assert_str_eq(s, "qweC");
+ // outside string
+ strcpy(s, "qwe");
+ bInsertUTF8(s, 4, "C");
+ ck_assert_str_eq(s, "qwe");
+ bInsertUTF8(s, -5, "C");
+ ck_assert_str_eq(s, "qwe");
+ // negative index in a one char string
+ strcpy(s, "s");
+ bInsertUTF8(s, -1, "S");
+ ck_assert_str_eq(s, "sS");
+ // empty string
+ bEmptyS(s);
+ bInsertUTF8(s, 0, "s");
+ ck_assert_str_eq(s, "s");
+ bEmptyS(s);
+ bInsertUTF8(s, -1, "s");
+ ck_assert_str_eq(s, "s");
+ // empty insert string
+ strcpy(s, "a");
+ bInsertUTF8(s, 0, "");
+ ck_assert_str_eq(s, "a");
+ // NULL insert string
+ strcpy(s, "a");
+ bInsertUTF8(s, 0, NULL);
+ ck_assert_str_eq(s, "a");
+ // NULL var
+ ck_assert_ptr_eq(bInsertUTF8(NULL, 0, "s"), NULL);
+
+
+}
+
+
+void bLInsertUTF8T(CuTest *tc UNUSED) {
+
+ char s[100];
+
+ // insert
+ strcpy(s, "sheepy");
+ bLInsertUTF8(s, sizeof s, 0, "lib");
+ ck_assert_str_eq(s, "libsheepy");
+ // shorter buffer
+ strcpy(s, "sheepy");
+ bLInsertUTF8(s, 5, 0, "lib");
+ ck_assert_str_eq(s, "libs");
+ // negative index
+ strcpy(s, "libsheepy");
+ bLInsertUTF8(s, sizeof s, -2, "P");
+ ck_assert_str_eq(s, "libsheepPy");
+ // edge
+ strcpy(s, "qwe");
+ bLInsertUTF8(s, sizeof s, 3, "C");
+ ck_assert_str_eq(s, "qweC");
+ // outside string
+ strcpy(s, "qwe");
+ bLInsertUTF8(s, sizeof s, 4, "C");
+ ck_assert_str_eq(s, "qwe");
+ bLInsertUTF8(s, sizeof s, -5, "C");
+ ck_assert_str_eq(s, "qwe");
+ // negative index in a one char string
+ strcpy(s, "s");
+ bLInsertUTF8(s, sizeof s, -1, "S");
+ ck_assert_str_eq(s, "sS");
+ // empty string
+ bEmptyS(s);
+ bLInsertUTF8(s, sizeof s, 0, "s");
+ ck_assert_str_eq(s, "s");
+ bEmptyS(s);
+ bLInsertUTF8(s, sizeof s, -1, "s");
+ ck_assert_str_eq(s, "s");
+ // empty insert string
+ strcpy(s, "a");
+ bLInsertUTF8(s, sizeof s, 0, "");
+ ck_assert_str_eq(s, "a");
+ // size 0 - no change
+ bLInsertUTF8(s, 0, 0, "qwe");
+ ck_assert_str_eq(s, "a");
+ // NULL insert string
+ strcpy(s, "a");
+ bLInsertUTF8(s, sizeof s, 0, NULL);
+ ck_assert_str_eq(s, "a");
+ // NULL var
+ ck_assert_ptr_eq(bLInsertUTF8(NULL, sizeof s, 0, "s"), NULL);
+
+
+}
+
+
+void delUTF8T(CuTest *tc UNUSED) {
+
+ // del
+ char *s = delUTF8("sheepy", 0,2);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // negative index
+ s = delUTF8("sheepy", -2,0);
+ ck_assert_str_eq(s, "shee");
+ free(s);
+ // positive and negative indexes
+ s = delUTF8("sheepy", 2,-2);
+ ck_assert_str_eq(s, "shpy");
+ free(s);
+ // start = end
+ s = delUTF8("sheepy", 2,-4);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // delete entire string
+ s = delUTF8("sheepy", 0,0);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end of string
+ s = delUTF8("sheepy", 2,6);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(delUTF8(NULL, 2,-4), NULL);
+ // start outside string
+ ck_assert_ptr_eq(delUTF8("sheepy", 20,-4), NULL);
+ s = delUTF8("sheepy", -20,-4);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // end outside string
+ s = delUTF8("sheepy", 2,40);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ ck_assert_ptr_eq(delUTF8("sheepy", 2,-40), NULL);
+ // end before start
+ ck_assert_ptr_eq(delUTF8("sheepy", 4,2), NULL);
+
+
+}
+
+
+void iDelUTF8T(CuTest *tc UNUSED) {
+
+ char *s;
+ // del
+ s = strdup("sheepy");
+ iDelUTF8(&s, 0,2);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // negative index
+ s = strdup("sheepy");
+ iDelUTF8(&s, -2,0);
+ ck_assert_str_eq(s, "shee");
+ free(s);
+ // positive and negative indexes
+ s = strdup("sheepy");
+ iDelUTF8(&s, 2,-2);
+ ck_assert_str_eq(s, "shpy");
+ free(s);
+ // start = end
+ s = strdup("sheepy");
+ iDelUTF8(&s, 2,-4);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // delete entire string
+ s = strdup("sheepy");
+ iDelUTF8(&s, 0,0);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end of string
+ s = strdup("sheepy");
+ iDelUTF8(&s, 2,6);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ // NULL string
+ s = NULL;
+ iDelUTF8(&s, 2,-4);
+ ck_assert_ptr_eq(s, NULL);
+ // start outside string
+ s = strdup("sheepy");
+ iDelUTF8(&s, 20,-4);
+ ck_assert_str_eq(s, "sheepy");
+ iDelUTF8(&s, -20,-4);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // end outside string
+ s = strdup("sheepy");
+ iDelUTF8(&s, 2,40);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ s = strdup("sheepy");
+ iDelUTF8(&s, 2,-40);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // end before start
+ s = strdup("sheepy");
+ iDelUTF8(&s, 4,2);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // NULL var
+ iDelUTF8(NULL, 4,2);
+
+
+}
+
+
+void bDelUTF8T(CuTest *tc UNUSED) {
+
+ char s[100];
+ // del
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 0,2);
+ ck_assert_str_eq(s, "eepy");
+ // negative index
+ strcpy(s, "sheepy");
+ bDelUTF8(s, -2,0);
+ ck_assert_str_eq(s, "shee");
+ // positive and negative indexes
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 2,-2);
+ ck_assert_str_eq(s, "shpy");
+ // start = end
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 2,-4);
+ ck_assert_str_eq(s, "sheepy");
+ // delete entire string
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 0,0);
+ ck_assert_str_eq(s, "");
+ // end of string
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 2,6);
+ ck_assert_str_eq(s, "sh");
+ // start outside string
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 20,-4);
+ ck_assert_str_eq(s, "sheepy");
+ bDelUTF8(s, -20,-4);
+ ck_assert_str_eq(s, "eepy");
+ // end outside string
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 2,40);
+ ck_assert_str_eq(s, "sh");
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 2,-40);
+ ck_assert_str_eq(s, "sheepy");
+ // end before start
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 4,2);
+ ck_assert_str_eq(s, "sheepy");
+ // NULL var
+ ck_assert_ptr_eq(bDelUTF8(NULL, 4,2), NULL);
+
+
+}
+
+
+void bLDelUTF8T(CuTest *tc UNUSED) {
+
+ char s[100];
+ // del
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 0,2);
+ ck_assert_str_eq(s, "eepy");
+ // buffer shorter than string
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, 5, 0,2);
+ ck_assert_str_eq(s, "ee");
+ // negative index
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), -2,0);
+ ck_assert_str_eq(s, "shee");
+ // positive and negative indexes
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 2,-2);
+ ck_assert_str_eq(s, "shpy");
+ // start = end
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 2,-4);
+ ck_assert_str_eq(s, "sheepy");
+ // end of string
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 2,6);
+ ck_assert_str_eq(s, "sh");
+ // start outside string
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 20,-4);
+ ck_assert_str_eq(s, "sheepy");
+ // end outside string
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 2,40);
+ ck_assert_str_eq(s, "sh");
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), -22,3);
+ ck_assert_str_eq(s, "epy");
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 2,-40);
+ ck_assert_str_eq(s, "sheepy");
+ // end before start
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 4,2);
+ ck_assert_str_eq(s, "sheepy");
+ // size 0
+ ck_assert_ptr_eq(bLDelUTF8(s, 0, 0, 0), NULL);
+ // NULL var
+ ck_assert_ptr_eq(bLDelUTF8(NULL, sizeof(s), 0, 0), NULL);
+
+
+}
+
+
+void indexOfUTF8T(CuTest *tc UNUSED) {
+
+ // indexOf string in the middle
+ ck_assert_int_eq(indexOfUTF8("sheepy", "ee"), 2);
+ // indexOf non existing string
+ ck_assert_int_eq(indexOfUTF8("sheepy", "$"), -1);
+ // indexOf NULL
+ ck_assert_int_eq(indexOfUTF8("sheepy", NULL), -1);
+ // NULL string
+ ck_assert_int_eq(indexOfUTF8(NULL, "$"), -1);
+
+
+}
+
+
+void icHasUTF8T(CuTest *tc UNUSED) {
+
+ // find string in the middle
+ ck_assert(icHasUTF8("sheepy", "EE"));
+ // find non existing string
+ ck_assert(!icHasUTF8("sheepy", "$"));
+ // find NULL
+ ck_assert(!icHasUTF8("sheepy", NULL));
+ // NULL string
+ ck_assert(!icHasUTF8(NULL, "$"));
+
+
+}
+
+
+void icListSortUTF8T(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list
+ listPushS(&l, "1sdfdsf");
+ listPushS(&l, "4444");
+ listPushS(&l, "3");
+ listPushS(&l, "22sdf");
+ l2 = icListSortUTF8(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 = icListSortUTF8(l);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "1sdfdsf");
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l2)
+ l = icListSortUTF8(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(icListSortUTF8(NULL), NULL);
+
+
+}
+
+
+void iicListSortUTF8T(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+
+ // list
+ listPushS(&l, "1sdfdsf");
+ listPushS(&l, "4444");
+ listPushS(&l, "3");
+ listPushS(&l, "22sdf");
+ iicListSortUTF8(&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");
+ iicListSortUTF8(&l);
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "1sdfdsf");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ iicListSortUTF8(&l);
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ iicListSortUTF8(&l);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iicListSortUTF8(NULL);
+
+
+}
+
+
+void icListEqUTF8T(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+ char **l2;
+
+ // identical lists
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = listDupS(l);
+ ck_assert(icListEqUTF8(l,l2));
+ // NULL lists
+ ck_assert(!icListEqUTF8(NULL,l));
+ ck_assert(!icListEqUTF8(l,NULL));
+ ck_assert(!icListEqUTF8(NULL,NULL));
+ // different lists same number of elements
+ l[3][0] = 'A';
+ ck_assert(!icListEqUTF8(l,l2));
+ // different number of elements
+ char *s = listPopS(&l);
+ free(s);
+ ck_assert(!icListEqUTF8(l,l2));
+ listFreeS(l);
+ listFreeS(l2);
+
+
+}
+
+
+void icListHasUTF8T(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+
+ // string
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ ck_assert(icListHasUTF8(l, "1"));
+ // NULL list
+ ck_assert(!icListHasUTF8(NULL, "1"));
+ // NULL string
+ ck_assert(!icListHasUTF8(l, NULL));
+ // non existing element
+ ck_assert(!icListHasUTF8(l, "wfe"));
+ // string in list
+ ck_assert(icListHasUTF8(l, "333"));
+ listFreeS(l);
+
+
+}
+
+
+void icListIndexOfUTF8T(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+
+ // string
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ ck_assert_uint_eq(icListIndexOfUTF8(l, "1"),0);
+ // NULL list
+ ck_assert_uint_eq(icListIndexOfUTF8(NULL, "1"),-1);
+ // NULL string
+ ck_assert_uint_eq(icListIndexOfUTF8(l, NULL),-1);
+ // non existing element
+ ck_assert_uint_eq(icListIndexOfUTF8(l, "wfe"),-1);
+ // string in list
+ ck_assert_uint_eq(icListIndexOfUTF8(l, "333"),2);
+ listFreeS(l);
+
+
+}
+
+
+void icListBinarySearchUTF8T(CuTest *tc UNUSED) {
+
+ 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(icListBinarySearchUTF8(l, "1"),0);
+ // NULL list
+ ck_assert_uint_eq(icListBinarySearchUTF8(NULL, "1"),-1);
+ // NULL string
+ ck_assert_uint_eq(icListBinarySearchUTF8(l, NULL),-1);
+ // non existing element
+ ck_assert_uint_eq(icListBinarySearchUTF8(l, "wfe"),-1);
+ // string in list
+ ck_assert_uint_eq(icListBinarySearchUTF8(l, "333"),2);
+ listFreeS(l);
+
+
+}
+
+
+void icListUniqUTF8T(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list with unique elements
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = icListUniqUTF8(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 = icListUniqUTF8(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 = icListUniqUTF8(l);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "1");
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l)
+ l2 = icListUniqUTF8(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(icListUniqUTF8(NULL), NULL);
+
+
+}
+
+
+void iicListUniqUTF8T(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list with unique elements
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = listDupS(l);
+ iicListUniqUTF8(&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);
+ iicListUniqUTF8(&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);
+ iicListUniqUTF8(&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);
+ iicListUniqUTF8(&l2);
+ ck_assert_uint_eq(listLengthS(l2),0);
+ ck_assert_ptr_eq(l2[0], NULL);
+ listFreeS(l);
+ listFreeS(l2);
+ // NULL list
+ l = NULL;
+ iicListUniqUTF8(&l);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iicListUniqUTF8(NULL);
+
+
+}
+
+
+void emptySFT(CuTest *tc UNUSED) {
+
+ char *s;
+
+ // empty string
+ s = emptySF();
+ ck_assert(isEmptyS(s));
+ free(s);
+
+}
+
+
+void iEmptySFT(CuTest *tc UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 intIndexT(CuTest *tc UNUSED) {
+
+ ssize_t r;
+
+ // positive index
+ r = intIndex(2,3);
+ ck_assert_int_eq(r, 2);
+ // negative index
+ r = intIndex(-1,3);
+ ck_assert_int_eq(r, 2);
+ r = intIndex(-3,3);
+ ck_assert_int_eq(r, 0);
+ // outside length
+ r = intIndex(3,3);
+ ck_assert_int_eq(r, -1);
+ r = intIndex(-4,3);
+ ck_assert_int_eq(r, -1);
+ // length 0
+ r = intIndex(-1,0);
+ ck_assert_int_eq(r, -1);
+
+}
+
+
+void listEmptySFT(CuTest *tc UNUSED) {
+
+ char **l;
+
+ // empty list
+ l = listEmptySF();
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+
+}
+
+
+void iListEmptySFT(CuTest *tc UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 listStrLengthST(CuTest *tc UNUSED) {
+
+ char **l = null;
+ ssize_t r;
+
+ listPushS(&l, "lib");
+ listPushS(&l, "sheepy");
+ r = listStrLengthS(l);
+ ck_assert_int_eq(r, 9);
+ listFreeS(l);
+ // null list
+ ck_assert_int_eq(listStrLengthS(null), -1);
+
+}
+
+
+void listIntIndexST(CuTest *tc UNUSED) {
+
+ char **l = null;
+ ssize_t r;
+ listPushS(&l, "lib");
+ listPushS(&l, "sheepy");
+ listPushS(&l, "sheepy");
+ // positive index
+ r = listIntIndexS(l, 2);
+ ck_assert_int_eq(r, 2);
+ // negative index
+ r = listIntIndexS(l, -1);
+ ck_assert_int_eq(r, 2);
+ r = listIntIndexS(l, -3);
+ ck_assert_int_eq(r, 0);
+ // outside length
+ r = listIntIndexS(l, 3);
+ ck_assert_int_eq(r, -1);
+ r = listIntIndexS(l, -4);
+ ck_assert_int_eq(r, -1);
+ listFreeS(l);
+ // length 0
+ listEmptyS(l);
+ r = listIntIndexS(l, -1);
+ ck_assert_int_eq(r, -1);
+ listFreeS(l);
+ // null list
+ ck_assert_int_eq(listIntIndexS(NULL, 1), -1);
+
+}
+
+
+void listAddrST(CuTest *tc UNUSED) {
+
+ char **l = null;
+ char **r;
+ listPushS(&l, "lib");
+ listPushS(&l, "sheepy");
+ listPushS(&l, "sheepy");
+ // positive index
+ r = listAddrS(l, 2);
+ ck_assert_ptr_eq(r, &l[2]);
+ // negative index
+ r = listAddrS(l, -1);
+ ck_assert_ptr_eq(r, &l[2]);
+ r = listAddrS(l, -3);
+ ck_assert_ptr_eq(r, &l[0]);
+ // outside length
+ r = listAddrS(l, 3);
+ ck_assert_ptr_eq(r, null);
+ r = listAddrS(l, -4);
+ ck_assert_ptr_eq(r, null);
+ listFreeS(l);
+ // length 0
+ listEmptyS(l);
+ r = listAddrS(l, -1);
+ ck_assert_ptr_eq(r, null);
+ listFreeS(l);
+ // null list
+ ck_assert_ptr_eq(listAddrS(NULL, 1), null);
+
+
+}
+
+
+void listCreateST(CuTest *tc UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 listPushCharST(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+
+ // push strings and NULL list
+ listPushCharS(&l, 's');
+ // check ck_assert_ptr_null not available in jessie
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert_str_eq(l[0], "s");
+ listPushCharS(&l, 'S');
+ ck_assert_str_eq(l[1], "S");
+ ck_assert_str_eq(l[0], "s");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ listPushCharS(&l, 's');
+ ck_assert_str_eq(l[0], "s");
+ ck_assert_ptr_eq(l[1], NULL);
+ listFreeS(l);
+ // NULL pointer to list
+ listPushCharS(NULL, 's');
+
+
+}
+
+
+void iListPushST(CuTest *tc UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 listPrependCharST(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+
+ // push strings and NULL list
+ listPrependCharS(&l, 's');
+ // check ck_assert_ptr_null not available in jessie
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert_str_eq(l[0], "s");
+ listPrependCharS(&l, 'S');
+ ck_assert_str_eq(l[0], "S");
+ ck_assert_str_eq(l[1], "s");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ listPrependCharS(&l, 's');
+ ck_assert_str_eq(l[0], "s");
+ ck_assert_ptr_eq(l[1], NULL);
+ listFreeS(l);
+ // NULL pointer to list
+ listPrependCharS(NULL, 's');
+
+
+}
+
+
+void iListPrependST(CuTest *tc UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ // 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 UNUSED) {
+
+ // 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 UNUSED) {
+
+ char **l;
+
+ // print text
+ l = readText("textTest.null");
+ // TODO check stdout
+ //listPrintS(l);
+ listFreeS(l);
+ // NULL list
+ listPrintS(NULL);
+
+}
+
+
+void listForEachT(CuTest *tc UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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);
+
+}
+
+/**
+ * list Sort String Compare function
+ *
+ * in:
+ * a
+ * b
+ * out:
+ * test result
+ */
+local int listSortSCmp(const void * a, const void * b) {
+
+ // sanity checks
+ if (!a && !b) {
+ return(0);
+ }
+ if (!a && b) {
+ return(-1);
+ }
+ if (a && !b) {
+ return(1);
+ }
+ return(strcmp(*(char **)a,*(char **)b));
+}
+
+void listSortFST(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list
+ listPushS(&l, "1sdfdsf");
+ listPushS(&l, "4444");
+ listPushS(&l, "3");
+ listPushS(&l, "22sdf");
+ l2 = listSortFS(l, listSortSCmp);
+ 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 = listSortFS(l, listSortSCmp);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "1sdfdsf");
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l2)
+ l = listSortFS(l2, listSortSCmp);
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ listFreeS(l);
+ // NULL compare function
+ ck_assert_ptr_eq(listSortFS(l2, NULL), NULL);
+ listFreeS(l2);
+ // NULL list
+ ck_assert_ptr_eq(listSortFS(NULL, listSortSCmp), NULL);
+
+
+}
+
+
+void iListSortFST(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+
+ // list
+ listPushS(&l, "1sdfdsf");
+ listPushS(&l, "4444");
+ listPushS(&l, "3");
+ listPushS(&l, "22sdf");
+ iListSortFS(&l, listSortSCmp);
+ ck_assert_str_eq(l[0], "1sdfdsf");
+ ck_assert_str_eq(l[3], "4444");
+ listFreeS(l);
+ // one element list
+ l = NULL;
+ listPushS(&l, "1sdfdsf");
+ iListSortFS(&l, listSortSCmp);
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "1sdfdsf");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ iListSortFS(&l, listSortSCmp);
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ // NULL compare function
+ ck_assert_ptr_eq(iListSortFS(&l, null), null);
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ iListSortFS(&l, listSortSCmp);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListSortFS(NULL, listSortSCmp);
+
+
+}
+
+
+void icListSortST(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+ char **l2;
+
+ // list
+ listPushS(&l, "A1sdfdsf");
+ listPushS(&l, "d4444");
+ listPushS(&l, "c3");
+ listPushS(&l, "B22sdf");
+ l2 = icListSortS(l);
+ ck_assert_str_eq(l2[0], "A1sdfdsf");
+ ck_assert_str_eq(l2[3], "d4444");
+ listFreeS(l);
+ listFreeS(l2);
+ // one element list
+ l = NULL;
+ listPushS(&l, "1sdfdsf");
+ l2 = icListSortS(l);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "1sdfdsf");
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l2)
+ l = icListSortS(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(icListSortS(NULL), NULL);
+
+
+}
+
+
+void iicListSortST(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+
+ // list
+ listPushS(&l, "a1sdfdsf");
+ listPushS(&l, "D4444");
+ listPushS(&l, "B3");
+ listPushS(&l, "c22sdf");
+ iicListSortS(&l);
+ ck_assert_str_eq(l[0], "a1sdfdsf");
+ ck_assert_str_eq(l[3], "D4444");
+ listFreeS(l);
+ // one element list
+ l = NULL;
+ listPushS(&l, "1sdfdsf");
+ iicListSortS(&l);
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "1sdfdsf");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ iicListSortS(&l);
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ iicListSortS(&l);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iicListSortS(NULL);
+
+
+}
+
+
+void readTextT(CuTest *tc UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 listSetCharST(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+
+ // get string
+ listPushS(&l, "@@");
+ listPushS(&l, "22");
+ listPushS(&l, "|");
+ listPushS(&l, "4444");
+ listSetCharS(l, 0, '1');
+ char *s = listGetS(l, 0);
+ ck_assert_str_eq(s, "1");
+ free(s);
+ // negative index
+ listSetCharS(l, -2, '3');
+ s = listGetS(l, -2);
+ ck_assert_str_eq(s, "3");
+ free(s);
+ // outside list
+ // list is unchanged
+ listSetCharS(l, 10, 'Q');
+ listSetCharS(l, -10, 'Q');
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_str_eq(l[2], "3");
+ ck_assert_str_eq(l[3], "4444");
+ listFreeS(l);
+ // negative index in a one element list
+ l = NULL;
+ listPushS(&l, "ASD");
+ listPushS(&l, NULL);
+ listSetCharS(l, -1, 'Q');
+ s = listGetS(l,-1);
+ ck_assert_str_eq(s, "Q");
+ free(s);
+ listFreeS(l);
+ // empty list - should not crash
+ listEmptyS(l)
+ listSetCharS(l, 0, 'Q');
+ ck_assert_ptr_eq(listGetS(l,0),NULL);
+ free(l);
+ // NULL list
+ listSetCharS(NULL, 0, 'Q');
+ ck_assert_ptr_eq(listGetS(NULL, 0), NULL);
+
+
+}
+
+
+void iListSetST(CuTest *tc UNUSED) {
+
+ 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 listSwapST(CuTest *tc UNUSED) {
+
+ char **l = null;
+ char **r;
+ listPushS(&l, "lib");
+ listPushS(&l, "sheepy");
+ listPushS(&l, "spm");
+ // positive index
+ r = listSwapS(l, 0, 2);
+ ck_assert_str_eq(r[0], "spm");
+ ck_assert_str_eq(r[1], "sheepy");
+ ck_assert_str_eq(r[2], "lib");
+ listFreeS(r);
+ // negative index
+ r = listSwapS(l, -1, 1);
+ ck_assert_str_eq(r[0], "lib");
+ ck_assert_str_eq(r[1], "spm");
+ ck_assert_str_eq(r[2], "sheepy");
+ listFreeS(r);
+ r = listSwapS(l, -3, 1);
+ ck_assert_str_eq(r[0], "sheepy");
+ ck_assert_str_eq(r[1], "lib");
+ ck_assert_str_eq(r[2], "spm");
+ listFreeS(r);
+ // swap equal indexes
+ r = listSwapS(l, -3, -3);
+ ck_assert_str_eq(r[0], "lib");
+ ck_assert_str_eq(r[1], "sheepy");
+ ck_assert_str_eq(r[2], "spm");
+ listFreeS(r);
+ r = listSwapS(&l[2], 0, -1);
+ ck_assert_str_eq(r[0], "spm");
+ listFreeS(r);
+ // 1 element list
+ // outside length
+ r = listSwapS(l, 0, 3);
+ ck_assert_ptr_eq(r, null);
+ r = listSwapS(l, 0, -4);
+ ck_assert_ptr_eq(r, null);
+ r = listSwapS(l, 3, 0);
+ ck_assert_ptr_eq(r, null);
+ r = listSwapS(l, -4, 0);
+ ck_assert_ptr_eq(r, null);
+ listFreeS(l);
+ // length 0
+ listEmptyS(l);
+ r = listSwapS(l, -1, 0);
+ ck_assert_ptr_eq(r, null);
+ listFreeS(l);
+ // null list
+ ck_assert_ptr_eq(listSwapS(NULL, 1, 1), null);
+
+
+}
+
+
+void iListSwapST(CuTest *tc UNUSED) {
+
+ char **l = null;
+ char **r;
+ listPushS(&l, "lib");
+ listPushS(&l, "sheepy");
+ listPushS(&l, "spm");
+ // positive index
+ r = iListSwapS(l, 0, 2);
+ ck_assert_str_eq(r[0], "spm");
+ ck_assert_str_eq(r[1], "sheepy");
+ ck_assert_str_eq(r[2], "lib");
+ // negative index
+ r = iListSwapS(l, -1, 1);
+ ck_assert_str_eq(r[0], "spm");
+ ck_assert_str_eq(r[1], "lib");
+ ck_assert_str_eq(r[2], "sheepy");
+ r = iListSwapS(l, -3, 1);
+ ck_assert_str_eq(r[0], "lib");
+ ck_assert_str_eq(r[1], "spm");
+ ck_assert_str_eq(r[2], "sheepy");
+ // swap equal indexes
+ r = iListSwapS(l, -3, -3);
+ ck_assert_str_eq(r[0], "lib");
+ ck_assert_str_eq(r[1], "spm");
+ ck_assert_str_eq(r[2], "sheepy");
+ r = iListSwapS(&l[2], 0, -1);
+ ck_assert_str_eq(r[0], "sheepy");
+ // 1 element list
+ // outside length
+ r = iListSwapS(l, 0, 3);
+ ck_assert_ptr_eq(r, null);
+ r = iListSwapS(l, 0, -4);
+ ck_assert_ptr_eq(r, null);
+ r = iListSwapS(l, 3, 0);
+ ck_assert_ptr_eq(r, null);
+ r = iListSwapS(l, -4, 0);
+ ck_assert_ptr_eq(r, null);
+ listFreeS(l);
+ // length 0
+ listEmptyS(l);
+ r = iListSwapS(l, -1, 0);
+ ck_assert_ptr_eq(r, null);
+ listFreeS(l);
+ // null list
+ ck_assert_ptr_eq(iListSwapS(NULL, 1, 1), null);
+
+
+}
+
+
+void splitT(CuTest *tc UNUSED) {
+
+ 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 splitCharT(CuTest *tc UNUSED) {
+
+ char **l;
+
+ // string
+ l = splitChar("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 = splitChar("/one", '/');
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "");
+ ck_assert_str_eq(l[1], "one");
+ listFreeS(l);
+ l = splitChar("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 = splitChar("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 = splitChar("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);
+ // empty string
+ l = splitChar("", '$');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "");
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(splitChar(NULL, ';'), NULL);
+
+
+}
+
+
+void icSplitT(CuTest *tc UNUSED) {
+
+ char **l;
+
+ // string
+ l = icSplit("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 = icSplit("/one", "/");
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "");
+ ck_assert_str_eq(l[1], "one");
+ listFreeS(l);
+ l = icSplit("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 = icSplit("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 = icSplit("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 = icSplit("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 = icSplit("AAd", "");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "AAd");
+ listFreeS(l);
+ // empty string
+ l = icSplit("", "$");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "");
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(icSplit(NULL, ";"), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(icSplit("test", NULL), NULL);
+
+
+}
+
+
+void icSplitCharT(CuTest *tc UNUSED) {
+
+ char **l;
+
+ // string
+ l = icSplitChar("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 = icSplitChar("/one", '/');
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "");
+ ck_assert_str_eq(l[1], "one");
+ listFreeS(l);
+ l = icSplitChar("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 = icSplitChar("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 = icSplitChar("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);
+ // empty string
+ l = icSplitChar("", '$');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "");
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(icSplitChar(NULL, ';'), NULL);
+
+
+}
+
+
+void joinLengthT(CuTest *tc UNUSED) {
+
+ ssize_t r;
+ char **l = listCreateS("","lib","sheepy");
+ char *s;
+
+ r = joinLength(l, "/");
+ s = join(l, "/");
+ ck_assert_int_eq(r, strlen(s));
+ free(s);
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ r = joinLength(l, "/");
+ ck_assert_int_eq(r, 0);
+ listFreeS(l);
+ // NULL delimiter
+ ck_assert_int_eq(joinLength(l, NULL), -1);
+ // NULL list
+ ck_assert_int_eq(joinLength(NULL, ";"), -1);
+
+}
+
+
+void joinT(CuTest *tc UNUSED) {
+
+ 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 joinCharT(CuTest *tc UNUSED) {
+
+ char **l;
+ char *s;
+
+ // list
+ l = split("one/two", "/");
+ s = joinChar(l, '/');
+ ck_assert_str_eq(s, "one/two");
+ listFreeS(l);
+ free(s);
+ // empty list
+ listEmptyS(l)
+ s = joinChar(l, '/');
+ ck_assert(isEmptyS(s));
+ listFreeS(l);
+ free(s);
+ // NULL list
+ ck_assert_ptr_eq(joinChar(NULL, ';'), NULL);
+
+
+}
+
+
+void bJoinT(CuTest *tc UNUSED) {
+
+ 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)
+ 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 bJoinCharT(CuTest *tc UNUSED) {
+
+ char **l;
+ char s[100];
+
+ // list
+ l = split("one/two", "/");
+ bJoinChar(s, l, '/');
+ ck_assert_str_eq(s, "one/two");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ ck_assert_ptr_eq(bJoinChar(s, l, '/'), NULL);
+ ck_assert_str_eq(s, "one/two");
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(bJoinChar(s, NULL, ';'), NULL);
+
+
+}
+
+
+void bLJoinT(CuTest *tc UNUSED) {
+
+ 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 bLJoinCharT(CuTest *tc UNUSED) {
+
+ char **l;
+ char s[100];
+
+ // list
+ l = split("one/two", "/");
+ bLJoinChar(s, sizeof s, l, '/');
+ ck_assert_str_eq(s, "one/two");
+ // shorter buffer
+ bLJoinChar(s, 5, l, '/');
+ ck_assert_str_eq(s, "one/");
+ // size 0 - no change
+ bLJoinChar(s, 0, l, '/');
+ ck_assert_str_eq(s, "one/");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ ck_assert_ptr_eq(bLJoinChar(s, sizeof s, l, '/'), NULL);
+ ck_assert_str_eq(s, "one/");
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(bLJoinChar(s, sizeof s, NULL, ';'), NULL);
+
+
+}
+
+
+void extractST(CuTest *tc UNUSED) {
+
+ 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 extractCharSST(CuTest *tc UNUSED) {
+
+ char **l;
+
+ // string
+ l = extractCharSS("one/two|", '/', "|");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "two");
+ listFreeS(l);
+ // delimiter not found
+ l = extractCharSS("one/two", '|', "/");
+ ck_assert_ptr_eq(l, NULL);
+ // extractCharSS with several delimiters after each other
+ l = extractCharSS("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);
+ // empty string
+ l = extractCharSS("", '$', "#");
+ ck_assert_ptr_eq(l, NULL);
+ // delim1 = delim2
+ l = extractCharSS("", '$', "$");
+ ck_assert_ptr_eq(l, NULL);
+ // NULL string
+ ck_assert_ptr_eq(extractCharSS(NULL, ';', ","), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(extractCharSS("test", ',', NULL), NULL);
+
+
+}
+
+
+void extractSCharST(CuTest *tc UNUSED) {
+
+ char **l;
+
+ // string
+ l = extractSCharS("one/two|", "/", '|');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "two");
+ listFreeS(l);
+ // delimiter not found
+ l = extractSCharS("one/two", "||", '/');
+ ck_assert_ptr_eq(l, NULL);
+ // extractSCharS with several delimiters after each other
+ l = extractSCharS("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 = extractSCharS("AAe thre|e extract", "e ", '|');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "thre");
+ listFreeS(l);
+ // empty delimiter
+ l = extractSCharS("AAd", "", 'A');
+ ck_assert_ptr_eq(l, NULL);
+ // empty string
+ l = extractSCharS("", "$", '#');
+ ck_assert_ptr_eq(l, NULL);
+ // delim1 = delim2
+ l = extractSCharS("", "$", '$');
+ ck_assert_ptr_eq(l, NULL);
+ // NULL string
+ ck_assert_ptr_eq(extractSCharS(NULL, ";", ','), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(extractSCharS("test", NULL, ','), NULL);
+
+
+}
+
+
+void extractCharCharST(CuTest *tc UNUSED) {
+
+ char **l;
+
+ // string
+ l = extractCharCharS("one/two|", '/', '|');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "two");
+ listFreeS(l);
+ // delimiter not found
+ l = extractCharCharS("one/two", '|', '/');
+ ck_assert_ptr_eq(l, NULL);
+ // extractCharCharS with several delimiters after each other
+ l = extractCharCharS("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);
+ // empty string
+ l = extractCharCharS("", '$', '#');
+ ck_assert_ptr_eq(l, NULL);
+ // delim1 = delim2
+ l = extractCharCharS("", '$', '$');
+ ck_assert_ptr_eq(l, NULL);
+ // NULL string
+ ck_assert_ptr_eq(extractCharCharS(NULL, ';', ','), NULL);
+
+
+}
+
+
+void icExtractST(CuTest *tc UNUSED) {
+
+ char **l;
+
+ // string
+ l = icExtractS("one/two|", "/", "|");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "two");
+ listFreeS(l);
+ // delimiter not found
+ l = icExtractS("one/two", "||", "/");
+ ck_assert_ptr_eq(l, NULL);
+ // icExtractS with several delimiters after each other
+ l = icExtractS("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 = icExtractS("AAe thre|e extract", "E ", "|");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "thre");
+ listFreeS(l);
+ // empty delimiter
+ l = icExtractS("AAd", "", "Ad");
+ ck_assert_ptr_eq(l, NULL);
+ l = icExtractS("AAd", "A", "");
+ ck_assert_ptr_eq(l, NULL);
+ // empty string
+ l = icExtractS("", "$", "#");
+ ck_assert_ptr_eq(l, NULL);
+ // delim1 = delim2
+ l = icExtractS("", "$", "$");
+ ck_assert_ptr_eq(l, NULL);
+ // NULL string
+ ck_assert_ptr_eq(icExtractS(NULL, ";", ","), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(icExtractS("test", NULL, ","), NULL);
+ ck_assert_ptr_eq(icExtractS("test", ",", NULL), NULL);
+
+
+}
+
+
+void icExtractCharSST(CuTest *tc UNUSED) {
+
+ char **l;
+
+ // string
+ l = icExtractCharSS("one/two|", '/', "|");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "two");
+ listFreeS(l);
+ // delimiter not found
+ l = icExtractCharSS("one/two", '|', "/");
+ ck_assert_ptr_eq(l, NULL);
+ // icExtractCharSS with several delimiters after each other
+ l = icExtractCharSS("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);
+ // empty string
+ l = icExtractCharSS("", '$', "#");
+ ck_assert_ptr_eq(l, NULL);
+ // delim1 = delim2
+ l = icExtractCharSS("", '$', "$");
+ ck_assert_ptr_eq(l, NULL);
+ // NULL string
+ ck_assert_ptr_eq(icExtractCharSS(NULL, ';', ","), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(icExtractCharSS("test", ',', NULL), NULL);
+
+
+}
+
+
+void icExtractSCharST(CuTest *tc UNUSED) {
+
+ char **l;
+
+ // string
+ l = icExtractSCharS("one/two|", "/", '|');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "two");
+ listFreeS(l);
+ // delimiter not found
+ l = icExtractSCharS("one/two", "||", '/');
+ ck_assert_ptr_eq(l, NULL);
+ // icExtractSCharS with several delimiters after each other
+ l = icExtractSCharS("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 = icExtractSCharS("AAe thre|e extract", "E ", '|');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "thre");
+ listFreeS(l);
+ // empty delimiter
+ l = icExtractSCharS("AAd", "", 'A');
+ ck_assert_ptr_eq(l, NULL);
+ // empty string
+ l = icExtractSCharS("", "$", '#');
+ ck_assert_ptr_eq(l, NULL);
+ // delim1 = delim2
+ l = icExtractSCharS("", "$", '$');
+ ck_assert_ptr_eq(l, NULL);
+ // NULL string
+ ck_assert_ptr_eq(icExtractSCharS(NULL, ";", ','), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(icExtractSCharS("test", NULL, ','), NULL);
+
+
+}
+
+
+void icExtractCharCharST(CuTest *tc UNUSED) {
+
+ char **l;
+
+ // string
+ l = icExtractCharCharS("one/two|", '/', '|');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "two");
+ listFreeS(l);
+ // delimiter not found
+ l = icExtractCharCharS("one/two", '|', '/');
+ ck_assert_ptr_eq(l, NULL);
+ // icExtractCharCharS with several delimiters after each other
+ l = icExtractCharCharS("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);
+ // empty string
+ l = icExtractCharCharS("", '$', '#');
+ ck_assert_ptr_eq(l, NULL);
+ // delim1 = delim2
+ l = icExtractCharCharS("", '$', '$');
+ ck_assert_ptr_eq(l, NULL);
+ // NULL string
+ ck_assert_ptr_eq(icExtractCharCharS(NULL, ';', ','), NULL);
+
+
+}
+
+
+void listDupST(CuTest *tc UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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);
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 listShiftST(CuTest *tc UNUSED) {
+
+ 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");
+ listShiftS(&l2,l);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[4], "A");
+ ck_assert_str_eq(l2[7], "DDDD");
+ ck_assert_str_eq(l2[0],"1");
+ ck_assert_str_eq(l2[3],"4444");
+ listFreeS(l);
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ listShiftS(&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)
+ listShiftS(&l, l2);
+ ck_assert(listEqS(l,l2));
+ listFreeS(l);
+ // list + empty list
+ listEmptyS(l)
+ listShiftS(&l2, l);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[4], "A");
+ ck_assert_str_eq(l2[7], "DDDD");
+ ck_assert_str_eq(l2[0],"1");
+ ck_assert_str_eq(l2[3],"4444");
+ listFreeS(l);
+ // empty list + empty list
+ listEmptyS(l)
+ listShiftS(&l, l);
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL list + list = duplicate
+ l = NULL;
+ listShiftS(&l,l2);
+ ck_assert(listEqS(l,l2));
+ listFreeS(l);
+ // list + NULL list
+ listShiftS(&l2, NULL);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[4], "A");
+ ck_assert_str_eq(l2[7], "DDDD");
+ ck_assert_str_eq(l2[0],"1");
+ ck_assert_str_eq(l2[3],"4444");
+ listFreeS(l2);
+ // NULL list pointer
+ listShiftS(NULL,l2);
+ // should not crash
+
+
+}
+
+
+void iListShiftST(CuTest *tc UNUSED) {
+
+ 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");
+ iListShiftS(&l2,l);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[4], "A");
+ ck_assert_str_eq(l2[7], "DDDD");
+ ck_assert_str_eq(l2[0],"1");
+ ck_assert_str_eq(l2[3],"4444");
+ free(l);
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ iListShiftS(&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)
+ iListShiftS(&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)
+ iListShiftS(&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);
+ iListShiftS(&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");
+ iListShiftS(&l,l2);
+ ck_assert(listEqS(l,l2));
+ free(l);
+ // list + NULL list
+ iListShiftS(&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
+ iListShiftS(NULL,l2);
+ // should not crash
+
+
+}
+
+
+void iListShiftNSmashST(CuTest *tc UNUSED) {
+
+ 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");
+ iListShiftNSmashS(&l2,l);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[4], "A");
+ ck_assert_str_eq(l2[7], "DDDD");
+ ck_assert_str_eq(l2[0],"1");
+ ck_assert_str_eq(l2[3],"4444");
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ iListShiftNSmashS(&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)
+ iListShiftNSmashS(&l, l2);
+ ck_assert_str_eq(l[4], "A");
+ ck_assert_str_eq(l[7], "DDDD");
+ ck_assert_str_eq(l[0],"1");
+ ck_assert_str_eq(l[3],"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)
+ iListShiftNSmashS(&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);
+ iListShiftNSmashS(&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");
+ iListShiftNSmashS(&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
+ iListShiftNSmashS(&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
+ iListShiftNSmashS(NULL,l);
+ // should not crash
+
+
+}
+
+
+void listAddST(CuTest *tc UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 listAppendST(CuTest *tc UNUSED) {
+void listCropST(CuTest *tc UNUSED) {
char **l = NULL;
- char **l2 = NULL;
+ char **l2;
- // lists
+ // list negative index
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");
+ l2 = listCropS(l, 1,-1);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[0], "22");
+ ck_assert_str_eq(l2[1], "333");
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "4444");
+ ck_assert_ptr_eq(l[2], null);
+ listFreeS(l2);
+ // start outside
+ ck_assert_ptr_eq(listCropS(l, 20,-4), NULL);
+ // end outside
+ l2 = listCropS(l, 0,40);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[1], "4444");
+ ck_assert_ptr_eq(l[0], null);
+ listFreeS(l2);
listFreeS(l);
+ // end negative and outside
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_ptr_eq(listCropS(l, 2,-40), 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");
+ // end before start
+ ck_assert_ptr_eq(listCropS(l, 3,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");
- 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));
+ // negative start last element
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ l2 = listCropS(l, -1,0);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "22");
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_ptr_eq(l[1], null);
listFreeS(l);
- // NULL list + list = duplicate
+ listFreeS(l2);
+ // start = end
l = NULL;
- listAppendS(&l,l2);
- ck_assert(listEqS(l,l2));
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ l2 = listCropS(l, 1,1);
+ ck_assert_uint_eq(listLengthS(l2),0);
+ ck_assert_ptr_eq(l2[0], NULL);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_ptr_eq(l[2], null);
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
+ // empty list
+ listEmptyS(l)
+ ck_assert_ptr_eq(listCropS(l, 0,0), NULL);
+ ck_assert_ptr_eq(listCropS(l, -1,0), NULL);
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(listCropS(NULL, 2,-4), NULL);
+
}
-void iListAppendST(CuTest *tc UNUSED) {
+void iListCropST(CuTest *tc UNUSED) {
char **l = NULL;
- char **l2 = NULL;
+ char **l2;
- // lists
+ // list negative index
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);
+ l2 = iListCropS(&l, 1,-1);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[0], "22");
+ ck_assert_str_eq(l2[1], "333");
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "4444");
+ ck_assert_ptr_eq(l[2], null);
+ listFreeS(l2);
+ // start outside
+ ck_assert_ptr_eq(iListCropS(&l, 20,-4), NULL);
+ // end outside
+ l2 = iListCropS(&l, 0,40);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[1], "4444");
+ ck_assert_ptr_eq(l[0], null);
+ listFreeS(l2);
+ listFreeS(l);
+ // end negative and outside
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_ptr_eq(iListCropS(&l, 2,-40), 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");
+ // end before start
+ ck_assert_ptr_eq(iListCropS(&l, 3,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);
- // 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));
+ // negative start last element
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ l2 = iListCropS(&l, -1,0);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "22");
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_ptr_eq(l[1], null);
listFreeS(l);
listFreeS(l2);
- // NULL list + list = duplicate
+ // start = end
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");
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ l2 = iListCropS(&l, 1,1);
+ ck_assert_uint_eq(listLengthS(l2),0);
+ ck_assert_ptr_eq(l2[0], NULL);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_ptr_eq(l[2], null);
+ listFreeS(l);
listFreeS(l2);
- // NULL list pointer
- iListAppendS(NULL,l2);
- // should not crash
+ // empty list
+ listEmptyS(l)
+ ck_assert_ptr_eq(iListCropS(&l, 0,0), NULL);
+ ck_assert_ptr_eq(iListCropS(&l, -1,0), NULL);
+ listFreeS(l);
+ // NULL list
+ l = null;
+ ck_assert_ptr_eq(iListCropS(&l, 2,-4), NULL);
+ ck_assert_ptr_eq(iListCropS(NULL, 2,-4), NULL);
+
}
-void iListAppendNSmashST(CuTest *tc UNUSED) {
+void listCropElemST(CuTest *tc UNUSED) {
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;
+ char *r;
+
+ // positive index
listPushS(&l, "1");
listPushS(&l, "22");
listPushS(&l, "333");
listPushS(&l, "4444");
- iListAppendNSmashS(&l,l);
- ck_assert_uint_eq(listLengthS(l),4);
+ r = listCropElemS(l, 1);
+ ck_assert_str_eq(r, "22");
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");
+ ck_assert_str_eq(l[1], "333");
+ ck_assert_str_eq(l[2], "4444");
+ ck_assert_ptr_eq(l[3], null);
+ free(r);
+ // list negative index
+ r = listCropElemS(l, -1);
+ ck_assert_str_eq(r, "4444");
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "333");
+ ck_assert_ptr_eq(l[2], null);
+ free(r);
+ // index outside
+ ck_assert_ptr_eq(listCropElemS(l, 20), NULL);
+ ck_assert_ptr_eq(listCropElemS(l, -4), NULL);
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");
+ // empty list
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");
+ ck_assert_ptr_eq(listCropElemS(l, 0), NULL);
+ ck_assert_ptr_eq(listCropElemS(l, -1), NULL);
listFreeS(l);
- // NULL list pointer
- iListAppendNSmashS(NULL,l);
- // should not crash
+ // NULL list
+ ck_assert_ptr_eq(listCropElemS(NULL, 2), NULL);
+
}
-void listAddST(CuTest *tc UNUSED) {
+void iListCropElemST(CuTest *tc UNUSED) {
char **l = NULL;
- char **l2 = NULL;
- char **l3;
+ char *r;
- // lists
+ // positive index
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);
+ r = iListCropElemS(&l, 1);
+ ck_assert_str_eq(r, "22");
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "333");
+ ck_assert_str_eq(l[2], "4444");
+ ck_assert_ptr_eq(l[3], null);
+ free(r);
+ // list negative index
+ r = iListCropElemS(&l, -1);
+ ck_assert_str_eq(r, "4444");
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "333");
+ ck_assert_ptr_eq(l[2], null);
+ free(r);
+ // index outside
+ ck_assert_ptr_eq(iListCropElemS(&l, 20), NULL);
+ ck_assert_ptr_eq(iListCropElemS(&l, -4), NULL);
listFreeS(l);
- // list + empty list
+ // empty list
listEmptyS(l)
- l3 = listAddS(l2, l);
- ck_assert(listEqS(l3,l2));
- listFreeS(l3);
+ ck_assert_ptr_eq(iListCropElemS(&l, 0), NULL);
+ ck_assert_ptr_eq(iListCropElemS(&l, -1), NULL);
listFreeS(l);
- // empty list + empty list
- listEmptyS(l)
- l3 = listAddS(l, l);
- ck_assert(listIsEmptyS(l3));
- listFreeS(l3);
+ // NULL list
+ l = null;
+ ck_assert_ptr_eq(iListCropElemS(&l, 2), NULL);
+ ck_assert_ptr_eq(iListCropElemS(NULL, 2), NULL);
+
+
+}
+
+
+void listInsertST(CuTest *tc UNUSED) {
+
+ 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);
- // 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);
+ // 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 listSliceST(CuTest *tc UNUSED) {
+void iListInsertST(CuTest *tc UNUSED) {
- char **l = NULL;
+ char **l;
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);
+ // 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);
- // 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");
+ // 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);
- // start = end
+ // NULL insert string
+ iListInsertS(&l, 0, NULL);
+ ck_assert_str_eq(l[0], "1");
+ listFreeS(l);
+ // NULL list and list to insert at index 0
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);
+ l2 = listCreateS("lib");
+ iListInsertS(&l, 0, l2);
+ ck_assert_str_eq(l[0], "lib");
+ free(l2);
listFreeS(l);
+ // NULL list and list to insert at non 0 index
+ l = NULL;
+ l2 = listCreateS("lib");
+ iListInsertS(&l, -1, l2);
+ ck_assert_ptr_eq(l, NULL);
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);
+ l = NULL;
+ iListInsertS(&l, 0, NULL);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListInsertS(NULL, 0, NULL);
}
-void iListCopyST(CuTest *tc UNUSED) {
+void iListInsertNFreeST(CuTest *tc UNUSED) {
- char **l = NULL;
+ char **l, **r;
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);
+ // 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);
- // 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);
+ // 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);
- // 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);
+ // 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);
- // 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);
+ // 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);
- // 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);
+ // 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)
- ck_assert_ptr_eq(iListCopyS(l, 0,0), NULL);
- ck_assert_ptr_eq(iListCopyS(l, -1,0), NULL);
+ 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
- ck_assert_ptr_eq(iListCopyS(NULL, 2,-4), NULL);
-
+ 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 iListSliceST(CuTest *tc UNUSED) {
+void listInjectST(CuTest *tc UNUSED) {
- char **l = NULL;
+ char **l;
+ char **r;
- // 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);
+ // 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)
- iListSliceS(&l, 0,0);
- ck_assert(listIsEmptyS(l));
- iListSliceS(&l, -1,0);
- ck_assert(listIsEmptyS(l));
- listFreeS(l);
+ 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
- l = NULL;
- iListSliceS(&l, 2,-4);
- // NULL var
- iListSliceS(NULL, 2,-4);
+ r = listInjectS(NULL, 0, NULL);
+ ck_assert_ptr_eq(r, NULL);
}
-void listInsertST(CuTest *tc UNUSED) {
+void listInjectCharST(CuTest *tc UNUSED) {
char **l;
- char **l2;
char **r;
// insert
l = listCreateS("1","22");
- l2 = listCreateS("lib");
- r = listInsertS(l, 0, l2);
+ r = listInjectCharS(l, 0, 'l');
ck_assert_uint_eq(listLengthS(r),3);
- ck_assert_str_eq(r[0], "lib");
+ ck_assert_str_eq(r[0], "l");
ck_assert_str_eq(r[1], "1");
ck_assert_str_eq(r[2], "22");
listFreeS(r);
// negative index
- r = listInsertS(l, -1, l2);
+ r = listInjectCharS(l, -1, 'l');
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");
+ ck_assert_str_eq(r[2], "l");
listFreeS(r);
// edge
- r = listInsertS(l, 2, l2);
+ r = listInjectCharS(l, 2, 'l');
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");
+ ck_assert_str_eq(r[2], "l");
listFreeS(r);
// outside list
- r = listInsertS(l, 4, l2);
+ r = listInjectCharS(l, 4, 'l');
ck_assert_ptr_eq(r, NULL);
- r = listInsertS(l, -4, l2);
+ r = listInjectCharS(l, -4, 'l');
ck_assert_ptr_eq(r, NULL);
listFreeS(l);
// negative index in a one element list
l = listCreateS("1");
- r = listInsertS(l, -1, l2);
+ r = listInjectCharS(l, -1, 'l');
ck_assert_str_eq(r[0], "1");
- ck_assert_str_eq(r[1], "lib");
+ ck_assert_str_eq(r[1], "l");
listFreeManyS(l,r);
// empty list
listEmptyS(l);
- r = listInsertS(l, 0, l2);
- ck_assert_str_eq(r[0], "lib");
+ r = listInjectCharS(l, 0, 'l');
+ ck_assert_str_eq(r[0], "l");
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");
+ r = listInjectCharS(l, -1, 'l');
+ ck_assert_str_eq(r[0], "l");
listFreeManyS(r,l);
// NULL list
- r = listInsertS(NULL, 0, NULL);
- ck_assert_ptr_eq(r, NULL);
+ r = listInjectCharS(NULL, 0, 'l');
+ ck_assert_str_eq(r[0], "l");
+ ck_assert_ptr_eq(r[1], NULL);
+ listFreeS(r);
}
-void iListInsertST(CuTest *tc UNUSED) {
+void iListInjectST(CuTest *tc UNUSED) {
char **l;
- char **l2;
// insert
l = listCreateS("1","22");
- l2 = listCreateS("lib");
- iListInsertS(&l, 0, l2);
+ 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");
- free(l2);
listFreeS(l);
// negative index
l = listCreateS("1","22");
- l2 = listCreateS("lib");
- iListInsertS(&l, -1, l2);
+ 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");
- free(l2);
listFreeS(l);
// edge
l = listCreateS("1","22");
- l2 = listCreateS("lib");
- iListInsertS(&l, 2, l2);
+ 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");
- free(l2);
listFreeS(l);
// outside list
l = listCreateS("1","22");
- l2 = listCreateS("lib");
- iListInsertS(&l, 4, l2);
+ 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");
- iListInsertS(&l, -4, l2);
+ 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");
- iListInsertS(&l, -1, l2);
+ iListInjectS(&l, -1, strdup("lib"));
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);
+ iListInjectS(&l, 0, strdup("lib"));
ck_assert_str_eq(l[0], "lib");
- free(l2);
listFreeS(l);
listEmptyS(l);
- l2 = listCreateS("lib");
- iListInsertS(&l, -1, l2);
+ iListInjectS(&l, -1, strdup("lib"));
ck_assert_str_eq(l[0], "lib");
- free(l2);
listFreeS(l);
- // empty insert list
+ // NULL insert string
l = listCreateS("1");
- listEmptyS(l2);
- iListInsertS(&l, 0, l2);
+ 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 UNUSED) {
+
+ 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);
- // NULL insert string
- iListInsertS(&l, 0, NULL);
+ // 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 UNUSED) {
+
+ char **l = NULL;
+
+ // 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;
- iListInsertS(&l, 0, NULL);
+ iListDelS(&l, 2,-4);
ck_assert_ptr_eq(l, NULL);
// NULL var
- iListInsertS(NULL, 0, NULL);
+ iListDelS(NULL, 2,-4);
}
-void iListInsertNFreeST(CuTest *tc UNUSED) {
+void listDelElemST(CuTest *tc UNUSED) {
- char **l, **r;
+ char **l = NULL;
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
+ // positive index
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = listDelElemS(l, 1);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[1], "333");
+ ck_assert_str_eq(l2[2], "4444");
+ ck_assert_ptr_eq(l2[3], null);
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
+ // list negative index
+ l2 = listDelElemS(l, -1);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[1], "22");
+ ck_assert_str_eq(l2[2], "333");
+ ck_assert_ptr_eq(l2[3], null);
listFreeS(l2);
- ck_assert_uint_eq(listLengthS(l),2);
- ck_assert_str_eq(l[0], "1");
- ck_assert_str_eq(l[1], "22");
+ // index outside
+ ck_assert_ptr_eq(listDelElemS(l, 20), NULL);
+ ck_assert_ptr_eq(listDelElemS(l, -5), NULL);
listFreeS(l);
- // negative index in a one element list
- l = listCreateS("1");
- l2 = listCreateS("lib");
- iListInsertNFreeS(&l, -1, l2);
+ // empty list
+ listEmptyS(l)
+ ck_assert_ptr_eq(listDelElemS(l, 0), NULL);
+ ck_assert_ptr_eq(listDelElemS(l, -1), NULL);
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(listDelElemS(NULL, 2), NULL);
+
+
+}
+
+
+void iListDelElemST(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+ char **r;
+
+ // positive index
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ r = iListDelElemS(&l, 1);
+ ck_assert_ptr_ne(r, null);
ck_assert_str_eq(l[0], "1");
- ck_assert_str_eq(l[1], "lib");
+ ck_assert_str_eq(l[1], "333");
+ ck_assert_str_eq(l[2], "4444");
+ ck_assert_ptr_eq(l[3], null);
+ // list negative index
+ r = iListDelElemS(&l, -1);
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "333");
+ ck_assert_ptr_eq(l[2], null);
+ // index outside
+ ck_assert_ptr_eq(iListDelElemS(&l, 20), NULL);
+ ck_assert_ptr_eq(iListDelElemS(&l, -4), NULL);
listFreeS(l);
// empty list
- listEmptyS(l);
- l2 = listCreateS("lib");
- iListInsertNFreeS(&l, 0, l2);
- ck_assert_str_eq(l[0], "lib");
+ listEmptyS(l)
+ ck_assert_ptr_eq(iListDelElemS(&l, 0), NULL);
+ ck_assert_ptr_eq(iListDelElemS(&l, -1), NULL);
listFreeS(l);
- listEmptyS(l);
- l2 = listCreateS("lib");
- iListInsertNFreeS(&l, -1, l2);
- ck_assert_str_eq(l[0], "lib");
+ // NULL list
+ l = null;
+ ck_assert_ptr_eq(iListDelElemS(&l, 2), NULL);
+ ck_assert_ptr_eq(iListDelElemS(NULL, 2), NULL);
+
+
+}
+
+
+void execOutT(CuTest *tc UNUSED) {
+
+ 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);
- // 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");
+
+ // invalid command
+ l = execOut("randomCommand");
+ 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 systemOutfT(CuTest *tc UNUSED) {
+
+ char **l;
+
+ // command
+ l = systemOutf("ls %s", "chmodTest.null");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "chmodTest.null");
+ listFreeS(l);
+
+ // invalid command
+ l = systemOutf("randomCommand");
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ listFreeS(l);
+ // NULL command
+ ck_assert_ptr_eq(systemOutf(NULL), NULL);
+
+
+}
+
+
+void systemfT(CuTest *tc UNUSED) {
+
+ int r;
+
+ // command
+ r = systemf("ls %s", "chmodTest.null");
+ ck_assert_int_eq(r,0);
+
+ // invalid command
+ r = systemf("randomCommand");
+ ck_assert_int_ne(r,0);
+
+ // NULL command
+ ck_assert_int_eq(systemf(NULL), -1);
+
+
+}
+
+
+void commandFT(CuTest *tc UNUSED) {
+
+ int r;
+
+ // command
+ r = command("ls chmodTest.null");
+ ck_assert_int_eq(r,0);
+
+ // invalid command
+ r = command("randomCommand");
+ ck_assert_int_ne(r,0);
+ // NULL command
+ ck_assert_int_eq(command(NULL), -1);
+
+
+}
+
+
+void commandfFT(CuTest *tc UNUSED) {
+
+ int r;
+
+ // command
+ r = commandf("ls %s", "chmodTest.null");
+ ck_assert_int_eq(r,0);
+
+ // invalid command
+ r = commandf("randomCommand");
+ ck_assert_int_ne(r,0);
+
+ // NULL command
+ ck_assert_int_eq(commandf(NULL), -1);
+
+
+}
+
+
+void commandNFreeFT(CuTest *tc UNUSED) {
+
+ int r;
+
+ // command
+ r = commandNFree(strdup("ls chmodTest.null"));
+ ck_assert_int_eq(r,0);
+
+ // invalid command
+ r = commandNFree(strdup("randomCommand"));
+ ck_assert_int_ne(r,0);
+ // NULL command
+ ck_assert_int_eq(commandNFree(NULL), -1);
+
+
+}
+
+
+void listEqST(CuTest *tc UNUSED) {
+
+ 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 UNUSED) {
+
+ 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 listHasCharST(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+
+ // string
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ ck_assert(listHasCharS(l, '1'));
// NULL list
- l = NULL;
- l2 = listCreateS("lib");
- iListInsertNFreeS(&l, 0, l2);
- ck_assert_str_eq(l[0], "lib");
+ ck_assert(!listHasCharS(NULL, '1'));
+ // non existing element
+ ck_assert(!listHasCharS(l, 'w'));
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 UNUSED) {
+void listIndexOfST(CuTest *tc UNUSED) {
- char **l;
- char **r;
+ char **l = NULL;
- // 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);
+ // 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);
- // 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);
+
+}
+
+
+void listIndexOfCharST(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+
+ // string
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ ck_assert_uint_eq(listIndexOfCharS(l, '1'),0);
// NULL list
- r = listInjectS(NULL, 0, NULL);
- ck_assert_ptr_eq(r, NULL);
+ ck_assert_uint_eq(listIndexOfCharS(NULL, '1'),-1);
+ // non existing element
+ ck_assert_uint_eq(listIndexOfCharS(l, 'w'),-1);
+ listFreeS(l);
}
-void iListInjectST(CuTest *tc UNUSED) {
+void listBinarySearchST(CuTest *tc UNUSED) {
- char **l;
+ char **l = NULL;
- // 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");
+ // 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 listBinarySearchCharST(CuTest *tc UNUSED) {
+
+ 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(listBinarySearchCharS(l, '1'),0);
// NULL list
- l = NULL;
- iListInjectS(&l, 0, NULL);
- ck_assert_ptr_eq(l, NULL);
- // NULL var
- iListInjectS(NULL, 0, NULL);
+ ck_assert_uint_eq(listBinarySearchCharS(NULL, '1'),-1);
+ // non existing element
+ ck_assert_uint_eq(listBinarySearchCharS(l, 'w'),-1);
+ // string in list
+ ck_assert_uint_eq(listBinarySearchCharS(l, '5'),4);
+ listFreeS(l);
}
-void listDelST(CuTest *tc UNUSED) {
+void listUniqST(CuTest *tc UNUSED) {
char **l = NULL;
char **l2;
- // list negative index
+ // list with unique elements
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");
+ 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);
- // 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);
+ l2 = listUniqS(l);
+ ck_assert_uint_eq(listLengthS(l2),3);
+ ck_assert_str_eq(l2[2], "4444");
listFreeS(l);
- // negative start last element
+ listFreeS(l2);
+ // list with one element
l = NULL;
listPushS(&l, "1");
- listPushS(&l, "22");
- l2 = listDelS(l, -1,0);
+ l2 = listUniqS(l);
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);
+ // 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 UNUSED) {
+
+ 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);
- // start = end
+ // list with one element
l = NULL;
listPushS(&l, "1");
- listPushS(&l, "22");
- l2 = listDelS(l, 1,1);
- ck_assert_uint_eq(listLengthS(l2),2);
+ l2 = listDupS(l);
+ iListUniqS(&l2);
+ ck_assert_uint_eq(listLengthS(l2),1);
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);
+ 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
- ck_assert_ptr_eq(listDelS(NULL, 2,-4), NULL);
-
+ l = NULL;
+ iListUniqS(&l);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListUniqS(NULL);
}
-void iListDelST(CuTest *tc UNUSED) {
+void icListEqST(CuTest *tc UNUSED) {
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
+ // identical lists
listPushS(&l, "1");
- listPushS(&l, "22");
+ listPushS(&l, "bb");
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");
+ l2 = listDupS(l);
+ iUpperS(&l2[1]);
+ ck_assert(icListEqS(l,l2));
+ // NULL lists
+ ck_assert(!icListEqS(NULL,l));
+ ck_assert(!icListEqS(l,NULL));
+ ck_assert(!icListEqS(NULL,NULL));
+ // different lists same number of elements
+ l[3][0] = 'A';
+ ck_assert(!icListEqS(l,l2));
+ // different number of elements
+ char *s = listPopS(&l);
+ free(s);
+ ck_assert(!icListEqS(l,l2));
+ listFreeS(l);
+ listFreeS(l2);
+
+
+}
+
+
+void icListHasST(CuTest *tc UNUSED) {
+
+ char **l = NULL;
+
+ // string
+ listPushS(&l, "a");
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);
+ ck_assert(icListHasS(l, "A"));
// NULL list
- l = NULL;
- iListDelS(&l, 2,-4);
- ck_assert_ptr_eq(l, NULL);
- // NULL var
- iListDelS(NULL, 2,-4);
+ ck_assert(!icListHasS(NULL, "1"));
+ // NULL string
+ ck_assert(!icListHasS(l, NULL));
+ // non existing element
+ ck_assert(!icListHasS(l, "wfe"));
+ // string in list
+ ck_assert(icListHasS(l, "333"));
+ listFreeS(l);
}
-void execOutT(CuTest *tc UNUSED) {
+void icListHasCharST(CuTest *tc UNUSED) {
- char **l;
+ char **l = NULL;
- // command
- l = execOut("ls chmodTest.null");
- ck_assert_uint_eq(listLengthS(l),1);
- ck_assert_str_eq(l[0], "chmodTest.null");
+ // string
+ listPushS(&l, "A");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ ck_assert(icListHasCharS(l, 'a'));
+ // NULL list
+ ck_assert(!icListHasCharS(NULL, '1'));
+ // non existing element
+ ck_assert(!icListHasCharS(l, 'w'));
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 UNUSED) {
+void icListIndexOfST(CuTest *tc UNUSED) {
char **l = NULL;
- char **l2;
- // identical lists
- listPushS(&l, "1");
+ // string
+ listPushS(&l, "a");
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));
+ ck_assert_uint_eq(icListIndexOfS(l, "A"),0);
+ // NULL list
+ ck_assert_uint_eq(icListIndexOfS(NULL, "1"),-1);
+ // NULL string
+ ck_assert_uint_eq(icListIndexOfS(l, NULL),-1);
+ // non existing element
+ ck_assert_uint_eq(icListIndexOfS(l, "wfe"),-1);
+ // string in list
+ ck_assert_uint_eq(icListIndexOfS(l, "333"),2);
listFreeS(l);
- listFreeS(l2);
+
}
-void listHasST(CuTest *tc UNUSED) {
+void icListIndexOfCharST(CuTest *tc UNUSED) {
char **l = NULL;
// string
- listPushS(&l, "1");
+ listPushS(&l, "A");
listPushS(&l, "22");
listPushS(&l, "333");
listPushS(&l, "4444");
- ck_assert(listHasS(l, "1"));
+ ck_assert_uint_eq(icListIndexOfCharS(l, 'a'),0);
// NULL list
- ck_assert(!listHasS(NULL, "1"));
- // NULL string
- ck_assert(!listHasS(l, NULL));
+ ck_assert_uint_eq(icListIndexOfCharS(NULL, '1'),-1);
// non existing element
- ck_assert(!listHasS(l, "wfe"));
- // string in list
- ck_assert(listHasS(l, "333"));
+ ck_assert_uint_eq(icListIndexOfCharS(l, 'w'),-1);
listFreeS(l);
+
}
-void listIndexOfST(CuTest *tc UNUSED) {
+void icListBinarySearchST(CuTest *tc UNUSED) {
char **l = NULL;
// string
- listPushS(&l, "1");
+ listPushS(&l, "a");
listPushS(&l, "22");
listPushS(&l, "333");
listPushS(&l, "4444");
- ck_assert_uint_eq(listIndexOfS(l, "1"),0);
+ listPushS(&l, "ccc");
+ listPushS(&l, "6");
+ iListSortS(&l);
+ ck_assert_uint_eq(icListBinarySearchS(l, "A"),4);
// NULL list
- ck_assert_uint_eq(listIndexOfS(NULL, "1"),-1);
+ ck_assert_uint_eq(icListBinarySearchS(NULL, "1"),-1);
// NULL string
- ck_assert_uint_eq(listIndexOfS(l, NULL),-1);
+ ck_assert_uint_eq(icListBinarySearchS(l, NULL),-1);
// non existing element
- ck_assert_uint_eq(listIndexOfS(l, "wfe"),-1);
+ ck_assert_uint_eq(icListBinarySearchS(l, "wfe"),-1);
// string in list
- ck_assert_uint_eq(listIndexOfS(l, "333"),2);
+ ck_assert_uint_eq(icListBinarySearchS(l, "Ccc"),5);
listFreeS(l);
+
}
-void listBinarySearchST(CuTest *tc UNUSED) {
+void icListBinarySearchCharST(CuTest *tc UNUSED) {
char **l = NULL;
// string
- listPushS(&l, "1");
+ listPushS(&l, "A");
listPushS(&l, "22");
listPushS(&l, "333");
listPushS(&l, "4444");
- listPushS(&l, "5");
+ listPushS(&l, "C");
listPushS(&l, "6");
- ck_assert_uint_eq(listBinarySearchS(l, "1"),0);
+ iListSortS(&l);
+ ck_assert_uint_eq(icListBinarySearchCharS(l, 'a'),4);
// NULL list
- ck_assert_uint_eq(listBinarySearchS(NULL, "1"),-1);
- // NULL string
- ck_assert_uint_eq(listBinarySearchS(l, NULL),-1);
+ ck_assert_uint_eq(icListBinarySearchCharS(NULL, '1'),-1);
// non existing element
- ck_assert_uint_eq(listBinarySearchS(l, "wfe"),-1);
+ ck_assert_uint_eq(icListBinarySearchCharS(l, 'w'),-1);
// string in list
- ck_assert_uint_eq(listBinarySearchS(l, "333"),2);
+ ck_assert_uint_eq(icListBinarySearchCharS(l, 'c'),5);
listFreeS(l);
+
}
-void listUniqST(CuTest *tc UNUSED) {
+void icListUniqST(CuTest *tc UNUSED) {
char **l = NULL;
char **l2;
// list with unique elements
listPushS(&l, "1");
- listPushS(&l, "22");
+ listPushS(&l, "bb");
listPushS(&l, "333");
listPushS(&l, "4444");
- l2 = listUniqS(l);
+ l2 = icListUniqS(l);
ck_assert(listEqS(l,l2));
// list with identical elements
- l[2][0] = '2';
- l[2][1] = '2';
+ l[2][0] = 'B';
+ l[2][1] = 'B';
l[2][2] = 0;
listFreeS(l2);
- l2 = listUniqS(l);
+ l2 = icListUniqS(l);
ck_assert_uint_eq(listLengthS(l2),3);
ck_assert_str_eq(l2[2], "4444");
listFreeS(l);
@@ -7262,44 +16092,45 @@ void listUniqST(CuTest *tc UNUSED) {
// list with one element
l = NULL;
listPushS(&l, "1");
- l2 = listUniqS(l);
+ l2 = icListUniqS(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);
+ l2 = icListUniqS(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);
+ ck_assert_ptr_eq(icListUniqS(NULL), NULL);
+
}
-void iListUniqST(CuTest *tc UNUSED) {
+void iicListUniqST(CuTest *tc UNUSED) {
char **l = NULL;
char **l2;
// list with unique elements
listPushS(&l, "1");
- listPushS(&l, "22");
+ listPushS(&l, "BB");
listPushS(&l, "333");
listPushS(&l, "4444");
l2 = listDupS(l);
- iListUniqS(&l2);
+ iicListUniqS(&l2);
ck_assert(listEqS(l,l2));
// list with identical elements
- l[2][0] = '2';
- l[2][1] = '2';
+ l[2][0] = 'b';
+ l[2][1] = 'b';
l[2][2] = 0;
listFreeS(l2);
l2 = listDupS(l);
- iListUniqS(&l2);
+ iicListUniqS(&l2);
ck_assert_uint_eq(listLengthS(l2),3);
ck_assert_str_eq(l2[2], "4444");
listFreeS(l);
@@ -7308,7 +16139,7 @@ void iListUniqST(CuTest *tc UNUSED) {
l = NULL;
listPushS(&l, "1");
l2 = listDupS(l);
- iListUniqS(&l2);
+ iicListUniqS(&l2);
ck_assert_uint_eq(listLengthS(l2),1);
ck_assert_str_eq(l2[0], "1");
listFreeS(l);
@@ -7316,17 +16147,18 @@ void iListUniqST(CuTest *tc UNUSED) {
// empty list
listEmptyS(l)
l2 = listDupS(l);
- iListUniqS(&l2);
+ iicListUniqS(&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);
+ iicListUniqS(&l);
ck_assert_ptr_eq(l, NULL);
// NULL var
- iListUniqS(NULL);
+ iicListUniqS(NULL);
+
}
@@ -7400,6 +16232,29 @@ void iListCompactST(CuTest *tc UNUSED) {
}
+void btraceEnableT(CuTest *tc UNUSED) {
+
+ btraceEnable();
+ ck_assert(btraceConfig());
+ btraceDisable();
+ ck_assert(!btraceConfig());
+
+
+}
+
+
+void btraceT(CuTest *tc UNUSED) {
+
+ char **r;
+
+ r = btrace();
+ ck_assert_ptr_ne(r, null);
+ listFreeS(r);
+
+
+}
+
+
void listEmptyFT(CuTest *tc UNUSED) {
void **l = NULL;
@@ -8545,6 +17400,25 @@ void ringInitT(CuTest *tc UNUSED) {
}
+void ringEmptyT(CuTest *tc UNUSED) {
+
+ ringTestT rg;
+ ringInit(&rg, 4);
+
+ // empty
+ ringPush(&rg);
+ ck_assert_int_eq(ringEmpty(&rg), 1);
+ ck_assert_int_eq(ringIsEmpty(&rg), 1);
+
+ // already empty
+ ck_assert_int_eq(ringEmpty(&rg), 1);
+
+ // null ring
+ ck_assert_int_eq(ringEmpty(null), 0);
+
+}
+
+
void ringIsEmptyT(CuTest *tc UNUSED) {
ringTestT rg;
@@ -8786,18 +17660,41 @@ int main(int n UNUSED, char**v UNUSED) {
CuString *output = CuStringNew();
CuSuite *suite = CuSuiteNew();
+ SUITE_ADD_TEST(suite, cleanUpCharFreeT);
+ SUITE_ADD_TEST(suite, cleanUpListFreeT);
+ SUITE_ADD_TEST(suite, cleanUpFileFreeT);
+ SUITE_ADD_TEST(suite, cleanUpCharFreeNullT);
+ SUITE_ADD_TEST(suite, cleanUpListFreeNullT);
+ SUITE_ADD_TEST(suite, cleanUpFileFreeNullT);
+ SUITE_ADD_TEST(suite, shStopwatchT);
+ SUITE_ADD_TEST(suite, setLogSymbolsT);
+ SUITE_ADD_TEST(suite, setMaxLogLevelT);
+ SUITE_ADD_TEST(suite, setLogShortPathT);
+ SUITE_ADD_TEST(suite, setLogStdoutT);
+ SUITE_ADD_TEST(suite, openProgLogFileT);
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, setProgNameT);
SUITE_ADD_TEST(suite, initLibsheepyFT);
+ SUITE_ADD_TEST(suite, setStackLimitT);
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, isReadableT);
+ SUITE_ADD_TEST(suite, isWritableT);
+ SUITE_ADD_TEST(suite, isExecutableT);
SUITE_ADD_TEST(suite, equalModificationTimesT);
+ SUITE_ADD_TEST(suite, getCurrentUnixTimeT);
+ SUITE_ADD_TEST(suite, strToUnixTimeT);
+ SUITE_ADD_TEST(suite, timeToST);
+ SUITE_ADD_TEST(suite, timeToYMDST);
+ SUITE_ADD_TEST(suite, getCurrentDateT);
+ SUITE_ADD_TEST(suite, getCurrentDateYMDT);
SUITE_ADD_TEST(suite, shDirnameT);
SUITE_ADD_TEST(suite, bDirnameT);
SUITE_ADD_TEST(suite, bLDirnameT);
@@ -8809,21 +17706,36 @@ int main(int n UNUSED, char**v UNUSED) {
SUITE_ADD_TEST(suite, iNormalizePathT);
SUITE_ADD_TEST(suite, bNormalizePathT);
SUITE_ADD_TEST(suite, bLNormalizePathT);
- SUITE_ADD_TEST(suite, timeToST);
+ SUITE_ADD_TEST(suite, relPathT);
+ SUITE_ADD_TEST(suite, iRelPathT);
+ SUITE_ADD_TEST(suite, bRelPathT);
+ SUITE_ADD_TEST(suite, bLRelPathT);
+ SUITE_ADD_TEST(suite, getHomePathT);
+ SUITE_ADD_TEST(suite, getCwdT);
SUITE_ADD_TEST(suite, chDirT);
SUITE_ADD_TEST(suite, isDirT);
+ SUITE_ADD_TEST(suite, shReadlinkT);
+ SUITE_ADD_TEST(suite, endlinkT);
SUITE_ADD_TEST(suite, isLinkT);
SUITE_ADD_TEST(suite, fileExistsT);
SUITE_ADD_TEST(suite, fileChmodT);
SUITE_ADD_TEST(suite, fileSizeT);
+ SUITE_ADD_TEST(suite, fileSizeFPT);
SUITE_ADD_TEST(suite, readFileToST);
+ SUITE_ADD_TEST(suite, readStreamToST);
SUITE_ADD_TEST(suite, bReadFileToST);
+ SUITE_ADD_TEST(suite, bReadStreamToST);
SUITE_ADD_TEST(suite, bLReadFileToST);
+ SUITE_ADD_TEST(suite, bLReadStreamToST);
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, writeStreamST);
+ SUITE_ADD_TEST(suite, writeLStreamT);
+ SUITE_ADD_TEST(suite, appendFileST);
+ SUITE_ADD_TEST(suite, appendFileT);
SUITE_ADD_TEST(suite, walkDirT);
SUITE_ADD_TEST(suite, walkDirDirT);
SUITE_ADD_TEST(suite, readDirT);
@@ -8847,6 +17759,10 @@ int main(int n UNUSED, char**v UNUSED) {
SUITE_ADD_TEST(suite, bRandomAlphaNumST);
SUITE_ADD_TEST(suite, readST);
SUITE_ADD_TEST(suite, bLReadST);
+ SUITE_ADD_TEST(suite, readPasswordST);
+ SUITE_ADD_TEST(suite, zeroST);
+ SUITE_ADD_TEST(suite, zeroBufT);
+ SUITE_ADD_TEST(suite, memdupT);
SUITE_ADD_TEST(suite, readEnterT);
SUITE_ADD_TEST(suite, readLineT);
SUITE_ADD_TEST(suite, dupST);
@@ -8854,7 +17770,12 @@ int main(int n UNUSED, char**v UNUSED) {
SUITE_ADD_TEST(suite, shEprintfT);
SUITE_ADD_TEST(suite, freeManyST);
SUITE_ADD_TEST(suite, logNFreeT);
+ SUITE_ADD_TEST(suite, loghexT);
+ SUITE_ADD_TEST(suite, toHexST);
+ SUITE_ADD_TEST(suite, toHexSepST);
+ SUITE_ADD_TEST(suite, toHexHeadSepST);
SUITE_ADD_TEST(suite, strCpyT);
+ SUITE_ADD_TEST(suite, strNCpyT);
SUITE_ADD_TEST(suite, strLCpyT);
SUITE_ADD_TEST(suite, strCatT);
SUITE_ADD_TEST(suite, strNCatT);
@@ -8891,10 +17812,18 @@ int main(int n UNUSED, char**v UNUSED) {
SUITE_ADD_TEST(suite, iReplaceCharCharST);
SUITE_ADD_TEST(suite, bReplaceST);
SUITE_ADD_TEST(suite, bLReplaceST);
+ SUITE_ADD_TEST(suite, icReplaceST);
+ SUITE_ADD_TEST(suite, iicReplaceST);
+ SUITE_ADD_TEST(suite, bicReplaceST);
+ SUITE_ADD_TEST(suite, bLicReplaceST);
SUITE_ADD_TEST(suite, replaceManyST);
SUITE_ADD_TEST(suite, iReplaceManyST);
SUITE_ADD_TEST(suite, bReplaceManyST);
SUITE_ADD_TEST(suite, bLReplaceManyST);
+ SUITE_ADD_TEST(suite, icReplaceManyST);
+ SUITE_ADD_TEST(suite, iicReplaceManyST);
+ SUITE_ADD_TEST(suite, bicReplaceManyST);
+ SUITE_ADD_TEST(suite, bLicReplaceManyST);
SUITE_ADD_TEST(suite, eqST);
SUITE_ADD_TEST(suite, eqCharST);
SUITE_ADD_TEST(suite, eqSCharT);
@@ -8906,16 +17835,36 @@ int main(int n UNUSED, char**v UNUSED) {
SUITE_ADD_TEST(suite, endsWithCharST);
SUITE_ADD_TEST(suite, countST);
SUITE_ADD_TEST(suite, countCharST);
+ SUITE_ADD_TEST(suite, icEqST);
+ SUITE_ADD_TEST(suite, icEqCharST);
+ SUITE_ADD_TEST(suite, icEqSCharT);
+ SUITE_ADD_TEST(suite, icEqIST);
+ SUITE_ADD_TEST(suite, icEqICharST);
+ SUITE_ADD_TEST(suite, icStartsWithST);
+ SUITE_ADD_TEST(suite, icStartsWithCharST);
+ SUITE_ADD_TEST(suite, icEndsWithST);
+ SUITE_ADD_TEST(suite, icEndsWithCharST);
+ SUITE_ADD_TEST(suite, icCountST);
+ SUITE_ADD_TEST(suite, icCountCharST);
+ SUITE_ADD_TEST(suite, hasCtrlCharT);
+ SUITE_ADD_TEST(suite, stripCtrlST);
+ SUITE_ADD_TEST(suite, iStripCtrlST);
+ SUITE_ADD_TEST(suite, bStripCtrlST);
SUITE_ADD_TEST(suite, isNumberT);
SUITE_ADD_TEST(suite, isIntT);
SUITE_ADD_TEST(suite, parseIntT);
SUITE_ADD_TEST(suite, parseIntCharT);
+ SUITE_ADD_TEST(suite, parseI64T);
+ SUITE_ADD_TEST(suite, parseI64CharT);
SUITE_ADD_TEST(suite, parseDoubleT);
+ SUITE_ADD_TEST(suite, parseDoubleCharT);
+ SUITE_ADD_TEST(suite, parseHexT);
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, sizeST);
SUITE_ADD_TEST(suite, upperST);
SUITE_ADD_TEST(suite, iUpperST);
SUITE_ADD_TEST(suite, bUpperST);
@@ -8934,11 +17883,66 @@ int main(int n UNUSED, char**v UNUSED) {
SUITE_ADD_TEST(suite, uniqST);
SUITE_ADD_TEST(suite, iUniqST);
SUITE_ADD_TEST(suite, bUniqST);
+ SUITE_ADD_TEST(suite, icUniqST);
+ SUITE_ADD_TEST(suite, iicUniqST);
+ SUITE_ADD_TEST(suite, bicUniqST);
+ SUITE_ADD_TEST(suite, repeatST);
+ SUITE_ADD_TEST(suite, iRepeatST);
+ SUITE_ADD_TEST(suite, bRepeatST);
+ SUITE_ADD_TEST(suite, bLRepeatST);
+ SUITE_ADD_TEST(suite, repeatCharST);
+ SUITE_ADD_TEST(suite, bRepeatCharST);
+ SUITE_ADD_TEST(suite, bLRepeatCharST);
+ SUITE_ADD_TEST(suite, repeatLenST);
+ SUITE_ADD_TEST(suite, ellipsisStartST);
+ SUITE_ADD_TEST(suite, iEllipsisStartST);
+ SUITE_ADD_TEST(suite, bEllipsisStartST);
+ SUITE_ADD_TEST(suite, bLEllipsisStartST);
+ SUITE_ADD_TEST(suite, ellipsisStartCharST);
+ SUITE_ADD_TEST(suite, iEllipsisStartCharST);
+ SUITE_ADD_TEST(suite, bEllipsisStartCharST);
+ SUITE_ADD_TEST(suite, bLEllipsisStartCharST);
+ SUITE_ADD_TEST(suite, ellipsisLenST);
+ SUITE_ADD_TEST(suite, ellipsisEndST);
+ SUITE_ADD_TEST(suite, iEllipsisEndST);
+ SUITE_ADD_TEST(suite, bEllipsisEndST);
+ SUITE_ADD_TEST(suite, bLEllipsisEndST);
+ SUITE_ADD_TEST(suite, ellipsisEndCharST);
+ SUITE_ADD_TEST(suite, iEllipsisEndCharST);
+ SUITE_ADD_TEST(suite, bEllipsisEndCharST);
+ SUITE_ADD_TEST(suite, bLEllipsisEndCharST);
+ SUITE_ADD_TEST(suite, padStartST);
+ SUITE_ADD_TEST(suite, iPadStartST);
+ SUITE_ADD_TEST(suite, bPadStartST);
+ SUITE_ADD_TEST(suite, bLPadStartST);
+ SUITE_ADD_TEST(suite, padStartCharST);
+ SUITE_ADD_TEST(suite, iPadStartCharST);
+ SUITE_ADD_TEST(suite, bPadStartCharST);
+ SUITE_ADD_TEST(suite, bLPadStartCharST);
+ SUITE_ADD_TEST(suite, padStartLenST);
+ SUITE_ADD_TEST(suite, padEndST);
+ SUITE_ADD_TEST(suite, iPadEndST);
+ SUITE_ADD_TEST(suite, bPadEndST);
+ SUITE_ADD_TEST(suite, bLPadEndST);
+ SUITE_ADD_TEST(suite, padEndCharST);
+ SUITE_ADD_TEST(suite, iPadEndCharST);
+ SUITE_ADD_TEST(suite, bPadEndCharST);
+ SUITE_ADD_TEST(suite, bLPadEndCharST);
+ SUITE_ADD_TEST(suite, padEndLenST);
SUITE_ADD_TEST(suite, getST);
SUITE_ADD_TEST(suite, setST);
+ SUITE_ADD_TEST(suite, swapST);
+ SUITE_ADD_TEST(suite, iSwapST);
+ SUITE_ADD_TEST(suite, bSwapST);
+ SUITE_ADD_TEST(suite, bLSwapST);
SUITE_ADD_TEST(suite, sliceST);
SUITE_ADD_TEST(suite, iSliceST);
SUITE_ADD_TEST(suite, bSliceST);
+ SUITE_ADD_TEST(suite, bLSliceST);
+ SUITE_ADD_TEST(suite, cropST);
+ SUITE_ADD_TEST(suite, iCropST);
+ SUITE_ADD_TEST(suite, cropElemST);
+ SUITE_ADD_TEST(suite, iCropElemST);
SUITE_ADD_TEST(suite, insertST);
SUITE_ADD_TEST(suite, insertNFreeST);
SUITE_ADD_TEST(suite, iInsertST);
@@ -8952,25 +17956,120 @@ int main(int n UNUSED, char**v UNUSED) {
SUITE_ADD_TEST(suite, delST);
SUITE_ADD_TEST(suite, iDelST);
SUITE_ADD_TEST(suite, bDelST);
+ SUITE_ADD_TEST(suite, bLDelST);
+ SUITE_ADD_TEST(suite, delElemST);
+ SUITE_ADD_TEST(suite, iDelElemST);
+ SUITE_ADD_TEST(suite, bDelElemST);
+ SUITE_ADD_TEST(suite, bLDelElemST);
SUITE_ADD_TEST(suite, findST);
SUITE_ADD_TEST(suite, findCharST);
+ SUITE_ADD_TEST(suite, indexOfST);
+ SUITE_ADD_TEST(suite, indexOfCharST);
SUITE_ADD_TEST(suite, hasST);
SUITE_ADD_TEST(suite, hasCharST);
+ SUITE_ADD_TEST(suite, icFindST);
+ SUITE_ADD_TEST(suite, icFindCharST);
+ SUITE_ADD_TEST(suite, icIndexOfST);
+ SUITE_ADD_TEST(suite, icIndexOfCharST);
+ SUITE_ADD_TEST(suite, icHasST);
+ SUITE_ADD_TEST(suite, icHasCharST);
+ SUITE_ADD_TEST(suite, tokST);
+ SUITE_ADD_TEST(suite, icTokST);
+ SUITE_ADD_TEST(suite, lenUTF8T);
+ SUITE_ADD_TEST(suite, bLLenUTF8T);
+ SUITE_ADD_TEST(suite, isUTF8T);
+ SUITE_ADD_TEST(suite, bLIsUTF8T);
+ SUITE_ADD_TEST(suite, isCodeUTF8T);
+ SUITE_ADD_TEST(suite, nextUTF8T);
+ SUITE_ADD_TEST(suite, bLNextUTF8T);
+ SUITE_ADD_TEST(suite, findNextUTF8T);
+ SUITE_ADD_TEST(suite, prevUTF8T);
+ SUITE_ADD_TEST(suite, bPrevUTF8T);
+ SUITE_ADD_TEST(suite, idx2PtrUTF8T);
+ SUITE_ADD_TEST(suite, bLIdx2PtrUTF8T);
+ SUITE_ADD_TEST(suite, ptr2IdxUTF8T);
+ SUITE_ADD_TEST(suite, bPtr2IdxUTF8T);
+ SUITE_ADD_TEST(suite, bLPtr2IdxUTF8T);
+ SUITE_ADD_TEST(suite, bLPtr2NegIdxUTF8T);
+ SUITE_ADD_TEST(suite, makeValidUTF8T);
+ SUITE_ADD_TEST(suite, bMakeValidUTF8T);
+ SUITE_ADD_TEST(suite, nMakeValidUTF8T);
+ SUITE_ADD_TEST(suite, bNMakeValidUTF8T);
+ SUITE_ADD_TEST(suite, bLMakeValidUTF8T);
+ SUITE_ADD_TEST(suite, bLNMakeValidUTF8T);
+ SUITE_ADD_TEST(suite, strNCpyUTF8T);
+ SUITE_ADD_TEST(suite, strLCpyUTF8T);
+ SUITE_ADD_TEST(suite, strNCatUTF8T);
+ SUITE_ADD_TEST(suite, strLCatUTF8T);
+ SUITE_ADD_TEST(suite, strLNCatUTF8T);
+ SUITE_ADD_TEST(suite, eqIUTF8T);
+ SUITE_ADD_TEST(suite, eqICharUTF8T);
+ SUITE_ADD_TEST(suite, icEqUTF8T);
+ SUITE_ADD_TEST(suite, icEqCharUTF8T);
+ SUITE_ADD_TEST(suite, icEqUTF8CharT);
+ SUITE_ADD_TEST(suite, icStartsWithUTF8T);
+ SUITE_ADD_TEST(suite, icEndsWithUTF8T);
+ SUITE_ADD_TEST(suite, icCountUTF8T);
+ SUITE_ADD_TEST(suite, code2RuneUTF8T);
+ SUITE_ADD_TEST(suite, code2RuneLUTF8T);
+ SUITE_ADD_TEST(suite, bRune2CodeUTF8T);
+ SUITE_ADD_TEST(suite, runeLenUTF8T);
+ SUITE_ADD_TEST(suite, toupperUTF8T);
+ SUITE_ADD_TEST(suite, upperUTF8T);
+ SUITE_ADD_TEST(suite, iUpperUTF8T);
+ SUITE_ADD_TEST(suite, tolowerUTF8T);
+ SUITE_ADD_TEST(suite, lowerUTF8T);
+ SUITE_ADD_TEST(suite, iLowerUTF8T);
+ SUITE_ADD_TEST(suite, uniqUTF8T);
+ SUITE_ADD_TEST(suite, iUniqUTF8T);
+ SUITE_ADD_TEST(suite, bUniqUTF8T);
+ SUITE_ADD_TEST(suite, getUTF8T);
+ SUITE_ADD_TEST(suite, setUTF8T);
+ SUITE_ADD_TEST(suite, sliceUTF8T);
+ SUITE_ADD_TEST(suite, iSliceUTF8T);
+ SUITE_ADD_TEST(suite, bSliceUTF8T);
+ SUITE_ADD_TEST(suite, bLSliceUTF8T);
+ SUITE_ADD_TEST(suite, insertUTF8T);
+ SUITE_ADD_TEST(suite, insertNFreeUTF8T);
+ SUITE_ADD_TEST(suite, iInsertUTF8T);
+ SUITE_ADD_TEST(suite, iInsertNFreeUTF8T);
+ SUITE_ADD_TEST(suite, bInsertUTF8T);
+ SUITE_ADD_TEST(suite, bLInsertUTF8T);
+ SUITE_ADD_TEST(suite, delUTF8T);
+ SUITE_ADD_TEST(suite, iDelUTF8T);
+ SUITE_ADD_TEST(suite, bDelUTF8T);
+ SUITE_ADD_TEST(suite, bLDelUTF8T);
+ SUITE_ADD_TEST(suite, indexOfUTF8T);
+ SUITE_ADD_TEST(suite, icHasUTF8T);
+ SUITE_ADD_TEST(suite, icListSortUTF8T);
+ SUITE_ADD_TEST(suite, iicListSortUTF8T);
+ SUITE_ADD_TEST(suite, icListEqUTF8T);
+ SUITE_ADD_TEST(suite, icListHasUTF8T);
+ SUITE_ADD_TEST(suite, icListIndexOfUTF8T);
+ SUITE_ADD_TEST(suite, icListBinarySearchUTF8T);
+ SUITE_ADD_TEST(suite, icListUniqUTF8T);
+ SUITE_ADD_TEST(suite, iicListUniqUTF8T);
SUITE_ADD_TEST(suite, emptySFT);
SUITE_ADD_TEST(suite, iEmptySFT);
SUITE_ADD_TEST(suite, isEmptyST);
SUITE_ADD_TEST(suite, isBlankST);
+ SUITE_ADD_TEST(suite, intIndexT);
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, listStrLengthST);
+ SUITE_ADD_TEST(suite, listIntIndexST);
+ SUITE_ADD_TEST(suite, listAddrST);
SUITE_ADD_TEST(suite, listCreateST);
SUITE_ADD_TEST(suite, listFromArrayST);
SUITE_ADD_TEST(suite, listPushST);
+ SUITE_ADD_TEST(suite, listPushCharST);
SUITE_ADD_TEST(suite, iListPushST);
SUITE_ADD_TEST(suite, listPopST);
SUITE_ADD_TEST(suite, listPrependST);
+ SUITE_ADD_TEST(suite, listPrependCharST);
SUITE_ADD_TEST(suite, iListPrependST);
SUITE_ADD_TEST(suite, listDequeueST);
SUITE_ADD_TEST(suite, listFreeST);
@@ -8980,6 +18079,10 @@ int main(int n UNUSED, char**v UNUSED) {
SUITE_ADD_TEST(suite, listEnumerateT);
SUITE_ADD_TEST(suite, listSortST);
SUITE_ADD_TEST(suite, iListSortST);
+ SUITE_ADD_TEST(suite, listSortFST);
+ SUITE_ADD_TEST(suite, iListSortFST);
+ SUITE_ADD_TEST(suite, icListSortST);
+ SUITE_ADD_TEST(suite, iicListSortST);
SUITE_ADD_TEST(suite, readTextT);
SUITE_ADD_TEST(suite, readStreamT);
SUITE_ADD_TEST(suite, writeTextT);
@@ -8988,13 +18091,29 @@ int main(int n UNUSED, char**v UNUSED) {
SUITE_ADD_TEST(suite, listGetST);
SUITE_ADD_TEST(suite, iListGetST);
SUITE_ADD_TEST(suite, listSetST);
+ SUITE_ADD_TEST(suite, listSetCharST);
SUITE_ADD_TEST(suite, iListSetST);
- SUITE_ADD_TEST(suite, tokST);
+ SUITE_ADD_TEST(suite, listSwapST);
+ SUITE_ADD_TEST(suite, iListSwapST);
SUITE_ADD_TEST(suite, splitT);
+ SUITE_ADD_TEST(suite, splitCharT);
+ SUITE_ADD_TEST(suite, icSplitT);
+ SUITE_ADD_TEST(suite, icSplitCharT);
+ SUITE_ADD_TEST(suite, joinLengthT);
SUITE_ADD_TEST(suite, joinT);
+ SUITE_ADD_TEST(suite, joinCharT);
SUITE_ADD_TEST(suite, bJoinT);
+ SUITE_ADD_TEST(suite, bJoinCharT);
SUITE_ADD_TEST(suite, bLJoinT);
+ SUITE_ADD_TEST(suite, bLJoinCharT);
SUITE_ADD_TEST(suite, extractST);
+ SUITE_ADD_TEST(suite, extractCharSST);
+ SUITE_ADD_TEST(suite, extractSCharST);
+ SUITE_ADD_TEST(suite, extractCharCharST);
+ SUITE_ADD_TEST(suite, icExtractST);
+ SUITE_ADD_TEST(suite, icExtractCharSST);
+ SUITE_ADD_TEST(suite, icExtractSCharST);
+ SUITE_ADD_TEST(suite, icExtractCharCharST);
SUITE_ADD_TEST(suite, listDupST);
SUITE_ADD_TEST(suite, iListDupST);
SUITE_ADD_TEST(suite, listReverseST);
@@ -9003,26 +18122,55 @@ int main(int n UNUSED, char**v UNUSED) {
SUITE_ADD_TEST(suite, listAppendST);
SUITE_ADD_TEST(suite, iListAppendST);
SUITE_ADD_TEST(suite, iListAppendNSmashST);
+ SUITE_ADD_TEST(suite, listShiftST);
+ SUITE_ADD_TEST(suite, iListShiftST);
+ SUITE_ADD_TEST(suite, iListShiftNSmashST);
SUITE_ADD_TEST(suite, listAddST);
SUITE_ADD_TEST(suite, listSliceST);
SUITE_ADD_TEST(suite, iListCopyST);
SUITE_ADD_TEST(suite, iListSliceST);
+ SUITE_ADD_TEST(suite, listCropST);
+ SUITE_ADD_TEST(suite, iListCropST);
+ SUITE_ADD_TEST(suite, listCropElemST);
+ SUITE_ADD_TEST(suite, iListCropElemST);
SUITE_ADD_TEST(suite, listInsertST);
SUITE_ADD_TEST(suite, iListInsertST);
SUITE_ADD_TEST(suite, iListInsertNFreeST);
SUITE_ADD_TEST(suite, listInjectST);
+ SUITE_ADD_TEST(suite, listInjectCharST);
SUITE_ADD_TEST(suite, iListInjectST);
SUITE_ADD_TEST(suite, listDelST);
SUITE_ADD_TEST(suite, iListDelST);
+ SUITE_ADD_TEST(suite, listDelElemST);
+ SUITE_ADD_TEST(suite, iListDelElemST);
SUITE_ADD_TEST(suite, execOutT);
+ SUITE_ADD_TEST(suite, systemOutfT);
+ SUITE_ADD_TEST(suite, systemfT);
+ SUITE_ADD_TEST(suite, commandFT);
+ SUITE_ADD_TEST(suite, commandfFT);
+ SUITE_ADD_TEST(suite, commandNFreeFT);
SUITE_ADD_TEST(suite, listEqST);
SUITE_ADD_TEST(suite, listHasST);
+ SUITE_ADD_TEST(suite, listHasCharST);
SUITE_ADD_TEST(suite, listIndexOfST);
+ SUITE_ADD_TEST(suite, listIndexOfCharST);
SUITE_ADD_TEST(suite, listBinarySearchST);
+ SUITE_ADD_TEST(suite, listBinarySearchCharST);
SUITE_ADD_TEST(suite, listUniqST);
SUITE_ADD_TEST(suite, iListUniqST);
+ SUITE_ADD_TEST(suite, icListEqST);
+ SUITE_ADD_TEST(suite, icListHasST);
+ SUITE_ADD_TEST(suite, icListHasCharST);
+ SUITE_ADD_TEST(suite, icListIndexOfST);
+ SUITE_ADD_TEST(suite, icListIndexOfCharST);
+ SUITE_ADD_TEST(suite, icListBinarySearchST);
+ SUITE_ADD_TEST(suite, icListBinarySearchCharST);
+ SUITE_ADD_TEST(suite, icListUniqST);
+ SUITE_ADD_TEST(suite, iicListUniqST);
SUITE_ADD_TEST(suite, listCompactST);
SUITE_ADD_TEST(suite, iListCompactST);
+ SUITE_ADD_TEST(suite, btraceEnableT);
+ SUITE_ADD_TEST(suite, btraceT);
SUITE_ADD_TEST(suite, listEmptyFT);
SUITE_ADD_TEST(suite, iListEmptyFT);
SUITE_ADD_TEST(suite, listIsEmptyT);
@@ -9050,6 +18198,7 @@ int main(int n UNUSED, char**v UNUSED) {
SUITE_ADD_TEST(suite, listDelT);
SUITE_ADD_TEST(suite, iListDelT);
SUITE_ADD_TEST(suite, ringInitT);
+ SUITE_ADD_TEST(suite, ringEmptyT);
SUITE_ADD_TEST(suite, ringIsEmptyT);
SUITE_ADD_TEST(suite, ringIsFullT);
SUITE_ADD_TEST(suite, ringCountT);
diff --git a/src/libsheepyTest.c b/src/libsheepyTest.c
@@ -8,6 +8,153 @@
// TODO redirect stderr
+START_TEST(cleanUpCharFreeT)
+
+ cleanCharP(s) = strdup("test");
+
+END_TEST
+
+
+START_TEST(cleanUpListFreeT)
+
+ cleanListP(l) = listCreateS("a","b");
+
+END_TEST
+
+
+START_TEST(cleanUpFileFreeT)
+
+ cleanFileP(f) = fopen("renameTest.null", "r");
+
+END_TEST
+
+
+START_TEST(cleanUpCharFreeNullT)
+
+ cleanCharP(s) = null;
+
+END_TEST
+
+
+START_TEST(cleanUpListFreeNullT)
+
+ cleanListP(l) = null;
+
+END_TEST
+
+
+START_TEST(cleanUpFileFreeNullT)
+
+ cleanFileP(f) = null;
+
+END_TEST
+
+
+START_TEST(shStopwatchT)
+
+ stopwatchStart;
+ stopwatchLog;
+
+END_TEST
+
+
+START_TEST(setLogSymbolsT)
+
+ int m;
+
+ // set mode utf8
+ setLogSymbols(LOG_UTF8);
+ m = getLogSymbols();
+ ck_assert_int_eq(m, LOG_UTF8);
+
+ // set invalid mode
+ setLogSymbols(LOG_INVALID_MODE);
+ m = getLogSymbols();
+ ck_assert_int_eq(m, LOG_INVALID_MODE);
+
+ setLogSymbols(LOG_UTF8);
+ setLogSymbols(LOG_INVALID_MODE+10);
+ m = getLogSymbols();
+ ck_assert_int_eq(m, LOG_INVALID_MODE);
+
+END_TEST
+
+
+START_TEST(setMaxLogLevelT)
+
+ int lv;
+
+ // set max level
+ setMaxLogLevel(LOG_DISABLE);
+ lv = getMaxLogLevel();
+ ck_assert_int_eq(lv, LOG_DISABLE);
+
+ // set invalid max level (all levels)
+ setMaxLogLevel(LOG_INVALID);
+ lv = getMaxLogLevel();
+ ck_assert_int_eq(lv, LOG_MAX_LEVEL);
+
+
+END_TEST
+
+
+START_TEST(setLogShortPathT)
+
+ bool sp;
+
+ // set long path
+ setLogShortPath(no);
+ sp = getLogShortPath();
+ ck_assert(!sp);
+
+ // set short path
+ setLogShortPath(yes);
+ sp = getLogShortPath();
+ ck_assert(sp);
+
+END_TEST
+
+
+START_TEST(setLogStdoutT)
+
+ bool std;
+
+ // set long path
+ setLogStdout(no);
+ std = getLogStdout();
+ ck_assert(!std);
+
+ // set short path
+ setLogStdout(yes);
+ std = getLogStdout();
+ ck_assert(std);
+
+END_TEST
+
+
+START_TEST(openProgLogFileT)
+
+ const char *pn;
+ bool r;
+
+ // check that prog name is not set
+ pn = getProgName();
+ ck_assert_ptr_eq(pn, null);
+ r = openProgLogFile();
+ ck_assert(!r);
+
+ // set progname and open file
+ setProgName("openProgLogFileT");
+ r = openProgLogFile();
+ ck_assert(r);
+
+ freeProgName();
+ closeLogFiles();
+ rmAll("openProgLogFileT.log");
+
+END_TEST
+
+
START_TEST(setLogFileT)
FILE *f;
@@ -250,6 +397,35 @@ START_TEST(_pLogT)
END_TEST
+START_TEST(setProgNameT)
+
+ bool r;
+
+ // set default prog name (null since init is not called yet)
+ setDefaultProgName();
+ ck_assert_ptr_eq(getProgName(), null);
+
+ // set prog name
+ r = setProgName("name");
+ ck_assert(r);
+
+ // set null prog name
+ r = setProgName(NULL);
+ ck_assert(!r);
+ ck_assert_ptr_ne(getProgName(), null);
+ ck_assert_str_eq(getProgName(), "name");
+
+ freeProgName();
+
+ // set prog name and then set default prog name
+ // no memory leak should happen
+ r = setProgName("name");
+ ck_assert(r);
+ setDefaultProgName();
+
+END_TEST
+
+
void initTest(void) { }
@@ -264,6 +440,24 @@ START_TEST(initLibsheepyFT)
END_TEST
+START_TEST(setStackLimitT)
+
+ int r;
+ i64 stackSize;
+
+ // set bigger stack
+ r = setStackLimit(16 * 1024 * 1024);
+ ck_assert(r!=0);
+ stackSize = getStackLimit();
+ ck_assert_int_eq(stackSize, 16 * 1024 * 1024);
+
+ // set unlimited stack
+ r = setStackLimit(-1);
+ ck_assert(r!=0);
+
+END_TEST
+
+
START_TEST(getProgPathT)
const char *s;
@@ -351,6 +545,75 @@ START_TEST(setModificationTimeT)
END_TEST
+START_TEST(isReadableT)
+
+ bool r;
+
+ // check readable file
+ r = isReadable("sizeTest.null");
+ ck_assert(r);
+
+ // non readable file
+ r = isReadable("writeOnlyText.null");
+ ck_assert(!r);
+
+ // non existing file
+ r = isReadable("random.null");
+ ck_assert(!r);
+
+ // null
+ r = isReadable(null);
+ ck_assert(!r);
+
+END_TEST
+
+
+START_TEST(isWritableT)
+
+ bool r;
+
+ // check writable file
+ r = isWritable("writeOnlyText.null");
+ ck_assert(r);
+
+ // non writable file
+ r = isWritable("sizeTest.null");
+ ck_assert(!r);
+
+ // non existing file
+ r = isWritable("random.null");
+ ck_assert(!r);
+
+ // null
+ r = isWritable(null);
+ ck_assert(!r);
+
+END_TEST
+
+
+START_TEST(isExecutableT)
+
+ bool r;
+
+ // check executable file
+ r = isExecutable("runCuTest.sh");
+ ck_assert(r);
+
+ // non executable file
+ r = isExecutable("sizeTest.null");
+ ck_assert(!r);
+
+ // non existing file
+ r = isExecutable("random.null");
+ ck_assert(!r);
+
+ // null
+ r = isExecutable(null);
+ ck_assert(!r);
+
+END_TEST
+
+
START_TEST(equalModificationTimesT)
// equal time
@@ -370,6 +633,147 @@ START_TEST(equalModificationTimesT)
END_TEST
+START_TEST(getCurrentUnixTimeT)
+
+ time_t t = getCurrentUnixTime();
+ ck_assert_int_ne(t, 0);
+
+END_TEST
+
+
+START_TEST(strToUnixTimeT)
+
+ time_t t;
+
+ // convert
+ t = strToUnixTime("2020-05-15 13:59:58", "%Y-%m-%d %H:%M");
+ ck_assert_int_ne(t, -1);
+ // depends on local settings - ck_assert_int_eq(t, 1589547540);
+
+
+ // bad date or format
+ t = strToUnixTime("", "%Y-%m-%d %H:%M");
+ ck_assert_int_eq(t, -1);
+
+ // null date
+ t = strToUnixTime(null, "%Y-%m-%d %H:%M");
+ ck_assert_int_eq(t, -1);
+
+ // null format
+ t = strToUnixTime("", null);
+ ck_assert_int_eq(t, -1);
+
+END_TEST
+
+
+START_TEST(timeToST)
+
+ char *s;
+
+ s = timeToS(0);
+ ck_assert_str_eq(s, "Thu Jan 1 01:00:00 1970");
+ free(s);
+
+ // bTimeToS
+ char b[80] = init0Var;
+ s = bTimeToS(b, 0);
+ ck_assert_ptr_ne(s, null);
+ ck_assert_str_eq(b, "Thu Jan 1 01:00:00 1970");
+
+ // bLTimeToS
+ char bL[50] = init0Var;
+ s = bLTimeToS(bL, sizeof(bL), 0);
+ ck_assert_ptr_ne(s, null);
+ ck_assert_str_eq(bL, "Thu Jan 1 01:00:00 1970");
+
+ // null parameter
+ s = bTimeToS(null, 0);
+ ck_assert_ptr_eq(s, null);
+ s = bLTimeToS(null, sizeof(bL), 0);
+ ck_assert_ptr_eq(s, null);
+
+END_TEST
+
+
+START_TEST(timeToYMDST)
+
+ char *s;
+
+ s = timeToYMDS(0);
+ ck_assert_str_eq(s, "1970-01-01 01:00:00");
+ free(s);
+
+ // bTimeToYMDS
+ char b[80] = init0Var;
+ s = bTimeToYMDS(b, 0);
+ ck_assert_ptr_ne(s, null);
+ ck_assert_str_eq(b, "1970-01-01 01:00:00");
+
+ // bLTimeToYMDS
+ char bL[50] = init0Var;
+ s = bLTimeToYMDS(bL, sizeof(bL), 0);
+ ck_assert_ptr_ne(s, null);
+ ck_assert_str_eq(bL, "1970-01-01 01:00:00");
+
+ // null parameter
+ s = bTimeToYMDS(null, 0);
+ ck_assert_ptr_eq(s, null);
+ s = bLTimeToYMDS(null, sizeof(bL), 0);
+ ck_assert_ptr_eq(s, null);
+
+END_TEST
+
+
+START_TEST(getCurrentDateT)
+
+ char *s;
+
+ s = getCurrentDate();
+ ck_assert_ptr_ne(s, null);
+ free(s);
+
+ char b[80] = init0Var;
+ s = bGetCurrentDate(b);
+ ck_assert_ptr_ne(s, null);
+
+ char bL[50] = init0Var;
+ s = bLGetCurrentDate(bL, sizeof(bL));
+ ck_assert_ptr_ne(s, null);
+
+ // null parameter
+ s = bGetCurrentDate(null);
+ ck_assert_ptr_eq(s, null);
+ s = bLGetCurrentDate(null, sizeof(bL));
+ ck_assert_ptr_eq(s, null);
+
+END_TEST
+
+
+START_TEST(getCurrentDateYMDT)
+
+ char *s;
+
+ s = getCurrentDateYMD();
+ ck_assert_ptr_ne(s, null);
+ free(s);
+
+ char b[80] = init0Var;
+ s = bGetCurrentDateYMD(b);
+ ck_assert_ptr_ne(s, null);
+
+ char bL[50] = init0Var;
+ s = bLGetCurrentDateYMD(bL, sizeof(bL));
+ ck_assert_ptr_ne(s, null);
+
+ // null parameter
+ s = bGetCurrentDateYMD(null);
+ ck_assert_ptr_eq(s, null);
+ s = bLGetCurrentDateYMD(null, sizeof(bL));
+ ck_assert_ptr_eq(s, null);
+
+END_TEST
+
+
START_TEST(shDirnameT)
char *s;
@@ -874,73 +1278,512 @@ START_TEST(bLNormalizePathT)
END_TEST
-START_TEST(timeToST)
+START_TEST(relPathT)
- char *s = timeToS(0);
- ck_assert_str_eq(s, "Thu Jan 1 01:00:00 1970");
- free(s);
+ char *r;
+ char *cwd;
-END_TEST
+ // relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = relPath(cwd, null);
+ ck_assert_str_eq(r, "../sheepy");
+ free(r);
+ free(cwd);
+
+ // relative to cwd and path starts with cwd but is a different path
+ // (no slash between cwd and "../sheepy")
+ cwd = getCwd();
+ iAppendS(&cwd, "../sheepy");
+ r = relPath(cwd, null);
+ ck_assert_str_eq(r, "../src../sheepy");
+ free(r);
+ free(cwd);
+ // subdirectory to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ r = relPath(cwd, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ free(cwd);
-START_TEST(chDirT)
+ // path = start
+ cwd = getCwd();
+ r = relPath(cwd, null);
+ ck_assert_str_eq(r, ".");
+ free(r);
+ free(cwd);
- // 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));
+ // start = root
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ r = relPath(cwd, "/../");
+ ck_assert_str_eq(r, cwd+1);
+ free(r);
+ free(cwd);
-END_TEST
+ // relative to start
+ r = relPath("/home/sheepy", "/home/test");
+ ck_assert_str_eq(r, "../sheepy");
+ free(r);
+ // path is relative (no leading slash), start is cwd
+ r = relPath("../src/sheepy", null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
-START_TEST(isDirT)
+ // path is relative (no leading slash)
+ r = relPath("../test/sheepy", "/home/test");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
- // dir
- ck_assert(isDir("dirTest.null"));
+ // start is relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = relPath(cwd, "test/");
+ ck_assert_str_eq(r, "../../sheepy");
+ free(r);
+ free(cwd);
- // non existing dir
- ck_assert(!isDir("RandomNonExistingDir"));
+ // all relative paths
+ // the reference for path and start parameters is an arbitrary directory
+ r = relPath("sheepy", "shefjf/test/src/");
+ ck_assert_str_eq(r, "../../../sheepy");
+ free(r);
- // blank
- ck_assert(!isDir(" "));
+ r = relPath("sheepy", "shee");
+ ck_assert_str_eq(r, "../sheepy");
+ free(r);
- // NULL path
- ck_assert(!isDir(NULL));
+ // null path
+ r = relPath(null, null);
+ ck_assert_ptr_eq(r, null);
END_TEST
-START_TEST(isLinkT)
+START_TEST(iRelPathT)
- // link
- ck_assert(isLink("linkTest.null"));
+ char *r;
+ char *cwd;
- // not link
- ck_assert(!isLink("textTest.null"));
+ // relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = iRelPath(&cwd, null);
+ ck_assert_str_eq(r, "../sheepy");
+ free(r);
- // non existing link
- ck_assert(!isLink("RandomNonExistingDir"));
+ // relative to cwd and path starts with cwd but is a different path
+ // (no slash between cwd and "../sheepy")
+ cwd = getCwd();
+ iAppendS(&cwd, "../sheepy");
+ r = iRelPath(&cwd, null);
+ ck_assert_str_eq(r, "../src../sheepy");
+ free(r);
- // blank
- ck_assert(!isLink(" "));
+ // subdirectory to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ r = iRelPath(&cwd, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
- // NULL path
- ck_assert(!isLink(NULL));
+ // path = start
+ cwd = getCwd();
+ r = iRelPath(&cwd, null);
+ ck_assert_str_eq(r, ".");
+ free(r);
-END_TEST
+ // start = root
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ char *expected = strdup(cwd+1);
+ r = iRelPath(&cwd, "/../");
+ ck_assert_str_eq(r, expected);
+ free(r);
+ free(expected);
+ // relative to start
+ cwd = strdup("/home/sheepy");
+ r = iRelPath(&cwd, "/home/test");
+ ck_assert_str_eq(r, "../sheepy");
+ free(r);
-START_TEST(fileExistsT)
+ // path is relative (no leading slash), start is cwd
+ cwd = strdup("../src/sheepy");
+ r = iRelPath(&cwd, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
- // detect existing file
- ck_assert(fileExists("libsheepyTest.c"));
+ // path is relative (no leading slash)
+ cwd = strdup("../test/sheepy");
+ r = iRelPath(&cwd, "/home/test");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // start is relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = iRelPath(&cwd, "test/");
+ ck_assert_str_eq(r, "../../sheepy");
+ free(r);
+
+ // all relative paths
+ // the reference for path and start parameters is an arbitrary directory
+ cwd = strdup("sheepy");
+ r = iRelPath(&cwd, "shefjf/test/src/");
+ ck_assert_str_eq(r, "../../../sheepy");
+ free(r);
+
+ cwd = strdup("sheepy");
+ r = iRelPath(&cwd, "shee");
+ ck_assert_str_eq(r, "../sheepy");
+ free(r);
+
+ // null path
+ cwd = null;
+ r = iRelPath(&cwd, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null var
+ r = iRelPath(null, null);
+ ck_assert_ptr_eq(r, null);
+
+END_TEST
+
+
+START_TEST(bRelPathT)
+
+ char b[8192] = init0Var;
+ char *r;
+ char *cwd;
+
+ // relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = bRelPath(b, cwd, null);
+ ck_assert_str_eq(r, "../sheepy");
+ free(cwd);
+
+ // relative to cwd and path starts with cwd but is a different path
+ // (no slash between cwd and "../sheepy")
+ cwd = getCwd();
+ iAppendS(&cwd, "../sheepy");
+ r = bRelPath(b, cwd, null);
+ ck_assert_str_eq(r, "../src../sheepy");
+ free(cwd);
+
+ // subdirectory to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ r = bRelPath(b, cwd, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(cwd);
+
+ // path = start
+ cwd = getCwd();
+ r = bRelPath(b, cwd, null);
+ ck_assert_str_eq(r, ".");
+ free(cwd);
+
+ // start = root
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ r = bRelPath(b, cwd, "/../");
+ ck_assert_str_eq(r, cwd+1);
+ free(cwd);
+
+ // relative to start
+ r = bRelPath(b, "/home/sheepy", "/home/test");
+ ck_assert_str_eq(r, "../sheepy");
+
+ // path is relative (no leading slash), start is cwd
+ r = bRelPath(b, "../src/sheepy", null);
+ ck_assert_str_eq(r, "sheepy");
+
+ // path is relative (no leading slash)
+ r = bRelPath(b, "../test/sheepy", "/home/test");
+ ck_assert_str_eq(r, "sheepy");
+
+ // start is relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = bRelPath(b, cwd, "test/");
+ ck_assert_str_eq(r, "../../sheepy");
+ free(cwd);
+
+ // all relative paths
+ // the reference for path and start parameters is an arbitrary directory
+ r = bRelPath(b, "sheepy", "shefjf/test/src/");
+ ck_assert_str_eq(r, "../../../sheepy");
+
+ r = bRelPath(b, "sheepy", "shee");
+ ck_assert_str_eq(r, "../sheepy");
+
+ // null path
+ r = bRelPath(b, null, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bRelPath(null, "", null);
+ ck_assert_ptr_eq(r, null);
+
+
+END_TEST
+
+
+START_TEST(bLRelPathT)
+
+ char b[8192] = init0Var;
+ char *r;
+ char *cwd;
+
+ // relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = bLRelPath(b, sizeof(b), cwd, null);
+ ck_assert_str_eq(r, "../sheepy");
+ free(cwd);
+
+ // relative to cwd and path starts with cwd but is a different path
+ // (no slash between cwd and "../sheepy")
+ cwd = getCwd();
+ iAppendS(&cwd, "../sheepy");
+ r = bLRelPath(b, sizeof(b), cwd, null);
+ ck_assert_str_eq(r, "../src../sheepy");
+ free(cwd);
+
+ // subdirectory to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ r = bLRelPath(b, sizeof(b), cwd, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(cwd);
+
+ // path = start
+ cwd = getCwd();
+ r = bLRelPath(b, sizeof(b), cwd, null);
+ ck_assert_str_eq(r, ".");
+ free(cwd);
+
+ // start = root
+ cwd = getCwd();
+ iAppendS(&cwd, "/sheepy");
+ r = bLRelPath(b, sizeof(b), cwd, "/../");
+ ck_assert_str_eq(r, cwd+1);
+ free(cwd);
+
+ // relative to start
+ r = bLRelPath(b, sizeof(b), "/home/sheepy", "/home/test");
+ ck_assert_str_eq(r, "../sheepy");
+
+ // path is relative (no leading slash), start is cwd
+ r = bLRelPath(b, sizeof(b), "../src/sheepy", null);
+ ck_assert_str_eq(r, "sheepy");
+
+ // path is relative (no leading slash)
+ r = bLRelPath(b, sizeof(b), "../test/sheepy", "/home/test");
+ ck_assert_str_eq(r, "sheepy");
+
+ // start is relative to cwd
+ cwd = getCwd();
+ iAppendS(&cwd, "/../sheepy");
+ r = bLRelPath(b, sizeof(b), cwd, "test/");
+ ck_assert_str_eq(r, "../../sheepy");
+ free(cwd);
+
+ // all relative paths
+ // the reference for path and start parameters is an arbitrary directory
+ r = bLRelPath(b, sizeof(b), "sheepy", "shefjf/test/src/");
+ ck_assert_str_eq(r, "../../../sheepy");
+
+ r = bLRelPath(b, sizeof(b), "sheepy", "shee");
+ ck_assert_str_eq(r, "../sheepy");
+
+ // null path
+ r = bLRelPath(b, sizeof(b), null, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bLRelPath(null, sizeof(b), "", null);
+ ck_assert_ptr_eq(r, null);
+
+END_TEST
+
+
+START_TEST(getHomePathT)
+
+ char *r = getHomePath();
+ ck_assert_ptr_ne(r, null);
+ ck_assert_int_eq(r[0], '/');
+ free(r);
+
+ char b[8192] = init0Var;
+ r = bGetHomePath(b);
+ ck_assert_ptr_ne(r, null);
+ ck_assert_int_eq(r[0], '/');
+
+ r = bLGetHomePath(b, sizeof(b));
+ ck_assert_ptr_ne(r, null);
+ ck_assert_int_eq(r[0], '/');
+
+ // buffer too short
+ char bL[2] = init0Var;
+ r = bLGetHomePath(bL, sizeof(bL));
+ ck_assert_ptr_eq(r, null);
+
+ const char *cR = getCHomePath();
+ ck_assert_ptr_ne(cR, null);
+ ck_assert_int_eq(cR[0], '/');
+
+END_TEST
+
+
+START_TEST(getCwdT)
+
+ char *r = getCwd();
+ ck_assert_ptr_ne(r, null);
+ ck_assert_int_eq(r[0], '/');
+ free(r);
+
+ // buffer
+ char b[8192] = init0Var;
+ r = bLGetCwd(b, sizeof(b));
+ ck_assert_ptr_ne(r, null);
+ ck_assert_int_eq(r[0], '/');
+
+ // buffer too short
+ char bL[2] = init0Var;
+ r = bLGetCwd(bL, sizeof(bL));
+ ck_assert_ptr_eq(r, null);
+
+END_TEST
+
+
+START_TEST(chDirT)
+
+ // 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));
+
+END_TEST
+
+
+START_TEST(isDirT)
+
+ // dir
+ ck_assert(isDir("dirTest.null"));
+
+ // non existing dir
+ ck_assert(!isDir("RandomNonExistingDir"));
+
+ // blank
+ ck_assert(!isDir(" "));
+
+ // NULL path
+ ck_assert(!isDir(NULL));
+
+END_TEST
+
+
+START_TEST(shReadlinkT)
+
+ char *r;
+
+ // read a link
+ r = shReadlink("linkTest.null");
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(r, "textTest.null");
+ free(r);
+
+ // not a link, regular file
+ r = shReadlink("textTest.null");
+ ck_assert_ptr_eq(r, null);
+
+ // non existing path
+ r = shReadlink("random");
+ ck_assert_ptr_eq(r, null);
+
+ // blank path
+ r = shReadlink(" ");
+ ck_assert_ptr_eq(r, null);
+
+ // null path
+ r = shReadlink(null);
+ ck_assert_ptr_eq(r, null);
+
+END_TEST
+
+
+START_TEST(endlinkT)
+
+ char *r;
+
+ // read a link
+ r = endlink("linkTest.null");
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(r, "textTest.null");
+ free(r);
+
+ // read a link to absolute path
+ r = endlink("absLinkTest.null");
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(r, "/usr/local/bin/sheepy");
+ free(r);
+
+ // not a link, regular file
+ r = endlink("textTest.null");
+ ck_assert_ptr_eq(r, null);
+
+ // non existing path
+ r = endlink("random");
+ ck_assert_ptr_eq(r, null);
+
+ // blank path
+ r = endlink(" ");
+ ck_assert_ptr_eq(r, null);
+
+ // null path
+ r = endlink(null);
+ ck_assert_ptr_eq(r, null);
+
+END_TEST
+
+
+START_TEST(isLinkT)
+
+ // 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));
+
+END_TEST
+
+
+START_TEST(fileExistsT)
+
+ // detect existing file
+ ck_assert(fileExists("libsheepyTest.c"));
// non existing file
ck_assert(!fileExists("wefwepfk34.c"));
// folder
@@ -984,6 +1827,26 @@ START_TEST(fileSizeT)
END_TEST
+START_TEST(fileSizeFPT)
+
+ FILE *f;
+
+ // existing file
+ f = fopen("sizeTest.null", "r");
+ ck_assert_int_eq(fileSizeFP(f), 743);
+ fclose(f);
+
+ // empty file
+ f = fopen("chmodTest.null", "r");
+ ck_assert_int_eq(fileSizeFP(f), 0);
+ fclose(f);
+
+ // null file
+ ck_assert_int_eq(fileSizeFP(null), -1);
+
+END_TEST
+
+
START_TEST(readFileToST)
char *l;
@@ -1015,6 +1878,31 @@ START_TEST(readFileToST)
END_TEST
+START_TEST(readStreamToST)
+
+ FILE *f;
+ char *l;
+
+ // text
+ f = fopen("textTest.null", "r");
+ l = readStreamToS(f);
+ ck_assert_str_eq(l, "LINE 1\nANOTHER line\n");
+ free(l);
+ fclose(f);
+
+ // empty text
+ f = fopen("chmodTest.null", "r");
+ l = readStreamToS(f);
+ ck_assert_str_eq(l, "");
+ free(l);
+ fclose(f);
+
+ // null file
+ ck_assert_ptr_eq(readStreamToS(null), null);
+
+END_TEST
+
+
START_TEST(bReadFileToST)
char l[100];
@@ -1047,6 +1935,34 @@ START_TEST(bReadFileToST)
END_TEST
+START_TEST(bReadStreamToST)
+
+ FILE *f;
+ char l[1024] = init0Var;
+ char *r;
+
+ // text
+ f = fopen("textTest.null", "r");
+ r = bReadStreamToS(f, l);
+ ck_assert_str_eq(r, "LINE 1\nANOTHER line\n");
+ fclose(f);
+
+ // empty text
+ f = fopen("chmodTest.null", "r");
+ r = bReadStreamToS(f, l);
+ ck_assert_str_eq(r, "");
+ fclose(f);
+
+ // null dst
+ ck_assert_ptr_eq(bReadStreamToS(f, null), null);
+
+ // null file
+ ck_assert_ptr_eq(bReadStreamToS(null, l), null);
+
+
+END_TEST
+
+
START_TEST(bLReadFileToST)
char l[100];
@@ -1088,6 +2004,45 @@ START_TEST(bLReadFileToST)
END_TEST
+START_TEST(bLReadStreamToST)
+
+ FILE *f;
+ char l[1024] = init0Var;
+ char *r;
+
+ // text
+ f = fopen("textTest.null", "r");
+ r = bLReadStreamToS(f, l, sizeof(l));
+ ck_assert_str_eq(r, "LINE 1\nANOTHER line\n");
+ fclose(f);
+
+ // shorter buffer
+ l[0] = 'a';
+ l[1] = 'a';
+ f = fopen("textTest.null", "r");
+ r = bLReadStreamToS(f, l, 2);
+ ck_assert_str_eq(r, "L");
+ fclose(f);
+
+ // empty text
+ f = fopen("chmodTest.null", "r");
+ r = bLReadStreamToS(f, l, sizeof(l));
+ ck_assert_str_eq(r, "");
+ fclose(f);
+
+ // dst size 0, no changes
+ r = bLReadStreamToS(f, l, 0);
+ ck_assert_str_eq(r, "");
+
+ // null dst
+ ck_assert_ptr_eq(bLReadStreamToS(f, null, sizeof(l)), null);
+
+ // null file
+ ck_assert_ptr_eq(bLReadStreamToS(null, l, sizeof(l)), null);
+
+END_TEST
+
+
START_TEST(readFileT)
char *l;
@@ -1283,58 +2238,182 @@ START_TEST(writeFileT)
END_TEST
-START_TEST(walkDirT)
-
- 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);
+START_TEST(writeStreamST)
-END_TEST
+ char *l;
+ int r;
+ FILE *f;
+ // write textOutTest.null
+ l = readFileToS("textTest.null");
+ f = fopen("textOutTest.null", "w");
+ r = writeStreamS(f, l);
+ ck_assert(r);
+ free(l);
+ fclose(f);
-START_TEST(walkDirDirT)
+ // check textOutTest.null
+ l = readFileToS("textOutTest.null");
+ ck_assert_uint_eq(strlen(l),20);
+ ck_assert_str_eq(l, "LINE 1\nANOTHER line\n");
- char **l;
+ // NULL file
+ ck_assert(!writeStreamS(NULL,l));
+ free(l);
+ // NULL string
+ ck_assert(!writeStreamS(f,NULL));
- // 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);
END_TEST
-START_TEST(readDirT)
+START_TEST(writeLStreamT)
- char **l;
+ char *l;
+ int r;
+ FILE *f;
- // existing directory
- l = readDir("dirTest.null");
- ck_assert_uint_eq(listLengthS(l),1);
+ // write textOutTest.null
+ l = readFileToS("textTest.null");
+ f = fopen("textOutTest.null", "w");
+ r = writeLStream(f, l, strlen(l));
+ ck_assert(r);
+ free(l);
+ fclose(f);
+
+ // check textOutTest.null
+ l = readFileToS("textOutTest.null");
+ ck_assert_uint_eq(strlen(l),20);
+ ck_assert_str_eq(l, "LINE 1\nANOTHER line\n");
+
+ // NULL file
+ ck_assert(!writeLStream(NULL,l, strlen(l)));
+ free(l);
+ // NULL string
+ ck_assert(!writeLStream(f,NULL, 10));
+
+
+END_TEST
+
+
+START_TEST(appendFileST)
+
+ char *l;
+ int r;
+
+ // write textOutTest.null
+ l = "appended line\n";
+ r = appendFileS("appendTextOutTest.null", l);
+ ck_assert(r);
+ l = "appended line 2\n";
+ r = appendFileS("appendTextOutTest.null", l);
+ ck_assert(r);
+
+ // check textOutTest.null
+ l = readFileToS("appendTextOutTest.null");
+ ck_assert_uint_eq(strlen(l),30);
+ ck_assert_str_eq(l, "appended line\nappended line 2\n");
+ if (fileExists("appendTextOutTest.null"))
+ rmAll("appendTextOutTest.null");
+ // blank file name
+ ck_assert(!appendFileS(" ",l));
+ // read only path
+ ck_assert(!appendFileS("/nonExistingFile",l));
+ // NULL path
+ ck_assert(!appendFileS(NULL,l));
+ free(l);
+ // NULL string
+ ck_assert(!appendFileS("a",NULL));
+
+
+END_TEST
+
+
+START_TEST(appendFileT)
+
+ char *l;
+ int r;
+
+ // write textOutTest.null
+ l = "appended line\n";
+ r = appendFile("appendTextOutTest.null", l, strlen(l));
+ ck_assert(r);
+ l = "appended line 2\n";
+ r = appendFile("appendTextOutTest.null", l, strlen(l));
+ ck_assert(r);
+
+ // check textOutTest.null
+ l = readFileToS("appendTextOutTest.null");
+ ck_assert_uint_eq(strlen(l),30);
+ ck_assert_str_eq(l, "appended line\nappended line 2\n");
+ if (fileExists("appendTextOutTest.null"))
+ rmAll("appendTextOutTest.null");
+ // blank file name
+ ck_assert(!appendFile(" ",l, strlen(l)));
+ // read only path
+ ck_assert(!appendFile("/nonExistingFile",l, strlen(l)));
+ // NULL path
+ ck_assert(!appendFile(NULL,l, strlen(l)));
+ free(l);
+ // NULL string
+ ck_assert(!appendFile("a",NULL, 0));
+
+
+END_TEST
+
+
+START_TEST(walkDirT)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(walkDirDirT)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(readDirT)
+
+ 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
@@ -1705,6 +2784,75 @@ START_TEST(bLReadST)
END_TEST
+START_TEST(readPasswordST)
+
+ char *r = readPasswordS();
+ ck_assert_str_eq(r, "*****");
+ free(r);
+
+END_TEST
+
+
+START_TEST(zeroST)
+
+ bool r;
+
+ // clear string
+ char *s = strdup("zero");
+ r = zeroS(s);
+ ck_assert_str_eq(s, "");
+ ck_assert(r);
+ free(s);
+
+ // null string
+ r = zeroS(null);
+ ck_assert(!r);
+
+END_TEST
+
+
+START_TEST(zeroBufT)
+
+ bool r;
+
+ // clear string
+ char *s = strdup("zero");
+ r = zeroBuf(s, strlen(s));
+ ck_assert_str_eq(s, "");
+ ck_assert(r);
+ free(s);
+
+ // 0 length
+ r = zeroBuf(s, 0);
+ ck_assert(!r);
+
+ // null string
+ r = zeroBuf(null, 1);
+ ck_assert(!r);
+
+END_TEST
+
+
+START_TEST(memdupT)
+
+ char *r;
+
+ // clear string
+ r = memdup("memdup", sizeof("memdup"));
+ ck_assert_str_eq(r, "memdup");
+ free(r);
+
+ // 0 length
+ r = memdup("wef", 0);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = memdup(null, 1);
+ ck_assert_ptr_eq(r, null);
+
+END_TEST
+
+
START_TEST(readEnterT)
readEnter();
@@ -1783,22 +2931,142 @@ START_TEST(logNFreeT)
END_TEST
+START_TEST(loghexT)
+
+ char *b = "abc";
+
+ // print hex
+ loghex(b, strlen(b)+1);
+
+ // size zero
+ loghex(b, 0);
+
+ // null buf
+ loghex(null, 1);
+
+END_TEST
+
+
+START_TEST(toHexST)
+
+ char *b = "abc";
+ char *r;
+
+ // print hex
+ r = toHexS(b, strlen(b)+1);
+ ck_assert_str_eq(r, "0x61, 0x62, 0x63, 0x00");
+ free(r);
+
+ // size zero
+ r = toHexS(b, 0);
+ ck_assert_ptr_eq(r, null);
+
+ // null buf
+ r = toHexS(null, 1);
+ ck_assert_ptr_eq(r, null);
+
+
+END_TEST
+
+
+START_TEST(toHexSepST)
+
+ char *b = "abc";
+ char *r;
+
+ // print hex
+ r = toHexSepS(b, strlen(b)+1, ",");
+ ck_assert_str_eq(r, "0x61,0x62,0x63,0x00");
+ free(r);
+
+ // size zero
+ r = toHexSepS(b, 0, "");
+ ck_assert_ptr_eq(r, null);
+
+ // null sep
+ r = toHexSepS(b, 1, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null buf
+ r = toHexSepS(null, 1, "");
+ ck_assert_ptr_eq(r, null);
+
+END_TEST
+
+
+START_TEST(toHexHeadSepST)
+
+ char *b = "abc";
+ char *r;
+
+ // print hex
+ r = toHexHeadSepS(b, strlen(b)+1, "x", ",");
+ ck_assert_str_eq(r, "x61,x62,x63,x00");
+ free(r);
+
+ // size zero
+ r = toHexHeadSepS(b, 0, "", "");
+ ck_assert_ptr_eq(r, null);
+
+ // null head
+ r = toHexHeadSepS(b, 1, null, "");
+ ck_assert_ptr_eq(r, null);
+
+ // null sep
+ r = toHexHeadSepS(b, 1, "", null);
+ ck_assert_ptr_eq(r, null);
+
+ // null buf
+ r = toHexHeadSepS(null, 1, "", "");
+ ck_assert_ptr_eq(r, null);
+
+END_TEST
+
+
START_TEST(strCpyT)
- char s[1024];
+ char s[1024] = init0Var;
+ char *r;
// copy string
- strCpy(s, "lib");
+ r = strCpy(s, "lib");
+ ck_assert_ptr_ne(r, null);
ck_assert_str_eq(s, "lib");
// NULL
s[0] = 0;
- strCpy(s, NULL);
+ r = strCpy(s, NULL);
+ ck_assert_ptr_eq(r, null);
ck_assert_str_eq(s, "");
ck_assert_ptr_eq(strCpy(NULL, "lib"), NULL);
END_TEST
+START_TEST(strNCpyT)
+
+ char s[1024] = init0Var;
+ char *r;
+
+ // copy string
+ r = strNCpy(s, "lib", 4);
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(s, "lib");
+
+ // size 0
+ r = strNCpy(s, "AAA", 0);
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(s, "lib");
+
+ // NULL
+ s[0] = 0;
+ r = strNCpy(s, NULL, 10);
+ ck_assert_ptr_eq(r, null);
+ ck_assert_str_eq(s, "");
+ ck_assert_ptr_eq(strNCpy(NULL, "lib", 1), NULL);
+
+END_TEST
+
+
START_TEST(strLCpyT)
char s[1024];
@@ -2036,6 +3304,7 @@ END_TEST
START_TEST(formatST)
char *s;
+ char r[128] = init0Var;
// format
s = formatS("sheepy is num %d", 1);
@@ -2044,6 +3313,26 @@ START_TEST(formatST)
// NULL
ck_assert_ptr_eq(formatS(NULL), NULL);
+ // bFormatS
+ s = bFormatS(r, "sheepy is num %d", 1);
+ ck_assert_str_eq(s, "sheepy is num 1");
+ // NULL
+ ck_assert_ptr_eq(bFormatS(r,NULL), NULL);
+ ck_assert_ptr_eq(bFormatS(NULL,"ojoi"), NULL);
+
+ // bLFormatS
+ s = bLFormatS(r, sizeof(r), "sheepy is num %d", 1);
+ ck_assert_str_eq(s, "sheepy is num 1");
+ // shorter buffer
+ s = bLFormatS(r, 7, "sheepy is num %d", 1);
+ ck_assert_str_eq(s, "sheepy");
+ // buffer size 0
+ s = bLFormatS(r, 0, "sheepy is num %d", 1);
+ ck_assert_str_eq(s, "sheepy");
+ // NULL
+ ck_assert_ptr_eq(bLFormatS(r,1,NULL), NULL);
+ ck_assert_ptr_eq(bLFormatS(NULL,1,"ojoi"), NULL);
+
END_TEST
@@ -2831,42 +4120,256 @@ START_TEST(bLReplaceST)
END_TEST
-START_TEST(replaceManyST)
+START_TEST(icReplaceST)
+
+ char *s;
// replace string, multiple character new delimeter
- char *s = replaceManyS("#ee#ee#ad", "#","^^","ad","AD");
- ck_assert_str_eq(s, "^^ee^^ee^^AD");
+ s = icReplaceS("#EE#ee#ad", "ee","VV", 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
free(s);
- // replace string, empty new delimeter
- s = replaceManyS("#ee#ee#ad", "#","","ad","AD");
- ck_assert_str_eq(s, "eeeeAD");
+ // icReplaceCharSS
+ s = icReplaceCharSS("#EE#ee#ad", 'e',"V", 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
free(s);
- // not enough olds:news pairs
- s = replaceManyS("#ee#ee#ad", "#","","ad");
- ck_assert_str_eq(s, "eeeead");
+ // icReplaceSCharS
+ s = icReplaceSCharS("#EE#ee#ad", "e",'V', 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
free(s);
- // only 2 parameters
- s = replaceManyS("#ee#ee#ad", "#");
- ck_assert_ptr_eq(s, NULL);
+ // icReplaceCharCharS
+ s = icReplaceCharCharS("#EE#ee#ad", 'e','V', 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
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);
+
+ // replace string, multiple character old delimeter
+ s = icReplaceS("AA##ee##ee#", "##","|", 0);
+ ck_assert_str_eq(s, "AA|ee|ee#");
free(s);
- // empty string
- s = replaceManyS("", "##", "");
- ck_assert_str_eq(s, "");
+ // replace one time at the start of string
+ s = icReplaceS("#ee#ee#ad", "#","^^",1);
+ ck_assert_str_eq(s, "^^ee#ee#ad");
free(s);
- // empty string many pairs
- s = replaceManyS("", "##", "", "$$", "");
- ck_assert_str_eq(s, "");
+ // replace one time
+ s = icReplaceS("AA##ee##ee#", "##","|",1);
+ ck_assert_str_eq(s, "AA|ee##ee#");
free(s);
- // empty string many pairs empty olds
- s = replaceManyS("", "##", "", "", "");
- ck_assert_str_eq(s, "");
+ // NULL new delimiter, one time: same as empty delimiter
+ s = icReplaceS("AA##ee##ee#", "##",NULL,1);
+ ck_assert_str_eq(s, "AAee##ee#");
free(s);
- // empty string and NULL old delimiter
- s = replaceManyS("", NULL,"|");
+ // empty string
+ s = icReplaceS("", "##",NULL,1);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty old delimiter
+ ck_assert_ptr_eq(icReplaceS("qwe", "","|",1), NULL);
+ // NULL old delimiter
+ ck_assert_ptr_eq(icReplaceS("qwe", NULL,"|",1), NULL);
+ // NULL string
+ ck_assert_ptr_eq(icReplaceS(NULL, "##","|",1), NULL);
+ // empty old delimiter
+ ck_assert_ptr_eq(icReplaceS("AA##ee##ee#", "","|",1), NULL);
+
+
+END_TEST
+
+
+START_TEST(iicReplaceST)
+
+ char *s;
+ // replace string, multiple character new delimeter
+ s = strdup("#EE#ee#ad");
+ iicReplaceS(&s, "EE","VV", 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
+ free(s);
+ // iicReplaceCharSS
+ s = strdup("#EE#ee#ad");
+ s = iicReplaceCharSS(&s, 'e',"V", 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
+ free(s);
+ // iicReplaceSCharS
+ s = strdup("#EE#ee#ad");
+ s = iicReplaceSCharS(&s, "e",'V', 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
+ free(s);
+ // iicReplaceCharCharS
+ s = strdup("#EE#ee#ad");
+ s = iicReplaceCharCharS(&s, 'e','V', 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
+ free(s);
+ // replace string, multiple character old delimeter
+ s = strdup("AA##ee##ee#");
+ iicReplaceS(&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");
+ iicReplaceS(&s, "#","^^",1);
+ ck_assert_str_eq(s, "^^ee#ee#ad");
+ free(s);
+ // replace one time
+ s = strdup("AA##ee##ee#");
+ iicReplaceS(&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#");
+ iicReplaceS(&s, "##",NULL,1);
+ ck_assert_str_eq(s, "AAee##ee#");
+ free(s);
+ // empty string
+ emptyS(s);
+ iicReplaceS(&s, "##",NULL,1);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty old delimiter
+ s = strdup("qwe");
+ iicReplaceS(&s, "","|",1);
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // NULL old delimiter
+ s = strdup("qwe");
+ iicReplaceS(&s, NULL,"|",1);
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // NULL string
+ s = NULL;
+ iicReplaceS(&s, "##","|",1);
+ // NULL var
+ iicReplaceS(NULL, "##","|",1);
+
+
+END_TEST
+
+
+START_TEST(bicReplaceST)
+
+ char s[100];
+ // replace string, multiple character new delimeter
+ strcpy(s, "#EE#ee#ad");
+ bicReplaceS(s, "ee","VV", 0);
+ ck_assert_str_eq(s, "#VV#VV#ad");
+ // replace string, multiple character old delimeter
+ strcpy(s, "AA##ee##ee#");
+ bicReplaceS(s, "##","|", 0);
+ ck_assert_str_eq(s, "AA|ee|ee#");
+ // replace one time at the start of string
+ strcpy(s, "#ee#ee#ad");
+ bicReplaceS(s, "#","^^",1);
+ ck_assert_str_eq(s, "^^ee#ee#ad");
+ // replace one time
+ strcpy(s, "AA##ee##ee#");
+ bicReplaceS(s, "##","|",1);
+ ck_assert_str_eq(s, "AA|ee##ee#");
+ // NULL new delimiter, one time: same as empty delimiter
+ strcpy(s, "AA##ee##ee#");
+ bicReplaceS(s, "##",NULL,1);
+ ck_assert_str_eq(s, "AAee##ee#");
+ // empty string
+ bEmptyS(s);
+ bicReplaceS(s, "##",NULL,1);
+ ck_assert_str_eq(s, "");
+ // empty old delimiter
+ strcpy(s, "qwe");
+ bicReplaceS(s, "","|",1);
+ ck_assert_str_eq(s, "qwe");
+ // NULL old delimiter
+ strcpy(s, "qwe");
+ bicReplaceS(s, NULL,"|",1);
+ ck_assert_str_eq(s, "qwe");
+ // NULL var
+ ck_assert_ptr_eq(bicReplaceS(NULL, "##","|",1), NULL);
+
+
+END_TEST
+
+
+START_TEST(bLicReplaceST)
+
+ char s[100];
+ // replace string, multiple character new delimeter
+ strcpy(s, "#ee#EE#ad");
+ bLicReplaceS(s, sizeof s, "ee","vv", 0);
+ ck_assert_str_eq(s, "#vv#vv#ad");
+ // shorter buffer
+ strcpy(s, "#ee#ee#ad");
+ bLicReplaceS(s, 5, "#","^^", 0);
+ ck_assert_str_eq(s, "^^ee");
+ // replace string, multiple character old delimeter
+ strcpy(s, "AA##ee##ee#");
+ bLicReplaceS(s, sizeof s, "##","|", 0);
+ 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);
+
+
+END_TEST
+
+
+START_TEST(replaceManyST)
+
+ // 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
@@ -3085,75 +4588,333 @@ START_TEST(bLReplaceManyST)
END_TEST
-START_TEST(eqST)
-
- // 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));
-
-END_TEST
-
-
-START_TEST(eqCharST)
+START_TEST(icReplaceManyST)
- // 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, ""));
+ // replace string, multiple character new delimeter
+ char *s = icReplaceManyS("#ee#ee#ad", "#","^^","AD","vv");
+ ck_assert_str_eq(s, "^^ee^^ee^^vv");
+ free(s);
+ // replace string, empty new delimeter
+ s = icReplaceManyS("#ee#ee#ad", "#","","ad","AD");
+ ck_assert_str_eq(s, "eeeeAD");
+ free(s);
+ // not enough olds:news pairs
+ s = icReplaceManyS("#ee#ee#ad", "#","","ad");
+ ck_assert_str_eq(s, "eeeead");
+ free(s);
+ // only 2 parameters
+ s = icReplaceManyS("#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 = icReplaceManyS("AA##ee##ee#", "##",NULL);
+ ck_assert_ptr_eq(s, NULL);
+ free(s);
+ // empty string
+ s = icReplaceManyS("", "##", "");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty string many pairs
+ s = icReplaceManyS("", "##", "", "$$", "");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty string many pairs empty olds
+ s = icReplaceManyS("", "##", "", "", "");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty string and NULL old delimiter
+ s = icReplaceManyS("", NULL,"|");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty string and NULL old delimiter not first - same as replace empty string
+ s = icReplaceManyS("","##","|", NULL,"|");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty old delimiter
+ ck_assert_ptr_eq(icReplaceManyS("AA##ee##ee#", "","|", "AA", "BB"), NULL);
+ // empty old delimiter not first
+ ck_assert_ptr_eq(icReplaceManyS("AA##ee##ee#", "##","|", "", "BB"), NULL);
// NULL string
- ck_assert(!eqCharS(0,"a"));
- ck_assert(!eqCharS('a', NULL));
-
-END_TEST
-
-
-START_TEST(eqSCharT)
+ ck_assert_ptr_eq(icReplaceManyS(NULL, "##","|"), NULL);
+ // NULL string many pairs
+ ck_assert_ptr_eq(icReplaceManyS(NULL, "##","|", "$$", ""), NULL);
- // 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));
END_TEST
-START_TEST(eqIST)
+START_TEST(iicReplaceManyST)
- // 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));
+ char *s;
+ // replace string, multiple character new delimeter
+ s = strdup("#ee#ee#ad");
+ iicReplaceManyS(&s, "#","^^","ad","vv");
+ ck_assert_str_eq(s, "^^ee^^ee^^vv");
+ free(s);
+ // replace string, empty new delimeter
+ s = strdup("#ee#ee#ad");
+ iicReplaceManyS(&s, "#","","ad","AD");
+ ck_assert_str_eq(s, "eeeeAD");
+ free(s);
+ // not enough olds:news pairs
+ s = strdup("#ee#ee#ad");
+ iicReplaceManyS(&s, "#","","ad");
+ ck_assert_str_eq(s, "eeeead");
+ free(s);
+ // only 2 parameters
+ // doesn't compile
+ /* s = strdup("#ee#ee#ad"); */
+ /* iicReplaceManyS(&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");
+ iicReplaceManyS(&s, "#", NULL);
+ ck_assert_str_eq(s, "#ee#ee#ad");
+ free(s);
+ // empty string
+ emptyS(s);
+ iicReplaceManyS(&s, "#", "");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // empty string many pairs
+ emptyS(s);
+ iicReplaceManyS(&s, "#", "", "%", "");
+ ck_assert_str_eq(s, "");
+ free(s);
+ // many pairs empty olds
+ s = strdup("qw#e");
+ iicReplaceManyS(&s, "#", "", "", "");
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // NULL old delimiter
+ s = strdup("qw#e");
+ iicReplaceManyS(&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");
+ iicReplaceManyS(&s, "#","|", NULL, "");
+ ck_assert_str_eq(s, "qw|e");
+ free(s);
+ // empty old delimiter
+ s = strdup("qw#e");
+ iicReplaceManyS(&s, "","|", NULL, "");
+ ck_assert_str_eq(s, "qw#e");
+ free(s);
+ // empty old delimiter not first
+ s = strdup("qw#e");
+ iicReplaceManyS(&s, "#","|", "", "*");
+ ck_assert_str_eq(s, "qw|e");
+ free(s);
+ // NULL string
+ s = NULL;
+ iicReplaceManyS(&s, "#","|", "$", "*");
+ ck_assert_ptr_eq(s, NULL);
+ free(s);
+ // NULL var
+ iicReplaceManyS(NULL, "#","|", "$", "*");
+
+
+END_TEST
+
+
+START_TEST(bicReplaceManyST)
+
+ char s[100];
+ // replace string, multiple character new delimeter
+ strcpy(s, "#ee#ee#ad");
+ bicReplaceManyS(s, "#","^^","AD","vv");
+ ck_assert_str_eq(s, "^^ee^^ee^^vv");
+ // replace string, empty new delimeter
+ strcpy(s, "#ee#ee#ad");
+ bicReplaceManyS(s, "#","","ad","AD");
+ ck_assert_str_eq(s, "eeeeAD");
+ // not enough olds:news pairs
+ strcpy(s, "#ee#ee#ad");
+ bicReplaceManyS(s, "#","","ad");
+ ck_assert_str_eq(s, "eeeead");
+ // only 2 parameters
+ // doesn't compile
+ /* strcpy(s, "#ee#ee#ad"); */
+ /* bicReplaceManyS(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");
+ bicReplaceManyS(s, "#", NULL);
+ ck_assert_str_eq(s, "#ee#ee#ad");
+ // empty string
+ bEmptyS(s);
+ bicReplaceManyS(s, "#", "");
+ ck_assert_str_eq(s, "");
+ // empty string many pairs
+ bEmptyS(s);
+ bicReplaceManyS(s, "#", "", "%", "");
+ ck_assert_str_eq(s, "");
+ // many pairs empty olds
+ strcpy(s, "qw#e");
+ bicReplaceManyS(s, "#", "", "", "");
+ ck_assert_str_eq(s, "qwe");
+ // NULL old delimiter
+ strcpy(s, "qw#e");
+ bicReplaceManyS(s, NULL, "");
+ ck_assert_str_eq(s, "qw#e");
+ // NULL old delimiter not first - same as replace empty string
+ strcpy(s, "qw#e");
+ bicReplaceManyS(s, "#","|", NULL, "");
+ ck_assert_str_eq(s, "qw|e");
+ // empty old delimiter
+ strcpy(s, "qw#e");
+ bicReplaceManyS(s, "","|", NULL, "");
+ ck_assert_str_eq(s, "qw#e");
+ // empty old delimiter not first
+ strcpy(s, "qw#e");
+ bicReplaceManyS(s, "#","|", "", "*");
+ ck_assert_str_eq(s, "qw|e");
+ // NULL var
+ ck_assert_ptr_eq(bicReplaceManyS(NULL, "#","|", "$", "*"), NULL);
+
+
+END_TEST
+
+
+START_TEST(bLicReplaceManyST)
+
+ char s[100];
+ // replace string, multiple character new delimeter
+ strcpy(s, "#ee#ee#ad");
+ bLicReplaceManyS(s, sizeof s, "#","^^","AD","vv");
+ ck_assert_str_eq(s, "^^ee^^ee^^vv");
+ // shorter buffer
+ strcpy(s, "#ee#ee#ad");
+ bLicReplaceManyS(s, 5, "#","^^","ad","AD");
+ ck_assert_str_eq(s, "^^ee");
+ // replace string, empty new delimeter
+ strcpy(s, "#ee#ee#ad");
+ bLicReplaceManyS(s, sizeof s, "#","","ad","AD");
+ ck_assert_str_eq(s, "eeeeAD");
+ // not enough olds:news pairs
+ strcpy(s, "#ee#ee#ad");
+ bLicReplaceManyS(s, sizeof s, "#","","ad");
+ ck_assert_str_eq(s, "eeeead");
+ // only 2 parameters
+ // doesn't compile
+ /* strcpy(s, "#ee#ee#ad"); */
+ /* bLicReplaceManyS(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");
+ bLicReplaceManyS(s, sizeof s, "#", NULL);
+ ck_assert_str_eq(s, "#ee#ee#ad");
+ // empty string
+ bEmptyS(s);
+ bLicReplaceManyS(s, sizeof s, "#", "");
+ ck_assert_str_eq(s, "");
+ // empty string many pairs
+ bEmptyS(s);
+ bLicReplaceManyS(s, sizeof s, "#", "", "%", "");
+ ck_assert_str_eq(s, "");
+ // many pairs empty olds
+ strcpy(s, "qw#e");
+ bLicReplaceManyS(s, sizeof s, "#", "", "", "");
+ ck_assert_str_eq(s, "qwe");
+ // NULL old delimiter
+ strcpy(s, "qw#e");
+ bLicReplaceManyS(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");
+ bLicReplaceManyS(s, sizeof s, "#","|", NULL, "");
+ ck_assert_str_eq(s, "qw|e");
+ // empty old delimiter
+ strcpy(s, "qw#e");
+ bLicReplaceManyS(s, sizeof s, "","|", NULL, "");
+ ck_assert_str_eq(s, "qw#e");
+ // empty old delimiter not first
+ strcpy(s, "qw#e");
+ bLicReplaceManyS(s, sizeof s, "#","|", "", "*");
+ ck_assert_str_eq(s, "qw|e");
+ // size 0 - no change
+ bLicReplaceManyS(s, 0, "#","|", "", "*");
+ ck_assert_str_eq(s, "qw|e");
+ // NULL var
+ ck_assert_ptr_eq(bLicReplaceManyS(NULL, sizeof s, "#","|", "$", "*"), NULL);
+
+
+END_TEST
+
+
+START_TEST(eqST)
+
+ // 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));
+
+END_TEST
+
+
+START_TEST(eqCharST)
+
+ // 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));
+
+END_TEST
+
+
+START_TEST(eqSCharT)
+
+ // 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));
+
+END_TEST
+
+
+START_TEST(eqIST)
+
+ // 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));
@@ -3289,41 +5050,335 @@ START_TEST(countCharST)
END_TEST
-START_TEST(isNumberT)
+START_TEST(icEqST)
- // 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(""));
+ // identical strings
+ ck_assert(icEqS("SHEE", "shee"));
+ // different strings
+ ck_assert(!icEqS("shee", "SH"));
+ // empty strings
+ ck_assert(!icEqS("shee", ""));
+ ck_assert(!icEqS("", "SH"));
+ ck_assert(icEqS("", ""));
+ // NULL string
+ ck_assert(!icEqS(NULL,"a"));
+ ck_assert(!icEqS("a", NULL));
+
+
+END_TEST
+
+
+START_TEST(icEqCharST)
+
+ // identical strings
+ ck_assert(icEqCharS('S', "s"));
+ // different strings
+ ck_assert(!icEqCharS('s', "SH"));
+ // empty strings
+ ck_assert(!icEqCharS('s', ""));
+ ck_assert(!icEqCharS(0, "SH"));
+ ck_assert(icEqCharS(0, ""));
+ // NULL string
+ ck_assert(!icEqCharS(0,"a"));
+ ck_assert(!icEqCharS('a', NULL));
+
+
+END_TEST
+
+
+START_TEST(icEqSCharT)
+
+ // identical strings
+ ck_assert(icEqSChar("S", 's'));
+ // different strings
+ ck_assert(!icEqSChar("shee", 'S'));
+ // empty strings
+ ck_assert(!icEqSChar("shee", 0));
+ ck_assert(!icEqSChar("", 'S'));
+ ck_assert(icEqSChar("", 0));
+ // NULL string
+ ck_assert(!icEqSChar(NULL,'a'));
+ ck_assert(!eqS("a", 0));
+
+
+END_TEST
+
+
+START_TEST(icEqIST)
+
+ // identical strings
+ ck_assert(icEqIS("AshEe|", "shee", 1));
+ ck_assert(icEqIS("AshEE", "shee", -4));
+ // string at index shorter than string2
+ ck_assert(!icEqIS("Ashee", "shee", 2));
+ // empty string
+ ck_assert(!icEqIS("", "shee", 0));
+ ck_assert(!icEqIS("Ashee", "", 0));
+ ck_assert(icEqIS("", "", 0));
+ // index mismatch
+ ck_assert(!icEqIS("Ashee", "shee", 0));
+ // index outside
+ ck_assert(!icEqIS("Ashee", "shee", 10));
+ ck_assert(!icEqIS("Ashee", "shee", -10));
+ // different strings
+ ck_assert(!icEqIS("shee", "Sg",0));
+ // NULL string
+ ck_assert(!icEqIS(NULL,"a", 0));
+ ck_assert(!icEqIS("a", NULL, 0));
+
+
+END_TEST
+
+
+START_TEST(icEqICharST)
+
+ // identical strings
+ ck_assert(icEqICharS("ASHEE", 's', 1));
+ ck_assert(icEqICharS("Ashee", 's', -4));
+ // string at index shorter than string2
+ ck_assert(!icEqICharS("Ashee", 's', 2));
+ // empty string
+ ck_assert(!icEqICharS("", 's', 0));
+ ck_assert(!icEqICharS("Ashee", 0, 0));
+ ck_assert(icEqICharS("", 0, 0));
+ // index mismatch
+ ck_assert(!icEqICharS("Ashee", 's', 0));
+ // index outside
+ ck_assert(!icEqICharS("Ashee", 's', 10));
+ ck_assert(!icEqICharS("Ashee", 's', -10));
+ // different strings
+ ck_assert(!icEqICharS("shee", 'd',0));
+ // NULL string
+ ck_assert(!icEqICharS(NULL,'a', 0));
+ ck_assert(!icEqICharS("a", 0, 0));
+
+
+END_TEST
+
+
+START_TEST(icStartsWithST)
+
+ // identical strings
+ ck_assert(icStartsWithS("SHEE", "shee"));
+ ck_assert(icStartsWithS("SHEEPY", "shee"));
+ // different strings
+ ck_assert(!icStartsWithS("shee", "aH"));
+ ck_assert(!icStartsWithS("shee", "sheep"));
+ ck_assert(!icStartsWithS("-shee", "shee"));
+ // NULL string
+ ck_assert(!icStartsWithS(NULL,"a"));
+ ck_assert(!icStartsWithS("a", NULL));
+
+
+END_TEST
+
+
+START_TEST(icStartsWithCharST)
+
+ // identical strings
+ ck_assert(icStartsWithCharS("Shee", 's'));
+ ck_assert(icStartsWithCharS("Sheepy", 's'));
+ ck_assert(icStartsWithCharS("", 0));
+ // different strings
+ ck_assert(!icStartsWithCharS("shee", 'a'));
+ ck_assert(!icStartsWithCharS("-shee", 's'));
+ ck_assert(!icStartsWithCharS("", '0'));
+ // NULL string
+ ck_assert(!icStartsWithCharS(NULL,'a'));
+ ck_assert(!icStartsWithCharS("a", 0));
+
+
+END_TEST
+
+
+START_TEST(icEndsWithST)
+
+ // identical strings
+ ck_assert(icEndsWithS("SHEE", "shee"));
+ ck_assert(icEndsWithS("SHEEPY", "eepy"));
+ // different strings
+ ck_assert(!icEndsWithS("shee", "SH"));
+ ck_assert(!icEndsWithS("shee", "sheep"));
+ ck_assert(!icEndsWithS("shee-", "shee"));
+ // NULL string
+ ck_assert(!icEndsWithS(NULL,"a"));
+ ck_assert(!icEndsWithS("a", NULL));
+
+
+END_TEST
+
+
+START_TEST(icEndsWithCharST)
+
+ // identical strings
+ ck_assert(icEndsWithCharS("sheE", 'e'));
+ ck_assert(icEndsWithCharS("sheepY", 'y'));
+ ck_assert(icEndsWithCharS("", 0));
+ // different strings
+ ck_assert(!icEndsWithCharS("shee", 'R'));
+ ck_assert(!icEndsWithCharS("shee", 'p'));
+ ck_assert(!icEndsWithCharS("shee-", 'e'));
+ ck_assert(!icEndsWithCharS("", '0'));
+ // NULL string
+ ck_assert(!icEndsWithCharS(NULL,'a'));
+ ck_assert(!icEndsWithCharS("a", 0));
+
+
+END_TEST
+
+
+START_TEST(icCountST)
+
+ // positive count
+ ck_assert_int_eq(icCountS("SHEE", "shee"), 1);
+ ck_assert_int_eq(icCountS("AAA AAA", "a"), 6);
+ ck_assert_int_eq(icCountS("AAA AAA", "aa"), 2);
+ // 0 count
+ ck_assert_int_eq(icCountS("shee", "eSH"), 0);
+ ck_assert_int_eq(icCountS("shee", "sheepy"), 0);
+ ck_assert_int_eq(icCountS("aaa aaa", "ab"), 0);
+ // NULL string
+ ck_assert_int_eq(icCountS(NULL,"a"), -1);
+ ck_assert_int_eq(icCountS("a", NULL), -1);
+
+
+END_TEST
+
+
+START_TEST(icCountCharST)
+
+ // positive count
+ ck_assert_int_eq(icCountCharS("Shee", 's'), 1);
+ ck_assert_int_eq(icCountCharS("AAA aaa", 'a'), 6);
+ // 0 count
+ ck_assert_int_eq(icCountCharS("shee", '0'), 0);
+ ck_assert_int_eq(icCountCharS("shee", 'y'), 0);
+ ck_assert_int_eq(icCountCharS("aaa aaa", 'b'), 0);
+ // empty string
+ ck_assert_int_eq(icCountCharS("", 'a'), 0);
+ ck_assert_int_eq(icCountCharS("", 0), -1);
+ // NULL string
+ ck_assert_int_eq(icCountCharS(NULL,'a'), -1);
+ ck_assert_int_eq(icCountCharS("a", 0), -1);
+
+
+END_TEST
+
+
+START_TEST(hasCtrlCharT)
+
+ // string with control char
+ ck_assert(hasCtrlChar("\tsheepy\n"));
+ // no control char
+ ck_assert(!hasCtrlChar("sheepy"));
+ // null string
+ ck_assert(!hasCtrlChar(null));
+
+
+END_TEST
+
+
+START_TEST(stripCtrlST)
+
+ char *r;
+
+ // string with control char
+ r = stripCtrlS("\tsheepy\n");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ // no control char
+ r = stripCtrlS("sheepy");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ // null string
+ r = stripCtrlS(null);
+ ck_assert_ptr_eq(r, null);
+
+
+END_TEST
+
+
+START_TEST(iStripCtrlST)
+
+ char *r, *s;
+
+ // string with control char
+ s = strdup("\tsheepy\n");
+ r = iStripCtrlS(&s);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ // no control char
+ s = strdup("sheepy");
+ r = iStripCtrlS(&s);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ // null string
+ s = null;
+ r = iStripCtrlS(&s);
+ ck_assert_ptr_eq(r, null);
+ r = iStripCtrlS(null);
+ ck_assert_ptr_eq(r, null);
+
+
+END_TEST
+
+
+START_TEST(bStripCtrlST)
+
+ char *r;
+ char s[40];
+
+ // string with control char
+ strLCpy(s, sizeof(s), "\tsheepy\n");
+ r = bStripCtrlS(s);
+ ck_assert_str_eq(r, "sheepy");
+ // no control char
+ strLCpy(s, sizeof(s), "sheepy");
+ r = bStripCtrlS(s);
+ ck_assert_str_eq(r, "sheepy");
+ // null string
+ r = bStripCtrlS(null);
+ ck_assert_ptr_eq(r, null);
+
+
+END_TEST
+
+
+START_TEST(isNumberT)
+
+ // 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));
@@ -3391,6 +5446,37 @@ START_TEST(parseIntCharT)
END_TEST
+START_TEST(parseI64T)
+
+ // number
+ ck_assert_int_eq(parseI64("123sheepy"), 123);
+ ck_assert_int_eq(parseI64("lib123sheepy"), 123);
+ ck_assert_int_eq(parseI64("-123"), -123);
+ // out of range - TODO check stderr
+ parseI64("999999999999999999999999999999999999999");
+ // string without number
+ ck_assert_int_eq(parseI64("sheepy"), 0);
+ // NULL string
+ ck_assert_int_eq(parseI64(NULL), 0);
+
+
+END_TEST
+
+
+START_TEST(parseI64CharT)
+
+ // number
+ ck_assert_int_eq(parseI64Char('1'),1);
+ ck_assert_int_eq(parseI64Char('0'),0);
+ ck_assert_int_eq(parseI64Char('9'),9);
+ // not a number
+ ck_assert_int_eq(parseI64Char('a'),-1);
+ ck_assert_int_eq(parseI64Char(0),-1);
+
+
+END_TEST
+
+
START_TEST(parseDoubleT)
// number
@@ -3407,6 +5493,36 @@ START_TEST(parseDoubleT)
END_TEST
+START_TEST(parseDoubleCharT)
+
+ // number
+ ck_assert_int_eq(parseDoubleChar('1'),1);
+ ck_assert_int_eq(parseDoubleChar('0'),0);
+ ck_assert_int_eq(parseDoubleChar('9'),9);
+ // not a number
+ ck_assert_int_eq(parseDoubleChar('a'),-1);
+ ck_assert_int_eq(parseDoubleChar(0),-1);
+
+END_TEST
+
+
+START_TEST(parseHexT)
+
+ u64 r;
+
+ // hex to int
+ r = parseHex("0x04");
+ ck_assert_int_eq(r, 4);
+ r = parseHex("aoij0xaa");
+ ck_assert_int_eq(r, 170);
+ // null string
+ r = parseHex(null);
+ ck_assert_int_eq(r, 0);
+
+
+END_TEST
+
+
START_TEST(intToST)
// number
@@ -3471,6 +5587,16 @@ START_TEST(lenST)
END_TEST
+START_TEST(sizeST)
+
+ // string
+ ck_assert_uint_eq(sizeS("sheepy"), 7);
+ // NULL string
+ ck_assert_uint_eq(sizeS(NULL), 0);
+
+END_TEST
+
+
START_TEST(upperST)
// string
@@ -3897,3353 +6023,10057 @@ START_TEST(bUniqST)
END_TEST
-START_TEST(getST)
+START_TEST(icUniqST)
+
+ char *s;
+
+ // uniquify
+ s = icUniqS("/qQqwd///", 'q');
+ ck_assert_str_eq(s, "/qwd///");
+ free(s);
+ // short string
+ s = icUniqS("?", '/');
+ ck_assert_str_eq(s, "?");
+ free(s);
+ // NULL
+ ck_assert_ptr_eq(icUniqS(NULL, '/'), NULL);
- // 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);
END_TEST
-START_TEST(setST)
+START_TEST(iicUniqST)
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");
+ // uniquify
+ s = strdup("/qQqwd///");
+ ck_assert_str_eq(iicUniqS(&s, 'Q'), "/qwd///");
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, "");
+ // short string
+ s = strdup("?");
+ ck_assert_str_eq(iicUniqS(&s, '/'), "?");
free(s);
// NULL string
- setS(NULL, 0, 's');
+ s = NULL;
+ ck_assert_ptr_eq(iicUniqS(&s, '/'), NULL);
+ // NULL
+ ck_assert_ptr_eq(iicUniqS(NULL, '/'), NULL);
END_TEST
-START_TEST(sliceST)
+START_TEST(bicUniqST)
+
+ char s[100];
+
+ // uniquify
+ strcpy(s, "/qQqwd///");
+ ck_assert_str_eq(bicUniqS(s, 'q'), "/qwd///");
+ // short string
+ strcpy(s, "?");
+ ck_assert_str_eq(bicUniqS(s, '/'), "?");
+ // NULL
+ ck_assert_ptr_eq(bicUniqS(NULL, '/'), NULL);
- // 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);
END_TEST
-START_TEST(iSliceST)
+START_TEST(repeatST)
- 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);
+ char *r;
+
+ // repeat
+ r = repeatS("abc", 2);
+ ck_assert_str_eq(r, "abcabc");
+ free(r);
+
+ // empty string
+ r = repeatS("", 2);
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // once
+ r = repeatS("ab", 1);
+ ck_assert_str_eq(r, "ab");
+ free(r);
+
+ // 0 times
+ r = repeatS("jhgjgh", 0);
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // null string
+ r = repeatS(null, 2);
+ ck_assert_ptr_eq(r, null);
END_TEST
-START_TEST(bSliceST)
+START_TEST(iRepeatST)
- 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);
+ char *s, *r;
+
+ // repeat
+ s = strdup("abc");
+ r = iRepeatS(&s, 2);
+ ck_assert_ptr_eq(r, s);
+ ck_assert_str_eq(r, "abcabc");
+ free(r);
+
+ // empty string
+ s = strdup("");
+ r = iRepeatS(&s, 2);
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // once
+ s = strdup("ab");
+ r = iRepeatS(&s, 1);
+ ck_assert_str_eq(r, "ab");
+ free(r);
+
+ // 0 times
+ s = strdup("jhgjgh");
+ r = iRepeatS(&s, 0);
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // null string
+ s = null;
+ r = iRepeatS(&s, 2);
+ ck_assert_ptr_eq(r, null);
+
+ r = iRepeatS(null, 2);
+ ck_assert_ptr_eq(r, null);
END_TEST
-START_TEST(insertST)
+START_TEST(bRepeatST)
- char *s;
+ char s[128] = init0Var;
+ char *r;
+
+ // repeat
+ r = bRepeatS(s, "abc", 2);
+ ck_assert_str_eq(r, "abcabc");
- // 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);
+ r = bRepeatS(s, "", 2);
+ ck_assert_str_eq(r, "");
+ // once
+ r = bRepeatS(s, "ab", 1);
+ ck_assert_str_eq(r, "ab");
+
+ // 0 times
+ r = bRepeatS(s, "adsad", 0);
+ ck_assert_str_eq(r, "");
+
+ // null string
+ r = bRepeatS(s, null, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bRepeatS(null, "asd", 2);
+ ck_assert_ptr_eq(r, null);
END_TEST
-START_TEST(insertNFreeST)
+START_TEST(bLRepeatST)
- char *s, *a;
+ char s[6] = init0Var;
+ char *r;
+
+ // repeat
+ r = bLRepeatS(s, sizeof(s), "ab", 2);
+ ck_assert_str_eq(r, "abab");
- // 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);
+ r = bLRepeatS(s, sizeof(s), "", 2);
+ ck_assert_str_eq(r, "");
+
+ // once
+ r = bLRepeatS(s, sizeof(s), "ab", 1);
+ ck_assert_str_eq(r, "ab");
+
+ // 0 times
+ r = bLRepeatS(s, sizeof(s), "asdasd", 0);
+ ck_assert_str_eq(r, "");
+
+ // once bigger than buffer
+ r = bLRepeatS(s, sizeof(s), "123456", 1);
+ ck_assert_ptr_eq(r, null);
+
+ // dest size 0
+ r = bLRepeatS(s, 0, "123", 2);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = bLRepeatS(s, sizeof(s), null, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bLRepeatS(null, sizeof(s), "asd", 2);
+ ck_assert_ptr_eq(r, null);
END_TEST
-START_TEST(iInsertST)
+START_TEST(repeatCharST)
- char *s;
+ char *r;
- // 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");
+ // repeat
+ r = repeatCharS('$', 2);
+ ck_assert_str_eq(r, "$$");
+ free(r);
+
+ // once
+ r = repeatCharS('!', 1);
+ ck_assert_str_eq(r, "!");
+ free(r);
+
+ // 0 times
+ r = repeatCharS('0', 0);
+ ck_assert_str_eq(r, "");
+ free(r);
END_TEST
-START_TEST(iInsertNFreeST)
+START_TEST(bRepeatCharST)
- char *s, *a, *r;
+ char s[128] = init0Var;
+ char *r;
+
+ // repeat
+ r = bRepeatCharS(s, 'a', 2);
+ ck_assert_str_eq(r, "aa");
+
+ // once
+ r = bRepeatCharS(s, 'a', 1);
+ ck_assert_str_eq(r, "a");
+
+ // 0 times
+ r = bRepeatCharS(s, '0', 0);
+ ck_assert_str_eq(r, "");
+
+ // null dest
+ r = bRepeatCharS(null, 'd', 2);
+ ck_assert_ptr_eq(r, null);
- // 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);
END_TEST
-START_TEST(bInsertST)
+START_TEST(bLRepeatCharST)
- char s[100];
+ char s[6] = init0Var;
+ char *r;
+
+ // repeat
+ r = bLRepeatCharS(s, sizeof(s), '$', 4);
+ ck_assert_str_eq(r, "$$$$");
+
+ // once
+ r = bLRepeatCharS(s, sizeof(s), '+', 1);
+ ck_assert_str_eq(r, "+");
+
+ // 0 times
+ r = bLRepeatCharS(s, sizeof(s), '1', 0);
+ ck_assert_str_eq(r, "");
+
+ // once bigger than buffer
+ r = bLRepeatCharS(s, sizeof(s), '=', 6);
+ ck_assert_ptr_eq(r, null);
+
+ // dest size 0
+ r = bLRepeatCharS(s, 0, '/', 2);
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bLRepeatCharS(null, sizeof(s), '\'', 2);
+ ck_assert_ptr_eq(r, null);
- // 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);
END_TEST
-START_TEST(bLInsertST)
+START_TEST(repeatLenST)
- char s[100];
+ ssize_t r;
+
+ r = repeatLenS("asd", 3);
+ ck_assert_int_eq(r, 9);
+
+ // 0 times
+ r = repeatLenS("asd", 0);
+ ck_assert_int_eq(r, 0);
- // 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);
+ r = repeatLenS("", 3);
+ ck_assert_int_eq(r, 0);
+
+ // null string
+ r = repeatLenS(null, 3);
+ ck_assert_int_eq(r, -1);
END_TEST
-START_TEST(injectST)
+START_TEST(ellipsisStartST)
- char *s;
+ char *r;
- // 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);
+ // no ellipsis
+ r = ellipsisStartS("sheepy", 10, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ r = ellipsisStartS("sheepy", 6, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // ellipsis
+ r = ellipsisStartS("sheepy", 5, "...");
+ ck_assert_str_eq(r, "...py");
+ free(r);
+
+ // ellipsis longer than target length
+ r = ellipsisStartS("sheepy", 5, "......");
+ ck_assert_str_eq(r, ".....");
+ free(r);
+
+ // empty ellipsis
+ r = ellipsisStartS("sheepy", 5, "");
+ ck_assert_str_eq(r, "heepy");
+ free(r);
+
+ // target length 0
+ r = ellipsisStartS("sheepy", 0, "...");
+ ck_assert_str_eq(r, "");
+ free(r);
+ // null string
+ ck_assert_ptr_eq(ellipsisStartS(null,4,""), null);
+ // null ellipsis
+ ck_assert_ptr_eq(ellipsisStartS("",4,null), null);
END_TEST
-START_TEST(iInjectST)
+START_TEST(iEllipsisStartST)
- char *s;
+ char *s, *r;
- // insert
+ // no ellipsis
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");
+ r = iEllipsisStartS(&s, 10, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ s = strdup("sheepy");
+ r = iEllipsisStartS(&s, 6, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // ellipsis
+ s = strdup("sheepy");
+ r = iEllipsisStartS(&s, 5, "...");
+ ck_assert_str_eq(r, "...py");
+ free(r);
+
+ // ellipsis longer than target length
+ s = strdup("sheepy");
+ r = iEllipsisStartS(&s, 5, "......");
+ ck_assert_str_eq(r, ".....");
+ free(r);
+
+ // empty ellipsis
+ s = strdup("sheepy");
+ r = iEllipsisStartS(&s, 5, "");
+ ck_assert_str_eq(r, "heepy");
+ free(r);
+
+ // target length 0
+ s = strdup("sheepy");
+ r = iEllipsisStartS(&s, 0, "...");
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // null string
+ s = null;
+ ck_assert_ptr_eq(iEllipsisStartS(&s,4,""), null);
+ ck_assert_ptr_eq(iEllipsisStartS(null,4,""), null);
+ // null ellipsis
+ s = strdup("sd");
+ ck_assert_ptr_eq(iEllipsisStartS(&s,4,null), null);
free(s);
- // NULL var
- iInjectS(NULL, 0, 's');
+
END_TEST
-START_TEST(bInjectST)
+START_TEST(bEllipsisStartST)
- char s[100];
+ char *r;
+ char dest[48];
+
+ // no ellipsis
+ r = bEllipsisStartS(dest, "sheepy", 10, "...");
+ ck_assert_str_eq(r, "sheepy");
+ r = bEllipsisStartS(dest, "sheepy", 6, "...");
+ ck_assert_str_eq(r, "sheepy");
+
+ // ellipsis
+ r = bEllipsisStartS(dest, "sheepy", 5, "...");
+ ck_assert_str_eq(r, "...py");
+
+ // ellipsis longer than target length
+ r = bEllipsisStartS(dest, "sheepy", 5, "......");
+ ck_assert_str_eq(r, ".....");
+
+ // empty ellipsis
+ r = bEllipsisStartS(dest, "sheepy", 5, "");
+ ck_assert_str_eq(r, "heepy");
+
+ // target length 0
+ r = bEllipsisStartS(dest, "sheepy", 0, "...");
+ ck_assert_str_eq(r, "");
+
+ // null string
+ ck_assert_ptr_eq(bEllipsisStartS(dest, null,4,""), null);
+ // null ellipsis
+ ck_assert_ptr_eq(bEllipsisStartS(dest, "",4,null), null);
+ // null dest
+ ck_assert_ptr_eq(bEllipsisStartS(null, "",4,""), null);
- // 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);
END_TEST
-START_TEST(bLInjectST)
+START_TEST(bLEllipsisStartST)
- char s[100];
+ char *r;
+ char dest[6];
+
+ // no ellipsis
+ r = bLEllipsisStartS(dest, sizeof(dest), "sheepy", 10, "...");
+ ck_assert_str_eq(r, "sheep");
+ r = bLEllipsisStartS(dest, sizeof(dest), "sheepy", 6, "...");
+ ck_assert_str_eq(r, "sheep");
+
+ // ellipsis
+ r = bLEllipsisStartS(dest, sizeof(dest), "sheepy", 5, "...");
+ ck_assert_str_eq(r, "...py");
+
+ // ellipsis longer than target length
+ r = bLEllipsisStartS(dest, sizeof(dest), "sheepy", 5, "......");
+ ck_assert_str_eq(r, ".....");
+
+ // empty ellipsis
+ r = bLEllipsisStartS(dest, sizeof(dest), "sheepy", 5, "");
+ ck_assert_str_eq(r, "heepy");
+
+ // target length 0
+ r = bLEllipsisStartS(dest, sizeof(dest), "sheepy", 0, "...");
+ ck_assert_str_eq(r, "");
+
+ // dest size 0, dest unchanged
+ dest[0] = 'a';
+ dest[1] = 0;
+ r = bLEllipsisStartS(dest, 0, "sheepy", 5, "");
+ ck_assert_str_eq(r, "a");
+
+ // null string
+ ck_assert_ptr_eq(bLEllipsisStartS(dest, sizeof(dest), null,4,""), null);
+ // null ellipsis
+ ck_assert_ptr_eq(bLEllipsisStartS(dest, sizeof(dest), "",4,null), null);
+ // null dest
+ ck_assert_ptr_eq(bLEllipsisStartS(null, sizeof(dest), "",4,""), null);
- // 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);
END_TEST
-START_TEST(delST)
+START_TEST(ellipsisStartCharST)
+
+ char *r;
+
+ // no ellipsis
+ r = ellipsisStartCharS("sheepy", 10, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ r = ellipsisStartCharS("sheepy", 6, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // ellipsis
+ r = ellipsisStartCharS("sheepy", 5, '-');
+ ck_assert_str_eq(r, "-eepy");
+ free(r);
+
+ // target length 0
+ r = ellipsisStartCharS("sheepy", 0, '-');
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // null string
+ ck_assert_ptr_eq(ellipsisStartCharS(null,4,'-'), null);
- // 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);
END_TEST
-START_TEST(iDelST)
+START_TEST(iEllipsisStartCharST)
- char *s;
- // del
+ char *s, *r;
+
+ // no ellipsis
s = strdup("sheepy");
- iDelS(&s, 0,2);
- ck_assert_str_eq(s, "eepy");
- free(s);
- // negative index
+ r = iEllipsisStartCharS(&s, 10, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
s = strdup("sheepy");
- iDelS(&s, -2,0);
- ck_assert_str_eq(s, "shee");
- free(s);
- // positive and negative indexes
+ r = iEllipsisStartCharS(&s, 6, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // ellipsis
s = strdup("sheepy");
- iDelS(&s, 2,-2);
- ck_assert_str_eq(s, "shpy");
- free(s);
- // start = end
+ r = iEllipsisStartCharS(&s, 5, '-');
+ ck_assert_str_eq(r, "-eepy");
+ free(r);
+
+ // target length 0
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);
+ r = iEllipsisStartCharS(&s, 0, '-');
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // null string
+ s = null;
+ ck_assert_ptr_eq(iEllipsisStartCharS(&s,4,'-'), null);
+ ck_assert_ptr_eq(iEllipsisStartCharS(null,4,'-'), null);
+
END_TEST
-START_TEST(bDelST)
+START_TEST(bEllipsisStartCharST)
- 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);
+ char *r;
+ char dest[48];
-END_TEST
+ // no ellipsis
+ r = bEllipsisStartCharS(dest, "sheepy", 10, '-');
+ ck_assert_str_eq(r, "sheepy");
+ r = bEllipsisStartCharS(dest, "sheepy", 6, '-');
+ ck_assert_str_eq(r, "sheepy");
+ // ellipsis
+ r = bEllipsisStartCharS(dest, "sheepy", 5, '-');
+ ck_assert_str_eq(r, "-eepy");
-START_TEST(findST)
+ // target length 0
+ r = bEllipsisStartCharS(dest, "sheepy", 0, '-');
+ ck_assert_str_eq(r, "");
+
+ // null string
+ ck_assert_ptr_eq(bEllipsisStartCharS(dest, null,4,'-'), null);
+ // null dest
+ ck_assert_ptr_eq(bEllipsisStartCharS(null, "",4,'-'), null);
- // 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);
END_TEST
-START_TEST(findCharST)
+START_TEST(bLEllipsisStartCharST)
- // 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);
+ char *r;
+ char dest[6];
-END_TEST
+ // no ellipsis
+ r = bLEllipsisStartCharS(dest, sizeof(dest), "sheepy", 10, '-');
+ ck_assert_str_eq(r, "sheep");
+ r = bLEllipsisStartCharS(dest, sizeof(dest), "sheepy", 6, '-');
+ ck_assert_str_eq(r, "sheep");
+ // ellipsis
+ r = bLEllipsisStartCharS(dest, sizeof(dest), "sheepy", 5, '-');
+ ck_assert_str_eq(r, "-eepy");
-START_TEST(hasST)
+ // target length 0
+ r = bLEllipsisStartCharS(dest, sizeof(dest), "sheepy", 0, '-');
+ ck_assert_str_eq(r, "");
+
+ // dest size 0, dest unchanged
+ dest[0] = 'a';
+ dest[1] = 0;
+ r = bLEllipsisStartCharS(dest, 0, "sheepy", 5, '-');
+ ck_assert_str_eq(r, "a");
+
+ // null string
+ ck_assert_ptr_eq(bLEllipsisStartCharS(dest, sizeof(dest), null,4,'-'), null);
+ // null dest
+ ck_assert_ptr_eq(bLEllipsisStartCharS(null, sizeof(dest), "",4,'-'), null);
- // 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, "$"));
END_TEST
-START_TEST(hasCharST)
+START_TEST(ellipsisLenST)
- // 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, '$'));
+ ssize_t r;
-END_TEST
+ // no ellipsis
+ r = ellipsisLenS("sheepy", 10, "...");
+ ck_assert_int_eq(r, 6);
+ r = ellipsisLenS("sheepy", 6, "...");
+ ck_assert_int_eq(r, 6);
+ // ellipsis
+ r = ellipsisLenS("sheepy", 5, "...");
+ ck_assert_int_eq(r, 5);
-START_TEST(emptySFT)
+ // ellipsis longer than target length
+ r = ellipsisLenS("sheepy", 5, "......");
+ ck_assert_int_eq(r, 5);
- char *s;
+ // empty ellipsis
+ r = ellipsisLenS("sheepy", 5, "");
+ ck_assert_int_eq(r, 5);
+
+ // target length 0
+ r = ellipsisLenS("sheepy", 0, "...");
+ ck_assert_int_eq(r, 0);
+
+ // null string
+ ck_assert_int_eq(ellipsisLenS(null,4,""), -1);
+ // null ellipsis
+ ck_assert_int_eq(ellipsisLenS("",4,null), -1);
- // empty string
- s = emptySF();
- ck_assert(isEmptyS(s));
- free(s);
END_TEST
-START_TEST(iEmptySFT)
+START_TEST(ellipsisEndST)
- char *s;
+ char *r;
- // 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);
+ // no ellipsis
+ r = ellipsisEndS("sheepy", 10, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ r = ellipsisEndS("sheepy", 6, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
-END_TEST
+ // ellipsis
+ r = ellipsisEndS("sheepy", 5, "...");
+ ck_assert_str_eq(r, "sh...");
+ free(r);
+ // ellipsis longer than target length
+ r = ellipsisEndS("sheepy", 5, "......");
+ ck_assert_str_eq(r, ".....");
+ free(r);
-START_TEST(isEmptyST)
+ // empty ellipsis
+ r = ellipsisEndS("sheepy", 5, "");
+ ck_assert_str_eq(r, "sheep");
+ free(r);
- char *s;
+ // target length 0
+ r = ellipsisEndS("sheepy", 0, "...");
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // null string
+ ck_assert_ptr_eq(ellipsisEndS(null,4,""), null);
+ // null ellipsis
+ ck_assert_ptr_eq(ellipsisEndS("",4,null), null);
- // 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));
END_TEST
-START_TEST(isBlankST)
+START_TEST(iEllipsisEndST)
- char *s;
+ char *s, *r;
- // 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));
+ // no ellipsis
+ s = strdup("sheepy");
+ r = iEllipsisEndS(&s, 10, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ s = strdup("sheepy");
+ r = iEllipsisEndS(&s, 6, "...");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
-END_TEST
+ // ellipsis
+ s = strdup("sheepy");
+ r = iEllipsisEndS(&s, 5, "...");
+ ck_assert_str_eq(r, "sh...");
+ free(r);
+ // ellipsis longer than target length
+ s = strdup("sheepy");
+ r = iEllipsisEndS(&s, 5, "......");
+ ck_assert_str_eq(r, ".....");
+ free(r);
-START_TEST(listEmptySFT)
+ // empty ellipsis
+ s = strdup("sheepy");
+ r = iEllipsisEndS(&s, 5, "");
+ ck_assert_str_eq(r, "sheep");
+ free(r);
- char **l;
+ // target length 0
+ s = strdup("sheepy");
+ r = iEllipsisEndS(&s, 0, "...");
+ ck_assert_str_eq(r, "");
+ free(r);
+
+ // null string
+ s = null;
+ ck_assert_ptr_eq(iEllipsisEndS(&s,4,""), null);
+ ck_assert_ptr_eq(iEllipsisEndS(null,4,""), null);
+ // null ellipsis
+ s = strdup("sd");
+ ck_assert_ptr_eq(iEllipsisEndS(&s,4,null), null);
+ free(s);
- // empty list
- l = listEmptySF();
- ck_assert(listIsEmptyS(l));
- listFreeS(l);
END_TEST
-START_TEST(iListEmptySFT)
+START_TEST(bEllipsisEndST)
- char **l;
+ char *r;
+ char dest[48];
- // 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);
+ // no ellipsis
+ r = bEllipsisEndS(dest, "sheepy", 10, "...");
+ ck_assert_str_eq(r, "sheepy");
+ r = bEllipsisEndS(dest, "sheepy", 6, "...");
+ ck_assert_str_eq(r, "sheepy");
-END_TEST
+ // ellipsis
+ r = bEllipsisEndS(dest, "sheepy", 5, "...");
+ ck_assert_str_eq(r, "sh...");
+ // ellipsis longer than target length
+ r = bEllipsisEndS(dest, "sheepy", 5, "......");
+ ck_assert_str_eq(r, ".....");
-START_TEST(listIsEmptyST)
+ // empty ellipsis
+ r = bEllipsisEndS(dest, "sheepy", 5, "");
+ ck_assert_str_eq(r, "sheep");
- char **l;
+ // target length 0
+ r = bEllipsisEndS(dest, "sheepy", 0, "...");
+ ck_assert_str_eq(r, "");
+
+ // null string
+ ck_assert_ptr_eq(bEllipsisEndS(dest, null,4,""), null);
+ // null ellipsis
+ ck_assert_ptr_eq(bEllipsisEndS(dest, "",4,null), null);
+ // null dest
+ ck_assert_ptr_eq(bEllipsisEndS(null, "",4,""), null);
- // 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));
END_TEST
-START_TEST(listIsBlankST)
+START_TEST(bLEllipsisEndST)
- char **l;
+ char *r;
+ char dest[6];
- // 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));
+ // no ellipsis
+ r = bLEllipsisEndS(dest, sizeof(dest), "sheepy", 10, "...");
+ ck_assert_str_eq(r, "sheep");
+ r = bLEllipsisEndS(dest, sizeof(dest), "sheepy", 6, "...");
+ ck_assert_str_eq(r, "sheep");
-END_TEST
+ // ellipsis
+ r = bLEllipsisEndS(dest, sizeof(dest), "sheepy", 5, "...");
+ ck_assert_str_eq(r, "sh...");
+ // ellipsis longer than target length
+ r = bLEllipsisEndS(dest, sizeof(dest), "sheepy", 5, "......");
+ ck_assert_str_eq(r, ".....");
-START_TEST(listLengthST)
-
- char **l;
+ // empty ellipsis
+ r = bLEllipsisEndS(dest, sizeof(dest), "sheepy", 4, "");
+ ck_assert_str_eq(r, "shee");
- // 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);
+ // target length 0
+ r = bLEllipsisEndS(dest, sizeof(dest), "sheepy", 0, "...");
+ ck_assert_str_eq(r, "");
+ // dest size 0, dest unchanged
+ dest[0] = 'a';
+ dest[1] = 0;
+ r = bLEllipsisEndS(dest, 0, "sheepy", 5, "");
+ ck_assert_str_eq(r, "a");
-END_TEST
+ // null string
+ ck_assert_ptr_eq(bLEllipsisEndS(dest, sizeof(dest), null,4,""), null);
+ // null ellipsis
+ ck_assert_ptr_eq(bLEllipsisEndS(dest, sizeof(dest), "",4,null), null);
+ // null dest
+ ck_assert_ptr_eq(bLEllipsisEndS(null, sizeof(dest), "",4,""), null);
-START_TEST(listCreateST)
+END_TEST
- 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);
+START_TEST(ellipsisEndCharST)
- // NULL first element
- ck_assert_ptr_eq(listCreateS(NULL, "sheepy"), NULL);
+ char *r;
-END_TEST
+ // no ellipsis
+ r = ellipsisEndCharS("sheepy", 10, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ r = ellipsisEndCharS("sheepy", 6, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ // ellipsis
+ r = ellipsisEndCharS("sheepy", 5, '-');
+ ck_assert_str_eq(r, "shee-");
+ free(r);
-START_TEST(listFromArrayST)
+ // target length 0
+ r = ellipsisEndCharS("sheepy", 0, '-');
+ ck_assert_str_eq(r, "");
+ free(r);
- char **l = NULL;
- char *array[] = {"1", "22", "333"};
- char *arrayNULL[] = {"1", NULL, "333"};
+ // null string
+ ck_assert_ptr_eq(ellipsisEndCharS(null,4,'-'), null);
- // 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);
END_TEST
-START_TEST(listPushST)
-
- char **l = NULL;
+START_TEST(iEllipsisEndCharST)
- // 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);
+ char *s, *r;
-END_TEST
+ // no ellipsis
+ s = strdup("sheepy");
+ r = iEllipsisEndCharS(&s, 10, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ s = strdup("sheepy");
+ r = iEllipsisEndCharS(&s, 6, '-');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ // ellipsis
+ s = strdup("sheepy");
+ r = iEllipsisEndCharS(&s, 5, '-');
+ ck_assert_str_eq(r, "shee-");
+ free(r);
-START_TEST(iListPushST)
+ // target length 0
+ s = strdup("sheepy");
+ r = iEllipsisEndCharS(&s, 0, '-');
+ ck_assert_str_eq(r, "");
+ free(r);
- char **l = NULL;
- char *s;
+ // null string
+ s = null;
+ ck_assert_ptr_eq(iEllipsisEndCharS(&s,4,'-'), null);
+ ck_assert_ptr_eq(iEllipsisEndCharS(null,4,'-'), null);
- // 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);
END_TEST
-START_TEST(listPopST)
-
- char **l = NULL;
- char *s;
+START_TEST(bEllipsisEndCharST)
- // 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);
+ char *r;
+ char dest[48];
-END_TEST
+ // no ellipsis
+ r = bEllipsisEndCharS(dest, "sheepy", 10, '-');
+ ck_assert_str_eq(r, "sheepy");
+ r = bEllipsisEndCharS(dest, "sheepy", 6, '-');
+ ck_assert_str_eq(r, "sheepy");
+ // ellipsis
+ r = bEllipsisEndCharS(dest, "sheepy", 5, '-');
+ ck_assert_str_eq(r, "shee-");
-START_TEST(listPrependST)
+ // target length 0
+ r = bEllipsisEndCharS(dest, "sheepy", 0, '-');
+ ck_assert_str_eq(r, "");
- char **l = NULL;
+ // null string
+ ck_assert_ptr_eq(bEllipsisEndCharS(dest, null,4,'-'), null);
+ // null dest
+ ck_assert_ptr_eq(bEllipsisEndCharS(null, "",4,'-'), 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);
END_TEST
-START_TEST(iListPrependST)
+START_TEST(bLEllipsisEndCharST)
- char **l = NULL;
- char *s;
+ char *r;
+ char dest[6];
- // 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);
+ // no ellipsis
+ r = bLEllipsisEndCharS(dest, sizeof(dest), "sheepy", 10, '-');
+ ck_assert_str_eq(r, "sheep");
+ r = bLEllipsisEndCharS(dest, sizeof(dest), "sheepy", 6, '-');
+ ck_assert_str_eq(r, "sheep");
-END_TEST
+ // ellipsis
+ r = bLEllipsisEndCharS(dest, sizeof(dest), "sheepy", 5, '-');
+ ck_assert_str_eq(r, "shee-");
+ // target length 0
+ r = bLEllipsisEndCharS(dest, sizeof(dest), "sheepy", 0, '-');
+ ck_assert_str_eq(r, "");
-START_TEST(listDequeueST)
+ // dest size 0, dest unchanged
+ dest[0] = 'a';
+ dest[1] = 0;
+ r = bLEllipsisEndCharS(dest, 0, "sheepy", 5, '-');
+ ck_assert_str_eq(r, "a");
- char **l = NULL;
- char *s;
+ // null string
+ ck_assert_ptr_eq(bLEllipsisEndCharS(dest, sizeof(dest), null,4,'-'), null);
+ // null dest
+ ck_assert_ptr_eq(bLEllipsisEndCharS(null, sizeof(dest), "",4,'-'), null);
- // 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);
END_TEST
-START_TEST(listFreeST)
+START_TEST(padStartST)
- // 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);
+ char *r;
-END_TEST
+ // pad string
+ r = padStartS("sheepy", 10, ">>>");
+ ck_assert_str_eq(r, ">>>>sheepy");
+ free(r);
+ r = padStartS("sheepy", 7, ">>>");
+ ck_assert_str_eq(r, ">sheepy");
+ free(r);
-START_TEST(listFreeManyST)
+ // string bigger than target length
+ r = padStartS("sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
- // not possible to know if a pointer is already freed
- char **l1 = listCreateS("we","sd");
- char **l2 = listEmptySF();
- listFreeManyS(l1, l2);
+ // empty pad string
+ r = padStartS("sheepy", 10, "");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // null pad string
+ r = padStartS("sheepy", 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ r = padStartS("sheepy", 10, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = padStartS(null, 4, "q");
+ ck_assert_ptr_eq(r, null);
END_TEST
-START_TEST(listPrintST)
+START_TEST(iPadStartST)
- char **l;
+ char *s, *r;
- // print text
- l = readText("textTest.null");
- // TODO check stdout
- //listPrintS(l);
- listFreeS(l);
- // NULL list
- listPrintS(NULL);
+ // pad string
+ s = strdup("sheepy");
+ r = iPadStartS(&s, 10, ">>>");
+ ck_assert_str_eq(r, ">>>>sheepy");
+ free(r);
-END_TEST
+ s = strdup("sheepy");
+ r = iPadStartS(&s, 7, ">>>");
+ ck_assert_str_eq(r, ">sheepy");
+ free(r);
+ // string bigger than target length
+ s = strdup("sheepy");
+ r = iPadStartS(&s, 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
-START_TEST(listForEachT)
+ // empty pad string
+ s = strdup("sheepy");
+ r = iPadStartS(&s, 10, "");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
- char **l = NULL;
- char **l2 = NULL;
+ // null pad string
+ s = strdup("sheepy");
+ r = iPadStartS(&s, 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ s = strdup("sheepy");
+ r = iPadStartS(&s, 10, null);
+ ck_assert_ptr_eq(r, null);
+ free(s);
+
+ // null string
+ s = null;
+ r = iPadStartS(&s, 4, "q");
+ ck_assert_ptr_eq(r, null);
+ r = iPadStartS(null, 4, "q");
+ ck_assert_ptr_eq(r, 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);
END_TEST
-START_TEST(listEnumerateT)
+START_TEST(bPadStartST)
- char **l = NULL;
- char **l2 = NULL;
+ char *r;
+ char b[48];
- // 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);
+ // pad string
+ r = bPadStartS(b, "sheepy", 10, ">>>");
+ ck_assert_str_eq(r, ">>>>sheepy");
-END_TEST
+ r = bPadStartS(b, "sheepy", 7, ">>>");
+ ck_assert_str_eq(r, ">sheepy");
+ // string bigger than target length
+ r = bPadStartS(b, "sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
-START_TEST(listSortST)
+ // empty pad string
+ r = bPadStartS(b, "sheepy", 10, "");
+ ck_assert_str_eq(r, "sheepy");
- char **l = NULL;
- char **l2;
+ // null pad string
+ r = bPadStartS(b, "sheepy", 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ r = bPadStartS(b, "sheepy", 10, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = bPadStartS(b, null, 4, "q");
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bPadStartS(null, "d", 4, "q");
+ ck_assert_ptr_eq(r, null);
- // 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);
END_TEST
-START_TEST(iListSortST)
+START_TEST(bLPadStartST)
- char **l = NULL;
+ char *r;
+ char b[48];
- // 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);
+ // pad string
+ r = bLPadStartS(b, sizeof(b), "sheepy", 10, ">>>");
+ ck_assert_str_eq(r, ">>>>sheepy");
+ r = bLPadStartS(b, sizeof(b), "sheepy", 7, ">>>");
+ ck_assert_str_eq(r, ">sheepy");
+ // smaller dest size
+ r = bLPadStartS(b, 4, "sheepy", 7, ">>>");
+ ck_assert_str_eq(r, ">sh");
-END_TEST
+ // string bigger than target length
+ r = bLPadStartS(b, sizeof(b), "sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
+ // smaller dest size
+ r = bLPadStartS(b, 4, "sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "she");
+ // empty pad string
+ r = bLPadStartS(b, sizeof(b), "sheepy", 10, "");
+ ck_assert_str_eq(r, "sheepy");
+ // smaller dest size
+ r = bLPadStartS(b, 4, "sheepy", 10, "");
+ ck_assert_str_eq(r, "she");
-START_TEST(readTextT)
- char **l;
+ // null pad string
+ r = bLPadStartS(b, sizeof(b), "sheepy", 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ r = bLPadStartS(b, sizeof(b), "sheepy", 10, null);
+ ck_assert_ptr_eq(r, null);
- // 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);
+ // null string
+ r = bLPadStartS(b, sizeof(b), null, 4, "q");
+ ck_assert_ptr_eq(r, null);
-END_TEST
+ // null dest
+ r = bLPadStartS(null, sizeof(b), "d", 4, "q");
+ ck_assert_ptr_eq(r, null);
-START_TEST(readStreamT)
+END_TEST
- 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);
+START_TEST(padStartCharST)
-END_TEST
+ char *r;
+ // pad string
+ r = padStartCharS("sheepy", 10, '>');
+ ck_assert_str_eq(r, ">>>>sheepy");
+ free(r);
-START_TEST(writeTextT)
+ r = padStartCharS("sheepy", 7, '>');
+ ck_assert_str_eq(r, ">sheepy");
+ free(r);
- char **l;
- bool r;
+ // string bigger than target length
+ r = padStartCharS("sheepy", 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
- // write textOutTest.null
- l = readText("textTest.null");
- r = writeText("textOutTest.null", l);
- ck_assert(r);
- listFreeS(l);
+ // null string
+ r = padStartCharS(null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
- // 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));
END_TEST
-START_TEST(writeStreamT)
+START_TEST(iPadStartCharST)
- char **l;
- FILE *fp;
- bool r;
+ char *s, *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);
+ // pad string
+ s = strdup("sheepy");
+ r = iPadStartCharS(&s, 10, '>');
+ ck_assert_str_eq(r, ">>>>sheepy");
+ free(r);
- // 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);
+ s = strdup("sheepy");
+ r = iPadStartCharS(&s, 7, '>');
+ ck_assert_str_eq(r, ">sheepy");
+ free(r);
-END_TEST
+ // string bigger than target length
+ s = strdup("sheepy");
+ r = iPadStartCharS(&s, 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ // null string
+ s = null;
+ r = iPadStartCharS(&s, 4, 'q');
+ ck_assert_ptr_eq(r, null);
+ r = iPadStartCharS(null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
-START_TEST(appendTextT)
- char **l;
- bool r;
+END_TEST
- // 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));
+START_TEST(bPadStartCharST)
-END_TEST
+ char *r;
+ char b[48];
+ // pad string
+ r = bPadStartCharS(b, "sheepy", 10, '>');
+ ck_assert_str_eq(r, ">>>>sheepy");
-START_TEST(listGetST)
+ r = bPadStartCharS(b, "sheepy", 7, '>');
+ ck_assert_str_eq(r, ">sheepy");
- char **l = NULL;
+ // string bigger than target length
+ r = bPadStartCharS(b, "sheepy", 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+
+ // null string
+ r = bPadStartCharS(b, null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bPadStartCharS(null, "d", 4, 'q');
+ ck_assert_ptr_eq(r, 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);
END_TEST
-START_TEST(iListGetST)
+START_TEST(bLPadStartCharST)
- char **l = NULL;
+ char *r;
+ char b[48];
+
+ // pad string
+ r = bLPadStartCharS(b, sizeof(b), "sheepy", 10, '>');
+ ck_assert_str_eq(r, ">>>>sheepy");
+ r = bLPadStartCharS(b, sizeof(b), "sheepy", 7, '>');
+ ck_assert_str_eq(r, ">sheepy");
+ // smaller dest size
+ r = bLPadStartCharS(b, 4, "sheepy", 7, '>');
+ ck_assert_str_eq(r, ">sh");
+
+ // string bigger than target length
+ r = bLPadStartCharS(b, sizeof(b), "sheepy", 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+ // smaller dest size
+ r = bLPadStartCharS(b, 4, "sheepy", 4, '>');
+ ck_assert_str_eq(r, "she");
+
+ // null string
+ r = bLPadStartCharS(b, sizeof(b), null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bLPadStartCharS(null, sizeof(b), "d", 4, 'q');
+ ck_assert_ptr_eq(r, 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);
END_TEST
-START_TEST(listSetST)
+START_TEST(padStartLenST)
- char **l = NULL;
+ ssize_t r;
- // 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);
+ // pad string
+ r = padStartLenS("sheepy", 10, ">>>");
+ ck_assert_int_eq(r, 10);
-END_TEST
+ r = padStartLenS("sheepy", 7, ">>>");
+ ck_assert_int_eq(r, 7);
+ // string bigger than target length
+ r = padStartLenS("sheepy", 4, ">>>");
+ ck_assert_int_eq(r, 6);
-START_TEST(iListSetST)
+ // empty pad string
+ r = padStartLenS("sheepy", 10, "");
+ ck_assert_int_eq(r, 6);
- char **l = NULL;
- char *s;
+ // null pad string
+ r = padStartLenS("sheepy", 4, null);
+ ck_assert_int_eq(r, 6);
+ r = padStartLenS("sheepy", 10, null);
+ ck_assert_int_eq(r, -1);
+
+ // null string
+ r = padStartLenS(null, 4, "q");
+ ck_assert_int_eq(r, -1);
- // 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);
END_TEST
-START_TEST(tokST)
+START_TEST(padEndST)
- // 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);
+ char *r;
-END_TEST
+ // pad string
+ r = padEndS("sheepy", 10, ">>>");
+ ck_assert_str_eq(r, "sheepy>>>>");
+ free(r);
+
+ r = padEndS("sheepy", 7, ">>>");
+ ck_assert_str_eq(r, "sheepy>");
+ free(r);
+ // string bigger than target length
+ r = padEndS("sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
-START_TEST(splitT)
+ // empty pad string
+ r = padEndS("sheepy", 10, "");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
- char **l;
+ // null pad string
+ r = padEndS("sheepy", 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ r = padEndS("sheepy", 10, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = padEndS(null, 4, "q");
+ ck_assert_ptr_eq(r, null);
- // 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);
END_TEST
-START_TEST(joinT)
+START_TEST(iPadEndST)
- char **l;
- char *s;
+ char *s, *r;
- // 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);
+ // pad string
+ s = strdup("sheepy");
+ r = iPadEndS(&s, 10, ">>>");
+ ck_assert_str_eq(r, "sheepy>>>>");
+ free(r);
+
+ s = strdup("sheepy");
+ r = iPadEndS(&s, 7, ">>>");
+ ck_assert_str_eq(r, "sheepy>");
+ free(r);
+
+ // string bigger than target length
+ s = strdup("sheepy");
+ r = iPadEndS(&s, 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // empty pad string
+ s = strdup("sheepy");
+ r = iPadEndS(&s, 10, "");
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // null pad string
+ s = strdup("sheepy");
+ r = iPadEndS(&s, 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+ s = strdup("sheepy");
+ r = iPadEndS(&s, 10, null);
+ ck_assert_ptr_eq(r, null);
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);
+
+ // null string
+ s = null;
+ r = iPadEndS(&s, 4, "q");
+ ck_assert_ptr_eq(r, null);
+ r = iPadEndS(null, 4, "q");
+ ck_assert_ptr_eq(r, null);
+
END_TEST
-START_TEST(bJoinT)
+START_TEST(bPadEndST)
- char **l;
- char s[100];
+ char *r;
+ char b[48];
- // 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);
+ // pad string
+ r = bPadEndS(b, "sheepy", 10, ">>>");
+ ck_assert_str_eq(r, "sheepy>>>>");
-END_TEST
+ r = bPadEndS(b, "sheepy", 7, ">>>");
+ ck_assert_str_eq(r, "sheepy>");
+ // string bigger than target length
+ r = bPadEndS(b, "sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
-START_TEST(bLJoinT)
+ // empty pad string
+ r = bPadEndS(b, "sheepy", 10, "");
+ ck_assert_str_eq(r, "sheepy");
- char **l;
- char s[100];
+ // null pad string
+ r = bPadEndS(b, "sheepy", 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ r = bPadEndS(b, "sheepy", 10, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = bPadEndS(b, null, 4, "q");
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bPadEndS(null, "d", 4, "q");
+ ck_assert_ptr_eq(r, null);
- // 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);
END_TEST
-START_TEST(extractST)
+START_TEST(bLPadEndST)
- char **l;
+ char *r;
+ char b[48];
- // 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);
+ // pad string
+ r = bLPadEndS(b, sizeof(b), "sheepy", 10, ">>>");
+ ck_assert_str_eq(r, "sheepy>>>>");
+ r = bLPadEndS(b, sizeof(b), "sheepy", 7, ">>>");
+ ck_assert_str_eq(r, "sheepy>");
+ // smaller dest size
+ r = bLPadEndS(b, 4, "sheepy", 7, ">>>");
+ ck_assert_str_eq(r, "she");
-END_TEST
+ // string bigger than target length
+ r = bLPadEndS(b, sizeof(b), "sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "sheepy");
+ // smaller dest size
+ r = bLPadEndS(b, 4, "sheepy", 4, ">>>");
+ ck_assert_str_eq(r, "she");
+ // empty pad string
+ r = bLPadEndS(b, sizeof(b), "sheepy", 10, "");
+ ck_assert_str_eq(r, "sheepy");
+ // smaller dest size
+ r = bLPadEndS(b, 4, "sheepy", 10, "");
+ ck_assert_str_eq(r, "she");
-START_TEST(listDupST)
- char **l = NULL;
- char **l2;
+ // null pad string
+ r = bLPadEndS(b, sizeof(b), "sheepy", 4, null);
+ ck_assert_str_eq(r, "sheepy");
+ r = bLPadEndS(b, sizeof(b), "sheepy", 10, null);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = bLPadEndS(b, sizeof(b), null, 4, "q");
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bLPadEndS(null, sizeof(b), "d", 4, "q");
+ ck_assert_ptr_eq(r, null);
- // 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);
END_TEST
-START_TEST(iListDupST)
+START_TEST(padEndCharST)
- char **l = NULL;
- char **l2;
+ char *r;
+
+ // pad string
+ r = padEndCharS("sheepy", 10, '>');
+ ck_assert_str_eq(r, "sheepy>>>>");
+ free(r);
+
+ r = padEndCharS("sheepy", 7, '>');
+ ck_assert_str_eq(r, "sheepy>");
+ free(r);
+
+ // string bigger than target length
+ r = padEndCharS("sheepy", 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // null string
+ r = padEndCharS(null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
- // 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);
END_TEST
-START_TEST(listReverseST)
+START_TEST(iPadEndCharST)
- char **l = NULL;
- char **l2;
+ char *s, *r;
+
+ // pad string
+ s = strdup("sheepy");
+ r = iPadEndCharS(&s, 10, '>');
+ ck_assert_str_eq(r, "sheepy>>>>");
+ free(r);
+
+ s = strdup("sheepy");
+ r = iPadEndCharS(&s, 7, '>');
+ ck_assert_str_eq(r, "sheepy>");
+ free(r);
+
+ // string bigger than target length
+ s = strdup("sheepy");
+ r = iPadEndCharS(&s, 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+ free(r);
+
+ // null string
+ s = null;
+ r = iPadEndCharS(&s, 4, 'q');
+ ck_assert_ptr_eq(r, null);
+ r = iPadEndCharS(null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
- // 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);
END_TEST
-START_TEST(iListReverseST)
+START_TEST(bPadEndCharST)
- char **l = NULL;
+ char *r;
+ char b[48];
+
+ // pad string
+ r = bPadEndCharS(b, "sheepy", 10, '>');
+ ck_assert_str_eq(r, "sheepy>>>>");
+
+ r = bPadEndCharS(b, "sheepy", 7, '>');
+ ck_assert_str_eq(r, "sheepy>");
+
+ // string bigger than target length
+ r = bPadEndCharS(b, "sheepy", 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+
+ // null string
+ r = bPadEndCharS(b, null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bPadEndCharS(null, "d", 4, 'q');
+ ck_assert_ptr_eq(r, 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);
END_TEST
-START_TEST(listCatST)
+START_TEST(bLPadEndCharST)
- char **l;
- char **l2;
- char **r;
+ char *r;
+ char b[48];
- // 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");
+ // pad string
+ r = bLPadEndCharS(b, sizeof(b), "sheepy", 10, '>');
+ ck_assert_str_eq(r, "sheepy>>>>");
+ r = bLPadEndCharS(b, sizeof(b), "sheepy", 7, '>');
+ ck_assert_str_eq(r, "sheepy>");
+ // smaller dest size
+ r = bLPadEndCharS(b, 4, "sheepy", 7, '>');
+ ck_assert_str_eq(r, "she");
+
+ // string bigger than target length
+ r = bLPadEndCharS(b, sizeof(b), "sheepy", 4, '>');
+ ck_assert_str_eq(r, "sheepy");
+ // smaller dest size
+ r = bLPadEndCharS(b, 4, "sheepy", 4, '>');
+ ck_assert_str_eq(r, "she");
+
+ // null string
+ r = bLPadEndCharS(b, sizeof(b), null, 4, 'q');
+ ck_assert_ptr_eq(r, null);
+
+ // null dest
+ r = bLPadEndCharS(null, sizeof(b), "d", 4, 'q');
+ ck_assert_ptr_eq(r, null);
+
+
+END_TEST
+
+
+START_TEST(padEndLenST)
+
+ ssize_t r;
+
+ // pad string
+ r = padEndLenS("sheepy", 10, ">>>");
+ ck_assert_int_eq(r, 10);
+
+ r = padEndLenS("sheepy", 7, ">>>");
+ ck_assert_int_eq(r, 7);
+
+ // string bigger than target length
+ r = padEndLenS("sheepy", 4, ">>>");
+ ck_assert_int_eq(r, 6);
+
+ // empty pad string
+ r = padEndLenS("sheepy", 10, "");
+ ck_assert_int_eq(r, 6);
+
+ // null pad string
+ r = padEndLenS("sheepy", 4, null);
+ ck_assert_int_eq(r, 6);
+ r = padEndLenS("sheepy", 10, null);
+ ck_assert_int_eq(r, -1);
+
+ // null string
+ r = padEndLenS(null, 4, "q");
+ ck_assert_int_eq(r, -1);
+
+
+END_TEST
+
+
+START_TEST(getST)
+
+ // 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);
+
+END_TEST
+
+
+START_TEST(setST)
+
+ 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');
+
+
+END_TEST
+
+
+START_TEST(swapST)
+
+ char *r;
+
+ // swap
+ r = swapS("sheepy", 0, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+ r = swapS("sheepy", -6, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+ r = swapS("sheepy", 2, 0);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+ r = swapS("sheepy", 2, -6);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+
+ // index1 >= len
+ r = swapS("sheepy", 6, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 >= len
+ r = swapS("sheepy", 2, 6);
+ ck_assert_ptr_eq(r, null);
+
+ // index1 < -len
+ r = swapS("sheepy", -10, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 < -len
+ r = swapS("sheepy", 2, -7);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = swapS(null, 0, 2);
+ ck_assert_ptr_eq(r, null);
+
+END_TEST
+
+
+START_TEST(iSwapST)
+
+ char *b;
+ char *r;
+
+ // swap
+ b = strdup("sheepy");
+ r = iSwapS(&b, 0, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+ b = strdup("sheepy");
+ r = iSwapS(&b, -6, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+ b = strdup("sheepy");
+ r = iSwapS(&b, 2, 0);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+ b = strdup("sheepy");
+ r = iSwapS(&b, 2, -6);
+ ck_assert_str_eq(r, "ehsepy");
+ free(r);
+
+ b = strdup("sheepy");
+
+ // index1 >= len
+ r = iSwapS(&b, 6, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 >= len
+ r = iSwapS(&b, 2, 6);
+ ck_assert_ptr_eq(r, null);
+
+ // index1 < -len
+ r = iSwapS(&b, -10, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 < -len
+ r = iSwapS(&b, 2, -7);
+ ck_assert_ptr_eq(r, null);
+
+ free(b);
+
+ // null string
+ b = null;
+ r = iSwapS(&b, 0, 2);
+ ck_assert_ptr_eq(r, null);
+ r = iSwapS(null, 0, 2);
+ ck_assert_ptr_eq(r, null);
+
+
+END_TEST
+
+
+START_TEST(bSwapST)
+
+ char b[20];
+ char *r;
+
+ // swap
+ strcpy(b, "sheepy");
+ r = bSwapS(b, 0, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ strcpy(b, "sheepy");
+ r = bSwapS(b, -6, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ strcpy(b, "sheepy");
+ r = bSwapS(b, 2, 0);
+ ck_assert_str_eq(r, "ehsepy");
+ strcpy(b, "sheepy");
+ r = bSwapS(b, 2, -6);
+ ck_assert_str_eq(r, "ehsepy");
+
+ // index1 >= len
+ r = bSwapS("sheepy", 6, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 >= len
+ r = bSwapS("sheepy", 2, 6);
+ ck_assert_ptr_eq(r, null);
+
+ // index1 < -len
+ r = bSwapS("sheepy", -10, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 < -len
+ r = bSwapS("sheepy", 2, -7);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = bSwapS(null, 0, 2);
+ ck_assert_ptr_eq(r, null);
+
+
+END_TEST
+
+
+START_TEST(bLSwapST)
+
+ char b[20];
+ char *r;
+
+ // swap
+ strcpy(b, "sheepy");
+ r = bLSwapS(b, sizeof(b), 0, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ strcpy(b, "sheepy");
+ r = bLSwapS(b, sizeof(b), -6, 2);
+ ck_assert_str_eq(r, "ehsepy");
+ strcpy(b, "sheepy");
+ r = bLSwapS(b, sizeof(b), 2, 0);
+ ck_assert_str_eq(r, "ehsepy");
+ strcpy(b, "sheepy");
+ r = bLSwapS(b, sizeof(b), 2, -6);
+ ck_assert_str_eq(r, "ehsepy");
+
+ // buffer = strlen+1
+ strcpy(b, "sheepy");
+ r = bLSwapS(b, 7, -1, 0);
+ ck_assert_str_eq(r, "yheeps");
+ // buffer shorter than strlen
+ strcpy(b, "sheepy");
+ r = bLSwapS(b, 6, -1, 0);
+ ck_assert_str_eq(r, "pheesy");
+
+ // size 0
+ strcpy(b, "sheepy");
+ r = bLSwapS(b, 0, -1, 0);
+ ck_assert_str_eq(r, "sheepy");
+
+ // index1 >= len
+ r = bLSwapS("sheepy", sizeof(b), 6, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 >= len
+ r = bLSwapS("sheepy", sizeof(b), 2, 6);
+ ck_assert_ptr_eq(r, null);
+
+ // index1 < -len
+ r = bLSwapS("sheepy", sizeof(b), -10, 2);
+ ck_assert_ptr_eq(r, null);
+
+ // index2 < -len
+ r = bLSwapS("sheepy", sizeof(b), 2, -7);
+ ck_assert_ptr_eq(r, null);
+
+ // null string
+ r = bLSwapS(null, sizeof(b), 0, 2);
+ ck_assert_ptr_eq(r, null);
+
+
+END_TEST
+
+
+START_TEST(sliceST)
+
+ // 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);
+
+END_TEST
+
+
+START_TEST(iSliceST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(bSliceST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(bLSliceST)
+
+ char s[100];
+ // slice
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 0,2);
+ ck_assert_str_eq(s, "sh");
+ // buffer shorter than string
+ strcpy(s, "sheepy");
+ bLSliceS(s, 5, 0,2);
+ ck_assert_str_eq(s, "sh");
+ // negative index
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), -2,0);
+ ck_assert_str_eq(s, "py");
+ // positive and negative indexes
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 2,-2);
+ ck_assert_str_eq(s, "ee");
+ // start = end
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 2,-4);
+ ck_assert_str_eq(s, "");
+ // end of string
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 2,6);
+ ck_assert_str_eq(s, "eepy");
+ // start outside string
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 20,-4);
+ ck_assert_str_eq(s, "");
+ // end outside string
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 2,40);
+ ck_assert_str_eq(s, "eepy");
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), -22,3);
+ ck_assert_str_eq(s, "she");
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 2,-40);
+ ck_assert_str_eq(s, "");
+ // end before start
+ strcpy(s, "sheepy");
+ bLSliceS(s, sizeof(s), 4,2);
+ ck_assert_str_eq(s, "");
+ // size 0
+ ck_assert_ptr_eq(bLSliceS(s, 0, 0, 0), NULL);
+ // NULL var
+ ck_assert_ptr_eq(bLSliceS(NULL, sizeof(s), 0, 0), NULL);
+
+
+END_TEST
+
+
+START_TEST(cropST)
+
+ char b[20];
+ char *s;
+
+ // crop
+ strcpy(b, "sheepy");
+ s = cropS(b, 0,2);
+ ck_assert_str_eq(s, "sh");
+ ck_assert_str_eq(b, "eepy");
+ free(s);
+ // negative index
+ strcpy(b, "sheepy");
+ s = cropS(b, -2,0);
+ ck_assert_str_eq(s, "py");
+ ck_assert_str_eq(b, "shee");
+ free(s);
+ // positive and negative indexes
+ strcpy(b, "sheepy");
+ s = cropS(b, 2,-2);
+ ck_assert_str_eq(s, "ee");
+ ck_assert_str_eq(b, "shpy");
+ free(s);
+ // start = end
+ strcpy(b, "sheepy");
+ s = cropS(b, 2,-4);
+ ck_assert_str_eq(s, "");
+ ck_assert_str_eq(b, "sheepy");
+ free(s);
+ // end of string
+ strcpy(b, "sheepy");
+ s = cropS(b, 2,6);
+ ck_assert_str_eq(s, "eepy");
+ ck_assert_str_eq(b, "sh");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(cropS(NULL, 2,-4), NULL);
+ // start outside string
+ ck_assert_ptr_eq(cropS("sheepy", 20,-4), NULL);
+ // end outside string
+ strcpy(b, "sheepy");
+ s = cropS(b, 2,40);
+ ck_assert_str_eq(s, "eepy");
+ ck_assert_str_eq(b, "sh");
+ free(s);
+ strcpy(b, "sheepy");
+ s = cropS(b, -22,3);
+ ck_assert_str_eq(s, "she");
+ ck_assert_str_eq(b, "epy");
+ free(s);
+ ck_assert_ptr_eq(cropS("sheepy", 2,-40), NULL);
+ // end before start
+ ck_assert_ptr_eq(cropS("sheepy", 4,2), NULL);
+
+
+END_TEST
+
+
+START_TEST(iCropST)
+
+ char *b;
+ char *s;
+
+ // crop
+ b = strdup("sheepy");
+ s = iCropS(&b, 0,2);
+ ck_assert_str_eq(s, "sh");
+ ck_assert_str_eq(b, "eepy");
+ free(s);
+ free(b);
+ // negative index
+ b = strdup("sheepy");
+ s = iCropS(&b, -2,0);
+ ck_assert_str_eq(s, "py");
+ ck_assert_str_eq(b, "shee");
+ free(s);
+ free(b);
+ // positive and negative indexes
+ b = strdup("sheepy");
+ s = iCropS(&b, 2,-2);
+ ck_assert_str_eq(s, "ee");
+ ck_assert_str_eq(b, "shpy");
+ free(s);
+ free(b);
+ // start = end
+ b = strdup("sheepy");
+ s = iCropS(&b, 2,-4);
+ ck_assert_str_eq(s, "");
+ ck_assert_str_eq(b, "sheepy");
+ free(s);
+ free(b);
+ // end of string
+ b = strdup("sheepy");
+ s = iCropS(&b, 2,6);
+ ck_assert_str_eq(s, "eepy");
+ ck_assert_str_eq(b, "sh");
+ free(s);
+ free(b);
+ // NULL string
+ b = null;
+ ck_assert_ptr_eq(iCropS(&b, 2,-4), NULL);
+ ck_assert_ptr_eq(iCropS(NULL, 2,-4), NULL);
+ // start outside string
+ b = strdup("sheepy");
+ ck_assert_ptr_eq(iCropS(&b, 20,-4), NULL);
+ free(b);
+ // end outside string
+ b = strdup("sheepy");
+ s = iCropS(&b, 2,40);
+ ck_assert_str_eq(s, "eepy");
+ ck_assert_str_eq(b, "sh");
+ free(s);
+ free(b);
+ b = strdup("sheepy");
+ s = iCropS(&b, -22,3);
+ ck_assert_str_eq(s, "she");
+ ck_assert_str_eq(b, "epy");
+ free(s);
+ free(b);
+ b = strdup("sheepy");
+ ck_assert_ptr_eq(iCropS(&b, 2,-40), NULL);
+ free(b);
+ // end before start
+ b = strdup("sheepy");
+ ck_assert_ptr_eq(iCropS(&b, 4,2), NULL);
+ free(b);
+
+
+END_TEST
+
+
+START_TEST(cropElemST)
+
+ char b[20];
+ char r;
+
+ // crop
+ strcpy(b, "sheepy");
+ r = cropElemS(b, 0);
+ ck_assert_int_eq(r, 's');
+ ck_assert_str_eq(b, "heepy");
+ strcpy(b, "sheepy");
+ r = cropElemS(b, 5);
+ ck_assert_int_eq(r, 'y');
+ ck_assert_str_eq(b, "sheep");
+ // negative index
+ strcpy(b, "sheepy");
+ r = cropElemS(b, -1);
+ ck_assert_int_eq(r, 'y');
+ ck_assert_str_eq(b, "sheep");
+ strcpy(b, "sheepy");
+ r = cropElemS(b, -6);
+ ck_assert_int_eq(r, 's');
+ ck_assert_str_eq(b, "heepy");
+ // index outside string
+ strcpy(b, "sheepy");
+ r = cropElemS(b, 6);
+ ck_assert_int_eq(r, 0);
+ ck_assert_str_eq(b, "sheepy");
+ strcpy(b, "sheepy");
+ r = cropElemS(b, -7);
+ ck_assert_int_eq(r, 0);
+ ck_assert_str_eq(b, "sheepy");
+ // null string
+ ck_assert_int_eq(cropElemS(null, 0), 0);
+
+END_TEST
+
+
+START_TEST(iCropElemST)
+
+ char *b;
+ char r;
+
+ // crop
+ b = strdup("sheepy");
+ r = iCropElemS(&b, 0);
+ ck_assert_int_eq(r, 's');
+ ck_assert_str_eq(b, "heepy");
+ free(b);
+ b = strdup("sheepy");
+ r = iCropElemS(&b, 5);
+ ck_assert_int_eq(r, 'y');
+ ck_assert_str_eq(b, "sheep");
+ free(b);
+ // negative index
+ b = strdup("sheepy");
+ r = iCropElemS(&b, -1);
+ ck_assert_int_eq(r, 'y');
+ ck_assert_str_eq(b, "sheep");
+ free(b);
+ b = strdup("sheepy");
+ r = iCropElemS(&b, -6);
+ ck_assert_int_eq(r, 's');
+ ck_assert_str_eq(b, "heepy");
+ free(b);
+ // index outside string
+ b = strdup("sheepy");
+ r = iCropElemS(&b, 6);
+ ck_assert_int_eq(r, 0);
+ ck_assert_str_eq(b, "sheepy");
+ free(b);
+ b = strdup("sheepy");
+ r = iCropElemS(&b, -7);
+ ck_assert_int_eq(r, 0);
+ ck_assert_str_eq(b, "sheepy");
+ free(b);
+ // null string
+ b = null;
+ ck_assert_int_eq(iCropElemS(&b, 0), 0);
+ ck_assert_int_eq(iCropElemS(null, 0), 0);
+
+
+END_TEST
+
+
+START_TEST(insertST)
+
+ 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);
+
+
+END_TEST
+
+
+START_TEST(insertNFreeST)
+
+ 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);
+
+
+END_TEST
+
+
+START_TEST(iInsertST)
+
+ 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");
+
+END_TEST
+
+
+START_TEST(iInsertNFreeST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(bInsertST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(bLInsertST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(injectST)
+
+ 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);
+
+
+END_TEST
+
+
+START_TEST(iInjectST)
+
+ 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');
+
+END_TEST
+
+
+START_TEST(bInjectST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(bLInjectST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(delST)
+
+ // 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);
+
+END_TEST
+
+
+START_TEST(iDelST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(bDelST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(bLDelST)
+
+ char s[100];
+ // del
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 0,2);
+ ck_assert_str_eq(s, "eepy");
+ // buffer shorter than string
+ strcpy(s, "sheepy");
+ bLDelS(s, 5, 0,2);
+ ck_assert_str_eq(s, "ee");
+ // negative index
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), -2,0);
+ ck_assert_str_eq(s, "shee");
+ // positive and negative indexes
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 2,-2);
+ ck_assert_str_eq(s, "shpy");
+ // start = end
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 2,-4);
+ ck_assert_str_eq(s, "sheepy");
+ // end of string
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 2,6);
+ ck_assert_str_eq(s, "sh");
+ // start outside string
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 20,-4);
+ ck_assert_str_eq(s, "sheepy");
+ // end outside string
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 2,40);
+ ck_assert_str_eq(s, "sh");
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), -22,3);
+ ck_assert_str_eq(s, "epy");
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 2,-40);
+ ck_assert_str_eq(s, "sheepy");
+ // end before start
+ strcpy(s, "sheepy");
+ bLDelS(s, sizeof(s), 4,2);
+ ck_assert_str_eq(s, "sheepy");
+ // size 0
+ ck_assert_ptr_eq(bLDelS(s, 0, 0, 0), NULL);
+ // NULL var
+ ck_assert_ptr_eq(bLDelS(NULL, sizeof(s), 0, 0), NULL);
+
+
+END_TEST
+
+
+START_TEST(delElemST)
+
+ char b[20];
+ char *r;
+
+ // del
+ strcpy(b, "sheepy");
+ r = delElemS(b, 0);
+ ck_assert_str_eq(r, "heepy");
+ free(r);
+ strcpy(b, "sheepy");
+ r = delElemS(b, 5);
+ ck_assert_str_eq(r, "sheep");
+ free(r);
+ // negative index
+ strcpy(b, "sheepy");
+ r = delElemS(b, -1);
+ ck_assert_str_eq(r, "sheep");
+ free(r);
+ strcpy(b, "sheepy");
+ r = delElemS(b, -6);
+ ck_assert_str_eq(r, "heepy");
+ free(r);
+ // index outside string
+ strcpy(b, "sheepy");
+ r = delElemS(b, 6);
+ ck_assert_ptr_eq(r, null);
+ free(r);
+ strcpy(b, "sheepy");
+ r = delElemS(b, -7);
+ ck_assert_ptr_eq(r, null);
+ free(r);
+ // null string
+ ck_assert_ptr_eq(delElemS(null, 0), null);
+
+
+END_TEST
+
+
+START_TEST(iDelElemST)
+
+ char *b;
+ char *r;
+
+ // del
+ b = strdup("sheepy");
+ r = iDelElemS(&b, 0);
+ ck_assert_str_eq(r, "heepy");
+ free(r);
+ b = strdup("sheepy");
+ r = iDelElemS(&b, 5);
+ ck_assert_str_eq(r, "sheep");
+ free(r);
+ // negative index
+ b = strdup("sheepy");
+ r = iDelElemS(&b, -1);
+ ck_assert_str_eq(r, "sheep");
+ free(r);
+ b = strdup("sheepy");
+ r = iDelElemS(&b, -6);
+ ck_assert_str_eq(r, "heepy");
+ free(r);
+ // index outside string
+ b = strdup("sheepy");
+ r = iDelElemS(&b, 6);
+ ck_assert_ptr_eq(r, null);
+ free(b);
+ b = strdup("sheepy");
+ r = iDelElemS(&b, -7);
+ ck_assert_ptr_eq(r, null);
+ free(b);
+ // null string
+ ck_assert_ptr_eq(iDelElemS(null, 0), null);
+
+
+END_TEST
+
+
+START_TEST(bDelElemST)
+
+ char b[20];
+ char *r;
+
+ // del
+ strcpy(b, "sheepy");
+ r = bDelElemS(b, 0);
+ ck_assert_str_eq(r, "heepy");
+ strcpy(b, "sheepy");
+ r = bDelElemS(b, 5);
+ ck_assert_str_eq(r, "sheep");
+ // negative index
+ strcpy(b, "sheepy");
+ r = bDelElemS(b, -1);
+ ck_assert_str_eq(r, "sheep");
+ strcpy(b, "sheepy");
+ r = bDelElemS(b, -6);
+ ck_assert_str_eq(r, "heepy");
+ // index outside string
+ strcpy(b, "sheepy");
+ r = bDelElemS(b, 6);
+ ck_assert_ptr_eq(r, null);
+ strcpy(b, "sheepy");
+ r = bDelElemS(b, -7);
+ ck_assert_ptr_eq(r, null);
+ // null string
+ ck_assert_ptr_eq(bDelElemS(null, 0), null);
+
+
+END_TEST
+
+
+START_TEST(bLDelElemST)
+
+ char b[20];
+ char *r;
+
+ // del
+ strcpy(b, "sheepy");
+ r = bLDelElemS(b, sizeof(b), 0);
+ ck_assert_str_eq(r, "heepy");
+ strcpy(b, "sheepy");
+ r = bLDelElemS(b, sizeof(b), 5);
+ ck_assert_str_eq(r, "sheep");
+ // negative index
+ strcpy(b, "sheepy");
+ r = bLDelElemS(b, sizeof(b), -1);
+ ck_assert_str_eq(r, "sheep");
+ strcpy(b, "sheepy");
+ r = bLDelElemS(b, sizeof(b), -6);
+ ck_assert_str_eq(r, "heepy");
+ // dest size shorter than strlen
+ strcpy(b, "sheepy");
+ r = bLDelElemS(b, 4, -1);
+ ck_assert_str_eq(r, "sh");
+ // index outside string
+ strcpy(b, "sheepy");
+ r = bLDelElemS(b, sizeof(b), 6);
+ ck_assert_ptr_eq(r, null);
+ strcpy(b, "sheepy");
+ r = bLDelElemS(b, sizeof(b), -7);
+ ck_assert_ptr_eq(r, null);
+ r = bLDelElemS(b, sizeof(b), -8);
+ ck_assert_ptr_eq(r, null);
+ // size 0
+ ck_assert_ptr_eq(bLDelElemS(b, 0, 0), null);
+ // null string
+ ck_assert_ptr_eq(bLDelElemS(null, sizeof(b), 0), null);
+
+
+END_TEST
+
+
+START_TEST(findST)
+
+ // 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);
+
+END_TEST
+
+
+START_TEST(findCharST)
+
+ // 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);
+
+END_TEST
+
+
+START_TEST(indexOfST)
+
+ // indexOf string in the middle
+ ck_assert_int_eq(indexOfS("sheepy", "ee"), 2);
+ // indexOf non existing string
+ ck_assert_int_eq(indexOfS("sheepy", "$"), -1);
+ // indexOf NULL
+ ck_assert_int_eq(indexOfS("sheepy", NULL), -1);
+ // NULL string
+ ck_assert_int_eq(indexOfS(NULL, "$"), -1);
+
+
+END_TEST
+
+
+START_TEST(indexOfCharST)
+
+ // indexOf string in the middle
+ ck_assert_int_eq(indexOfCharS("sheepy", 'e'), 2);
+ // indexOf non existing string
+ ck_assert_int_eq(indexOfCharS("sheepy", '$'), -1);
+ // indexOf 0
+ ck_assert_int_eq(indexOfCharS("sheepy", 0), 6);
+ // NULL string
+ ck_assert_int_eq(indexOfCharS(NULL, '$'), -1);
+
+
+END_TEST
+
+
+START_TEST(hasST)
+
+ // 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, "$"));
+
+END_TEST
+
+
+START_TEST(hasCharST)
+
+ // 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, '$'));
+
+END_TEST
+
+
+START_TEST(icFindST)
+
+ // find string in the middle
+ ck_assert_str_eq(icFindS("shEepy", "eE"), "Eepy");
+ // find non existing string
+ ck_assert_ptr_eq(icFindS("sheepy", "$"), NULL);
+ // find NULL
+ ck_assert_ptr_eq(icFindS("sheepy", NULL), NULL);
+ // NULL string
+ ck_assert_ptr_eq(icFindS(NULL, "$"), NULL);
+
+
+END_TEST
+
+
+START_TEST(icFindCharST)
+
+ // find string in the middle
+ ck_assert_str_eq(icFindCharS("shEEpy", 'e'), "EEpy");
+ // find non existing string
+ ck_assert_ptr_eq(icFindCharS("sheepy", '$'), NULL);
+ // find 0
+ ck_assert_str_eq(icFindCharS("sheepy", 0), "");
+ // NULL string
+ ck_assert_ptr_eq(icFindCharS(NULL, '$'), NULL);
+
+
+END_TEST
+
+
+START_TEST(icIndexOfST)
+
+ // indexOf string in the middle
+ ck_assert_int_eq(icIndexOfS("sheepy", "EE"), 2);
+ // indexOf non existing string
+ ck_assert_int_eq(icIndexOfS("sheepy", "$"), -1);
+ // indexOf NULL
+ ck_assert_int_eq(icIndexOfS("sheepy", NULL), -1);
+ // NULL string
+ ck_assert_int_eq(icIndexOfS(NULL, "$"), -1);
+
+
+END_TEST
+
+
+START_TEST(icIndexOfCharST)
+
+ // indexOf string in the middle
+ ck_assert_int_eq(icIndexOfCharS("sheepy", 'E'), 2);
+ // indexOf non existing string
+ ck_assert_int_eq(icIndexOfCharS("sheepy", '$'), -1);
+ // indexOf 0
+ ck_assert_int_eq(icIndexOfCharS("sheepy", 0), 6);
+ // NULL string
+ ck_assert_int_eq(icIndexOfCharS(NULL, '$'), -1);
+
+
+END_TEST
+
+
+START_TEST(icHasST)
+
+ // find string in the middle
+ ck_assert(icHasS("sheepy", "EE"));
+ // find non existing string
+ ck_assert(!icHasS("sheepy", "$"));
+ // find NULL
+ ck_assert(!icHasS("sheepy", NULL));
+ // NULL string
+ ck_assert(!icHasS(NULL, "$"));
+
+
+END_TEST
+
+
+START_TEST(icHasCharST)
+
+ // find string in the middle
+ ck_assert(icHasCharS("shEepy", 'e'));
+ // find non existing string
+ ck_assert(!icHasCharS("sheepy", '$'));
+ // find 0
+ ck_assert(icHasCharS("sheepy", 0));
+ // NULL string
+ ck_assert(!icHasCharS(NULL, '$'));
+
+
+END_TEST
+
+
+START_TEST(tokST)
+
+ // 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);
+
+END_TEST
+
+
+START_TEST(icTokST)
+
+ // string
+ char *s;
+ char *w;
+ s = strdup("172.16.43.0/24 dev ens32 dev proto");
+ w = s;
+ ck_assert_str_eq(icTokS(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(icTokS(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(icTokS(s, "dev ", &w), "172.16.43.0/24 ");
+ ck_assert_str_eq(w, "ens32 dev proto");
+ ck_assert_str_eq(icTokS(NULL, "dev ", &w), "ens32 ");
+ ck_assert_str_eq(w, "proto");
+ ck_assert_str_eq(icTokS(NULL, "dev ", &w), "proto");
+ ck_assert_ptr_eq(w, NULL);
+ free(s);
+ // NULL string
+ w = NULL;
+ ck_assert_ptr_eq(icTokS(NULL, ";", &w), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(icTokS("test", NULL, &w), NULL);
+
+
+END_TEST
+
+
+START_TEST(lenUTF8T)
+
+ // string
+ ck_assert_uint_eq(lenUTF8("sheepy"), 6);
+ // UTF8
+ ck_assert_uint_eq(lenUTF8("sheepy£"), 7);
+ ck_assert_uint_eq(lenS("sheepy£"), 8);
+ // NULL string
+ ck_assert_uint_eq(lenUTF8(NULL), 0);
+
+
+END_TEST
+
+
+START_TEST(bLLenUTF8T)
+
+ // string
+ ck_assert_uint_eq(bLLenUTF8("sheepy", 7), 6);
+ // UTF8
+ ck_assert_uint_eq(bLLenUTF8("sheepy£",9), 7);
+ ck_assert_uint_eq(bLLenUTF8("sheepy£", 6), 5);
+ ck_assert_uint_eq(lenS("sheepy£"), 8);
+ // size 0
+ ck_assert_uint_eq(bLLenUTF8("sheepy£", 0), 0);
+ // NULL string
+ ck_assert_uint_eq(bLLenUTF8(NULL, 1), 0);
+
+
+END_TEST
+
+
+START_TEST(isUTF8T)
+
+ char b[8];
+
+ // string
+ ck_assert(isUTF8("sheepy"));
+ // UTF8
+ ck_assert(isUTF8("sheepy£"));
+ // invalid UTF8
+ strLCpy(b, sizeof(b), "sheepy£");
+ ck_assert(!isUTF8(b));
+ // null string
+ ck_assert(!isUTF8(null));
+
+
+END_TEST
+
+
+START_TEST(bLIsUTF8T)
+
+ // string
+ ck_assert(bLIsUTF8("sheepy", 7));
+ // UTF8
+ ck_assert(bLIsUTF8("sheepy£", 9));
+ // buffer shorter than string (string is not nul terminated)
+ ck_assert(!bLIsUTF8("sheepy", 6));
+ // invalid UTF8
+ ck_assert(!bLIsUTF8("sheepy£", 8));
+ // size 0
+ ck_assert(!bLIsUTF8("sheepy£", 0));
+ // null string
+ ck_assert(!bLIsUTF8(null, 1));
+
+
+END_TEST
+
+
+START_TEST(isCodeUTF8T)
+
+ // valid
+ ck_assert(isCodeUTF8("as"));
+ ck_assert(isCodeUTF8("£s"));
+ // invalid
+ u8 b[3] = init0Var;
+ b[0] = 128;
+ ck_assert(!isCodeUTF8((char*)b));
+ // null string
+ ck_assert(!isCodeUTF8(null));
+
+
+END_TEST
+
+
+START_TEST(nextUTF8T)
+
+ char *r;
+
+ // next
+ r = nextUTF8("£sheepy");
+ ck_assert_str_eq(r, "sheepy");
+ // empty string
+ r = nextUTF8("");
+ ck_assert_ptr_eq(r, null);
+ // null string
+ r = nextUTF8(null);
+ ck_assert_ptr_eq(r, null);
+
+
+END_TEST
+
+
+START_TEST(bLNextUTF8T)
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // next
+ r = bLNextUTF8(b, sizeof(b), &b[3]);
+ ck_assert_str_eq(r, "eepy");
+ // last char
+ r = bLNextUTF8(b, sizeof(b), &b[7]);
+ ck_assert_ptr_eq(r, null);
+ // empty string
+ r = bLNextUTF8(b, sizeof(b), &b[10]);
+ ck_assert_ptr_eq(r, null);
+ // string longer than buffer
+ r = bLNextUTF8(b, 6, &b[7]);
+ ck_assert_ptr_eq(r, null);
+ r = bLNextUTF8(b, 6, &b[5]);
+ ck_assert_ptr_eq(r, null);
+ // size 0
+ r = bLNextUTF8(b, 0, b);
+ ck_assert_ptr_eq(r, null);
+ // null string
+ r = bLNextUTF8(null, 1, b);
+ ck_assert_ptr_eq(r, null);
+ r = bLNextUTF8(b, 1, null);
+ ck_assert_ptr_eq(r, null);
+
+
+END_TEST
+
+
+START_TEST(findNextUTF8T)
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // next
+ r = findNextUTF8(b, sizeof(b), &b[3]);
+ ck_assert_str_eq(r, "eepy");
+ // in a code point, find first valid code point in utf8 parameter
+ // same as findNextUTF8(b, sizeof(b), &b[2])
+ r = findNextUTF8(b, sizeof(b), &b[1]);
+ ck_assert_str_eq(r, "heepy");
+ // last char
+ r = findNextUTF8(b, sizeof(b), &b[7]);
+ ck_assert_ptr_eq(r, null);
+ // empty string
+ r = findNextUTF8(b, sizeof(b), &b[10]);
+ ck_assert_ptr_eq(r, null);
+ // string longer than buffer
+ r = findNextUTF8(b, 6, &b[7]);
+ ck_assert_ptr_eq(r, null);
+ r = findNextUTF8(b, 6, &b[5]);
+ ck_assert_ptr_eq(r, null);
+ // size 0
+ r = findNextUTF8(b, 0, b);
+ ck_assert_ptr_eq(r, null);
+ // null string
+ r = findNextUTF8(null, 1, b);
+ ck_assert_ptr_eq(r, null);
+ r = findNextUTF8(b, 1, null);
+ ck_assert_ptr_eq(r, null);
+
+
+END_TEST
+
+
+START_TEST(prevUTF8T)
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // prev
+ r = prevUTF8(&b[2]);
+ ck_assert_str_eq(r, "£sheepy");
+ // null string
+ r = prevUTF8(null);
+ ck_assert_ptr_eq(r, null);
+
+
+END_TEST
+
+
+START_TEST(bPrevUTF8T)
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // prev
+ r = bPrevUTF8(b, &b[2]);
+ ck_assert_str_eq(r, "£sheepy");
+ // string start
+ r = bPrevUTF8(b, b);
+ ck_assert_ptr_eq(r, null);
+ // null string
+ r = bPrevUTF8(null, b);
+ ck_assert_ptr_eq(r, null);
+ r = bPrevUTF8(b, null);
+ ck_assert_ptr_eq(r, null);
+
+END_TEST
+
+
+START_TEST(idx2PtrUTF8T)
+
+ char *emptys = "";
+ char *r;
+
+ // index
+ r = idx2PtrUTF8("£sheepy", 1);
+ ck_assert_str_eq(r, "sheepy");
+ r = idx2PtrUTF8("£sheepy", 2);
+ ck_assert_str_eq(r, "heepy");
+ r = idx2PtrUTF8("£sheepy", 0);
+ ck_assert_str_eq(r, "£sheepy");
+ // NUL byte index
+ r = idx2PtrUTF8("£sheepy", strlen("£sheepy")-1);
+ ck_assert_str_eq(r, "");
+ // negative index
+ r = idx2PtrUTF8("£sheepy", -1);
+ ck_assert_str_eq(r, "y");
+ // empty string
+ r = idx2PtrUTF8(emptys, -1);
+ ck_assert_ptr_eq(r, emptys);
+ // index outside buffer
+ r = idx2PtrUTF8("£sheepy", 8);
+ ck_assert_ptr_eq(r, null);
+ r = idx2PtrUTF8("£sheepy", 9);
+ ck_assert_ptr_eq(r, null);
+ r = idx2PtrUTF8("£sheepy", -9);
+ ck_assert_ptr_eq(r, null);
+ // null string
+ r = idx2PtrUTF8(null, 1);
+ ck_assert_ptr_eq(r, null);
+
+END_TEST
+
+
+START_TEST(bLIdx2PtrUTF8T)
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // index
+ r = bLIdx2PtrUTF8(b, sizeof(b), 3);
+ ck_assert_str_eq(r, "eepy");
+ r = bLIdx2PtrUTF8(b, sizeof(b), 0);
+ ck_assert_str_eq(r, b);
+ // NUL byte index
+ r = bLIdx2PtrUTF8(b, sizeS(b), strlen(b)-1);
+ ck_assert_str_eq(r, "");
+ // negative index
+ r = bLIdx2PtrUTF8(b, sizeof(b), -2);
+ ck_assert_str_eq(r, "py");
+ r = bLIdx2PtrUTF8(b, sizeof(b), -1);
+ ck_assert_str_eq(r, "y");
+ // string longer than buffer and negative index
+ r = bLIdx2PtrUTF8(b, 8, -1);
+ ck_assert_str_eq(r, "py");
+ // last char
+ r = bLIdx2PtrUTF8(b, sizeof(b), 7);
+ ck_assert_str_eq(r, "");
+ // empty string
+ r = bLIdx2PtrUTF8(&b[10], 2, 1);
+ ck_assert_str_eq(r, &b[10]);
+ // index outside string
+ r = bLIdx2PtrUTF8(b, 6, 7);
+ ck_assert_ptr_eq(r, null);
+ r = bLIdx2PtrUTF8(b, 6, 5);
+ ck_assert_ptr_eq(r, null);
+ r = bLIdx2PtrUTF8(b, 6, -7);
+ ck_assert_ptr_eq(r, null);
+ // size 0
+ r = bLIdx2PtrUTF8(b, 0, 0);
+ ck_assert_ptr_eq(r, b);
+ // null string
+ r = bLIdx2PtrUTF8(null, 1, 0);
+ ck_assert_ptr_eq(r, null);
+
+
+END_TEST
+
+
+START_TEST(ptr2IdxUTF8T)
+
+ char b[20] = init0Var;
+ intmax_t r;
+ strcpy(b, "£sheepy");
+
+ // pointer to index
+ r = ptr2IdxUTF8(b, &b[1]);
+ ck_assert_int_eq(r, 0);
+ r = ptr2IdxUTF8(b, &b[2]);
+ ck_assert_int_eq(r, 1);
+ r = ptr2IdxUTF8(&b[2], &b[4]);
+ ck_assert_int_eq(r, 2);
+ r = ptr2IdxUTF8(b, &b[7]);
+ ck_assert_int_eq(r, 6);
+ // negative index
+ r = ptr2IdxUTF8(&b[8], &b[7]);
+ ck_assert_int_eq(r, -1);
+ r = ptr2IdxUTF8(&b[8], &b[6]);
+ ck_assert_int_eq(r, -2);
+ r = ptr2IdxUTF8(&b[8], b);
+ ck_assert_int_eq(r, -7);
+ // string start
+ r = ptr2IdxUTF8(b, b);
+ ck_assert_int_eq(r, 0);
+ // null pos
+ r = ptr2IdxUTF8(b, null);
+ ck_assert_int_eq(r, 0);
+ // null string
+ r = ptr2IdxUTF8(null, b);
+ ck_assert_int_eq(r, 0);
+
+END_TEST
+
+
+START_TEST(bPtr2IdxUTF8T)
+
+ char b[20] = init0Var;
+ intmax_t r;
+ strcpy(b, "£sheepy");
+
+ // pointer to index
+ r = bPtr2IdxUTF8(b, b, &b[1]);
+ ck_assert_int_eq(r, 0);
+ r = bPtr2IdxUTF8(b, b, &b[2]);
+ ck_assert_int_eq(r, 1);
+ r = bPtr2IdxUTF8(b, b, &b[7]);
+ ck_assert_int_eq(r, 6);
+ // negative index
+ r = bPtr2IdxUTF8(b, &b[8], &b[7]);
+ ck_assert_int_eq(r, -1);
+ r = bPtr2IdxUTF8(b, &b[8], &b[6]);
+ ck_assert_int_eq(r, -2);
+ r = bPtr2IdxUTF8(b, &b[8], b);
+ ck_assert_int_eq(r, -7);
+ // string start
+ r = bPtr2IdxUTF8(b, b, b);
+ ck_assert_int_eq(r, 0);
+ // null pos
+ r = bPtr2IdxUTF8(b, b, null);
+ ck_assert_int_eq(r, 0);
+ // null string
+ r = bPtr2IdxUTF8(b, null, b);
+ ck_assert_int_eq(r, 0);
+ r = bPtr2IdxUTF8(null, b, b);
+ ck_assert_int_eq(r, 0);
+
+
+END_TEST
+
+
+START_TEST(bLPtr2IdxUTF8T)
+
+ char b[20] = init0Var;
+ intmax_t r;
+ strcpy(b, "£sheepy");
+
+ // pointer to index
+ r = bLPtr2IdxUTF8(b, sizeof(b), &b[1]);
+ ck_assert_int_eq(r, 0);
+ r = bLPtr2IdxUTF8(b, sizeof(b), &b[2]);
+ ck_assert_int_eq(r, 1);
+ r = bLPtr2IdxUTF8(b, sizeof(b), &b[7]);
+ ck_assert_int_eq(r, 6);
+ // string start
+ r = bLPtr2IdxUTF8(b, sizeof(b), b);
+ ck_assert_int_eq(r, 0);
+ // null pos
+ r = bLPtr2IdxUTF8(b, sizeof(b), null);
+ ck_assert_int_eq(r, -1);
+ // pos outside buffer
+ r = bLPtr2IdxUTF8(b, 8, &b[10]);
+ ck_assert_int_eq(r, -1);
+ // pos before buffer start
+ r = bLPtr2IdxUTF8(&b[1], 8, b);
+ ck_assert_int_eq(r, -1);
+ // size 0 buffer
+ r = bLPtr2IdxUTF8(b, 0, b);
+ ck_assert_int_eq(r, -1);
+ r = bLPtr2IdxUTF8(null, sizeof(b), b);
+ ck_assert_int_eq(r, -1);
+
+
+END_TEST
+
+
+START_TEST(bLPtr2NegIdxUTF8T)
+
+ char b[20] = init0Var;
+ intmax_t r;
+ strcpy(b, "£sheepy");
+
+ // negative index
+ r = bLPtr2NegIdxUTF8(b, 9, &b[7]);
+ ck_assert_int_eq(r, -1);
+ r = bLPtr2NegIdxUTF8(b, 9, &b[6]);
+ ck_assert_int_eq(r, -2);
+ r = bLPtr2NegIdxUTF8(b, 9, b);
+ ck_assert_int_eq(r, -7);
+ // null pos
+ r = bLPtr2NegIdxUTF8(b, sizeof(b), null);
+ ck_assert_int_eq(r, 0);
+ // pos outside buffer
+ r = bLPtr2NegIdxUTF8(b, 9, &b[10]);
+ ck_assert_int_eq(r, 0);
+ // pos before buffer start
+ r = bLPtr2NegIdxUTF8(&b[1], 9, b);
+ ck_assert_int_eq(r, 0);
+ // size 0 buffer
+ r = bLPtr2NegIdxUTF8(b, 0, b);
+ ck_assert_int_eq(r, 0);
+ r = bLPtr2NegIdxUTF8(null, sizeof(b), b);
+ ck_assert_int_eq(r, 0);
+
+END_TEST
+
+
+START_TEST(makeValidUTF8T)
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // valid utf8, no change
+ r = makeValidUTF8(b);
+ ck_assert_str_eq(r, b);
+ free(r);
+ // invalid utf8 string
+ r = makeValidUTF8(&b[1]);
+ ck_assert_str_eq(r, "?sheepy");
+ free(r);
+ // null string
+ ck_assert_ptr_eq(makeValidUTF8(null), null);
+
+
+END_TEST
+
+
+START_TEST(bMakeValidUTF8T)
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // valid utf8, no change
+ r = bMakeValidUTF8(b);
+ ck_assert_str_eq(r, "£sheepy");
+ // invalid utf8 string
+ r = bMakeValidUTF8(&b[1]);
+ ck_assert_str_eq(r, "?sheepy");
+ // null string
+ ck_assert_ptr_eq(bMakeValidUTF8(null), null);
+
+
+END_TEST
+
+
+START_TEST(nMakeValidUTF8T)
+
+ char b[20] = init0Var;
+ char *r;
+ strcpy(b, "£sheepy");
+
+ // valid utf8, no change
+ r = nMakeValidUTF8(b, 4);
+ ck_assert_str_eq(r, "£sh");
+ free(r);
+ // invalid utf8 string
+ r = nMakeValidUTF8(&b[1], 4);
+ ck_assert_str_eq(r, "?she");
+ free(r);
+ // len 0
+ ck_assert_ptr_eq(nMakeValidUTF8(b, 0), null);
+ // null string
+ ck_assert_ptr_eq(nMakeValidUTF8(null, 1), null);
+
+
+END_TEST
+
+
+START_TEST(bNMakeValidUTF8T)
+
+ char b[20] = init0Var;
+ char s[20] = init0Var;
+ char *r;
+
+ // valid utf8, no change
+ strcpy(b, "£sheepy");
+ r = bNMakeValidUTF8(s, b, 4);
+ ck_assert_str_eq(r, "£sh");
+ // invalid utf8 string
+ strcpy(b, "£sheepy");
+ r = bNMakeValidUTF8(s, &b[1], 4);
+ ck_assert_str_eq(r, "?she");
+ // len 0
+ ck_assert_ptr_eq(bNMakeValidUTF8(s, b, 0), null);
+ // null string
+ ck_assert_ptr_eq(bNMakeValidUTF8(s, null, 1), null);
+ // null dest
+ ck_assert_ptr_eq(bNMakeValidUTF8(null, b, 1), null);
+
+
+END_TEST
+
+
+START_TEST(bLMakeValidUTF8T)
+
+ char b[20] = init0Var;
+ char s[20] = init0Var;
+ char *r;
+
+ // valid utf8, no change
+ strcpy(b, "£sheepy");
+ r = bLMakeValidUTF8(s, 5, b);
+ ck_assert_str_eq(r, "£sh");
+ // invalid utf8 string
+ strcpy(b, "£sheepy");
+ r = bLMakeValidUTF8(s, 5, &b[1]);
+ ck_assert_str_eq(r, "?she");
+ // len 0
+ ck_assert_ptr_eq(bLMakeValidUTF8(s, 0, b), null);
+ // null string
+ ck_assert_ptr_eq(bLMakeValidUTF8(s, 1, null), null);
+ // null dest
+ ck_assert_ptr_eq(bLMakeValidUTF8(null, 1, b), null);
+
+
+END_TEST
+
+
+START_TEST(bLNMakeValidUTF8T)
+
+ char b[20] = init0Var;
+ char s[20] = init0Var;
+ char *r;
+
+ // valid utf8, no change
+ strcpy(b, "£sheepy");
+ r = bLNMakeValidUTF8(s, 5, b, 4);
+ ck_assert_str_eq(r, "£sh");
+ r = bLNMakeValidUTF8(s, 5, b, 3);
+ ck_assert_str_eq(r, "£s");
+ r = bLNMakeValidUTF8(s, 5, b, 6);
+ ck_assert_str_eq(r, "£sh");
+ // invalid utf8 string
+ strcpy(b, "£sheepy");
+ r = bLNMakeValidUTF8(s, 5, &b[1],4);
+ ck_assert_str_eq(r, "?she");
+ // len 0
+ ck_assert_ptr_eq(bLNMakeValidUTF8(s, 0, b, 1), null);
+ ck_assert_ptr_eq(bLNMakeValidUTF8(s, 2, b, 0), null);
+ // null string
+ ck_assert_ptr_eq(bLNMakeValidUTF8(s, 1, null, 1), null);
+ // null dest
+ ck_assert_ptr_eq(bLNMakeValidUTF8(null, 1, b, 1), null);
+
+
+END_TEST
+
+
+START_TEST(strNCpyUTF8T)
+
+ char s[1024] = init0Var;
+ char *r;
+
+ // copy string
+ r = strNCpyUTF8(s, "lib", 4);
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(s, "lib");
+
+ // size 0
+ r = strNCpyUTF8(s, "AAA", 0);
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(s, "lib");
+
+ // NULL
+ s[0] = 0;
+ r = strNCpyUTF8(s, NULL, 10);
+ ck_assert_ptr_eq(r, null);
+ ck_assert_str_eq(s, "");
+ ck_assert_ptr_eq(strNCpyUTF8(NULL, "lib", 1), NULL);
+
+
+END_TEST
+
+
+START_TEST(strLCpyUTF8T)
+
+ char s[1024];
+
+ // copy string
+ strLCpyUTF8(s, 100, "lib");
+ ck_assert_str_eq(s, "lib");
+ // truncate src
+ s[0] = 0;
+ s[1] = 0;
+ s[2] = 0;
+ strLCpyUTF8(s, 3, "lib");
+ ck_assert_str_eq(s, "li");
+ s[0] = 'a';
+ s[1] = 'a';
+ s[2] = 'a';
+ s[3] = 0;
+ strLCpyUTF8(s, 3, "lib");
+ ck_assert_str_eq(s, "li");
+ // size 0 - no change in s
+ strLCpyUTF8(s, 0, "libsheepy");
+ ck_assert_str_eq(s, "li");
+ // NULL
+ s[0] = 0;
+ strLCpyUTF8(s, 1, NULL);
+ ck_assert_str_eq(s, "");
+ ck_assert_ptr_eq(strLCpyUTF8(NULL,1, "lib"), NULL);
+
+
+END_TEST
+
+
+START_TEST(strNCatUTF8T)
+
+ char s[1024];
+
+ // append string
+ strCpy(s, "lib");
+ strNCatUTF8(s, "sheepy", 100);
+ ck_assert_str_eq(s, "libsheepy");
+ // empty string2
+ strNCatUTF8(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");
+ strNCatUTF8(s, "sheepy", 2);
+ ck_assert_str_eq(s, "libsh");
+ // length 0
+ strNCatUTF8(s, "sheepy", 0);
+ ck_assert_str_eq(s, "libsh");
+ // NULL string2
+ strNCatUTF8(s, NULL, 1);
+ ck_assert_str_eq(s, "libsh");
+ // NULL parameter
+ ck_assert_ptr_eq(strNCatUTF8(NULL, "ad", 1), NULL);
+
+
+END_TEST
+
+
+START_TEST(strLCatUTF8T)
+
+ char s[1024];
+
+ // append string
+ strCpy(s, "lib");
+ strLCatUTF8(s, 100, "sheepy");
+ ck_assert_str_eq(s, "libsheepy");
+ // empty string2
+ strLCatUTF8(s, 20, "");
+ ck_assert_str_eq(s, "libsheepy");
+ // s strlen bigger than s size - keep s as it is
+ strLCatUTF8(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");
+ strLCatUTF8(s, 6, "sheepy");
+ ck_assert_str_eq(s, "libsh");
+ // NULL string2
+ strLCatUTF8(s, 1, NULL);
+ ck_assert_str_eq(s, "libsh");
+ // NULL parameter
+ ck_assert_ptr_eq(strLCatUTF8(NULL, 1, "ad"), NULL);
+
+
+END_TEST
+
+
+START_TEST(strLNCatUTF8T)
+
+ char s[1024];
+
+ // append string
+ strCpy(s, "lib");
+ strLNCatUTF8(s, 100, "sheepy", 100);
+ ck_assert_str_eq(s, "libsheepy");
+ // empty string2
+ strLNCatUTF8(s, 20, "", 10);
+ ck_assert_str_eq(s, "libsheepy");
+ // s strlen bigger than s size - keep s as it is
+ strLNCatUTF8(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");
+ strLNCatUTF8(s, 6, "sheepy", 4);
+ ck_assert_str_eq(s, "libsh");
+ // 0 source length
+ strLNCatUTF8(s, 6, "sheepy", 0);
+ ck_assert_str_eq(s, "libsh");
+ // NULL string2
+ strLNCatUTF8(s, 1, NULL, 1);
+ ck_assert_str_eq(s, "libsh");
+ // NULL parameter
+ ck_assert_ptr_eq(strLNCatUTF8(NULL, 1, "ad", 1), NULL);
+
+
+END_TEST
+
+
+START_TEST(eqIUTF8T)
+
+ // identical strings
+ ck_assert(eqIUTF8("Ashee|", "shee", 1));
+ ck_assert(eqIUTF8("Ashee", "shee", -4));
+ // string at index shorter than string2
+ ck_assert(!eqIUTF8("Ashee", "shee", 2));
+ // empty string
+ ck_assert(!eqIUTF8("", "shee", 0));
+ ck_assert(!eqIUTF8("Ashee", "", 0));
+ ck_assert(eqIUTF8("", "", 0));
+ // index mismatch
+ ck_assert(!eqIUTF8("Ashee", "shee", 0));
+ // index outside
+ ck_assert(!eqIUTF8("Ashee", "shee", 10));
+ ck_assert(!eqIUTF8("Ashee", "shee", -10));
+ // different strings
+ ck_assert(!eqIUTF8("shee", "SH",0));
+ // NULL string
+ ck_assert(!eqIUTF8(NULL,"a", 0));
+ ck_assert(!eqIUTF8("a", NULL, 0));
+
+
+END_TEST
+
+
+START_TEST(eqICharUTF8T)
+
+ // identical strings
+ ck_assert(eqICharUTF8("Ashee", 's', 1));
+ ck_assert(eqICharUTF8("Ashee", 's', -4));
+ // string at index shorter than string2
+ ck_assert(!eqICharUTF8("Ashee", 's', 2));
+ // empty string
+ ck_assert(!eqICharUTF8("", 's', 0));
+ ck_assert(!eqICharUTF8("Ashee", 0, 0));
+ ck_assert(eqICharUTF8("", 0, 0));
+ // index mismatch
+ ck_assert(!eqICharUTF8("Ashee", 's', 0));
+ // index outside
+ ck_assert(!eqICharUTF8("Ashee", 's', 10));
+ ck_assert(!eqICharUTF8("Ashee", 's', -10));
+ // different strings
+ ck_assert(!eqICharUTF8("shee", 'S',0));
+ // NULL string
+ ck_assert(!eqICharUTF8(NULL,'a', 0));
+ ck_assert(!eqICharUTF8("a", 0, 0));
+
+
+END_TEST
+
+
+START_TEST(icEqUTF8T)
+
+ // identical strings
+ ck_assert(icEqUTF8("SHEE", "shee"));
+ // different strings
+ ck_assert(!icEqUTF8("shee", "SH"));
+ // empty strings
+ ck_assert(!icEqUTF8("shee", ""));
+ ck_assert(!icEqUTF8("", "SH"));
+ ck_assert(icEqUTF8("", ""));
+ // NULL string
+ ck_assert(!icEqUTF8(NULL,"a"));
+ ck_assert(!icEqUTF8("a", NULL));
+
+
+END_TEST
+
+
+START_TEST(icEqCharUTF8T)
+
+ // identical strings
+ ck_assert(icEqCharUTF8('S', "s"));
+ // different strings
+ ck_assert(!icEqCharUTF8('s', "SH"));
+ // empty strings
+ ck_assert(!icEqCharUTF8('s', ""));
+ ck_assert(!icEqCharUTF8(0, "SH"));
+ ck_assert(icEqCharUTF8(0, ""));
+ // NULL string
+ ck_assert(!icEqCharUTF8(0,"a"));
+ ck_assert(!icEqCharUTF8('a', NULL));
+
+
+END_TEST
+
+
+START_TEST(icEqUTF8CharT)
+
+ // identical strings
+ ck_assert(icEqUTF8Char("S", 's'));
+ // different strings
+ ck_assert(!icEqUTF8Char("shee", 'S'));
+ // empty strings
+ ck_assert(!icEqUTF8Char("shee", 0));
+ ck_assert(!icEqUTF8Char("", 'S'));
+ ck_assert(icEqUTF8Char("", 0));
+ // NULL string
+ ck_assert(!icEqUTF8Char(NULL,'a'));
+ ck_assert(!icEqUTF8Char("a", 0));
+
+
+END_TEST
+
+
+START_TEST(icStartsWithUTF8T)
+
+ // identical strings
+ ck_assert(icStartsWithUTF8("SHEE", "shee"));
+ ck_assert(icStartsWithUTF8("SHEEPY", "shee"));
+ // different strings
+ ck_assert(!icStartsWithUTF8("shee", "aH"));
+ ck_assert(!icStartsWithUTF8("shee", "sheep"));
+ ck_assert(!icStartsWithUTF8("-shee", "shee"));
+ // NULL string
+ ck_assert(!icStartsWithUTF8(NULL,"a"));
+ ck_assert(!icStartsWithUTF8("a", NULL));
+
+
+END_TEST
+
+
+START_TEST(icEndsWithUTF8T)
+
+ // identical strings
+ ck_assert(icEndsWithUTF8("SHEE", "shee"));
+ ck_assert(icEndsWithUTF8("SHEEPY", "eepy"));
+ // different strings
+ ck_assert(!icEndsWithUTF8("shee", "SH"));
+ ck_assert(!icEndsWithUTF8("shee", "sheep"));
+ ck_assert(!icEndsWithUTF8("shee-", "shee"));
+ // NULL string
+ ck_assert(!icEndsWithUTF8(NULL,"a"));
+ ck_assert(!icEndsWithUTF8("a", NULL));
+
+
+END_TEST
+
+
+START_TEST(icCountUTF8T)
+
+ // positive count
+ ck_assert_int_eq(icCountUTF8("SHEE", "shee"), 1);
+ ck_assert_int_eq(icCountUTF8("AAA AAA", "a"), 6);
+ ck_assert_int_eq(icCountUTF8("AAA AAA", "aa"), 2);
+ // 0 count
+ ck_assert_int_eq(icCountUTF8("shee", "eSH"), 0);
+ ck_assert_int_eq(icCountUTF8("shee", "sheepy"), 0);
+ ck_assert_int_eq(icCountUTF8("aaa aaa", "ab"), 0);
+ // NULL string
+ ck_assert_int_eq(icCountUTF8(NULL,"a"), -1);
+ ck_assert_int_eq(icCountUTF8("a", NULL), -1);
+
+
+END_TEST
+
+
+START_TEST(code2RuneUTF8T)
+
+ u32 r;
+
+ r = code2RuneUTF8("£");
+ ck_assert_int_eq(r, 163);
+
+END_TEST
+
+
+START_TEST(code2RuneLUTF8T)
+
+ u8 n;
+ u32 r;
+
+ r = code2RuneLUTF8("£", &n);
+ ck_assert_int_eq(r, 163);
+ ck_assert_int_eq(n, 2);
+ // empty string
+ r = code2RuneLUTF8("", &n);
+ ck_assert_int_eq(r, 0);
+ // null length
+ r = code2RuneLUTF8("£", null);
+ ck_assert_int_eq(r, 0);
+ // null string
+ r = code2RuneLUTF8(null, &n);
+ ck_assert_int_eq(r, 0);
+
+
+END_TEST
+
+
+START_TEST(bRune2CodeUTF8T)
+
+ u8 n;
+ char r[20] = init0Var;
+
+ // pound
+ n = bRune2CodeUTF8(r, 163);
+ ck_assert_str_eq(r, "£");
+ ck_assert_int_eq(n, 2);
+
+ // null dst
+ n = 0;
+ n = bRune2CodeUTF8(null, 163);
+ ck_assert_int_eq(n, 2);
+
+END_TEST
+
+
+START_TEST(runeLenUTF8T)
+
+ u8 r;
+
+ r = runeLenUTF8(163);
+ ck_assert_int_eq(r, 2);
+
+
+END_TEST
+
+
+START_TEST(toupperUTF8T)
+
+ rune r;
+ char dst[20] = init0Var;
+
+ r = toupperUTF8(163);
+ ck_assert_int_eq(r, 163);
+
+ r = code2RuneUTF8("Ã¥");
+ r = toupperUTF8(r);
+ bRune2CodeUTF8(dst,r);
+ ck_assert_str_eq(dst, "Ã…");
+
+END_TEST
+
+
+START_TEST(upperUTF8T)
+
+ // string
+ char *s = upperUTF8("sheepyå");
+ ck_assert_str_eq(s, "SHEEPYÃ…");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(upperUTF8(NULL), NULL);
+
+
+END_TEST
+
+
+START_TEST(iUpperUTF8T)
+
+ char *s;
+ // string
+ s = strdup("sheepy");
+ iUpperUTF8(&s);
+ ck_assert_str_eq(s, "SHEEPY");
+ free(s);
+ // NULL string
+ s = NULL;
+ iUpperUTF8(&s);
+ ck_assert_ptr_eq(s, NULL);
+ // NULL var
+ iUpperUTF8(NULL);
+
+
+END_TEST
+
+
+START_TEST(tolowerUTF8T)
+
+ rune r;
+ char dst[20] = init0Var;
+
+ r = tolowerUTF8(163);
+ ck_assert_int_eq(r, 163);
+
+ r = code2RuneUTF8("Ã…");
+ r = tolowerUTF8(r);
+ bRune2CodeUTF8(dst,r);
+ ck_assert_str_eq(dst, "Ã¥");
+
+
+END_TEST
+
+
+START_TEST(lowerUTF8T)
+
+ // string
+ char *s = lowerUTF8("SHeePY");
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(lowerUTF8(NULL), NULL);
+
+
+END_TEST
+
+
+START_TEST(iLowerUTF8T)
+
+ char *s;
+ // string
+ s = strdup("SHEEPY");
+ iLowerUTF8(&s);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // NULL string
+ s = NULL;
+ iLowerUTF8(&s);
+ ck_assert_ptr_eq(s, NULL);
+ // NULL var
+ iLowerUTF8(NULL);
+
+
+END_TEST
+
+
+START_TEST(uniqUTF8T)
+
+ char *s;
+
+ // uniquify
+ s = uniqUTF8("∑qwd∑∑∑", "∑");
+ ck_assert_str_eq(s, "∑qwd∑");
+ free(s);
+ // short string
+ s = uniqUTF8("?", "/");
+ ck_assert_str_eq(s, "?");
+ free(s);
+ // NULL
+ ck_assert_ptr_eq(uniqUTF8(NULL, "/"), NULL);
+ ck_assert_ptr_eq(uniqUTF8("sd", null), NULL);
+
+
+END_TEST
+
+
+START_TEST(iUniqUTF8T)
+
+ char *s;
+
+ // uniquify
+ s = strdup("/qwd///");
+ ck_assert_str_eq(iUniqUTF8(&s, "/"), "/qwd/");
+ free(s);
+ // short string
+ s = strdup("?");
+ ck_assert_str_eq(iUniqUTF8(&s, "/"), "?");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(iUniqUTF8(&s, null), NULL);
+ s = NULL;
+ ck_assert_ptr_eq(iUniqUTF8(&s, "/"), NULL);
+ // NULL
+ ck_assert_ptr_eq(iUniqUTF8(NULL, "/"), NULL);
+
+
+END_TEST
+
+
+START_TEST(bUniqUTF8T)
+
+ char s[100];
+
+ // uniquify
+ strcpy(s, "/qwd///");
+ ck_assert_str_eq(bUniqUTF8(s, "/"), "/qwd/");
+ // short string
+ strcpy(s, "?");
+ ck_assert_str_eq(bUniqUTF8(s, "/"), "?");
+ // NULL
+ ck_assert_ptr_eq(bUniqUTF8(s, null), NULL);
+ ck_assert_ptr_eq(bUniqUTF8(NULL, "/"), NULL);
+
+
+END_TEST
+
+
+START_TEST(getUTF8T)
+
+ // get char
+ ck_assert_uint_eq(getUTF8("sheepy", 0), 's');
+ // negative index
+ ck_assert_uint_eq(getUTF8("sheepy", -1), 'y');
+ // outside string
+ ck_assert_uint_eq(getUTF8("sheepy", 10), 0);
+ ck_assert_uint_eq(getUTF8("sheepy", -10), 0);
+ // negative index in a one char string
+ ck_assert_uint_eq(getUTF8("z", -1), 'z');
+ // empty string
+ ck_assert_uint_eq(getUTF8("", 0), 0);
+ // NULL string
+ ck_assert_uint_eq(getUTF8(NULL, 0), 0);
+
+
+END_TEST
+
+
+START_TEST(setUTF8T)
+
+ char *s;
+ s = strdup("sheepy");
+
+ // set char
+ setUTF8(s, 0, 'S');
+ ck_assert_uint_eq(s[0], 'S');
+ // negative index
+ setUTF8(s, -2, 'P');
+ ck_assert_uint_eq(s[4], 'P');
+ // outside string
+ setUTF8(s, 20, 'Y');
+ setUTF8(s, -20, 'Y');
+ ck_assert_str_eq(s, "SheePy");
+ free(s);
+ // negative index in a one char string
+ s = strdup("s");
+ setUTF8(s, -1, 'S');
+ ck_assert_uint_eq(s[0], 'S');
+ free(s);
+ // empty string
+ emptyS(s);
+ setUTF8(s, -1, 'S');
+ ck_assert_str_eq(s, "");
+ free(s);
+ // NULL string
+ setUTF8(NULL, 0, 's');
+
+
+END_TEST
+
+
+START_TEST(sliceUTF8T)
+
+ // slice
+ char *s = sliceUTF8("sheepy", 0,2);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ // negative index
+ s = sliceUTF8("sheepy", -2,0);
+ ck_assert_str_eq(s, "py");
+ free(s);
+ // positive and negative indexes
+ s = sliceUTF8("sheepy", 2,-2);
+ ck_assert_str_eq(s, "ee");
+ free(s);
+ // start = end
+ s = sliceUTF8("sheepy", 2,-4);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end of string
+ s = sliceUTF8("sheepy", 2,6);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(sliceUTF8(NULL, 2,-4), NULL);
+ // start outside string
+ ck_assert_ptr_eq(sliceUTF8("sheepy", 20,-4), NULL);
+ // end outside string
+ s = sliceUTF8("sheepy", 2,40);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ s = sliceUTF8("sheepy", -22,3);
+ ck_assert_str_eq(s, "she");
+ free(s);
+ ck_assert_ptr_eq(sliceUTF8("sheepy", 2,-40), NULL);
+ // end before start
+ ck_assert_ptr_eq(sliceUTF8("sheepy", 4,2), NULL);
+
+
+END_TEST
+
+
+START_TEST(iSliceUTF8T)
+
+ char *s;
+ // slice
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 0,2);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ // negative index
+ s = strdup("sheepy");
+ iSliceUTF8(&s, -2,0);
+ ck_assert_str_eq(s, "py");
+ free(s);
+ // positive and negative indexes
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 2,-2);
+ ck_assert_str_eq(s, "ee");
+ free(s);
+ // start = end
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 2,-4);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end of string
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 2,6);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // NULL string
+ s = NULL;
+ iSliceUTF8(&s, 2,-4);
+ ck_assert_ptr_eq(s, NULL);
+ // start outside string
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 20,-4);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end outside string
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 2,40);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ s = strdup("sheepy");
+ iSliceUTF8(&s, -22,3);
+ ck_assert_str_eq(s, "she");
+ free(s);
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 2,-40);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end before start
+ s = strdup("sheepy");
+ iSliceUTF8(&s, 4,2);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // NULL var
+ iSliceUTF8(NULL, 0, 0);
+
+
+END_TEST
+
+
+START_TEST(bSliceUTF8T)
+
+ char s[100];
+ // slice
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 0,2);
+ ck_assert_str_eq(s, "sh");
+ // negative index
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, -2,0);
+ ck_assert_str_eq(s, "py");
+ // positive and negative indexes
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 2,-2);
+ ck_assert_str_eq(s, "ee");
+ // start = end
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 2,-4);
+ ck_assert_str_eq(s, "");
+ // end of string
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 2,6);
+ ck_assert_str_eq(s, "eepy");
+ // start outside string
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 20,-4);
+ ck_assert_str_eq(s, "");
+ // end outside string
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 2,40);
+ ck_assert_str_eq(s, "eepy");
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, -22,3);
+ ck_assert_str_eq(s, "she");
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 2,-40);
+ ck_assert_str_eq(s, "");
+ // end before start
+ strcpy(s, "sheepy");
+ bSliceUTF8(s, 4,2);
+ ck_assert_str_eq(s, "");
+ // NULL var
+ ck_assert_ptr_eq(bSliceUTF8(NULL, 0, 0), NULL);
+
+
+END_TEST
+
+
+START_TEST(bLSliceUTF8T)
+
+ char s[100];
+ // slice
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 0,2);
+ ck_assert_str_eq(s, "sh");
+ // buffer shorter than string
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, 5, 0,2);
+ ck_assert_str_eq(s, "sh");
+ // negative index
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), -2,0);
+ ck_assert_str_eq(s, "py");
+ // positive and negative indexes
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 2,-2);
+ ck_assert_str_eq(s, "ee");
+ // start = end
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 2,-4);
+ ck_assert_str_eq(s, "");
+ // end of string
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 2,6);
+ ck_assert_str_eq(s, "eepy");
+ // start outside string
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 20,-4);
+ ck_assert_str_eq(s, "");
+ // end outside string
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 2,40);
+ ck_assert_str_eq(s, "eepy");
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), -22,3);
+ ck_assert_str_eq(s, "she");
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 2,-40);
+ ck_assert_str_eq(s, "");
+ // end before start
+ strcpy(s, "sheepy");
+ bLSliceUTF8(s, sizeof(s), 4,2);
+ ck_assert_str_eq(s, "");
+ // size 0
+ ck_assert_ptr_eq(bLSliceUTF8(s, 0, 0, 0), NULL);
+ // NULL var
+ ck_assert_ptr_eq(bLSliceUTF8(NULL, sizeof(s), 0, 0), NULL);
+
+
+END_TEST
+
+
+START_TEST(insertUTF8T)
+
+ char *s;
+
+ // insert
+ s = insertUTF8("sheepy", 0, "lib");
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // negative index
+ s = insertUTF8("libsheepy", -2, "P");
+ ck_assert_str_eq(s, "libsheepPy");
+ free(s);
+ // edge
+ s = insertUTF8("qwe", 3, "C");
+ ck_assert_str_eq(s, "qweC");
+ free(s);
+ // outside string
+ s = insertUTF8("qwe", 4, "C");
+ ck_assert_ptr_eq(s, NULL);
+ s = insertUTF8("qwe", -5, "C");
+ ck_assert_ptr_eq(s, NULL);
+ // negative index in a one char string
+ s = insertUTF8("s", -1, "S");
+ ck_assert_str_eq(s, "sS");
+ free(s);
+ // empty string
+ s = insertUTF8("", 0, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+ s = insertUTF8("", -1, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // empty insert string
+ s = insertUTF8("a", 0, "");
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL insert string
+ s = insertUTF8("a", 0, NULL);
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL string
+ s = insertUTF8(NULL, 0, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+
+
+END_TEST
+
+
+START_TEST(insertNFreeUTF8T)
+
+ char *s, *a;
+
+ // insert
+ s = insertNFreeUTF8("sheepy", 0, strdup("lib"));
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // negative index
+ s = insertNFreeUTF8("libsheepy", -2, strdup("P"));
+ ck_assert_str_eq(s, "libsheepPy");
+ free(s);
+ // edge
+ s = insertNFreeUTF8("qwe", 3, strdup("C"));
+ ck_assert_str_eq(s, "qweC");
+ free(s);
+ // outside string
+ a = strdup("C");
+ s = insertNFreeUTF8("qwe", 4, a);
+ ck_assert_ptr_eq(s, NULL);
+ s = insertNFreeUTF8("qwe", -5, a);
+ ck_assert_ptr_eq(s, NULL);
+ free(a);
+ // negative index in a one char string
+ s = insertNFreeUTF8("s", -1, strdup("S"));
+ ck_assert_str_eq(s, "sS");
+ free(s);
+ // empty string
+ s = insertNFreeUTF8("", 0, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+ s = insertNFreeUTF8("", -1, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // empty insert string
+ s = insertNFreeUTF8("a", 0, strdup(""));
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL insert string
+ s = insertNFreeUTF8("a", 0, NULL);
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL string
+ s = insertNFreeUTF8(NULL, 0, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+
+
+END_TEST
+
+
+START_TEST(iInsertUTF8T)
+
+ char *s;
+
+ // insert
+ s = strdup("sheepy");
+ iInsertUTF8(&s, 0, "lib");
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // negative index
+ s = strdup("libsheepy");
+ iInsertUTF8(&s, -2, "P");
+ ck_assert_str_eq(s, "libsheepPy");
+ free(s);
+ // edge
+ s = strdup("qwe");
+ iInsertUTF8(&s, 3, "C");
+ ck_assert_str_eq(s, "qweC");
+ free(s);
+ // outside string
+ s = strdup("qwe");
+ iInsertUTF8(&s, 4, "C");
+ ck_assert_str_eq(s, "qwe");
+ iInsertUTF8(&s, -5, "C");
+ ck_assert_str_eq(s, "qwe");
+ free(s);
+ // negative index in a one char string
+ s = strdup("s");
+ iInsertUTF8(&s, -1, "S");
+ ck_assert_str_eq(s, "sS");
+ free(s);
+ // empty string
+ emptyS(s);
+ iInsertUTF8(&s, 0, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+ emptyS(s);
+ iInsertUTF8(&s, -1, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // empty insert string
+ s = strdup("a");
+ iInsertUTF8(&s, 0, "");
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL insert string
+ s = strdup("a");
+ iInsertUTF8(&s, 0, NULL);
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL string
+ s = NULL;
+ iInsertUTF8(&s, 0, "s");
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // NULL var
+ iInsertUTF8(NULL, 0, "s");
+
+
+END_TEST
+
+
+START_TEST(iInsertNFreeUTF8T)
+
+ char *s, *a, *r;
+
+ // insert
+ s = strdup("sheepy");
+ iInsertNFreeUTF8(&s, 0, strdup("lib"));
+ ck_assert_str_eq(s, "libsheepy");
+ free(s);
+ // negative index
+ s = strdup("libsheepy");
+ iInsertNFreeUTF8(&s, -2, strdup("P"));
+ ck_assert_str_eq(s, "libsheepPy");
+ free(s);
+ // edge
+ s = strdup("qwe");
+ iInsertNFreeUTF8(&s, 3, strdup("C"));
+ ck_assert_str_eq(s, "qweC");
+ free(s);
+ // outside string
+ s = strdup("qwe");
+ a = strdup("C");
+ r = iInsertNFreeUTF8(&s, 4, a);
+ ck_assert_ptr_eq(r, NULL);
+ ck_assert_str_eq(s, "qwe");
+ r = iInsertNFreeUTF8(&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");
+ iInsertNFreeUTF8(&s, -1, strdup("S"));
+ ck_assert_str_eq(s, "sS");
+ free(s);
+ // empty string
+ emptyS(s);
+ iInsertNFreeUTF8(&s, 0, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+ emptyS(s);
+ iInsertNFreeUTF8(&s, -1, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // empty insert string
+ s = strdup("a");
+ iInsertNFreeUTF8(&s, 0, strdup(""));
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL insert string
+ s = strdup("a");
+ iInsertNFreeUTF8(&s, 0, NULL);
+ ck_assert_str_eq(s, "a");
+ free(s);
+ // NULL string
+ s = NULL;
+ iInsertNFreeUTF8(&s, 0, strdup("s"));
+ ck_assert_str_eq(s, "s");
+ free(s);
+ // NULL var
+ s = strdup("s");
+ r = iInsertNFreeUTF8(NULL, 0, s);
+ ck_assert_ptr_eq(r, NULL);
+ free(s);
+
+
+END_TEST
+
+
+START_TEST(bInsertUTF8T)
+
+ char s[100];
+
+ // insert
+ strcpy(s, "sheepy");
+ bInsertUTF8(s, 0, "lib");
+ ck_assert_str_eq(s, "libsheepy");
+ // negative index
+ strcpy(s, "libsheepy");
+ bInsertUTF8(s, -2, "P");
+ ck_assert_str_eq(s, "libsheepPy");
+ // edge
+ strcpy(s, "qwe");
+ bInsertUTF8(s, 3, "C");
+ ck_assert_str_eq(s, "qweC");
+ // outside string
+ strcpy(s, "qwe");
+ bInsertUTF8(s, 4, "C");
+ ck_assert_str_eq(s, "qwe");
+ bInsertUTF8(s, -5, "C");
+ ck_assert_str_eq(s, "qwe");
+ // negative index in a one char string
+ strcpy(s, "s");
+ bInsertUTF8(s, -1, "S");
+ ck_assert_str_eq(s, "sS");
+ // empty string
+ bEmptyS(s);
+ bInsertUTF8(s, 0, "s");
+ ck_assert_str_eq(s, "s");
+ bEmptyS(s);
+ bInsertUTF8(s, -1, "s");
+ ck_assert_str_eq(s, "s");
+ // empty insert string
+ strcpy(s, "a");
+ bInsertUTF8(s, 0, "");
+ ck_assert_str_eq(s, "a");
+ // NULL insert string
+ strcpy(s, "a");
+ bInsertUTF8(s, 0, NULL);
+ ck_assert_str_eq(s, "a");
+ // NULL var
+ ck_assert_ptr_eq(bInsertUTF8(NULL, 0, "s"), NULL);
+
+
+END_TEST
+
+
+START_TEST(bLInsertUTF8T)
+
+ char s[100];
+
+ // insert
+ strcpy(s, "sheepy");
+ bLInsertUTF8(s, sizeof s, 0, "lib");
+ ck_assert_str_eq(s, "libsheepy");
+ // shorter buffer
+ strcpy(s, "sheepy");
+ bLInsertUTF8(s, 5, 0, "lib");
+ ck_assert_str_eq(s, "libs");
+ // negative index
+ strcpy(s, "libsheepy");
+ bLInsertUTF8(s, sizeof s, -2, "P");
+ ck_assert_str_eq(s, "libsheepPy");
+ // edge
+ strcpy(s, "qwe");
+ bLInsertUTF8(s, sizeof s, 3, "C");
+ ck_assert_str_eq(s, "qweC");
+ // outside string
+ strcpy(s, "qwe");
+ bLInsertUTF8(s, sizeof s, 4, "C");
+ ck_assert_str_eq(s, "qwe");
+ bLInsertUTF8(s, sizeof s, -5, "C");
+ ck_assert_str_eq(s, "qwe");
+ // negative index in a one char string
+ strcpy(s, "s");
+ bLInsertUTF8(s, sizeof s, -1, "S");
+ ck_assert_str_eq(s, "sS");
+ // empty string
+ bEmptyS(s);
+ bLInsertUTF8(s, sizeof s, 0, "s");
+ ck_assert_str_eq(s, "s");
+ bEmptyS(s);
+ bLInsertUTF8(s, sizeof s, -1, "s");
+ ck_assert_str_eq(s, "s");
+ // empty insert string
+ strcpy(s, "a");
+ bLInsertUTF8(s, sizeof s, 0, "");
+ ck_assert_str_eq(s, "a");
+ // size 0 - no change
+ bLInsertUTF8(s, 0, 0, "qwe");
+ ck_assert_str_eq(s, "a");
+ // NULL insert string
+ strcpy(s, "a");
+ bLInsertUTF8(s, sizeof s, 0, NULL);
+ ck_assert_str_eq(s, "a");
+ // NULL var
+ ck_assert_ptr_eq(bLInsertUTF8(NULL, sizeof s, 0, "s"), NULL);
+
+
+END_TEST
+
+
+START_TEST(delUTF8T)
+
+ // del
+ char *s = delUTF8("sheepy", 0,2);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // negative index
+ s = delUTF8("sheepy", -2,0);
+ ck_assert_str_eq(s, "shee");
+ free(s);
+ // positive and negative indexes
+ s = delUTF8("sheepy", 2,-2);
+ ck_assert_str_eq(s, "shpy");
+ free(s);
+ // start = end
+ s = delUTF8("sheepy", 2,-4);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // delete entire string
+ s = delUTF8("sheepy", 0,0);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end of string
+ s = delUTF8("sheepy", 2,6);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ // NULL string
+ ck_assert_ptr_eq(delUTF8(NULL, 2,-4), NULL);
+ // start outside string
+ ck_assert_ptr_eq(delUTF8("sheepy", 20,-4), NULL);
+ s = delUTF8("sheepy", -20,-4);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // end outside string
+ s = delUTF8("sheepy", 2,40);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ ck_assert_ptr_eq(delUTF8("sheepy", 2,-40), NULL);
+ // end before start
+ ck_assert_ptr_eq(delUTF8("sheepy", 4,2), NULL);
+
+
+END_TEST
+
+
+START_TEST(iDelUTF8T)
+
+ char *s;
+ // del
+ s = strdup("sheepy");
+ iDelUTF8(&s, 0,2);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // negative index
+ s = strdup("sheepy");
+ iDelUTF8(&s, -2,0);
+ ck_assert_str_eq(s, "shee");
+ free(s);
+ // positive and negative indexes
+ s = strdup("sheepy");
+ iDelUTF8(&s, 2,-2);
+ ck_assert_str_eq(s, "shpy");
+ free(s);
+ // start = end
+ s = strdup("sheepy");
+ iDelUTF8(&s, 2,-4);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // delete entire string
+ s = strdup("sheepy");
+ iDelUTF8(&s, 0,0);
+ ck_assert_str_eq(s, "");
+ free(s);
+ // end of string
+ s = strdup("sheepy");
+ iDelUTF8(&s, 2,6);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ // NULL string
+ s = NULL;
+ iDelUTF8(&s, 2,-4);
+ ck_assert_ptr_eq(s, NULL);
+ // start outside string
+ s = strdup("sheepy");
+ iDelUTF8(&s, 20,-4);
+ ck_assert_str_eq(s, "sheepy");
+ iDelUTF8(&s, -20,-4);
+ ck_assert_str_eq(s, "eepy");
+ free(s);
+ // end outside string
+ s = strdup("sheepy");
+ iDelUTF8(&s, 2,40);
+ ck_assert_str_eq(s, "sh");
+ free(s);
+ s = strdup("sheepy");
+ iDelUTF8(&s, 2,-40);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // end before start
+ s = strdup("sheepy");
+ iDelUTF8(&s, 4,2);
+ ck_assert_str_eq(s, "sheepy");
+ free(s);
+ // NULL var
+ iDelUTF8(NULL, 4,2);
+
+
+END_TEST
+
+
+START_TEST(bDelUTF8T)
+
+ char s[100];
+ // del
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 0,2);
+ ck_assert_str_eq(s, "eepy");
+ // negative index
+ strcpy(s, "sheepy");
+ bDelUTF8(s, -2,0);
+ ck_assert_str_eq(s, "shee");
+ // positive and negative indexes
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 2,-2);
+ ck_assert_str_eq(s, "shpy");
+ // start = end
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 2,-4);
+ ck_assert_str_eq(s, "sheepy");
+ // delete entire string
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 0,0);
+ ck_assert_str_eq(s, "");
+ // end of string
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 2,6);
+ ck_assert_str_eq(s, "sh");
+ // start outside string
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 20,-4);
+ ck_assert_str_eq(s, "sheepy");
+ bDelUTF8(s, -20,-4);
+ ck_assert_str_eq(s, "eepy");
+ // end outside string
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 2,40);
+ ck_assert_str_eq(s, "sh");
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 2,-40);
+ ck_assert_str_eq(s, "sheepy");
+ // end before start
+ strcpy(s, "sheepy");
+ bDelUTF8(s, 4,2);
+ ck_assert_str_eq(s, "sheepy");
+ // NULL var
+ ck_assert_ptr_eq(bDelUTF8(NULL, 4,2), NULL);
+
+
+END_TEST
+
+
+START_TEST(bLDelUTF8T)
+
+ char s[100];
+ // del
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 0,2);
+ ck_assert_str_eq(s, "eepy");
+ // buffer shorter than string
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, 5, 0,2);
+ ck_assert_str_eq(s, "ee");
+ // negative index
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), -2,0);
+ ck_assert_str_eq(s, "shee");
+ // positive and negative indexes
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 2,-2);
+ ck_assert_str_eq(s, "shpy");
+ // start = end
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 2,-4);
+ ck_assert_str_eq(s, "sheepy");
+ // end of string
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 2,6);
+ ck_assert_str_eq(s, "sh");
+ // start outside string
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 20,-4);
+ ck_assert_str_eq(s, "sheepy");
+ // end outside string
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 2,40);
+ ck_assert_str_eq(s, "sh");
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), -22,3);
+ ck_assert_str_eq(s, "epy");
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 2,-40);
+ ck_assert_str_eq(s, "sheepy");
+ // end before start
+ strcpy(s, "sheepy");
+ bLDelUTF8(s, sizeof(s), 4,2);
+ ck_assert_str_eq(s, "sheepy");
+ // size 0
+ ck_assert_ptr_eq(bLDelUTF8(s, 0, 0, 0), NULL);
+ // NULL var
+ ck_assert_ptr_eq(bLDelUTF8(NULL, sizeof(s), 0, 0), NULL);
+
+
+END_TEST
+
+
+START_TEST(indexOfUTF8T)
+
+ // indexOf string in the middle
+ ck_assert_int_eq(indexOfUTF8("sheepy", "ee"), 2);
+ // indexOf non existing string
+ ck_assert_int_eq(indexOfUTF8("sheepy", "$"), -1);
+ // indexOf NULL
+ ck_assert_int_eq(indexOfUTF8("sheepy", NULL), -1);
+ // NULL string
+ ck_assert_int_eq(indexOfUTF8(NULL, "$"), -1);
+
+
+END_TEST
+
+
+START_TEST(icHasUTF8T)
+
+ // find string in the middle
+ ck_assert(icHasUTF8("sheepy", "EE"));
+ // find non existing string
+ ck_assert(!icHasUTF8("sheepy", "$"));
+ // find NULL
+ ck_assert(!icHasUTF8("sheepy", NULL));
+ // NULL string
+ ck_assert(!icHasUTF8(NULL, "$"));
+
+
+END_TEST
+
+
+START_TEST(icListSortUTF8T)
+
+ char **l = NULL;
+ char **l2;
+
+ // list
+ listPushS(&l, "1sdfdsf");
+ listPushS(&l, "4444");
+ listPushS(&l, "3");
+ listPushS(&l, "22sdf");
+ l2 = icListSortUTF8(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 = icListSortUTF8(l);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "1sdfdsf");
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l2)
+ l = icListSortUTF8(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(icListSortUTF8(NULL), NULL);
+
+
+END_TEST
+
+
+START_TEST(iicListSortUTF8T)
+
+ char **l = NULL;
+
+ // list
+ listPushS(&l, "1sdfdsf");
+ listPushS(&l, "4444");
+ listPushS(&l, "3");
+ listPushS(&l, "22sdf");
+ iicListSortUTF8(&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");
+ iicListSortUTF8(&l);
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "1sdfdsf");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ iicListSortUTF8(&l);
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ iicListSortUTF8(&l);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iicListSortUTF8(NULL);
+
+
+END_TEST
+
+
+START_TEST(icListEqUTF8T)
+
+ char **l = NULL;
+ char **l2;
+
+ // identical lists
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = listDupS(l);
+ ck_assert(icListEqUTF8(l,l2));
+ // NULL lists
+ ck_assert(!icListEqUTF8(NULL,l));
+ ck_assert(!icListEqUTF8(l,NULL));
+ ck_assert(!icListEqUTF8(NULL,NULL));
+ // different lists same number of elements
+ l[3][0] = 'A';
+ ck_assert(!icListEqUTF8(l,l2));
+ // different number of elements
+ char *s = listPopS(&l);
+ free(s);
+ ck_assert(!icListEqUTF8(l,l2));
+ listFreeS(l);
+ listFreeS(l2);
+
+
+END_TEST
+
+
+START_TEST(icListHasUTF8T)
+
+ char **l = NULL;
+
+ // string
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ ck_assert(icListHasUTF8(l, "1"));
+ // NULL list
+ ck_assert(!icListHasUTF8(NULL, "1"));
+ // NULL string
+ ck_assert(!icListHasUTF8(l, NULL));
+ // non existing element
+ ck_assert(!icListHasUTF8(l, "wfe"));
+ // string in list
+ ck_assert(icListHasUTF8(l, "333"));
+ listFreeS(l);
+
+
+END_TEST
+
+
+START_TEST(icListIndexOfUTF8T)
+
+ char **l = NULL;
+
+ // string
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ ck_assert_uint_eq(icListIndexOfUTF8(l, "1"),0);
+ // NULL list
+ ck_assert_uint_eq(icListIndexOfUTF8(NULL, "1"),-1);
+ // NULL string
+ ck_assert_uint_eq(icListIndexOfUTF8(l, NULL),-1);
+ // non existing element
+ ck_assert_uint_eq(icListIndexOfUTF8(l, "wfe"),-1);
+ // string in list
+ ck_assert_uint_eq(icListIndexOfUTF8(l, "333"),2);
+ listFreeS(l);
+
+
+END_TEST
+
+
+START_TEST(icListBinarySearchUTF8T)
+
+ 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(icListBinarySearchUTF8(l, "1"),0);
+ // NULL list
+ ck_assert_uint_eq(icListBinarySearchUTF8(NULL, "1"),-1);
+ // NULL string
+ ck_assert_uint_eq(icListBinarySearchUTF8(l, NULL),-1);
+ // non existing element
+ ck_assert_uint_eq(icListBinarySearchUTF8(l, "wfe"),-1);
+ // string in list
+ ck_assert_uint_eq(icListBinarySearchUTF8(l, "333"),2);
+ listFreeS(l);
+
+
+END_TEST
+
+
+START_TEST(icListUniqUTF8T)
+
+ char **l = NULL;
+ char **l2;
+
+ // list with unique elements
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = icListUniqUTF8(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 = icListUniqUTF8(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 = icListUniqUTF8(l);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "1");
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l)
+ l2 = icListUniqUTF8(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(icListUniqUTF8(NULL), NULL);
+
+
+END_TEST
+
+
+START_TEST(iicListUniqUTF8T)
+
+ char **l = NULL;
+ char **l2;
+
+ // list with unique elements
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = listDupS(l);
+ iicListUniqUTF8(&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);
+ iicListUniqUTF8(&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);
+ iicListUniqUTF8(&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);
+ iicListUniqUTF8(&l2);
+ ck_assert_uint_eq(listLengthS(l2),0);
+ ck_assert_ptr_eq(l2[0], NULL);
+ listFreeS(l);
+ listFreeS(l2);
+ // NULL list
+ l = NULL;
+ iicListUniqUTF8(&l);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iicListUniqUTF8(NULL);
+
+
+END_TEST
+
+
+START_TEST(emptySFT)
+
+ char *s;
+
+ // empty string
+ s = emptySF();
+ ck_assert(isEmptyS(s));
+ free(s);
+
+END_TEST
+
+
+START_TEST(iEmptySFT)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(isEmptyST)
+
+ 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));
+
+END_TEST
+
+
+START_TEST(isBlankST)
+
+ 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));
+
+END_TEST
+
+
+START_TEST(intIndexT)
+
+ ssize_t r;
+
+ // positive index
+ r = intIndex(2,3);
+ ck_assert_int_eq(r, 2);
+ // negative index
+ r = intIndex(-1,3);
+ ck_assert_int_eq(r, 2);
+ r = intIndex(-3,3);
+ ck_assert_int_eq(r, 0);
+ // outside length
+ r = intIndex(3,3);
+ ck_assert_int_eq(r, -1);
+ r = intIndex(-4,3);
+ ck_assert_int_eq(r, -1);
+ // length 0
+ r = intIndex(-1,0);
+ ck_assert_int_eq(r, -1);
+
+END_TEST
+
+
+START_TEST(listEmptySFT)
+
+ char **l;
+
+ // empty list
+ l = listEmptySF();
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+
+END_TEST
+
+
+START_TEST(iListEmptySFT)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listIsEmptyST)
+
+ 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));
+
+END_TEST
+
+
+START_TEST(listIsBlankST)
+
+ 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));
+
+END_TEST
+
+
+START_TEST(listLengthST)
+
+ 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);
+
+
+END_TEST
+
+
+START_TEST(listStrLengthST)
+
+ char **l = null;
+ ssize_t r;
+
+ listPushS(&l, "lib");
+ listPushS(&l, "sheepy");
+ r = listStrLengthS(l);
+ ck_assert_int_eq(r, 9);
+ listFreeS(l);
+ // null list
+ ck_assert_int_eq(listStrLengthS(null), -1);
+
+END_TEST
+
+
+START_TEST(listIntIndexST)
+
+ char **l = null;
+ ssize_t r;
+ listPushS(&l, "lib");
+ listPushS(&l, "sheepy");
+ listPushS(&l, "sheepy");
+ // positive index
+ r = listIntIndexS(l, 2);
+ ck_assert_int_eq(r, 2);
+ // negative index
+ r = listIntIndexS(l, -1);
+ ck_assert_int_eq(r, 2);
+ r = listIntIndexS(l, -3);
+ ck_assert_int_eq(r, 0);
+ // outside length
+ r = listIntIndexS(l, 3);
+ ck_assert_int_eq(r, -1);
+ r = listIntIndexS(l, -4);
+ ck_assert_int_eq(r, -1);
+ listFreeS(l);
+ // length 0
+ listEmptyS(l);
+ r = listIntIndexS(l, -1);
+ ck_assert_int_eq(r, -1);
+ listFreeS(l);
+ // null list
+ ck_assert_int_eq(listIntIndexS(NULL, 1), -1);
+
+END_TEST
+
+
+START_TEST(listAddrST)
+
+ char **l = null;
+ char **r;
+ listPushS(&l, "lib");
+ listPushS(&l, "sheepy");
+ listPushS(&l, "sheepy");
+ // positive index
+ r = listAddrS(l, 2);
+ ck_assert_ptr_eq(r, &l[2]);
+ // negative index
+ r = listAddrS(l, -1);
+ ck_assert_ptr_eq(r, &l[2]);
+ r = listAddrS(l, -3);
+ ck_assert_ptr_eq(r, &l[0]);
+ // outside length
+ r = listAddrS(l, 3);
+ ck_assert_ptr_eq(r, null);
+ r = listAddrS(l, -4);
+ ck_assert_ptr_eq(r, null);
+ listFreeS(l);
+ // length 0
+ listEmptyS(l);
+ r = listAddrS(l, -1);
+ ck_assert_ptr_eq(r, null);
+ listFreeS(l);
+ // null list
+ ck_assert_ptr_eq(listAddrS(NULL, 1), null);
+
+
+END_TEST
+
+
+START_TEST(listCreateST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listFromArrayST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listPushST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listPushCharST)
+
+ char **l = NULL;
+
+ // push strings and NULL list
+ listPushCharS(&l, 's');
+ // check ck_assert_ptr_null not available in jessie
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert_str_eq(l[0], "s");
+ listPushCharS(&l, 'S');
+ ck_assert_str_eq(l[1], "S");
+ ck_assert_str_eq(l[0], "s");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ listPushCharS(&l, 's');
+ ck_assert_str_eq(l[0], "s");
+ ck_assert_ptr_eq(l[1], NULL);
+ listFreeS(l);
+ // NULL pointer to list
+ listPushCharS(NULL, 's');
+
+
+END_TEST
+
+
+START_TEST(iListPushST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listPopST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listPrependST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listPrependCharST)
+
+ char **l = NULL;
+
+ // push strings and NULL list
+ listPrependCharS(&l, 's');
+ // check ck_assert_ptr_null not available in jessie
+ ck_assert_ptr_ne(l, NULL);
+ ck_assert_str_eq(l[0], "s");
+ listPrependCharS(&l, 'S');
+ ck_assert_str_eq(l[0], "S");
+ ck_assert_str_eq(l[1], "s");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ listPrependCharS(&l, 's');
+ ck_assert_str_eq(l[0], "s");
+ ck_assert_ptr_eq(l[1], NULL);
+ listFreeS(l);
+ // NULL pointer to list
+ listPrependCharS(NULL, 's');
+
+
+END_TEST
+
+
+START_TEST(iListPrependST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listDequeueST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listFreeST)
+
+ // 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);
+
+END_TEST
+
+
+START_TEST(listFreeManyST)
+
+ // not possible to know if a pointer is already freed
+ char **l1 = listCreateS("we","sd");
+ char **l2 = listEmptySF();
+ listFreeManyS(l1, l2);
+
+END_TEST
+
+
+START_TEST(listPrintST)
+
+ char **l;
+
+ // print text
+ l = readText("textTest.null");
+ // TODO check stdout
+ //listPrintS(l);
+ listFreeS(l);
+ // NULL list
+ listPrintS(NULL);
+
+END_TEST
+
+
+START_TEST(listForEachT)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listEnumerateT)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listSortST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(iListSortST)
+
+ 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);
+
+END_TEST
+
+/**
+ * list Sort String Compare function
+ *
+ * in:
+ * a
+ * b
+ * out:
+ * test result
+ */
+local int listSortSCmp(const void * a, const void * b) {
+
+ // sanity checks
+ if (!a && !b) {
+ return(0);
+ }
+ if (!a && b) {
+ return(-1);
+ }
+ if (a && !b) {
+ return(1);
+ }
+ return(strcmp(*(char **)a,*(char **)b));
+}
+
+START_TEST(listSortFST)
+
+ char **l = NULL;
+ char **l2;
+
+ // list
+ listPushS(&l, "1sdfdsf");
+ listPushS(&l, "4444");
+ listPushS(&l, "3");
+ listPushS(&l, "22sdf");
+ l2 = listSortFS(l, listSortSCmp);
+ 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 = listSortFS(l, listSortSCmp);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "1sdfdsf");
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l2)
+ l = listSortFS(l2, listSortSCmp);
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ listFreeS(l);
+ // NULL compare function
+ ck_assert_ptr_eq(listSortFS(l2, NULL), NULL);
+ listFreeS(l2);
+ // NULL list
+ ck_assert_ptr_eq(listSortFS(NULL, listSortSCmp), NULL);
+
+
+END_TEST
+
+
+START_TEST(iListSortFST)
+
+ char **l = NULL;
+
+ // list
+ listPushS(&l, "1sdfdsf");
+ listPushS(&l, "4444");
+ listPushS(&l, "3");
+ listPushS(&l, "22sdf");
+ iListSortFS(&l, listSortSCmp);
+ ck_assert_str_eq(l[0], "1sdfdsf");
+ ck_assert_str_eq(l[3], "4444");
+ listFreeS(l);
+ // one element list
+ l = NULL;
+ listPushS(&l, "1sdfdsf");
+ iListSortFS(&l, listSortSCmp);
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "1sdfdsf");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ iListSortFS(&l, listSortSCmp);
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ // NULL compare function
+ ck_assert_ptr_eq(iListSortFS(&l, null), null);
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ iListSortFS(&l, listSortSCmp);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListSortFS(NULL, listSortSCmp);
+
+
+END_TEST
+
+
+START_TEST(icListSortST)
+
+ char **l = NULL;
+ char **l2;
+
+ // list
+ listPushS(&l, "A1sdfdsf");
+ listPushS(&l, "d4444");
+ listPushS(&l, "c3");
+ listPushS(&l, "B22sdf");
+ l2 = icListSortS(l);
+ ck_assert_str_eq(l2[0], "A1sdfdsf");
+ ck_assert_str_eq(l2[3], "d4444");
+ listFreeS(l);
+ listFreeS(l2);
+ // one element list
+ l = NULL;
+ listPushS(&l, "1sdfdsf");
+ l2 = icListSortS(l);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "1sdfdsf");
+ listFreeS(l);
+ listFreeS(l2);
+ // empty list
+ listEmptyS(l2)
+ l = icListSortS(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(icListSortS(NULL), NULL);
+
+
+END_TEST
+
+
+START_TEST(iicListSortST)
+
+ char **l = NULL;
+
+ // list
+ listPushS(&l, "a1sdfdsf");
+ listPushS(&l, "D4444");
+ listPushS(&l, "B3");
+ listPushS(&l, "c22sdf");
+ iicListSortS(&l);
+ ck_assert_str_eq(l[0], "a1sdfdsf");
+ ck_assert_str_eq(l[3], "D4444");
+ listFreeS(l);
+ // one element list
+ l = NULL;
+ listPushS(&l, "1sdfdsf");
+ iicListSortS(&l);
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "1sdfdsf");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ iicListSortS(&l);
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ listFreeS(l);
+ // NULL list
+ l = NULL;
+ iicListSortS(&l);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iicListSortS(NULL);
+
+
+END_TEST
+
+
+START_TEST(readTextT)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(readStreamT)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(writeTextT)
+
+ 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));
+
+END_TEST
+
+
+START_TEST(writeStreamT)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(appendTextT)
+
+ 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));
+
+END_TEST
+
+
+START_TEST(listGetST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(iListGetST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listSetST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listSetCharST)
+
+ char **l = NULL;
+
+ // get string
+ listPushS(&l, "@@");
+ listPushS(&l, "22");
+ listPushS(&l, "|");
+ listPushS(&l, "4444");
+ listSetCharS(l, 0, '1');
+ char *s = listGetS(l, 0);
+ ck_assert_str_eq(s, "1");
+ free(s);
+ // negative index
+ listSetCharS(l, -2, '3');
+ s = listGetS(l, -2);
+ ck_assert_str_eq(s, "3");
+ free(s);
+ // outside list
+ // list is unchanged
+ listSetCharS(l, 10, 'Q');
+ listSetCharS(l, -10, 'Q');
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_str_eq(l[2], "3");
+ ck_assert_str_eq(l[3], "4444");
+ listFreeS(l);
+ // negative index in a one element list
+ l = NULL;
+ listPushS(&l, "ASD");
+ listPushS(&l, NULL);
+ listSetCharS(l, -1, 'Q');
+ s = listGetS(l,-1);
+ ck_assert_str_eq(s, "Q");
+ free(s);
+ listFreeS(l);
+ // empty list - should not crash
+ listEmptyS(l)
+ listSetCharS(l, 0, 'Q');
+ ck_assert_ptr_eq(listGetS(l,0),NULL);
+ free(l);
+ // NULL list
+ listSetCharS(NULL, 0, 'Q');
+ ck_assert_ptr_eq(listGetS(NULL, 0), NULL);
+
+
+END_TEST
+
+
+START_TEST(iListSetST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listSwapST)
+
+ char **l = null;
+ char **r;
+ listPushS(&l, "lib");
+ listPushS(&l, "sheepy");
+ listPushS(&l, "spm");
+ // positive index
+ r = listSwapS(l, 0, 2);
+ ck_assert_str_eq(r[0], "spm");
+ ck_assert_str_eq(r[1], "sheepy");
+ ck_assert_str_eq(r[2], "lib");
+ listFreeS(r);
+ // negative index
+ r = listSwapS(l, -1, 1);
+ ck_assert_str_eq(r[0], "lib");
+ ck_assert_str_eq(r[1], "spm");
+ ck_assert_str_eq(r[2], "sheepy");
+ listFreeS(r);
+ r = listSwapS(l, -3, 1);
+ ck_assert_str_eq(r[0], "sheepy");
+ ck_assert_str_eq(r[1], "lib");
+ ck_assert_str_eq(r[2], "spm");
+ listFreeS(r);
+ // swap equal indexes
+ r = listSwapS(l, -3, -3);
+ ck_assert_str_eq(r[0], "lib");
+ ck_assert_str_eq(r[1], "sheepy");
+ ck_assert_str_eq(r[2], "spm");
+ listFreeS(r);
+ r = listSwapS(&l[2], 0, -1);
+ ck_assert_str_eq(r[0], "spm");
+ listFreeS(r);
+ // 1 element list
+ // outside length
+ r = listSwapS(l, 0, 3);
+ ck_assert_ptr_eq(r, null);
+ r = listSwapS(l, 0, -4);
+ ck_assert_ptr_eq(r, null);
+ r = listSwapS(l, 3, 0);
+ ck_assert_ptr_eq(r, null);
+ r = listSwapS(l, -4, 0);
+ ck_assert_ptr_eq(r, null);
+ listFreeS(l);
+ // length 0
+ listEmptyS(l);
+ r = listSwapS(l, -1, 0);
+ ck_assert_ptr_eq(r, null);
+ listFreeS(l);
+ // null list
+ ck_assert_ptr_eq(listSwapS(NULL, 1, 1), null);
+
+
+END_TEST
+
+
+START_TEST(iListSwapST)
+
+ char **l = null;
+ char **r;
+ listPushS(&l, "lib");
+ listPushS(&l, "sheepy");
+ listPushS(&l, "spm");
+ // positive index
+ r = iListSwapS(l, 0, 2);
+ ck_assert_str_eq(r[0], "spm");
+ ck_assert_str_eq(r[1], "sheepy");
+ ck_assert_str_eq(r[2], "lib");
+ // negative index
+ r = iListSwapS(l, -1, 1);
+ ck_assert_str_eq(r[0], "spm");
+ ck_assert_str_eq(r[1], "lib");
+ ck_assert_str_eq(r[2], "sheepy");
+ r = iListSwapS(l, -3, 1);
+ ck_assert_str_eq(r[0], "lib");
+ ck_assert_str_eq(r[1], "spm");
+ ck_assert_str_eq(r[2], "sheepy");
+ // swap equal indexes
+ r = iListSwapS(l, -3, -3);
+ ck_assert_str_eq(r[0], "lib");
+ ck_assert_str_eq(r[1], "spm");
+ ck_assert_str_eq(r[2], "sheepy");
+ r = iListSwapS(&l[2], 0, -1);
+ ck_assert_str_eq(r[0], "sheepy");
+ // 1 element list
+ // outside length
+ r = iListSwapS(l, 0, 3);
+ ck_assert_ptr_eq(r, null);
+ r = iListSwapS(l, 0, -4);
+ ck_assert_ptr_eq(r, null);
+ r = iListSwapS(l, 3, 0);
+ ck_assert_ptr_eq(r, null);
+ r = iListSwapS(l, -4, 0);
+ ck_assert_ptr_eq(r, null);
+ listFreeS(l);
+ // length 0
+ listEmptyS(l);
+ r = iListSwapS(l, -1, 0);
+ ck_assert_ptr_eq(r, null);
+ listFreeS(l);
+ // null list
+ ck_assert_ptr_eq(iListSwapS(NULL, 1, 1), null);
+
+
+END_TEST
+
+
+START_TEST(splitT)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(splitCharT)
+
+ char **l;
+
+ // string
+ l = splitChar("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 = splitChar("/one", '/');
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "");
+ ck_assert_str_eq(l[1], "one");
+ listFreeS(l);
+ l = splitChar("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 = splitChar("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 = splitChar("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);
+ // empty string
+ l = splitChar("", '$');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "");
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(splitChar(NULL, ';'), NULL);
+
+
+END_TEST
+
+
+START_TEST(icSplitT)
+
+ char **l;
+
+ // string
+ l = icSplit("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 = icSplit("/one", "/");
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "");
+ ck_assert_str_eq(l[1], "one");
+ listFreeS(l);
+ l = icSplit("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 = icSplit("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 = icSplit("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 = icSplit("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 = icSplit("AAd", "");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "AAd");
+ listFreeS(l);
+ // empty string
+ l = icSplit("", "$");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "");
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(icSplit(NULL, ";"), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(icSplit("test", NULL), NULL);
+
+
+END_TEST
+
+
+START_TEST(icSplitCharT)
+
+ char **l;
+
+ // string
+ l = icSplitChar("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 = icSplitChar("/one", '/');
+ ck_assert_uint_eq(listLengthS(l),2);
+ ck_assert_str_eq(l[0], "");
+ ck_assert_str_eq(l[1], "one");
+ listFreeS(l);
+ l = icSplitChar("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 = icSplitChar("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 = icSplitChar("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);
+ // empty string
+ l = icSplitChar("", '$');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "");
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(icSplitChar(NULL, ';'), NULL);
+
+
+END_TEST
+
+
+START_TEST(joinLengthT)
+
+ ssize_t r;
+ char **l = listCreateS("","lib","sheepy");
+ char *s;
+
+ r = joinLength(l, "/");
+ s = join(l, "/");
+ ck_assert_int_eq(r, strlen(s));
+ free(s);
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ r = joinLength(l, "/");
+ ck_assert_int_eq(r, 0);
+ listFreeS(l);
+ // NULL delimiter
+ ck_assert_int_eq(joinLength(l, NULL), -1);
+ // NULL list
+ ck_assert_int_eq(joinLength(NULL, ";"), -1);
+
+END_TEST
+
+
+START_TEST(joinT)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(joinCharT)
+
+ char **l;
+ char *s;
+
+ // list
+ l = split("one/two", "/");
+ s = joinChar(l, '/');
+ ck_assert_str_eq(s, "one/two");
+ listFreeS(l);
+ free(s);
+ // empty list
+ listEmptyS(l)
+ s = joinChar(l, '/');
+ ck_assert(isEmptyS(s));
+ listFreeS(l);
+ free(s);
+ // NULL list
+ ck_assert_ptr_eq(joinChar(NULL, ';'), NULL);
+
+
+END_TEST
+
+
+START_TEST(bJoinT)
+
+ 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)
+ 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);
+
+END_TEST
+
+
+START_TEST(bJoinCharT)
+
+ char **l;
+ char s[100];
+
+ // list
+ l = split("one/two", "/");
+ bJoinChar(s, l, '/');
+ ck_assert_str_eq(s, "one/two");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ ck_assert_ptr_eq(bJoinChar(s, l, '/'), NULL);
+ ck_assert_str_eq(s, "one/two");
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(bJoinChar(s, NULL, ';'), NULL);
+
+
+END_TEST
+
+
+START_TEST(bLJoinT)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(bLJoinCharT)
+
+ char **l;
+ char s[100];
+
+ // list
+ l = split("one/two", "/");
+ bLJoinChar(s, sizeof s, l, '/');
+ ck_assert_str_eq(s, "one/two");
+ // shorter buffer
+ bLJoinChar(s, 5, l, '/');
+ ck_assert_str_eq(s, "one/");
+ // size 0 - no change
+ bLJoinChar(s, 0, l, '/');
+ ck_assert_str_eq(s, "one/");
+ listFreeS(l);
+ // empty list
+ listEmptyS(l)
+ ck_assert_ptr_eq(bLJoinChar(s, sizeof s, l, '/'), NULL);
+ ck_assert_str_eq(s, "one/");
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(bLJoinChar(s, sizeof s, NULL, ';'), NULL);
+
+
+END_TEST
+
+
+START_TEST(extractST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(extractCharSST)
+
+ char **l;
+
+ // string
+ l = extractCharSS("one/two|", '/', "|");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "two");
+ listFreeS(l);
+ // delimiter not found
+ l = extractCharSS("one/two", '|', "/");
+ ck_assert_ptr_eq(l, NULL);
+ // extractCharSS with several delimiters after each other
+ l = extractCharSS("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);
+ // empty string
+ l = extractCharSS("", '$', "#");
+ ck_assert_ptr_eq(l, NULL);
+ // delim1 = delim2
+ l = extractCharSS("", '$', "$");
+ ck_assert_ptr_eq(l, NULL);
+ // NULL string
+ ck_assert_ptr_eq(extractCharSS(NULL, ';', ","), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(extractCharSS("test", ',', NULL), NULL);
+
+
+END_TEST
+
+
+START_TEST(extractSCharST)
+
+ char **l;
+
+ // string
+ l = extractSCharS("one/two|", "/", '|');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "two");
+ listFreeS(l);
+ // delimiter not found
+ l = extractSCharS("one/two", "||", '/');
+ ck_assert_ptr_eq(l, NULL);
+ // extractSCharS with several delimiters after each other
+ l = extractSCharS("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 = extractSCharS("AAe thre|e extract", "e ", '|');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "thre");
+ listFreeS(l);
+ // empty delimiter
+ l = extractSCharS("AAd", "", 'A');
+ ck_assert_ptr_eq(l, NULL);
+ // empty string
+ l = extractSCharS("", "$", '#');
+ ck_assert_ptr_eq(l, NULL);
+ // delim1 = delim2
+ l = extractSCharS("", "$", '$');
+ ck_assert_ptr_eq(l, NULL);
+ // NULL string
+ ck_assert_ptr_eq(extractSCharS(NULL, ";", ','), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(extractSCharS("test", NULL, ','), NULL);
+
+
+END_TEST
+
+
+START_TEST(extractCharCharST)
+
+ char **l;
+
+ // string
+ l = extractCharCharS("one/two|", '/', '|');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "two");
+ listFreeS(l);
+ // delimiter not found
+ l = extractCharCharS("one/two", '|', '/');
+ ck_assert_ptr_eq(l, NULL);
+ // extractCharCharS with several delimiters after each other
+ l = extractCharCharS("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);
+ // empty string
+ l = extractCharCharS("", '$', '#');
+ ck_assert_ptr_eq(l, NULL);
+ // delim1 = delim2
+ l = extractCharCharS("", '$', '$');
+ ck_assert_ptr_eq(l, NULL);
+ // NULL string
+ ck_assert_ptr_eq(extractCharCharS(NULL, ';', ','), NULL);
+
+
+END_TEST
+
+
+START_TEST(icExtractST)
+
+ char **l;
+
+ // string
+ l = icExtractS("one/two|", "/", "|");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "two");
+ listFreeS(l);
+ // delimiter not found
+ l = icExtractS("one/two", "||", "/");
+ ck_assert_ptr_eq(l, NULL);
+ // icExtractS with several delimiters after each other
+ l = icExtractS("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 = icExtractS("AAe thre|e extract", "E ", "|");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "thre");
+ listFreeS(l);
+ // empty delimiter
+ l = icExtractS("AAd", "", "Ad");
+ ck_assert_ptr_eq(l, NULL);
+ l = icExtractS("AAd", "A", "");
+ ck_assert_ptr_eq(l, NULL);
+ // empty string
+ l = icExtractS("", "$", "#");
+ ck_assert_ptr_eq(l, NULL);
+ // delim1 = delim2
+ l = icExtractS("", "$", "$");
+ ck_assert_ptr_eq(l, NULL);
+ // NULL string
+ ck_assert_ptr_eq(icExtractS(NULL, ";", ","), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(icExtractS("test", NULL, ","), NULL);
+ ck_assert_ptr_eq(icExtractS("test", ",", NULL), NULL);
+
+
+END_TEST
+
+
+START_TEST(icExtractCharSST)
+
+ char **l;
+
+ // string
+ l = icExtractCharSS("one/two|", '/', "|");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "two");
+ listFreeS(l);
+ // delimiter not found
+ l = icExtractCharSS("one/two", '|', "/");
+ ck_assert_ptr_eq(l, NULL);
+ // icExtractCharSS with several delimiters after each other
+ l = icExtractCharSS("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);
+ // empty string
+ l = icExtractCharSS("", '$', "#");
+ ck_assert_ptr_eq(l, NULL);
+ // delim1 = delim2
+ l = icExtractCharSS("", '$', "$");
+ ck_assert_ptr_eq(l, NULL);
+ // NULL string
+ ck_assert_ptr_eq(icExtractCharSS(NULL, ';', ","), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(icExtractCharSS("test", ',', NULL), NULL);
+
+
+END_TEST
+
+
+START_TEST(icExtractSCharST)
+
+ char **l;
+
+ // string
+ l = icExtractSCharS("one/two|", "/", '|');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "two");
+ listFreeS(l);
+ // delimiter not found
+ l = icExtractSCharS("one/two", "||", '/');
+ ck_assert_ptr_eq(l, NULL);
+ // icExtractSCharS with several delimiters after each other
+ l = icExtractSCharS("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 = icExtractSCharS("AAe thre|e extract", "E ", '|');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "thre");
+ listFreeS(l);
+ // empty delimiter
+ l = icExtractSCharS("AAd", "", 'A');
+ ck_assert_ptr_eq(l, NULL);
+ // empty string
+ l = icExtractSCharS("", "$", '#');
+ ck_assert_ptr_eq(l, NULL);
+ // delim1 = delim2
+ l = icExtractSCharS("", "$", '$');
+ ck_assert_ptr_eq(l, NULL);
+ // NULL string
+ ck_assert_ptr_eq(icExtractSCharS(NULL, ";", ','), NULL);
+ // NULL delimiter
+ ck_assert_ptr_eq(icExtractSCharS("test", NULL, ','), NULL);
+
+
+END_TEST
+
+
+START_TEST(icExtractCharCharST)
+
+ char **l;
+
+ // string
+ l = icExtractCharCharS("one/two|", '/', '|');
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "two");
+ listFreeS(l);
+ // delimiter not found
+ l = icExtractCharCharS("one/two", '|', '/');
+ ck_assert_ptr_eq(l, NULL);
+ // icExtractCharCharS with several delimiters after each other
+ l = icExtractCharCharS("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);
+ // empty string
+ l = icExtractCharCharS("", '$', '#');
+ ck_assert_ptr_eq(l, NULL);
+ // delim1 = delim2
+ l = icExtractCharCharS("", '$', '$');
+ ck_assert_ptr_eq(l, NULL);
+ // NULL string
+ ck_assert_ptr_eq(icExtractCharCharS(NULL, ';', ','), NULL);
+
+
+END_TEST
+
+
+START_TEST(listDupST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(iListDupST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listReverseST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(iListReverseST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listCatST)
+
+ 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);
+ 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);
+
+END_TEST
+
+
+START_TEST(listAppendST)
+
+ 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
+
+END_TEST
+
+
+START_TEST(iListAppendST)
+
+ 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
+
+END_TEST
+
+
+START_TEST(iListAppendNSmashST)
+
+ 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
+
+END_TEST
+
+
+START_TEST(listShiftST)
+
+ 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");
+ listShiftS(&l2,l);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[4], "A");
+ ck_assert_str_eq(l2[7], "DDDD");
+ ck_assert_str_eq(l2[0],"1");
+ ck_assert_str_eq(l2[3],"4444");
+ listFreeS(l);
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ listShiftS(&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)
+ listShiftS(&l, l2);
+ ck_assert(listEqS(l,l2));
+ listFreeS(l);
+ // list + empty list
+ listEmptyS(l)
+ listShiftS(&l2, l);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[4], "A");
+ ck_assert_str_eq(l2[7], "DDDD");
+ ck_assert_str_eq(l2[0],"1");
+ ck_assert_str_eq(l2[3],"4444");
+ listFreeS(l);
+ // empty list + empty list
+ listEmptyS(l)
+ listShiftS(&l, l);
+ ck_assert(listIsEmptyS(l));
+ listFreeS(l);
+ // NULL list + list = duplicate
+ l = NULL;
+ listShiftS(&l,l2);
+ ck_assert(listEqS(l,l2));
+ listFreeS(l);
+ // list + NULL list
+ listShiftS(&l2, NULL);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[4], "A");
+ ck_assert_str_eq(l2[7], "DDDD");
+ ck_assert_str_eq(l2[0],"1");
+ ck_assert_str_eq(l2[3],"4444");
+ listFreeS(l2);
+ // NULL list pointer
+ listShiftS(NULL,l2);
+ // should not crash
+
+
+END_TEST
+
+
+START_TEST(iListShiftST)
+
+ 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");
+ iListShiftS(&l2,l);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[4], "A");
+ ck_assert_str_eq(l2[7], "DDDD");
+ ck_assert_str_eq(l2[0],"1");
+ ck_assert_str_eq(l2[3],"4444");
+ free(l);
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ iListShiftS(&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)
+ iListShiftS(&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)
+ iListShiftS(&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);
+ iListShiftS(&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");
+ iListShiftS(&l,l2);
+ ck_assert(listEqS(l,l2));
+ free(l);
+ // list + NULL list
+ iListShiftS(&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
+ iListShiftS(NULL,l2);
+ // should not crash
+
+
+END_TEST
+
+
+START_TEST(iListShiftNSmashST)
+
+ 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");
+ iListShiftNSmashS(&l2,l);
+ ck_assert_uint_eq(listLengthS(l2),8);
+ ck_assert_str_eq(l2[4], "A");
+ ck_assert_str_eq(l2[7], "DDDD");
+ ck_assert_str_eq(l2[0],"1");
+ ck_assert_str_eq(l2[3],"4444");
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ iListShiftNSmashS(&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)
+ iListShiftNSmashS(&l, l2);
+ ck_assert_str_eq(l[4], "A");
+ ck_assert_str_eq(l[7], "DDDD");
+ ck_assert_str_eq(l[0],"1");
+ ck_assert_str_eq(l[3],"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)
+ iListShiftNSmashS(&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);
+ iListShiftNSmashS(&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");
+ iListShiftNSmashS(&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
+ iListShiftNSmashS(&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
+ iListShiftNSmashS(NULL,l);
+ // should not crash
+
+
+END_TEST
+
+
+START_TEST(listAddST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listSliceST)
+
+ 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);
+
+
+END_TEST
+
+
+START_TEST(iListCopyST)
+
+ 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);
+
+
+END_TEST
+
+
+START_TEST(iListSliceST)
+
+ 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);
+
END_TEST
-START_TEST(listAppendST)
+START_TEST(listCropST)
char **l = NULL;
- char **l2 = NULL;
+ char **l2;
- // lists
+ // list negative index
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");
+ l2 = listCropS(l, 1,-1);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[0], "22");
+ ck_assert_str_eq(l2[1], "333");
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "4444");
+ ck_assert_ptr_eq(l[2], null);
+ listFreeS(l2);
+ // start outside
+ ck_assert_ptr_eq(listCropS(l, 20,-4), NULL);
+ // end outside
+ l2 = listCropS(l, 0,40);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[1], "4444");
+ ck_assert_ptr_eq(l[0], null);
+ listFreeS(l2);
listFreeS(l);
+ // end negative and outside
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_ptr_eq(listCropS(l, 2,-40), 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");
+ // end before start
+ ck_assert_ptr_eq(listCropS(l, 3,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");
- 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));
+ // negative start last element
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ l2 = listCropS(l, -1,0);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "22");
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_ptr_eq(l[1], null);
listFreeS(l);
- // NULL list + list = duplicate
+ listFreeS(l2);
+ // start = end
l = NULL;
- listAppendS(&l,l2);
- ck_assert(listEqS(l,l2));
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ l2 = listCropS(l, 1,1);
+ ck_assert_uint_eq(listLengthS(l2),0);
+ ck_assert_ptr_eq(l2[0], NULL);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_ptr_eq(l[2], null);
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
+ // empty list
+ listEmptyS(l)
+ ck_assert_ptr_eq(listCropS(l, 0,0), NULL);
+ ck_assert_ptr_eq(listCropS(l, -1,0), NULL);
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(listCropS(NULL, 2,-4), NULL);
+
END_TEST
-START_TEST(iListAppendST)
+START_TEST(iListCropST)
char **l = NULL;
- char **l2 = NULL;
+ char **l2;
- // lists
+ // list negative index
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);
+ l2 = iListCropS(&l, 1,-1);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[0], "22");
+ ck_assert_str_eq(l2[1], "333");
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "4444");
+ ck_assert_ptr_eq(l[2], null);
+ listFreeS(l2);
+ // start outside
+ ck_assert_ptr_eq(iListCropS(&l, 20,-4), NULL);
+ // end outside
+ l2 = iListCropS(&l, 0,40);
+ ck_assert_uint_eq(listLengthS(l2),2);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[1], "4444");
+ ck_assert_ptr_eq(l[0], null);
+ listFreeS(l2);
+ listFreeS(l);
+ // end negative and outside
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_ptr_eq(iListCropS(&l, 2,-40), 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");
+ // end before start
+ ck_assert_ptr_eq(iListCropS(&l, 3,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);
- // 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));
+ // negative start last element
+ l = NULL;
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ l2 = iListCropS(&l, -1,0);
+ ck_assert_uint_eq(listLengthS(l2),1);
+ ck_assert_str_eq(l2[0], "22");
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_ptr_eq(l[1], null);
listFreeS(l);
listFreeS(l2);
- // NULL list + list = duplicate
+ // start = end
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");
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ l2 = iListCropS(&l, 1,1);
+ ck_assert_uint_eq(listLengthS(l2),0);
+ ck_assert_ptr_eq(l2[0], NULL);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "22");
+ ck_assert_ptr_eq(l[2], null);
+ listFreeS(l);
listFreeS(l2);
- // NULL list pointer
- iListAppendS(NULL,l2);
- // should not crash
+ // empty list
+ listEmptyS(l)
+ ck_assert_ptr_eq(iListCropS(&l, 0,0), NULL);
+ ck_assert_ptr_eq(iListCropS(&l, -1,0), NULL);
+ listFreeS(l);
+ // NULL list
+ l = null;
+ ck_assert_ptr_eq(iListCropS(&l, 2,-4), NULL);
+ ck_assert_ptr_eq(iListCropS(NULL, 2,-4), NULL);
+
END_TEST
-START_TEST(iListAppendNSmashST)
+START_TEST(listCropElemST)
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;
+ char *r;
+
+ // positive index
listPushS(&l, "1");
listPushS(&l, "22");
listPushS(&l, "333");
listPushS(&l, "4444");
- iListAppendNSmashS(&l,l);
- ck_assert_uint_eq(listLengthS(l),4);
+ r = listCropElemS(l, 1);
+ ck_assert_str_eq(r, "22");
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");
+ ck_assert_str_eq(l[1], "333");
+ ck_assert_str_eq(l[2], "4444");
+ ck_assert_ptr_eq(l[3], null);
+ free(r);
+ // list negative index
+ r = listCropElemS(l, -1);
+ ck_assert_str_eq(r, "4444");
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "333");
+ ck_assert_ptr_eq(l[2], null);
+ free(r);
+ // index outside
+ ck_assert_ptr_eq(listCropElemS(l, 20), NULL);
+ ck_assert_ptr_eq(listCropElemS(l, -4), NULL);
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");
+ // empty list
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");
+ ck_assert_ptr_eq(listCropElemS(l, 0), NULL);
+ ck_assert_ptr_eq(listCropElemS(l, -1), NULL);
listFreeS(l);
- // NULL list pointer
- iListAppendNSmashS(NULL,l);
- // should not crash
+ // NULL list
+ ck_assert_ptr_eq(listCropElemS(NULL, 2), NULL);
+
END_TEST
-START_TEST(listAddST)
+START_TEST(iListCropElemST)
char **l = NULL;
- char **l2 = NULL;
- char **l3;
+ char *r;
- // lists
+ // positive index
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);
+ r = iListCropElemS(&l, 1);
+ ck_assert_str_eq(r, "22");
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "333");
+ ck_assert_str_eq(l[2], "4444");
+ ck_assert_ptr_eq(l[3], null);
+ free(r);
+ // list negative index
+ r = iListCropElemS(&l, -1);
+ ck_assert_str_eq(r, "4444");
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "333");
+ ck_assert_ptr_eq(l[2], null);
+ free(r);
+ // index outside
+ ck_assert_ptr_eq(iListCropElemS(&l, 20), NULL);
+ ck_assert_ptr_eq(iListCropElemS(&l, -4), NULL);
listFreeS(l);
- // list + empty list
+ // empty list
listEmptyS(l)
- l3 = listAddS(l2, l);
- ck_assert(listEqS(l3,l2));
- listFreeS(l3);
+ ck_assert_ptr_eq(iListCropElemS(&l, 0), NULL);
+ ck_assert_ptr_eq(iListCropElemS(&l, -1), NULL);
listFreeS(l);
- // empty list + empty list
- listEmptyS(l)
- l3 = listAddS(l, l);
- ck_assert(listIsEmptyS(l3));
- listFreeS(l3);
+ // NULL list
+ l = null;
+ ck_assert_ptr_eq(iListCropElemS(&l, 2), NULL);
+ ck_assert_ptr_eq(iListCropElemS(NULL, 2), NULL);
+
+
+END_TEST
+
+
+START_TEST(listInsertST)
+
+ 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);
- // 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);
+ // 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);
+
END_TEST
-START_TEST(listSliceST)
+START_TEST(iListInsertST)
- char **l = NULL;
+ char **l;
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);
+ // 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);
- // 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");
+ // 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);
- // start = end
+ // NULL insert string
+ iListInsertS(&l, 0, NULL);
+ ck_assert_str_eq(l[0], "1");
+ listFreeS(l);
+ // NULL list and list to insert at index 0
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);
+ l2 = listCreateS("lib");
+ iListInsertS(&l, 0, l2);
+ ck_assert_str_eq(l[0], "lib");
+ free(l2);
listFreeS(l);
+ // NULL list and list to insert at non 0 index
+ l = NULL;
+ l2 = listCreateS("lib");
+ iListInsertS(&l, -1, l2);
+ ck_assert_ptr_eq(l, NULL);
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);
+ l = NULL;
+ iListInsertS(&l, 0, NULL);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListInsertS(NULL, 0, NULL);
END_TEST
-START_TEST(iListCopyST)
+START_TEST(iListInsertNFreeST)
- char **l = NULL;
+ char **l, **r;
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);
+ // 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);
- // 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);
+ // 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);
- // 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);
+ // 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);
- // 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);
+ // 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);
- // 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);
+ // 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)
- ck_assert_ptr_eq(iListCopyS(l, 0,0), NULL);
- ck_assert_ptr_eq(iListCopyS(l, -1,0), NULL);
+ 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
- ck_assert_ptr_eq(iListCopyS(NULL, 2,-4), NULL);
-
+ 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);
END_TEST
-START_TEST(iListSliceST)
+START_TEST(listInjectST)
- char **l = NULL;
+ char **l;
+ char **r;
- // 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);
+ // 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)
- iListSliceS(&l, 0,0);
- ck_assert(listIsEmptyS(l));
- iListSliceS(&l, -1,0);
- ck_assert(listIsEmptyS(l));
- listFreeS(l);
+ 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
- l = NULL;
- iListSliceS(&l, 2,-4);
- // NULL var
- iListSliceS(NULL, 2,-4);
+ r = listInjectS(NULL, 0, NULL);
+ ck_assert_ptr_eq(r, NULL);
END_TEST
-START_TEST(listInsertST)
+START_TEST(listInjectCharST)
char **l;
- char **l2;
char **r;
// insert
l = listCreateS("1","22");
- l2 = listCreateS("lib");
- r = listInsertS(l, 0, l2);
+ r = listInjectCharS(l, 0, 'l');
ck_assert_uint_eq(listLengthS(r),3);
- ck_assert_str_eq(r[0], "lib");
+ ck_assert_str_eq(r[0], "l");
ck_assert_str_eq(r[1], "1");
ck_assert_str_eq(r[2], "22");
listFreeS(r);
// negative index
- r = listInsertS(l, -1, l2);
+ r = listInjectCharS(l, -1, 'l');
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");
+ ck_assert_str_eq(r[2], "l");
listFreeS(r);
// edge
- r = listInsertS(l, 2, l2);
+ r = listInjectCharS(l, 2, 'l');
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");
+ ck_assert_str_eq(r[2], "l");
listFreeS(r);
// outside list
- r = listInsertS(l, 4, l2);
+ r = listInjectCharS(l, 4, 'l');
ck_assert_ptr_eq(r, NULL);
- r = listInsertS(l, -4, l2);
+ r = listInjectCharS(l, -4, 'l');
ck_assert_ptr_eq(r, NULL);
listFreeS(l);
// negative index in a one element list
l = listCreateS("1");
- r = listInsertS(l, -1, l2);
+ r = listInjectCharS(l, -1, 'l');
ck_assert_str_eq(r[0], "1");
- ck_assert_str_eq(r[1], "lib");
+ ck_assert_str_eq(r[1], "l");
listFreeManyS(l,r);
// empty list
listEmptyS(l);
- r = listInsertS(l, 0, l2);
- ck_assert_str_eq(r[0], "lib");
+ r = listInjectCharS(l, 0, 'l');
+ ck_assert_str_eq(r[0], "l");
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");
+ r = listInjectCharS(l, -1, 'l');
+ ck_assert_str_eq(r[0], "l");
listFreeManyS(r,l);
// NULL list
- r = listInsertS(NULL, 0, NULL);
- ck_assert_ptr_eq(r, NULL);
+ r = listInjectCharS(NULL, 0, 'l');
+ ck_assert_str_eq(r[0], "l");
+ ck_assert_ptr_eq(r[1], NULL);
+ listFreeS(r);
END_TEST
-START_TEST(iListInsertST)
+START_TEST(iListInjectST)
char **l;
- char **l2;
// insert
l = listCreateS("1","22");
- l2 = listCreateS("lib");
- iListInsertS(&l, 0, l2);
+ 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");
- free(l2);
listFreeS(l);
// negative index
l = listCreateS("1","22");
- l2 = listCreateS("lib");
- iListInsertS(&l, -1, l2);
+ 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");
- free(l2);
listFreeS(l);
// edge
l = listCreateS("1","22");
- l2 = listCreateS("lib");
- iListInsertS(&l, 2, l2);
+ 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");
- free(l2);
listFreeS(l);
// outside list
l = listCreateS("1","22");
- l2 = listCreateS("lib");
- iListInsertS(&l, 4, l2);
+ 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");
- iListInsertS(&l, -4, l2);
+ 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");
- iListInsertS(&l, -1, l2);
+ iListInjectS(&l, -1, strdup("lib"));
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);
+ iListInjectS(&l, 0, strdup("lib"));
ck_assert_str_eq(l[0], "lib");
- free(l2);
listFreeS(l);
listEmptyS(l);
- l2 = listCreateS("lib");
- iListInsertS(&l, -1, l2);
+ iListInjectS(&l, -1, strdup("lib"));
ck_assert_str_eq(l[0], "lib");
- free(l2);
listFreeS(l);
- // empty insert list
+ // NULL insert string
l = listCreateS("1");
- listEmptyS(l2);
- iListInsertS(&l, 0, l2);
+ 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);
+
+
+END_TEST
+
+
+START_TEST(listDelST)
+
+ 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);
- // NULL insert string
- iListInsertS(&l, 0, NULL);
+ // 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);
+
+
+END_TEST
+
+
+START_TEST(iListDelST)
+
+ char **l = NULL;
+
+ // 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;
- iListInsertS(&l, 0, NULL);
+ iListDelS(&l, 2,-4);
ck_assert_ptr_eq(l, NULL);
// NULL var
- iListInsertS(NULL, 0, NULL);
+ iListDelS(NULL, 2,-4);
END_TEST
-START_TEST(iListInsertNFreeST)
+START_TEST(listDelElemST)
- char **l, **r;
+ char **l = NULL;
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
+ // positive index
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ l2 = listDelElemS(l, 1);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[1], "333");
+ ck_assert_str_eq(l2[2], "4444");
+ ck_assert_ptr_eq(l2[3], null);
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
+ // list negative index
+ l2 = listDelElemS(l, -1);
+ ck_assert_str_eq(l2[0], "1");
+ ck_assert_str_eq(l2[1], "22");
+ ck_assert_str_eq(l2[2], "333");
+ ck_assert_ptr_eq(l2[3], null);
listFreeS(l2);
- ck_assert_uint_eq(listLengthS(l),2);
- ck_assert_str_eq(l[0], "1");
- ck_assert_str_eq(l[1], "22");
+ // index outside
+ ck_assert_ptr_eq(listDelElemS(l, 20), NULL);
+ ck_assert_ptr_eq(listDelElemS(l, -5), NULL);
listFreeS(l);
- // negative index in a one element list
- l = listCreateS("1");
- l2 = listCreateS("lib");
- iListInsertNFreeS(&l, -1, l2);
+ // empty list
+ listEmptyS(l)
+ ck_assert_ptr_eq(listDelElemS(l, 0), NULL);
+ ck_assert_ptr_eq(listDelElemS(l, -1), NULL);
+ listFreeS(l);
+ // NULL list
+ ck_assert_ptr_eq(listDelElemS(NULL, 2), NULL);
+
+
+END_TEST
+
+
+START_TEST(iListDelElemST)
+
+ char **l = NULL;
+ char **r;
+
+ // positive index
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ r = iListDelElemS(&l, 1);
+ ck_assert_ptr_ne(r, null);
ck_assert_str_eq(l[0], "1");
- ck_assert_str_eq(l[1], "lib");
+ ck_assert_str_eq(l[1], "333");
+ ck_assert_str_eq(l[2], "4444");
+ ck_assert_ptr_eq(l[3], null);
+ // list negative index
+ r = iListDelElemS(&l, -1);
+ ck_assert_ptr_ne(r, null);
+ ck_assert_str_eq(l[0], "1");
+ ck_assert_str_eq(l[1], "333");
+ ck_assert_ptr_eq(l[2], null);
+ // index outside
+ ck_assert_ptr_eq(iListDelElemS(&l, 20), NULL);
+ ck_assert_ptr_eq(iListDelElemS(&l, -4), NULL);
listFreeS(l);
// empty list
- listEmptyS(l);
- l2 = listCreateS("lib");
- iListInsertNFreeS(&l, 0, l2);
- ck_assert_str_eq(l[0], "lib");
+ listEmptyS(l)
+ ck_assert_ptr_eq(iListDelElemS(&l, 0), NULL);
+ ck_assert_ptr_eq(iListDelElemS(&l, -1), NULL);
listFreeS(l);
- listEmptyS(l);
- l2 = listCreateS("lib");
- iListInsertNFreeS(&l, -1, l2);
- ck_assert_str_eq(l[0], "lib");
+ // NULL list
+ l = null;
+ ck_assert_ptr_eq(iListDelElemS(&l, 2), NULL);
+ ck_assert_ptr_eq(iListDelElemS(NULL, 2), NULL);
+
+
+END_TEST
+
+
+START_TEST(execOutT)
+
+ 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);
- // 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");
+
+ // invalid command
+ l = execOut("randomCommand");
+ 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);
+
+END_TEST
+
+
+START_TEST(systemOutfT)
+
+ char **l;
+
+ // command
+ l = systemOutf("ls %s", "chmodTest.null");
+ ck_assert_uint_eq(listLengthS(l),1);
+ ck_assert_str_eq(l[0], "chmodTest.null");
+ listFreeS(l);
+
+ // invalid command
+ l = systemOutf("randomCommand");
+ ck_assert_uint_eq(listLengthS(l),0);
+ ck_assert_ptr_eq(l[0], NULL);
+ listFreeS(l);
+ // NULL command
+ ck_assert_ptr_eq(systemOutf(NULL), NULL);
+
+
+END_TEST
+
+
+START_TEST(systemfT)
+
+ int r;
+
+ // command
+ r = systemf("ls %s", "chmodTest.null");
+ ck_assert_int_eq(r,0);
+
+ // invalid command
+ r = systemf("randomCommand");
+ ck_assert_int_ne(r,0);
+
+ // NULL command
+ ck_assert_int_eq(systemf(NULL), -1);
+
+
+END_TEST
+
+
+START_TEST(commandFT)
+
+ int r;
+
+ // command
+ r = command("ls chmodTest.null");
+ ck_assert_int_eq(r,0);
+
+ // invalid command
+ r = command("randomCommand");
+ ck_assert_int_ne(r,0);
+ // NULL command
+ ck_assert_int_eq(command(NULL), -1);
+
+
+END_TEST
+
+
+START_TEST(commandfFT)
+
+ int r;
+
+ // command
+ r = commandf("ls %s", "chmodTest.null");
+ ck_assert_int_eq(r,0);
+
+ // invalid command
+ r = commandf("randomCommand");
+ ck_assert_int_ne(r,0);
+
+ // NULL command
+ ck_assert_int_eq(commandf(NULL), -1);
+
+
+END_TEST
+
+
+START_TEST(commandNFreeFT)
+
+ int r;
+
+ // command
+ r = commandNFree(strdup("ls chmodTest.null"));
+ ck_assert_int_eq(r,0);
+
+ // invalid command
+ r = commandNFree(strdup("randomCommand"));
+ ck_assert_int_ne(r,0);
+ // NULL command
+ ck_assert_int_eq(commandNFree(NULL), -1);
+
+
+END_TEST
+
+
+START_TEST(listEqST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listHasST)
+
+ 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);
+
+END_TEST
+
+
+START_TEST(listHasCharST)
+
+ char **l = NULL;
+
+ // string
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ ck_assert(listHasCharS(l, '1'));
// NULL list
- l = NULL;
- l2 = listCreateS("lib");
- iListInsertNFreeS(&l, 0, l2);
- ck_assert_str_eq(l[0], "lib");
+ ck_assert(!listHasCharS(NULL, '1'));
+ // non existing element
+ ck_assert(!listHasCharS(l, 'w'));
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);
+
END_TEST
-START_TEST(listInjectST)
+START_TEST(listIndexOfST)
- char **l;
- char **r;
+ char **l = NULL;
- // 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);
+ // 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);
- // 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);
+
+END_TEST
+
+
+START_TEST(listIndexOfCharST)
+
+ char **l = NULL;
+
+ // string
+ listPushS(&l, "1");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ ck_assert_uint_eq(listIndexOfCharS(l, '1'),0);
// NULL list
- r = listInjectS(NULL, 0, NULL);
- ck_assert_ptr_eq(r, NULL);
+ ck_assert_uint_eq(listIndexOfCharS(NULL, '1'),-1);
+ // non existing element
+ ck_assert_uint_eq(listIndexOfCharS(l, 'w'),-1);
+ listFreeS(l);
END_TEST
-START_TEST(iListInjectST)
+START_TEST(listBinarySearchST)
- char **l;
+ char **l = NULL;
- // 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");
+ // 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);
+
+END_TEST
+
+
+START_TEST(listBinarySearchCharST)
+
+ 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(listBinarySearchCharS(l, '1'),0);
// NULL list
- l = NULL;
- iListInjectS(&l, 0, NULL);
- ck_assert_ptr_eq(l, NULL);
- // NULL var
- iListInjectS(NULL, 0, NULL);
+ ck_assert_uint_eq(listBinarySearchCharS(NULL, '1'),-1);
+ // non existing element
+ ck_assert_uint_eq(listBinarySearchCharS(l, 'w'),-1);
+ // string in list
+ ck_assert_uint_eq(listBinarySearchCharS(l, '5'),4);
+ listFreeS(l);
END_TEST
-START_TEST(listDelST)
+START_TEST(listUniqST)
char **l = NULL;
char **l2;
- // list negative index
+ // list with unique elements
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");
+ 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);
- // 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);
+ l2 = listUniqS(l);
+ ck_assert_uint_eq(listLengthS(l2),3);
+ ck_assert_str_eq(l2[2], "4444");
listFreeS(l);
- // negative start last element
+ listFreeS(l2);
+ // list with one element
l = NULL;
listPushS(&l, "1");
- listPushS(&l, "22");
- l2 = listDelS(l, -1,0);
+ l2 = listUniqS(l);
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);
+ // 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);
+
+END_TEST
+
+
+START_TEST(iListUniqST)
+
+ 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);
- // start = end
+ // list with one element
l = NULL;
listPushS(&l, "1");
- listPushS(&l, "22");
- l2 = listDelS(l, 1,1);
- ck_assert_uint_eq(listLengthS(l2),2);
+ l2 = listDupS(l);
+ iListUniqS(&l2);
+ ck_assert_uint_eq(listLengthS(l2),1);
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);
+ 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
- ck_assert_ptr_eq(listDelS(NULL, 2,-4), NULL);
-
+ l = NULL;
+ iListUniqS(&l);
+ ck_assert_ptr_eq(l, NULL);
+ // NULL var
+ iListUniqS(NULL);
END_TEST
-START_TEST(iListDelST)
+START_TEST(icListEqST)
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
+ // identical lists
listPushS(&l, "1");
- listPushS(&l, "22");
+ listPushS(&l, "bb");
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");
+ l2 = listDupS(l);
+ iUpperS(&l2[1]);
+ ck_assert(icListEqS(l,l2));
+ // NULL lists
+ ck_assert(!icListEqS(NULL,l));
+ ck_assert(!icListEqS(l,NULL));
+ ck_assert(!icListEqS(NULL,NULL));
+ // different lists same number of elements
+ l[3][0] = 'A';
+ ck_assert(!icListEqS(l,l2));
+ // different number of elements
+ char *s = listPopS(&l);
+ free(s);
+ ck_assert(!icListEqS(l,l2));
+ listFreeS(l);
+ listFreeS(l2);
+
+
+END_TEST
+
+
+START_TEST(icListHasST)
+
+ char **l = NULL;
+
+ // string
+ listPushS(&l, "a");
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);
+ ck_assert(icListHasS(l, "A"));
// NULL list
- l = NULL;
- iListDelS(&l, 2,-4);
- ck_assert_ptr_eq(l, NULL);
- // NULL var
- iListDelS(NULL, 2,-4);
+ ck_assert(!icListHasS(NULL, "1"));
+ // NULL string
+ ck_assert(!icListHasS(l, NULL));
+ // non existing element
+ ck_assert(!icListHasS(l, "wfe"));
+ // string in list
+ ck_assert(icListHasS(l, "333"));
+ listFreeS(l);
END_TEST
-START_TEST(execOutT)
+START_TEST(icListHasCharST)
- char **l;
+ char **l = NULL;
- // command
- l = execOut("ls chmodTest.null");
- ck_assert_uint_eq(listLengthS(l),1);
- ck_assert_str_eq(l[0], "chmodTest.null");
+ // string
+ listPushS(&l, "A");
+ listPushS(&l, "22");
+ listPushS(&l, "333");
+ listPushS(&l, "4444");
+ ck_assert(icListHasCharS(l, 'a'));
+ // NULL list
+ ck_assert(!icListHasCharS(NULL, '1'));
+ // non existing element
+ ck_assert(!icListHasCharS(l, 'w'));
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);
END_TEST
-START_TEST(listEqST)
+START_TEST(icListIndexOfST)
char **l = NULL;
- char **l2;
- // identical lists
- listPushS(&l, "1");
+ // string
+ listPushS(&l, "a");
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));
+ ck_assert_uint_eq(icListIndexOfS(l, "A"),0);
+ // NULL list
+ ck_assert_uint_eq(icListIndexOfS(NULL, "1"),-1);
+ // NULL string
+ ck_assert_uint_eq(icListIndexOfS(l, NULL),-1);
+ // non existing element
+ ck_assert_uint_eq(icListIndexOfS(l, "wfe"),-1);
+ // string in list
+ ck_assert_uint_eq(icListIndexOfS(l, "333"),2);
listFreeS(l);
- listFreeS(l2);
+
END_TEST
-START_TEST(listHasST)
+START_TEST(icListIndexOfCharST)
char **l = NULL;
// string
- listPushS(&l, "1");
+ listPushS(&l, "A");
listPushS(&l, "22");
listPushS(&l, "333");
listPushS(&l, "4444");
- ck_assert(listHasS(l, "1"));
+ ck_assert_uint_eq(icListIndexOfCharS(l, 'a'),0);
// NULL list
- ck_assert(!listHasS(NULL, "1"));
- // NULL string
- ck_assert(!listHasS(l, NULL));
+ ck_assert_uint_eq(icListIndexOfCharS(NULL, '1'),-1);
// non existing element
- ck_assert(!listHasS(l, "wfe"));
- // string in list
- ck_assert(listHasS(l, "333"));
+ ck_assert_uint_eq(icListIndexOfCharS(l, 'w'),-1);
listFreeS(l);
+
END_TEST
-START_TEST(listIndexOfST)
+START_TEST(icListBinarySearchST)
char **l = NULL;
// string
- listPushS(&l, "1");
+ listPushS(&l, "a");
listPushS(&l, "22");
listPushS(&l, "333");
listPushS(&l, "4444");
- ck_assert_uint_eq(listIndexOfS(l, "1"),0);
+ listPushS(&l, "ccc");
+ listPushS(&l, "6");
+ iListSortS(&l);
+ ck_assert_uint_eq(icListBinarySearchS(l, "A"),4);
// NULL list
- ck_assert_uint_eq(listIndexOfS(NULL, "1"),-1);
+ ck_assert_uint_eq(icListBinarySearchS(NULL, "1"),-1);
// NULL string
- ck_assert_uint_eq(listIndexOfS(l, NULL),-1);
+ ck_assert_uint_eq(icListBinarySearchS(l, NULL),-1);
// non existing element
- ck_assert_uint_eq(listIndexOfS(l, "wfe"),-1);
+ ck_assert_uint_eq(icListBinarySearchS(l, "wfe"),-1);
// string in list
- ck_assert_uint_eq(listIndexOfS(l, "333"),2);
+ ck_assert_uint_eq(icListBinarySearchS(l, "Ccc"),5);
listFreeS(l);
+
END_TEST
-START_TEST(listBinarySearchST)
+START_TEST(icListBinarySearchCharST)
char **l = NULL;
// string
- listPushS(&l, "1");
+ listPushS(&l, "A");
listPushS(&l, "22");
listPushS(&l, "333");
listPushS(&l, "4444");
- listPushS(&l, "5");
+ listPushS(&l, "C");
listPushS(&l, "6");
- ck_assert_uint_eq(listBinarySearchS(l, "1"),0);
+ iListSortS(&l);
+ ck_assert_uint_eq(icListBinarySearchCharS(l, 'a'),4);
// NULL list
- ck_assert_uint_eq(listBinarySearchS(NULL, "1"),-1);
- // NULL string
- ck_assert_uint_eq(listBinarySearchS(l, NULL),-1);
+ ck_assert_uint_eq(icListBinarySearchCharS(NULL, '1'),-1);
// non existing element
- ck_assert_uint_eq(listBinarySearchS(l, "wfe"),-1);
+ ck_assert_uint_eq(icListBinarySearchCharS(l, 'w'),-1);
// string in list
- ck_assert_uint_eq(listBinarySearchS(l, "333"),2);
+ ck_assert_uint_eq(icListBinarySearchCharS(l, 'c'),5);
listFreeS(l);
+
END_TEST
-START_TEST(listUniqST)
+START_TEST(icListUniqST)
char **l = NULL;
char **l2;
// list with unique elements
listPushS(&l, "1");
- listPushS(&l, "22");
+ listPushS(&l, "bb");
listPushS(&l, "333");
listPushS(&l, "4444");
- l2 = listUniqS(l);
+ l2 = icListUniqS(l);
ck_assert(listEqS(l,l2));
// list with identical elements
- l[2][0] = '2';
- l[2][1] = '2';
+ l[2][0] = 'B';
+ l[2][1] = 'B';
l[2][2] = 0;
listFreeS(l2);
- l2 = listUniqS(l);
+ l2 = icListUniqS(l);
ck_assert_uint_eq(listLengthS(l2),3);
ck_assert_str_eq(l2[2], "4444");
listFreeS(l);
@@ -7251,44 +16081,45 @@ START_TEST(listUniqST)
// list with one element
l = NULL;
listPushS(&l, "1");
- l2 = listUniqS(l);
+ l2 = icListUniqS(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);
+ l2 = icListUniqS(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);
+ ck_assert_ptr_eq(icListUniqS(NULL), NULL);
+
END_TEST
-START_TEST(iListUniqST)
+START_TEST(iicListUniqST)
char **l = NULL;
char **l2;
// list with unique elements
listPushS(&l, "1");
- listPushS(&l, "22");
+ listPushS(&l, "BB");
listPushS(&l, "333");
listPushS(&l, "4444");
l2 = listDupS(l);
- iListUniqS(&l2);
+ iicListUniqS(&l2);
ck_assert(listEqS(l,l2));
// list with identical elements
- l[2][0] = '2';
- l[2][1] = '2';
+ l[2][0] = 'b';
+ l[2][1] = 'b';
l[2][2] = 0;
listFreeS(l2);
l2 = listDupS(l);
- iListUniqS(&l2);
+ iicListUniqS(&l2);
ck_assert_uint_eq(listLengthS(l2),3);
ck_assert_str_eq(l2[2], "4444");
listFreeS(l);
@@ -7297,7 +16128,7 @@ START_TEST(iListUniqST)
l = NULL;
listPushS(&l, "1");
l2 = listDupS(l);
- iListUniqS(&l2);
+ iicListUniqS(&l2);
ck_assert_uint_eq(listLengthS(l2),1);
ck_assert_str_eq(l2[0], "1");
listFreeS(l);
@@ -7305,17 +16136,18 @@ START_TEST(iListUniqST)
// empty list
listEmptyS(l)
l2 = listDupS(l);
- iListUniqS(&l2);
+ iicListUniqS(&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);
+ iicListUniqS(&l);
ck_assert_ptr_eq(l, NULL);
// NULL var
- iListUniqS(NULL);
+ iicListUniqS(NULL);
+
END_TEST
@@ -7389,6 +16221,29 @@ START_TEST(iListCompactST)
END_TEST
+START_TEST(btraceEnableT)
+
+ btraceEnable();
+ ck_assert(btraceConfig());
+ btraceDisable();
+ ck_assert(!btraceConfig());
+
+
+END_TEST
+
+
+START_TEST(btraceT)
+
+ char **r;
+
+ r = btrace();
+ ck_assert_ptr_ne(r, null);
+ listFreeS(r);
+
+
+END_TEST
+
+
START_TEST(listEmptyFT)
void **l = NULL;
@@ -8534,6 +17389,25 @@ START_TEST(ringInitT)
END_TEST
+START_TEST(ringEmptyT)
+
+ ringTestT rg;
+ ringInit(&rg, 4);
+
+ // empty
+ ringPush(&rg);
+ ck_assert_int_eq(ringEmpty(&rg), 1);
+ ck_assert_int_eq(ringIsEmpty(&rg), 1);
+
+ // already empty
+ ck_assert_int_eq(ringEmpty(&rg), 1);
+
+ // null ring
+ ck_assert_int_eq(ringEmpty(null), 0);
+
+END_TEST
+
+
START_TEST(ringIsEmptyT)
ringTestT rg;
@@ -8779,18 +17653,41 @@ Suite * libsheepySuite(void) {
// disable btrace to make the test run faster
btraceDisable();
+ tcase_add_test(tc_core, cleanUpCharFreeT);
+ tcase_add_test(tc_core, cleanUpListFreeT);
+ tcase_add_test(tc_core, cleanUpFileFreeT);
+ tcase_add_test(tc_core, cleanUpCharFreeNullT);
+ tcase_add_test(tc_core, cleanUpListFreeNullT);
+ tcase_add_test(tc_core, cleanUpFileFreeNullT);
+ tcase_add_test(tc_core, setLogSymbolsT);
+ tcase_add_test(tc_core, setMaxLogLevelT);
+ tcase_add_test(tc_core, setLogShortPathT);
+ tcase_add_test(tc_core, setLogStdoutT);
+ tcase_add_test(tc_core, openProgLogFileT);
+ tcase_add_test(tc_core, shStopwatchT);
tcase_add_test(tc_core, setLogFileT);
tcase_add_test(tc_core, closeLogFilesT);
tcase_add_test(tc_core, getLogModeT);
tcase_add_test(tc_core, setLogModeT);
tcase_add_test(tc_core, _pLogT);
tcase_add_test(tc_core, initLibsheepyFT);
+ tcase_add_test(tc_core, setStackLimitT);
+ tcase_add_test(tc_core, setProgNameT);
tcase_add_test(tc_core, getProgPathT);
tcase_add_test(tc_core, getRealProgPathT);
tcase_add_test(tc_core, systemNFreeFT);
tcase_add_test(tc_core, getModificationTimeT);
tcase_add_test(tc_core, setModificationTimeT);
+ tcase_add_test(tc_core, isReadableT);
+ tcase_add_test(tc_core, isWritableT);
+ tcase_add_test(tc_core, isExecutableT);
tcase_add_test(tc_core, equalModificationTimesT);
+ tcase_add_test(tc_core, getCurrentUnixTimeT);
+ tcase_add_test(tc_core, strToUnixTimeT);
+ tcase_add_test(tc_core, timeToST);
+ tcase_add_test(tc_core, timeToYMDST);
+ tcase_add_test(tc_core, getCurrentDateT);
+ tcase_add_test(tc_core, getCurrentDateYMDT);
tcase_add_test(tc_core, shDirnameT);
tcase_add_test(tc_core, bDirnameT);
tcase_add_test(tc_core, bLDirnameT);
@@ -8802,21 +17699,36 @@ Suite * libsheepySuite(void) {
tcase_add_test(tc_core, iNormalizePathT);
tcase_add_test(tc_core, bNormalizePathT);
tcase_add_test(tc_core, bLNormalizePathT);
- tcase_add_test(tc_core, timeToST);
+ tcase_add_test(tc_core, relPathT);
+ tcase_add_test(tc_core, iRelPathT);
+ tcase_add_test(tc_core, bRelPathT);
+ tcase_add_test(tc_core, bLRelPathT);
+ tcase_add_test(tc_core, getHomePathT);
+ tcase_add_test(tc_core, getCwdT);
tcase_add_test(tc_core, chDirT);
tcase_add_test(tc_core, isDirT);
+ tcase_add_test(tc_core, shReadlinkT);
+ tcase_add_test(tc_core, endlinkT);
tcase_add_test(tc_core, isLinkT);
tcase_add_test(tc_core, fileExistsT);
tcase_add_test(tc_core, fileChmodT);
tcase_add_test(tc_core, fileSizeT);
+ tcase_add_test(tc_core, fileSizeFPT);
tcase_add_test(tc_core, readFileToST);
+ tcase_add_test(tc_core, readStreamToST);
tcase_add_test(tc_core, bReadFileToST);
+ tcase_add_test(tc_core, bReadStreamToST);
tcase_add_test(tc_core, bLReadFileToST);
+ tcase_add_test(tc_core, bLReadStreamToST);
tcase_add_test(tc_core, readFileT);
tcase_add_test(tc_core, bReadFileT);
tcase_add_test(tc_core, bLReadFileT);
tcase_add_test(tc_core, writeFileST);
tcase_add_test(tc_core, writeFileT);
+ tcase_add_test(tc_core, writeStreamST);
+ tcase_add_test(tc_core, writeLStreamT);
+ tcase_add_test(tc_core, appendFileST);
+ tcase_add_test(tc_core, appendFileT);
tcase_add_test(tc_core, walkDirT);
tcase_add_test(tc_core, walkDirDirT);
tcase_add_test(tc_core, readDirT);
@@ -8840,6 +17752,10 @@ Suite * libsheepySuite(void) {
tcase_add_test(tc_core, bRandomAlphaNumST);
tcase_add_test(tc_core, readST);
tcase_add_test(tc_core, bLReadST);
+ tcase_add_test(tc_core, readPasswordST);
+ tcase_add_test(tc_core, zeroST);
+ tcase_add_test(tc_core, zeroBufT);
+ tcase_add_test(tc_core, memdupT);
tcase_add_test(tc_core, readEnterT);
tcase_add_test(tc_core, readLineT);
tcase_add_test(tc_core, dupST);
@@ -8847,7 +17763,12 @@ Suite * libsheepySuite(void) {
tcase_add_test(tc_core, shEprintfT);
tcase_add_test(tc_core, freeManyST);
tcase_add_test(tc_core, logNFreeT);
+ tcase_add_test(tc_core, loghexT);
+ tcase_add_test(tc_core, toHexST);
+ tcase_add_test(tc_core, toHexSepST);
+ tcase_add_test(tc_core, toHexHeadSepST);
tcase_add_test(tc_core, strCpyT);
+ tcase_add_test(tc_core, strNCpyT);
tcase_add_test(tc_core, strLCpyT);
tcase_add_test(tc_core, strCatT);
tcase_add_test(tc_core, strNCatT);
@@ -8884,10 +17805,18 @@ Suite * libsheepySuite(void) {
tcase_add_test(tc_core, iReplaceCharCharST);
tcase_add_test(tc_core, bReplaceST);
tcase_add_test(tc_core, bLReplaceST);
+ tcase_add_test(tc_core, icReplaceST);
+ tcase_add_test(tc_core, iicReplaceST);
+ tcase_add_test(tc_core, bicReplaceST);
+ tcase_add_test(tc_core, bLicReplaceST);
tcase_add_test(tc_core, replaceManyST);
tcase_add_test(tc_core, iReplaceManyST);
tcase_add_test(tc_core, bReplaceManyST);
tcase_add_test(tc_core, bLReplaceManyST);
+ tcase_add_test(tc_core, icReplaceManyST);
+ tcase_add_test(tc_core, iicReplaceManyST);
+ tcase_add_test(tc_core, bicReplaceManyST);
+ tcase_add_test(tc_core, bLicReplaceManyST);
tcase_add_test(tc_core, eqST);
tcase_add_test(tc_core, eqCharST);
tcase_add_test(tc_core, eqSCharT);
@@ -8899,16 +17828,36 @@ Suite * libsheepySuite(void) {
tcase_add_test(tc_core, endsWithCharST);
tcase_add_test(tc_core, countST);
tcase_add_test(tc_core, countCharST);
+ tcase_add_test(tc_core, icEqST);
+ tcase_add_test(tc_core, icEqCharST);
+ tcase_add_test(tc_core, icEqSCharT);
+ tcase_add_test(tc_core, icEqIST);
+ tcase_add_test(tc_core, icEqICharST);
+ tcase_add_test(tc_core, icStartsWithST);
+ tcase_add_test(tc_core, icStartsWithCharST);
+ tcase_add_test(tc_core, icEndsWithST);
+ tcase_add_test(tc_core, icEndsWithCharST);
+ tcase_add_test(tc_core, icCountST);
+ tcase_add_test(tc_core, icCountCharST);
+ tcase_add_test(tc_core, hasCtrlCharT);
+ tcase_add_test(tc_core, stripCtrlST);
+ tcase_add_test(tc_core, iStripCtrlST);
+ tcase_add_test(tc_core, bStripCtrlST);
tcase_add_test(tc_core, isNumberT);
tcase_add_test(tc_core, isIntT);
tcase_add_test(tc_core, parseIntT);
tcase_add_test(tc_core, parseIntCharT);
+ tcase_add_test(tc_core, parseI64T);
+ tcase_add_test(tc_core, parseI64CharT);
tcase_add_test(tc_core, parseDoubleT);
+ tcase_add_test(tc_core, parseDoubleCharT);
+ tcase_add_test(tc_core, parseHexT);
tcase_add_test(tc_core, intToST);
tcase_add_test(tc_core, bIntToST);
tcase_add_test(tc_core, doubleToST);
tcase_add_test(tc_core, bDoubleToST);
tcase_add_test(tc_core, lenST);
+ tcase_add_test(tc_core, sizeST);
tcase_add_test(tc_core, upperST);
tcase_add_test(tc_core, iUpperST);
tcase_add_test(tc_core, bUpperST);
@@ -8927,11 +17876,66 @@ Suite * libsheepySuite(void) {
tcase_add_test(tc_core, uniqST);
tcase_add_test(tc_core, iUniqST);
tcase_add_test(tc_core, bUniqST);
+ tcase_add_test(tc_core, icUniqST);
+ tcase_add_test(tc_core, iicUniqST);
+ tcase_add_test(tc_core, bicUniqST);
+ tcase_add_test(tc_core, repeatST);
+ tcase_add_test(tc_core, iRepeatST);
+ tcase_add_test(tc_core, bRepeatST);
+ tcase_add_test(tc_core, bLRepeatST);
+ tcase_add_test(tc_core, repeatCharST);
+ tcase_add_test(tc_core, bRepeatCharST);
+ tcase_add_test(tc_core, bLRepeatCharST);
+ tcase_add_test(tc_core, repeatLenST);
+ tcase_add_test(tc_core, ellipsisStartST);
+ tcase_add_test(tc_core, iEllipsisStartST);
+ tcase_add_test(tc_core, bEllipsisStartST);
+ tcase_add_test(tc_core, bLEllipsisStartST);
+ tcase_add_test(tc_core, ellipsisStartCharST);
+ tcase_add_test(tc_core, iEllipsisStartCharST);
+ tcase_add_test(tc_core, bEllipsisStartCharST);
+ tcase_add_test(tc_core, bLEllipsisStartCharST);
+ tcase_add_test(tc_core, ellipsisLenST);
+ tcase_add_test(tc_core, ellipsisEndST);
+ tcase_add_test(tc_core, iEllipsisEndST);
+ tcase_add_test(tc_core, bEllipsisEndST);
+ tcase_add_test(tc_core, bLEllipsisEndST);
+ tcase_add_test(tc_core, ellipsisEndCharST);
+ tcase_add_test(tc_core, iEllipsisEndCharST);
+ tcase_add_test(tc_core, bEllipsisEndCharST);
+ tcase_add_test(tc_core, bLEllipsisEndCharST);
+ tcase_add_test(tc_core, padStartST);
+ tcase_add_test(tc_core, iPadStartST);
+ tcase_add_test(tc_core, bPadStartST);
+ tcase_add_test(tc_core, bLPadStartST);
+ tcase_add_test(tc_core, padStartCharST);
+ tcase_add_test(tc_core, iPadStartCharST);
+ tcase_add_test(tc_core, bPadStartCharST);
+ tcase_add_test(tc_core, bLPadStartCharST);
+ tcase_add_test(tc_core, padStartLenST);
+ tcase_add_test(tc_core, padEndST);
+ tcase_add_test(tc_core, iPadEndST);
+ tcase_add_test(tc_core, bPadEndST);
+ tcase_add_test(tc_core, bLPadEndST);
+ tcase_add_test(tc_core, padEndCharST);
+ tcase_add_test(tc_core, iPadEndCharST);
+ tcase_add_test(tc_core, bPadEndCharST);
+ tcase_add_test(tc_core, bLPadEndCharST);
+ tcase_add_test(tc_core, padEndLenST);
tcase_add_test(tc_core, getST);
tcase_add_test(tc_core, setST);
+ tcase_add_test(tc_core, swapST);
+ tcase_add_test(tc_core, iSwapST);
+ tcase_add_test(tc_core, bSwapST);
+ tcase_add_test(tc_core, bLSwapST);
tcase_add_test(tc_core, sliceST);
tcase_add_test(tc_core, iSliceST);
tcase_add_test(tc_core, bSliceST);
+ tcase_add_test(tc_core, bLSliceST);
+ tcase_add_test(tc_core, cropST);
+ tcase_add_test(tc_core, iCropST);
+ tcase_add_test(tc_core, cropElemST);
+ tcase_add_test(tc_core, iCropElemST);
tcase_add_test(tc_core, insertST);
tcase_add_test(tc_core, insertNFreeST);
tcase_add_test(tc_core, iInsertST);
@@ -8945,25 +17949,120 @@ Suite * libsheepySuite(void) {
tcase_add_test(tc_core, delST);
tcase_add_test(tc_core, iDelST);
tcase_add_test(tc_core, bDelST);
+ tcase_add_test(tc_core, bLDelST);
+ tcase_add_test(tc_core, delElemST);
+ tcase_add_test(tc_core, iDelElemST);
+ tcase_add_test(tc_core, bDelElemST);
+ tcase_add_test(tc_core, bLDelElemST);
tcase_add_test(tc_core, findST);
tcase_add_test(tc_core, findCharST);
+ tcase_add_test(tc_core, indexOfST);
+ tcase_add_test(tc_core, indexOfCharST);
tcase_add_test(tc_core, hasST);
tcase_add_test(tc_core, hasCharST);
+ tcase_add_test(tc_core, icFindST);
+ tcase_add_test(tc_core, icFindCharST);
+ tcase_add_test(tc_core, icIndexOfST);
+ tcase_add_test(tc_core, icIndexOfCharST);
+ tcase_add_test(tc_core, icHasST);
+ tcase_add_test(tc_core, icHasCharST);
+ tcase_add_test(tc_core, tokST);
+ tcase_add_test(tc_core, icTokST);
+ tcase_add_test(tc_core, lenUTF8T);
+ tcase_add_test(tc_core, bLLenUTF8T);
+ tcase_add_test(tc_core, isUTF8T);
+ tcase_add_test(tc_core, bLIsUTF8T);
+ tcase_add_test(tc_core, isCodeUTF8T);
+ tcase_add_test(tc_core, nextUTF8T);
+ tcase_add_test(tc_core, bLNextUTF8T);
+ tcase_add_test(tc_core, findNextUTF8T);
+ tcase_add_test(tc_core, prevUTF8T);
+ tcase_add_test(tc_core, bPrevUTF8T);
+ tcase_add_test(tc_core, idx2PtrUTF8T);
+ tcase_add_test(tc_core, bLIdx2PtrUTF8T);
+ tcase_add_test(tc_core, ptr2IdxUTF8T);
+ tcase_add_test(tc_core, bPtr2IdxUTF8T);
+ tcase_add_test(tc_core, bLPtr2IdxUTF8T);
+ tcase_add_test(tc_core, bLPtr2NegIdxUTF8T);
+ tcase_add_test(tc_core, makeValidUTF8T);
+ tcase_add_test(tc_core, bMakeValidUTF8T);
+ tcase_add_test(tc_core, nMakeValidUTF8T);
+ tcase_add_test(tc_core, bNMakeValidUTF8T);
+ tcase_add_test(tc_core, bLMakeValidUTF8T);
+ tcase_add_test(tc_core, bLNMakeValidUTF8T);
+ tcase_add_test(tc_core, strNCpyUTF8T);
+ tcase_add_test(tc_core, strLCpyUTF8T);
+ tcase_add_test(tc_core, strNCatUTF8T);
+ tcase_add_test(tc_core, strLCatUTF8T);
+ tcase_add_test(tc_core, strLNCatUTF8T);
+ tcase_add_test(tc_core, eqIUTF8T);
+ tcase_add_test(tc_core, eqICharUTF8T);
+ tcase_add_test(tc_core, icEqUTF8T);
+ tcase_add_test(tc_core, icEqCharUTF8T);
+ tcase_add_test(tc_core, icEqUTF8CharT);
+ tcase_add_test(tc_core, icStartsWithUTF8T);
+ tcase_add_test(tc_core, icEndsWithUTF8T);
+ tcase_add_test(tc_core, icCountUTF8T);
+ tcase_add_test(tc_core, code2RuneUTF8T);
+ tcase_add_test(tc_core, code2RuneLUTF8T);
+ tcase_add_test(tc_core, bRune2CodeUTF8T);
+ tcase_add_test(tc_core, runeLenUTF8T);
+ tcase_add_test(tc_core, toupperUTF8T);
+ tcase_add_test(tc_core, upperUTF8T);
+ tcase_add_test(tc_core, iUpperUTF8T);
+ tcase_add_test(tc_core, tolowerUTF8T);
+ tcase_add_test(tc_core, lowerUTF8T);
+ tcase_add_test(tc_core, iLowerUTF8T);
+ tcase_add_test(tc_core, uniqUTF8T);
+ tcase_add_test(tc_core, iUniqUTF8T);
+ tcase_add_test(tc_core, bUniqUTF8T);
+ tcase_add_test(tc_core, getUTF8T);
+ tcase_add_test(tc_core, setUTF8T);
+ tcase_add_test(tc_core, sliceUTF8T);
+ tcase_add_test(tc_core, iSliceUTF8T);
+ tcase_add_test(tc_core, bSliceUTF8T);
+ tcase_add_test(tc_core, bLSliceUTF8T);
+ tcase_add_test(tc_core, insertUTF8T);
+ tcase_add_test(tc_core, insertNFreeUTF8T);
+ tcase_add_test(tc_core, iInsertUTF8T);
+ tcase_add_test(tc_core, iInsertNFreeUTF8T);
+ tcase_add_test(tc_core, bInsertUTF8T);
+ tcase_add_test(tc_core, bLInsertUTF8T);
+ tcase_add_test(tc_core, delUTF8T);
+ tcase_add_test(tc_core, iDelUTF8T);
+ tcase_add_test(tc_core, bDelUTF8T);
+ tcase_add_test(tc_core, bLDelUTF8T);
+ tcase_add_test(tc_core, indexOfUTF8T);
+ tcase_add_test(tc_core, icHasUTF8T);
+ tcase_add_test(tc_core, icListSortUTF8T);
+ tcase_add_test(tc_core, iicListSortUTF8T);
+ tcase_add_test(tc_core, icListEqUTF8T);
+ tcase_add_test(tc_core, icListHasUTF8T);
+ tcase_add_test(tc_core, icListIndexOfUTF8T);
+ tcase_add_test(tc_core, icListBinarySearchUTF8T);
+ tcase_add_test(tc_core, icListUniqUTF8T);
+ tcase_add_test(tc_core, iicListUniqUTF8T);
tcase_add_test(tc_core, emptySFT);
tcase_add_test(tc_core, iEmptySFT);
tcase_add_test(tc_core, isEmptyST);
tcase_add_test(tc_core, isBlankST);
+ tcase_add_test(tc_core, intIndexT);
tcase_add_test(tc_core, listEmptySFT);
tcase_add_test(tc_core, iListEmptySFT);
tcase_add_test(tc_core, listIsEmptyST);
tcase_add_test(tc_core, listIsBlankST);
tcase_add_test(tc_core, listLengthST);
+ tcase_add_test(tc_core, listStrLengthST);
+ tcase_add_test(tc_core, listIntIndexST);
+ tcase_add_test(tc_core, listAddrST);
tcase_add_test(tc_core, listCreateST);
tcase_add_test(tc_core, listFromArrayST);
tcase_add_test(tc_core, listPushST);
+ tcase_add_test(tc_core, listPushCharST);
tcase_add_test(tc_core, iListPushST);
tcase_add_test(tc_core, listPopST);
tcase_add_test(tc_core, listPrependST);
+ tcase_add_test(tc_core, listPrependCharST);
tcase_add_test(tc_core, iListPrependST);
tcase_add_test(tc_core, listDequeueST);
tcase_add_test(tc_core, listFreeST);
@@ -8973,6 +18072,10 @@ Suite * libsheepySuite(void) {
tcase_add_test(tc_core, listEnumerateT);
tcase_add_test(tc_core, listSortST);
tcase_add_test(tc_core, iListSortST);
+ tcase_add_test(tc_core, listSortFST);
+ tcase_add_test(tc_core, iListSortFST);
+ tcase_add_test(tc_core, icListSortST);
+ tcase_add_test(tc_core, iicListSortST);
tcase_add_test(tc_core, readTextT);
tcase_add_test(tc_core, readStreamT);
tcase_add_test(tc_core, writeTextT);
@@ -8981,13 +18084,29 @@ Suite * libsheepySuite(void) {
tcase_add_test(tc_core, listGetST);
tcase_add_test(tc_core, iListGetST);
tcase_add_test(tc_core, listSetST);
+ tcase_add_test(tc_core, listSetCharST);
+ tcase_add_test(tc_core, listSwapST);
+ tcase_add_test(tc_core, iListSwapST);
tcase_add_test(tc_core, iListSetST);
- tcase_add_test(tc_core, tokST);
tcase_add_test(tc_core, splitT);
+ tcase_add_test(tc_core, splitCharT);
+ tcase_add_test(tc_core, icSplitT);
+ tcase_add_test(tc_core, icSplitCharT);
+ tcase_add_test(tc_core, joinLengthT);
tcase_add_test(tc_core, joinT);
+ tcase_add_test(tc_core, joinCharT);
tcase_add_test(tc_core, bJoinT);
+ tcase_add_test(tc_core, bJoinCharT);
tcase_add_test(tc_core, bLJoinT);
+ tcase_add_test(tc_core, bLJoinCharT);
tcase_add_test(tc_core, extractST);
+ tcase_add_test(tc_core, extractCharSST);
+ tcase_add_test(tc_core, extractSCharST);
+ tcase_add_test(tc_core, extractCharCharST);
+ tcase_add_test(tc_core, icExtractST);
+ tcase_add_test(tc_core, icExtractCharSST);
+ tcase_add_test(tc_core, icExtractSCharST);
+ tcase_add_test(tc_core, icExtractCharCharST);
tcase_add_test(tc_core, listDupST);
tcase_add_test(tc_core, iListDupST);
tcase_add_test(tc_core, listReverseST);
@@ -8996,26 +18115,55 @@ Suite * libsheepySuite(void) {
tcase_add_test(tc_core, listAppendST);
tcase_add_test(tc_core, iListAppendST);
tcase_add_test(tc_core, iListAppendNSmashST);
+ tcase_add_test(tc_core, listShiftST);
+ tcase_add_test(tc_core, iListShiftST);
+ tcase_add_test(tc_core, iListShiftNSmashST);
tcase_add_test(tc_core, listAddST);
tcase_add_test(tc_core, listSliceST);
tcase_add_test(tc_core, iListCopyST);
tcase_add_test(tc_core, iListSliceST);
+ tcase_add_test(tc_core, listCropST);
+ tcase_add_test(tc_core, iListCropST);
+ tcase_add_test(tc_core, listCropElemST);
+ tcase_add_test(tc_core, iListCropElemST);
tcase_add_test(tc_core, listInsertST);
tcase_add_test(tc_core, iListInsertST);
tcase_add_test(tc_core, iListInsertNFreeST);
tcase_add_test(tc_core, listInjectST);
+ tcase_add_test(tc_core, listInjectCharST);
tcase_add_test(tc_core, iListInjectST);
tcase_add_test(tc_core, listDelST);
tcase_add_test(tc_core, iListDelST);
+ tcase_add_test(tc_core, listDelElemST);
+ tcase_add_test(tc_core, iListDelElemST);
tcase_add_test(tc_core, execOutT);
+ tcase_add_test(tc_core, systemOutfT);
+ tcase_add_test(tc_core, systemfT);
+ tcase_add_test(tc_core, commandFT);
+ tcase_add_test(tc_core, commandfFT);
+ tcase_add_test(tc_core, commandNFreeFT);
tcase_add_test(tc_core, listEqST);
tcase_add_test(tc_core, listHasST);
+ tcase_add_test(tc_core, listHasCharST);
tcase_add_test(tc_core, listIndexOfST);
+ tcase_add_test(tc_core, listIndexOfCharST);
tcase_add_test(tc_core, listBinarySearchST);
+ tcase_add_test(tc_core, listBinarySearchCharST);
tcase_add_test(tc_core, listUniqST);
tcase_add_test(tc_core, iListUniqST);
+ tcase_add_test(tc_core, icListEqST);
+ tcase_add_test(tc_core, icListHasST);
+ tcase_add_test(tc_core, icListHasCharST);
+ tcase_add_test(tc_core, icListIndexOfST);
+ tcase_add_test(tc_core, icListIndexOfCharST);
+ tcase_add_test(tc_core, icListBinarySearchST);
+ tcase_add_test(tc_core, icListBinarySearchCharST);
+ tcase_add_test(tc_core, icListUniqST);
+ tcase_add_test(tc_core, iicListUniqST);
tcase_add_test(tc_core, listCompactST);
tcase_add_test(tc_core, iListCompactST);
+ tcase_add_test(tc_core, btraceEnableT);
+ tcase_add_test(tc_core, btraceT);
tcase_add_test(tc_core, listEmptyFT);
tcase_add_test(tc_core, iListEmptyFT);
tcase_add_test(tc_core, listIsEmptyT);
@@ -9052,6 +18200,7 @@ Suite * libsheepySuite(void) {
//tcase_add_test(tc_core, listCompactST);
//tcase_add_test(tc_core, iListCompactST);
tcase_add_test(tc_core, ringInitT);
+ tcase_add_test(tc_core, ringEmptyT);
tcase_add_test(tc_core, ringIsEmptyT);
tcase_add_test(tc_core, ringIsFullT);
tcase_add_test(tc_core, ringCountT);