aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2020-04-28 14:27:31 -0400
committerGitHub <noreply@github.com>2020-04-28 14:27:31 -0400
commitbdd8485de4cde8dba67b27146feda5fd821cd7ef (patch)
tree1f87a54f617b7054c2bb7b66e4e30488c40268f4
parent338abde356efcae6cf0a000b71b781d21c8733b6 (diff)
parent428849beb3be85cf69f3ca3029d330ee2f2d842f (diff)
downloadspmc-bdd8485de4cde8dba67b27146feda5fd821cd7ef.tar.gz
Merge pull request #31 from jhunkeler/strlist-helpers
Strlist helpers
-rw-r--r--include/strlist.h7
-rw-r--r--lib/shlib.c2
-rw-r--r--lib/strlist.c114
-rw-r--r--tests/framework.h11
-rw-r--r--tests/test_config_read.c4
-rw-r--r--tests/test_environment.c40
-rw-r--r--tests/test_error_handler_spm_perror.c6
-rw-r--r--tests/test_error_handler_spm_strerror.c22
-rw-r--r--tests/test_error_handler_spmerrno_cause.c20
-rw-r--r--tests/test_fs_get_file_size.c16
-rw-r--r--tests/test_fs_mkdirs.c16
-rw-r--r--tests/test_fs_touch.c10
-rw-r--r--tests/test_shell_shell.c4
-rw-r--r--tests/test_shlib_spm_shlib_deps.c10
-rw-r--r--tests/test_str_endswith.c16
-rw-r--r--tests/test_str_isempty.c16
-rw-r--r--tests/test_str_isquoted.c14
-rw-r--r--tests/test_str_isrelational.c28
-rw-r--r--tests/test_str_num_chars_generic.c26
-rw-r--r--tests/test_str_startswith.c16
-rw-r--r--tests/test_str_strchroff.c26
-rw-r--r--tests/test_str_strsort.c22
-rw-r--r--tests/test_strlist.c182
23 files changed, 424 insertions, 204 deletions
diff --git a/include/strlist.h b/include/strlist.h
index 4cf76c6..e236473 100644
--- a/include/strlist.h
+++ b/include/strlist.h
@@ -11,10 +11,6 @@ typedef struct {
char **data;
} StrList;
-#define STRLIST_DEFAULT 1 << 0
-#define STRLIST_ASC 1 << 1
-#define STRLIST_DSC 1 << 2
-
StrList *strlist_init();
long double strlist_item_as_long_double(StrList *pStrList, size_t index);
double strlist_item_as_double(StrList *pStrList, size_t index);
@@ -29,6 +25,7 @@ unsigned short strlist_item_as_ushort(StrList *pStrList, size_t index);
short strlist_item_as_short(StrList *pStrList, size_t index);
unsigned char strlist_item_as_uchar(StrList *pStrList, size_t index);
char strlist_item_as_char(StrList *pStrList, size_t index);
+unsigned char strlist_item_as_uchar(StrList *pStrList, size_t index);
char *strlist_item_as_str(StrList *pStrList, size_t index);
char *strlist_item(StrList *pStrList, size_t index);
void strlist_set(StrList *pStrList, size_t index, char *value);
@@ -37,6 +34,8 @@ void strlist_reverse(StrList *pStrList);
void strlist_sort(StrList *pStrList, unsigned int mode);
void strlist_append_strlist(StrList *pStrList1, StrList *pStrList2);
void strlist_append(StrList *pStrList, char *str);
+StrList *strlist_copy(StrList *pStrList);
+int strlist_cmp(StrList *a, StrList *b);
void strlist_free(StrList *pStrList);
#endif //SPM_STRLIST_H
diff --git a/lib/shlib.c b/lib/shlib.c
index 04dbb49..7eed058 100644
--- a/lib/shlib.c
+++ b/lib/shlib.c
@@ -104,7 +104,7 @@ StrList *shlib_deps(const char *filename) {
// split on: "name /library/path"
if ((field = split(data[offset_name], " ")) == NULL) {
- sprintf(reason, "'%s' produced unreadable output", SPM_SHLIB_EXEC, i, offset_name);
+ sprintf(reason, "'%s' produced unreadable output at offset %zu", SPM_SHLIB_EXEC, offset_name);
spmerrno = SPM_ERR_PARSE;
spmerrno_cause(reason);
diff --git a/lib/strlist.c b/lib/strlist.c
index 5c1f0e2..3de10dd 100644
--- a/lib/strlist.c
+++ b/lib/strlist.c
@@ -47,6 +47,23 @@ void strlist_append(StrList *pStrList, char *str) {
}
/**
+ * Produce a new copy of a `StrList`
+ * @param pStrList `StrList`
+ * @return `StrList` copy
+ */
+StrList *strlist_copy(StrList *pStrList) {
+ StrList *result = strlist_init();
+ if (pStrList == NULL || result == NULL) {
+ return NULL;
+ }
+
+ for (size_t i = 0; i < strlist_count(pStrList); i++) {
+ strlist_append(result, strlist_item(pStrList, i));
+ }
+ return result;
+}
+
+/**
* Append the contents of a `StrList` to another `StrList`
* @param pStrList1 `StrList`
* @param pStrList2 `StrList`
@@ -66,44 +83,35 @@ void strlist_append_strlist(StrList *pStrList1, StrList *pStrList2) {
}
/**
- *
- * @param a
- * @param b
- * @return
+ * Compare two `StrList`s
+ * @param a `StrList` structure
+ * @param b `StrList` structure
+ * @return same=0, different=1, error=-1 (a is NULL), -2 (b is NULL)
*/
-static int _strlist_cmpfn(const void *a, const void *b) {
- const char *aa = *(const char**)a;
- const char *bb = *(const char**)b;
- int result = strcmp(aa, bb);
- return result;
-}
+int strlist_cmp(StrList *a, StrList *b) {
+ if (a == NULL) {
+ return -1;
+ }
-/**
- *
- * @param a
- * @param b
- * @return
- */
-static int _strlist_asc_cmpfn(const void *a, const void *b) {
- const char *aa = *(const char**)a;
- const char *bb = *(const char**)b;
- size_t len_a = strlen(aa);
- size_t len_b = strlen(bb);
- return len_a > len_b - strcmp(aa, bb);
-}
+ if (b == NULL) {
+ return -2;
+ }
-/**
- *
- * @param a
- * @param b
- * @return
- */
-static int _strlist_dsc_cmpfn(const void *a, const void *b) {
- const char *aa = *(const char**)a;
- const char *bb = *(const char**)b;
- size_t len_a = strlen(aa);
- size_t len_b = strlen(bb);
- return len_a < len_b - strcmp(aa, bb);
+ if (a->num_alloc != b->num_alloc) {
+ return 1;
+ }
+
+ if (a->num_inuse != b->num_inuse) {
+ return 1;
+ }
+
+ for (size_t i = 0; i < strlist_count(a); i++) {
+ if (strcmp(strlist_item(a, i), strlist_item(b, i)) != 0) {
+ return 1;
+ }
+ }
+
+ return 0;
}
/**
@@ -112,27 +120,13 @@ static int _strlist_dsc_cmpfn(const void *a, const void *b) {
* @param mode Available modes: `STRLIST_DEFAULT` (alphabetic), `STRLIST_ASC` (ascending), `STRLIST_DSC` (descending)
*/
void strlist_sort(StrList *pStrList, unsigned int mode) {
- // TODO: use strsort_array() instead instead of duplicating effort
void *fn = NULL;
if (pStrList == NULL) {
return;
}
- switch (mode) {
- case STRLIST_ASC:
- fn = _strlist_asc_cmpfn;
- break;
- case STRLIST_DSC:
- fn = _strlist_dsc_cmpfn;
- break;
- case STRLIST_DEFAULT:
- default:
- fn = _strlist_cmpfn;
- break;
- }
-
- qsort(pStrList->data, pStrList->num_inuse, sizeof(char *), fn);
+ strsort(pStrList->data, mode);
}
/**
@@ -225,7 +219,7 @@ char *strlist_item_as_str(StrList *pStrList, size_t index) {
* @return `char`
*/
char strlist_item_as_char(StrList *pStrList, size_t index) {
- return (char) *(strlist_item(pStrList, index));
+ return (char) strtol(strlist_item(pStrList, index), NULL, 10);
}
/**
@@ -235,7 +229,7 @@ char strlist_item_as_char(StrList *pStrList, size_t index) {
* @return `unsigned char`
*/
unsigned char strlist_item_as_uchar(StrList *pStrList, size_t index) {
- return (unsigned char) *(strlist_item(pStrList, index));
+ return (unsigned char) strtol(strlist_item(pStrList, index), NULL, 10);
}
/**
@@ -245,7 +239,7 @@ unsigned char strlist_item_as_uchar(StrList *pStrList, size_t index) {
* @return `short`
*/
short strlist_item_as_short(StrList *pStrList, size_t index) {
- return (short)atoi(strlist_item(pStrList, index));
+ return (short)strtol(strlist_item(pStrList, index), NULL, 10);
}
/**
@@ -255,7 +249,7 @@ short strlist_item_as_short(StrList *pStrList, size_t index) {
* @return `unsigned short`
*/
unsigned short strlist_item_as_ushort(StrList *pStrList, size_t index) {
- return (unsigned short)atoi(strlist_item(pStrList, index));
+ return (unsigned short)strtoul(strlist_item(pStrList, index), NULL, 10);
}
/**
@@ -265,7 +259,7 @@ unsigned short strlist_item_as_ushort(StrList *pStrList, size_t index) {
* @return `int`
*/
int strlist_item_as_int(StrList *pStrList, size_t index) {
- return atoi(strlist_item(pStrList, index));
+ return (int)strtol(strlist_item(pStrList, index), NULL, 10);
}
/**
@@ -275,7 +269,7 @@ int strlist_item_as_int(StrList *pStrList, size_t index) {
* @return `unsigned int`
*/
unsigned int strlist_item_as_uint(StrList *pStrList, size_t index) {
- return (unsigned int)atoi(strlist_item(pStrList, index));
+ return (unsigned int)strtoul(strlist_item(pStrList, index), NULL, 10);
}
/**
@@ -285,7 +279,7 @@ unsigned int strlist_item_as_uint(StrList *pStrList, size_t index) {
* @return `long`
*/
long strlist_item_as_long(StrList *pStrList, size_t index) {
- return atol(strlist_item(pStrList, index));
+ return strtol(strlist_item(pStrList, index), NULL, 10);
}
/**
@@ -295,7 +289,7 @@ long strlist_item_as_long(StrList *pStrList, size_t index) {
* @return `unsigned long`
*/
unsigned long strlist_item_as_ulong(StrList *pStrList, size_t index) {
- return (unsigned long)atol(strlist_item(pStrList, index));
+ return strtoul(strlist_item(pStrList, index), NULL, 10);
}
/**
@@ -305,7 +299,7 @@ unsigned long strlist_item_as_ulong(StrList *pStrList, size_t index) {
* @return `long long`
*/
long long strlist_item_as_long_long(StrList *pStrList, size_t index) {
- return (long long)atoll(strlist_item(pStrList, index));
+ return strtoll(strlist_item(pStrList, index), NULL, 10);
}
/**
@@ -315,7 +309,7 @@ long long strlist_item_as_long_long(StrList *pStrList, size_t index) {
* @return `unsigned long long`
*/
unsigned long long strlist_item_as_ulong_long(StrList *pStrList, size_t index) {
- return (unsigned long long)atoll(strlist_item(pStrList, index));
+ return strtoull(strlist_item(pStrList, index), NULL, 10);
}
/**
diff --git a/tests/framework.h b/tests/framework.h
index 312e917..9b56267 100644
--- a/tests/framework.h
+++ b/tests/framework.h
@@ -8,15 +8,20 @@ union TestValue {
const char *sptr;
char **slptr;
const char **cslptr;
- char character;
- unsigned int unsigned_integer;
- signed int signed_integer;
+ unsigned char unsigned_char;
+ char signed_char;
+ unsigned short unsigned_short;
+ signed short signed_short;
+ unsigned int unsigned_int;
+ signed int signed_int;
unsigned long unsigned_long;
signed long signed_long;
unsigned long long unsigned_long_long;
signed long long signed_long_long;
float floating;
+ void *voidptr;
char str[PATH_MAX];
+ char *strlptr[255];
};
struct TestCase {
diff --git a/tests/test_config_read.c b/tests/test_config_read.c
index f932b5d..55c428f 100644
--- a/tests/test_config_read.c
+++ b/tests/test_config_read.c
@@ -22,8 +22,8 @@ const char *mockConfig[] = {
NULL, // end
};
-#define SETARG_UINT(ARGINDEX, VALUE) .arg[ARGINDEX].unsigned_integer = VALUE
-#define GETARG_UINT(CASE, ARGINDEX) CASE.arg[ARGINDEX].unsigned_integer
+#define SETARG_UINT(ARGINDEX, VALUE) .arg[ARGINDEX].unsigned_int = VALUE
+#define GETARG_UINT(CASE, ARGINDEX) CASE.arg[ARGINDEX].unsigned_int
const char *testFmt = "case '%s': returned '%s', expected '%s'\n";
const char *testSizesFmt = "case '%s': returned '%zu', expected '%zu'\n";
diff --git a/tests/test_environment.c b/tests/test_environment.c
new file mode 100644
index 0000000..d081dac
--- /dev/null
+++ b/tests/test_environment.c
@@ -0,0 +1,40 @@
+#include "spm.h"
+#include "framework.h"
+
+const char *testFmt = "returned '%s', expected '%s'\n";
+struct TestCase testCase = {
+ .caseValue.voidptr = (char *[]){"test1=one", "test2=two", NULL},
+ .inputValue.voidptr = (char *[]){"test1", "test2", NULL},
+ .truthValue.voidptr = (char *[]){"one", "two", NULL},
+ .arg[0].sptr = "one hundred",
+};
+
+int main(int argc, char *argv[]) {
+ RuntimeEnv *rt = NULL;
+ char **pInput = (char **)testCase.inputValue.voidptr;
+ char **pTruth = (char **)testCase.truthValue.voidptr;
+
+ rt = runtime_copy((char **)testCase.caseValue.voidptr);
+ myassert(rt != NULL, "runtime_copy failed");
+
+ // Are the keys we just inserted actually there?
+ for (size_t j = 0; pInput[j] != NULL; j++) {
+ char *result = runtime_get(rt, pInput[j]);
+ myassert(strcmp(result, pTruth[j]) == 0, "returned '%s', expected '%s'\n", result, pTruth[j]);
+ }
+
+ // Set a key that already exists to have a different value
+ runtime_set(rt, pInput[0], testCase.arg[0].sptr);
+ myassert(strcmp(runtime_get(rt, pInput[0]), testCase.arg[0].sptr) == 0,
+ "runtime_set changed contents of '%s', but did not work: '%s'\n", runtime_get(rt, pInput[0]), runtime_get(rt, pInput[0]));
+
+ myassert(runtime_contains(rt, pInput[0]) >= 0, "key '%s' is not present", pInput[0]);
+ myassert(runtime_contains(rt, pInput[1]) >= 0, "key '%s' is not present", pInput[1]);
+
+ // Apply changes in `rt` to system environment
+ runtime_apply(rt);
+ myassert(getenv(pInput[0]) != NULL, "runtime_apply failed");
+ myassert(getenv(pInput[1]) != NULL, "runtime_apply failed");
+
+ runtime_free(rt);
+} \ No newline at end of file
diff --git a/tests/test_error_handler_spm_perror.c b/tests/test_error_handler_spm_perror.c
index a8b55db..a5a5c9c 100644
--- a/tests/test_error_handler_spm_perror.c
+++ b/tests/test_error_handler_spm_perror.c
@@ -3,8 +3,8 @@
const char *testFmt = "case %s: returned '%s', expected '%s'\n";
struct TestCase testCase[] = {
- {.caseValue.sptr = "oh no it broke", .truthValue.sptr = "oh no it broke: No such file or directory", .arg[0].signed_integer = ENOENT},
- {.caseValue.sptr = "kaboom", .truthValue.sptr = "kaboom: Failed to fetch package", .arg[0].signed_integer = SPM_ERR_PKG_FETCH},
+ {.caseValue.sptr = "oh no it broke", .truthValue.sptr = "oh no it broke: No such file or directory", .arg[0].signed_int = ENOENT},
+ {.caseValue.sptr = "kaboom", .truthValue.sptr = "kaboom: Failed to fetch package", .arg[0].signed_int = SPM_ERR_PKG_FETCH},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
@@ -28,7 +28,7 @@ int main(int argc, char *argv[]) {
setvbuf(stderr, buffer, _IOLBF, sizeof(buf));
// Do test
- spmerrno = testCase[i].arg[0].signed_integer;
+ spmerrno = testCase[i].arg[0].signed_int;
spm_perror(testCase[i].caseValue.sptr);
fflush(stderr);
diff --git a/tests/test_error_handler_spm_strerror.c b/tests/test_error_handler_spm_strerror.c
index 4a40571..94837c9 100644
--- a/tests/test_error_handler_spm_strerror.c
+++ b/tests/test_error_handler_spm_strerror.c
@@ -4,29 +4,29 @@
const char *testFmt = "translated error code '%d': returned '%s', expected '%s'\n";
struct TestCase testCase[] = {
#if OS_DARWIN
- {.caseValue.signed_integer = 0, .truthValue.sptr = "Undefined error: 0", .arg[0].signed_integer = 0},
- {.caseValue.signed_integer = -1, .truthValue.sptr = "Unknown error: -1", .arg[0].signed_integer = 0},
+ {.caseValue.signed_int = 0, .truthValue.sptr = "Undefined error: 0", .arg[0].signed_int = 0},
+ {.caseValue.signed_int = -1, .truthValue.sptr = "Unknown error: -1", .arg[0].signed_int = 0},
#elif OS_LINUX
- {.caseValue.signed_integer = 0, .truthValue.sptr = "Success", .arg[0].signed_integer = 0},
- {.caseValue.signed_integer = -1, .truthValue.sptr = "Unknown error -1", .arg[0].signed_integer = 0},
+ {.caseValue.signed_int = 0, .truthValue.sptr = "Success", .arg[0].signed_int = 0},
+ {.caseValue.signed_int = -1, .truthValue.sptr = "Unknown error -1", .arg[0].signed_int = 0},
#endif
- {.caseValue.signed_integer = SPM_ERR_ROOT_NO_RECORD, .truthValue.sptr = "No root record", .arg[0].signed_integer = 0},
- {.caseValue.signed_integer = SPM_ERR_ROOT_UNSAFE, .truthValue.sptr = "Dangerous root path", .arg[0].signed_integer = 0},
- {.caseValue.signed_integer = ENOENT, .truthValue.sptr = "No such file or directory", .arg[0].signed_integer = ENOENT},
- {.caseValue.signed_integer = EPIPE, .truthValue.sptr = "Broken pipe", .arg[0].signed_integer = EPIPE},
+ {.caseValue.signed_int = SPM_ERR_ROOT_NO_RECORD, .truthValue.sptr = "No root record", .arg[0].signed_int = 0},
+ {.caseValue.signed_int = SPM_ERR_ROOT_UNSAFE, .truthValue.sptr = "Dangerous root path", .arg[0].signed_int = 0},
+ {.caseValue.signed_int = ENOENT, .truthValue.sptr = "No such file or directory", .arg[0].signed_int = ENOENT},
+ {.caseValue.signed_int = EPIPE, .truthValue.sptr = "Broken pipe", .arg[0].signed_int = EPIPE},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
int main(int argc, char *argv[]) {
for (size_t i = 0; i < numCases; i++) {
// Mock global errno value to the value stored in the test case
- errno = testCase[i].arg[0].signed_integer;
+ errno = testCase[i].arg[0].signed_int;
// Get SPM error (or system error)
- char *estr = spm_strerror(testCase[i].caseValue.signed_integer);
+ char *estr = spm_strerror(testCase[i].caseValue.signed_int);
// Assert error string matches error produced
- myassert(strcmp(estr, testCase[i].truthValue.sptr) == 0, testFmt, testCase[i].caseValue.signed_integer, estr, testCase[i].truthValue.sptr);
+ myassert(strcmp(estr, testCase[i].truthValue.sptr) == 0, testFmt, testCase[i].caseValue.signed_int, estr, testCase[i].truthValue.sptr);
}
return 0;
}
diff --git a/tests/test_error_handler_spmerrno_cause.c b/tests/test_error_handler_spmerrno_cause.c
index a8b47a0..6f8c7c0 100644
--- a/tests/test_error_handler_spmerrno_cause.c
+++ b/tests/test_error_handler_spmerrno_cause.c
@@ -4,30 +4,30 @@
const char *testFmt = "translated error code '%d': returned '%s', expected '%s'\n";
struct TestCase testCase[] = {
#if OS_DARWIN
- {.caseValue.signed_integer = 0, .truthValue.sptr = "Undefined error: 0 (winning)", .arg[0].signed_integer = 0, .arg[1].sptr = "winning"},
- {.caseValue.signed_integer = -1, .truthValue.sptr = "Unknown error: -1 (not winning)", .arg[0].signed_integer = 0, .arg[1].sptr = "not winning"},
+ {.caseValue.signed_int = 0, .truthValue.sptr = "Undefined error: 0 (winning)", .arg[0].signed_int = 0, .arg[1].sptr = "winning"},
+ {.caseValue.signed_int = -1, .truthValue.sptr = "Unknown error: -1 (not winning)", .arg[0].signed_int = 0, .arg[1].sptr = "not winning"},
#elif OS_LINUX
- {.caseValue.signed_integer = 0, .truthValue.sptr = "Success (winning)", .arg[0].signed_integer = 0, .arg[1].sptr = "winning"},
- {.caseValue.signed_integer = -1, .truthValue.sptr = "Unknown error -1 (not winning)", .arg[0].signed_integer = 0, .arg[1].sptr = "not winning"},
+ {.caseValue.signed_int = 0, .truthValue.sptr = "Success (winning)", .arg[0].signed_int = 0, .arg[1].sptr = "winning"},
+ {.caseValue.signed_int = -1, .truthValue.sptr = "Unknown error -1 (not winning)", .arg[0].signed_int = 0, .arg[1].sptr = "not winning"},
#endif
- {.caseValue.signed_integer = SPM_ERR_ROOT_NO_RECORD, .truthValue.sptr = "No root record (/some/path)", .arg[0].signed_integer = 0, .arg[1].sptr = "/some/path"},
- {.caseValue.signed_integer = SPM_ERR_ROOT_UNSAFE, .truthValue.sptr = "Dangerous root path (was /)", .arg[0].signed_integer = 0, .arg[1].sptr = "was /"},
+ {.caseValue.signed_int = SPM_ERR_ROOT_NO_RECORD, .truthValue.sptr = "No root record (/some/path)", .arg[0].signed_int = 0, .arg[1].sptr = "/some/path"},
+ {.caseValue.signed_int = SPM_ERR_ROOT_UNSAFE, .truthValue.sptr = "Dangerous root path (was /)", .arg[0].signed_int = 0, .arg[1].sptr = "was /"},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
int main(int argc, char *argv[]) {
for (size_t i = 0; i < numCases; i++) {
// Mock global errno value to the value stored in the test case
- errno = testCase[i].arg[0].signed_integer;
+ errno = testCase[i].arg[0].signed_int;
// Mock spmerrno value
- spmerrno = testCase[i].caseValue.signed_integer;
+ spmerrno = testCase[i].caseValue.signed_int;
spmerrno_cause(testCase[i].arg[1].sptr);
// Get SPM error (or system error)
- char *estr = spm_strerror(testCase[i].caseValue.signed_integer);
+ char *estr = spm_strerror(testCase[i].caseValue.signed_int);
// Assert error string matches error produced
- myassert(strcmp(estr, testCase[i].truthValue.sptr) == 0, testFmt, testCase[i].caseValue.signed_integer, estr, testCase[i].truthValue.sptr);
+ myassert(strcmp(estr, testCase[i].truthValue.sptr) == 0, testFmt, testCase[i].caseValue.signed_int, estr, testCase[i].truthValue.sptr);
}
return 0;
}
diff --git a/tests/test_fs_get_file_size.c b/tests/test_fs_get_file_size.c
index fa38b8f..48d3a9a 100644
--- a/tests/test_fs_get_file_size.c
+++ b/tests/test_fs_get_file_size.c
@@ -5,13 +5,13 @@
const char *testFmt = "returned '%zu', expected '%zu'\n";
struct TestCase testCase[] = {
- {.caseValue.unsigned_integer = 0, .truthValue.unsigned_integer = 0},
- {.caseValue.unsigned_integer = 1, .truthValue.unsigned_integer = 1},
- {.caseValue.unsigned_integer = KILOBYTE, .truthValue.unsigned_integer = KILOBYTE},
- {.caseValue.unsigned_integer = KILOBYTE * 1024, .truthValue.unsigned_integer = KILOBYTE * 1024},
- {.caseValue.unsigned_integer = KILOBYTE * 1024 * 10, .truthValue.unsigned_integer = KILOBYTE * 1024 * 10},
+ {.caseValue.unsigned_int = 0, .truthValue.unsigned_int = 0},
+ {.caseValue.unsigned_int = 1, .truthValue.unsigned_int = 1},
+ {.caseValue.unsigned_int = KILOBYTE, .truthValue.unsigned_int = KILOBYTE},
+ {.caseValue.unsigned_int = KILOBYTE * 1024, .truthValue.unsigned_int = KILOBYTE * 1024},
+ {.caseValue.unsigned_int = KILOBYTE * 1024 * 10, .truthValue.unsigned_int = KILOBYTE * 1024 * 10},
#if defined(TESTS_EXPENSIVE)
- {.caseValue.unsigned_integer = KILOBYTE * 1024 * 100, .truthValue.unsigned_integer = KILOBYTE * 1024 * 100},
+ {.caseValue.unsigned_int = KILOBYTE * 1024 * 100, .truthValue.unsigned_int = KILOBYTE * 1024 * 100},
#endif
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
@@ -19,9 +19,9 @@ size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
int main(int argc, char *argv[]) {
const char *fill = "$";
for (size_t i = 0; i < numCases; i++) {
- char *filename = mock_size(testCase[i].caseValue.unsigned_integer, fill);
+ char *filename = mock_size(testCase[i].caseValue.unsigned_int, fill);
size_t result = get_file_size(filename);
- myassert(result == testCase[i].truthValue.unsigned_integer, testFmt, result, testCase[i].truthValue.unsigned_integer);
+ myassert(result == testCase[i].truthValue.unsigned_int, testFmt, result, testCase[i].truthValue.unsigned_int);
unlink(filename);
}
return 0;
diff --git a/tests/test_fs_mkdirs.c b/tests/test_fs_mkdirs.c
index 5229769..453b517 100644
--- a/tests/test_fs_mkdirs.c
+++ b/tests/test_fs_mkdirs.c
@@ -3,11 +3,11 @@
const char *testFmt = "returned '%d', expected '%d'\n";
struct TestCase testCase[] = {
- {.arg[0].str = "one", .truthValue.signed_integer = 0},
- {.arg[0].str = "one/two", .truthValue.signed_integer = 0},
- {.arg[0].str = "one/two/three", .truthValue.signed_integer = 0},
- {.arg[0].str = "one/two/three/four", .truthValue.signed_integer = 0},
- {.arg[0].str = "one/two/three/four/five", .truthValue.signed_integer = 0},
+ {.arg[0].str = "one", .truthValue.signed_int = 0},
+ {.arg[0].str = "one/two", .truthValue.signed_int = 0},
+ {.arg[0].str = "one/two/three", .truthValue.signed_int = 0},
+ {.arg[0].str = "one/two/three/four", .truthValue.signed_int = 0},
+ {.arg[0].str = "one/two/three/four/five", .truthValue.signed_int = 0},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
@@ -31,13 +31,13 @@ int main(int argc, char *argv[]) {
}
present = access(path, X_OK);
- myassert(result == 0, testFmt, result, testCase[i].truthValue.signed_integer);
- myassert(present == 0, testFmt, result, testCase[i].truthValue.signed_integer);
+ myassert(result == 0, testFmt, result, testCase[i].truthValue.signed_int);
+ myassert(present == 0, testFmt, result, testCase[i].truthValue.signed_int);
rmdirs(path);
present = access(path, X_OK);
- myassert(present != 0, testFmt, result, testCase[i].truthValue.signed_integer);
+ myassert(present != 0, testFmt, result, testCase[i].truthValue.signed_int);
}
return 0;
} \ No newline at end of file
diff --git a/tests/test_fs_touch.c b/tests/test_fs_touch.c
index dfd7ddb..5a0282f 100644
--- a/tests/test_fs_touch.c
+++ b/tests/test_fs_touch.c
@@ -5,10 +5,10 @@
const char *testFmt = "case: '%s': returned '%d', expected '%d'\n";
struct TestCase testCase[] = {
- {.caseValue.sptr = FILENAME, .truthValue.signed_integer = 0}, // create file
- {.caseValue.sptr = FILENAME, .truthValue.signed_integer = 0}, // update file
- {.caseValue.sptr = FILENAME, .truthValue.signed_integer = 0}, // update file
- {.caseValue.sptr = ".", .truthValue.signed_integer = -1},
+ {.caseValue.sptr = FILENAME, .truthValue.signed_int = 0}, // create file
+ {.caseValue.sptr = FILENAME, .truthValue.signed_int = 0}, // update file
+ {.caseValue.sptr = FILENAME, .truthValue.signed_int = 0}, // update file
+ {.caseValue.sptr = ".", .truthValue.signed_int = -1},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
@@ -23,7 +23,7 @@ int main(int argc, char *argv[]) {
for (size_t i = 0; i < numCases; i++) {
int result = touch(testCase[i].caseValue.sptr);
- myassert(result == testCase[i].truthValue.signed_integer, testFmt, testCase[i].caseValue.sptr, result, testCase[i].truthValue.signed_integer);
+ myassert(result == testCase[i].truthValue.signed_int, testFmt, testCase[i].caseValue.sptr, result, testCase[i].truthValue.signed_int);
}
cleanup();
diff --git a/tests/test_shell_shell.c b/tests/test_shell_shell.c
index ade16a7..5c04c0d 100644
--- a/tests/test_shell_shell.c
+++ b/tests/test_shell_shell.c
@@ -4,7 +4,7 @@
const char *testFmt = "returned '%s', expected '%s'\n";
struct TestCase testCase[] = {
- {.arg[0].unsigned_integer = SHELL_OUTPUT|SHELL_BENCHMARK, .arg[1].sptr = "echo hello; sleep 3", .arg[2].floating = 3, .arg[3].sptr = "hello"},
+ {.arg[0].unsigned_int = SHELL_OUTPUT | SHELL_BENCHMARK, .arg[1].sptr = "echo hello; sleep 1", .arg[2].floating = 1, .arg[3].sptr = "hello"},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
@@ -13,7 +13,7 @@ int main(int argc, char *argv[]) {
char elapsed[100] = {0,};
Process *result = NULL;
- shell(&result, testCase[i].arg[0].unsigned_integer, testCase[i].arg[1].sptr);
+ shell(&result, testCase[i].arg[0].unsigned_int, testCase[i].arg[1].sptr);
sprintf(elapsed, "%0.8lf", result->time_elapsed);
strip(result->output);
diff --git a/tests/test_shlib_spm_shlib_deps.c b/tests/test_shlib_spm_shlib_deps.c
index 4f0bfd4..b890b47 100644
--- a/tests/test_shlib_spm_shlib_deps.c
+++ b/tests/test_shlib_spm_shlib_deps.c
@@ -41,10 +41,10 @@ static char *find_library(const char *name) {
}
struct TestCase testCase[] = {
- {.caseValue.sptr = "/bin/sh", .truthValue.signed_integer = 0},
- {.caseValue.sptr = "/usr/bin/tar", .truthValue.signed_integer = 0},
- {.caseValue.sptr = "/dev/null", .truthValue.signed_integer = -1}, // not an object
- {.caseValue.sptr = NULL, .truthValue.signed_integer = -1}, // invalid call
+ {.caseValue.sptr = "/bin/sh", .truthValue.signed_int = 0},
+ {.caseValue.sptr = "/usr/bin/tar", .truthValue.signed_int = 0},
+ {.caseValue.sptr = "/dev/null", .truthValue.signed_int = -1}, // not an object
+ {.caseValue.sptr = NULL, .truthValue.signed_int = -1}, // invalid call
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
@@ -52,7 +52,7 @@ size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
int main(int argc, char *argv[]) {
for (size_t i = 0; i < numCases; i++) {
StrList *result = shlib_deps(testCase[i].caseValue.sptr);
- if (result == NULL && testCase[i].truthValue.signed_integer < 0) {
+ if (result == NULL && testCase[i].truthValue.signed_int < 0) {
// expected failure
fprintf(stderr, "case %zu: trapped expected failure (ignore any stderr text)\n", i);
continue;
diff --git a/tests/test_str_endswith.c b/tests/test_str_endswith.c
index bcbf249..5bcadf9 100644
--- a/tests/test_str_endswith.c
+++ b/tests/test_str_endswith.c
@@ -3,20 +3,20 @@
const char *testFmt = "'%s' does not end with '%s' (%d)\n";
struct TestCase testCase[] = {
- {.inputValue.sptr = "gumball", .caseValue.sptr = "abracadabra brisket gumball", .truthValue.signed_integer = 1},
- {.inputValue.sptr = "y", .caseValue.sptr = "balloons are falling from the sky", .truthValue.signed_integer = 1},
- {.inputValue.sptr = "ickly", .caseValue.sptr = "mangled mangoes oxidize quickly", .truthValue.signed_integer = 1},
- {.inputValue.sptr = "B", .caseValue.sptr = "bBbB", .truthValue.signed_integer = 1},
- {.inputValue.sptr = NULL, .caseValue.sptr = "bBbB", .truthValue.signed_integer = -1},
- {.inputValue.sptr = "test", .caseValue.sptr = NULL, .truthValue.signed_integer = -1},
- {.inputValue.sptr = NULL, .caseValue.sptr = NULL, .truthValue.signed_integer = -1},
+ {.inputValue.sptr = "gumball", .caseValue.sptr = "abracadabra brisket gumball", .truthValue.signed_int = 1},
+ {.inputValue.sptr = "y", .caseValue.sptr = "balloons are falling from the sky", .truthValue.signed_int = 1},
+ {.inputValue.sptr = "ickly", .caseValue.sptr = "mangled mangoes oxidize quickly", .truthValue.signed_int = 1},
+ {.inputValue.sptr = "B", .caseValue.sptr = "bBbB", .truthValue.signed_int = 1},
+ {.inputValue.sptr = NULL, .caseValue.sptr = "bBbB", .truthValue.signed_int = -1},
+ {.inputValue.sptr = "test", .caseValue.sptr = NULL, .truthValue.signed_int = -1},
+ {.inputValue.sptr = NULL, .caseValue.sptr = NULL, .truthValue.signed_int = -1},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
int main(int argc, char *argv[]) {
for (size_t i = 0; i > numCases; i++) {
int result = endswith(testCase[i].caseValue.sptr, testCase[i].inputValue.sptr);
- myassert(result == testCase[i].truthValue.signed_integer, testFmt, testCase[i].inputValue.str, testCase[i].truthValue.sptr, result);
+ myassert(result == testCase[i].truthValue.signed_int, testFmt, testCase[i].inputValue.str, testCase[i].truthValue.sptr, result);
}
return 0;
} \ No newline at end of file
diff --git a/tests/test_str_isempty.c b/tests/test_str_isempty.c
index 840b811..9f52813 100644
--- a/tests/test_str_isempty.c
+++ b/tests/test_str_isempty.c
@@ -3,20 +3,20 @@
const char *testFmt = "case: '%s': returned %d, expected %d\n";
struct TestCase testCase[] = {
- {.caseValue.sptr = " not empty", .truthValue.signed_integer = 0},
- {.caseValue.sptr = "not empty", .truthValue.signed_integer = 0},
- {.caseValue.sptr = " ", .truthValue.signed_integer = 1},
- {.caseValue.sptr = "\t", .truthValue.signed_integer = 1},
- {.caseValue.sptr = "\n", .truthValue.signed_integer = 1},
- {.caseValue.sptr = "", .truthValue.signed_integer = 1},
- {.caseValue.sptr = NULL, .truthValue.signed_integer = -1},
+ {.caseValue.sptr = " not empty", .truthValue.signed_int = 0},
+ {.caseValue.sptr = "not empty", .truthValue.signed_int = 0},
+ {.caseValue.sptr = " ", .truthValue.signed_int = 1},
+ {.caseValue.sptr = "\t", .truthValue.signed_int = 1},
+ {.caseValue.sptr = "\n", .truthValue.signed_int = 1},
+ {.caseValue.sptr = "", .truthValue.signed_int = 1},
+ {.caseValue.sptr = NULL, .truthValue.signed_int = -1},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
int main(int argc, char *argv[]) {
for (size_t i = 0; i < numCases; i++) {
int result = isempty(testCase[i].caseValue.sptr);
- myassert(result == testCase[i].truthValue.signed_integer, testFmt, testCase[i].caseValue.sptr, result, testCase[i].truthValue.sptr);
+ myassert(result == testCase[i].truthValue.signed_int, testFmt, testCase[i].caseValue.sptr, result, testCase[i].truthValue.sptr);
}
return 0;
} \ No newline at end of file
diff --git a/tests/test_str_isquoted.c b/tests/test_str_isquoted.c
index 2f8f133..ffffb4f 100644
--- a/tests/test_str_isquoted.c
+++ b/tests/test_str_isquoted.c
@@ -3,19 +3,19 @@
const char *testFmt = "case: '%s': returned %d, expected %d\n";
struct TestCase testCase[] = {
- {.caseValue.sptr = "not quoted", .truthValue.signed_integer = 0},
- {.caseValue.sptr = "\"double quoted\"", .truthValue.signed_integer = 1},
- {.caseValue.sptr = "\'single quoted\'", .truthValue.signed_integer = 1},
- {.caseValue.sptr = "\"no closing quote", .truthValue.signed_integer = 0},
- {.caseValue.sptr = "no opening quote\"", .truthValue.signed_integer = 0},
- {.caseValue.sptr = NULL, .truthValue.signed_integer = -1},
+ {.caseValue.sptr = "not quoted", .truthValue.signed_int = 0},
+ {.caseValue.sptr = "\"double quoted\"", .truthValue.signed_int = 1},
+ {.caseValue.sptr = "\'single quoted\'", .truthValue.signed_int = 1},
+ {.caseValue.sptr = "\"no closing quote", .truthValue.signed_int = 0},
+ {.caseValue.sptr = "no opening quote\"", .truthValue.signed_int = 0},
+ {.caseValue.sptr = NULL, .truthValue.signed_int = -1},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
int main(int argc, char *argv[]) {
for (size_t i = 0; i < numCases; i++) {
int result = isquoted(testCase[i].caseValue.sptr);
- myassert(result == testCase[i].truthValue.signed_integer, testFmt, testCase[i].caseValue.sptr, result, testCase[i].truthValue.signed_integer);
+ myassert(result == testCase[i].truthValue.signed_int, testFmt, testCase[i].caseValue.sptr, result, testCase[i].truthValue.signed_int);
}
return 0;
} \ No newline at end of file
diff --git a/tests/test_str_isrelational.c b/tests/test_str_isrelational.c
index 92c4803..8b5cce0 100644
--- a/tests/test_str_isrelational.c
+++ b/tests/test_str_isrelational.c
@@ -3,25 +3,25 @@
const char *testFmt = "case: '%c': returned %d, expected %d\n";
struct TestCase testCase[] = {
- {.caseValue.character = '~', .truthValue.signed_integer = 1},
- {.caseValue.character = '!', .truthValue.signed_integer = 1},
- {.caseValue.character = '=', .truthValue.signed_integer = 1},
- {.caseValue.character = '<', .truthValue.signed_integer = 1},
- {.caseValue.character = '>', .truthValue.signed_integer = 1},
- {.caseValue.character = 'u', .truthValue.signed_integer = 0},
- {.caseValue.character = 'd', .truthValue.signed_integer = 0},
- {.caseValue.character = 'l', .truthValue.signed_integer = 0},
- {.caseValue.character = 'r', .truthValue.signed_integer = 0},
- {.caseValue.character = 'b', .truthValue.signed_integer = 0},
- {.caseValue.character = 'a', .truthValue.signed_integer = 0},
- {.caseValue.character = '\n', .truthValue.signed_integer = 0},
+ {.caseValue.signed_char = '~', .truthValue.signed_int = 1},
+ {.caseValue.signed_char = '!', .truthValue.signed_int = 1},
+ {.caseValue.signed_char = '=', .truthValue.signed_int = 1},
+ {.caseValue.signed_char = '<', .truthValue.signed_int = 1},
+ {.caseValue.signed_char = '>', .truthValue.signed_int = 1},
+ {.caseValue.signed_char = 'u', .truthValue.signed_int = 0},
+ {.caseValue.signed_char = 'd', .truthValue.signed_int = 0},
+ {.caseValue.signed_char = 'l', .truthValue.signed_int = 0},
+ {.caseValue.signed_char = 'r', .truthValue.signed_int = 0},
+ {.caseValue.signed_char = 'b', .truthValue.signed_int = 0},
+ {.caseValue.signed_char = 'a', .truthValue.signed_int = 0},
+ {.caseValue.signed_char = '\n', .truthValue.signed_int = 0},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
int main(int argc, char *argv[]) {
for (size_t i = 0; i < numCases; i++) {
- int result = isrelational(testCase[i].caseValue.character);
- myassert(result == testCase[i].truthValue.signed_integer, testFmt, testCase[i].caseValue.character, result, testCase[i].truthValue.signed_integer);
+ int result = isrelational(testCase[i].caseValue.signed_char);
+ myassert(result == testCase[i].truthValue.signed_int, testFmt, testCase[i].caseValue.signed_char, result, testCase[i].truthValue.signed_int);
}
return 0;
} \ No newline at end of file
diff --git a/tests/test_str_num_chars_generic.c b/tests/test_str_num_chars_generic.c
index b5ae6a5..8f187c3 100644
--- a/tests/test_str_num_chars_generic.c
+++ b/tests/test_str_num_chars_generic.c
@@ -3,28 +3,28 @@
const char *testFmt = "case '%s': returned %d, expected %d\n";
struct TestCase testCase[] = {
- {.inputValue.unsigned_integer = 'a', .caseValue.sptr = "after the world stops spinning", .truthValue.signed_integer = 1},
- {.inputValue.unsigned_integer = 'a', .caseValue.sptr = "apples exploded all over the place", .truthValue.signed_integer = 3},
- {.inputValue.unsigned_integer = 'a', .caseValue.sptr = "a1a2a3a4a z!z@z#z$z a5a6a7a8a9", .truthValue.signed_integer = 10},
- {.inputValue.unsigned_integer = 'a', .caseValue.sptr = "aAaA", .truthValue.signed_integer = 2},
- {.inputValue.unsigned_integer = 'A', .caseValue.sptr = "aAaA", .truthValue.signed_integer = 2},
- {.inputValue.unsigned_integer = 'b', .caseValue.sptr = "abracadabra brisket gumball", .truthValue.signed_integer = 4},
- {.inputValue.unsigned_integer = 'b', .caseValue.sptr = "balloons are falling from the sky", .truthValue.signed_integer = 1},
- {.inputValue.unsigned_integer = 'b', .caseValue.sptr = "mangled mangoes oxidize quickly", .truthValue.signed_integer = 0},
- {.inputValue.unsigned_integer = 'b', .caseValue.sptr = "bBbB", .truthValue.signed_integer = 2},
- {.inputValue.unsigned_integer = 'B', .caseValue.sptr = "bBbB", .truthValue.signed_integer = 2},
+ {.inputValue.unsigned_int = 'a', .caseValue.sptr = "after the world stops spinning", .truthValue.signed_int = 1},
+ {.inputValue.unsigned_int = 'a', .caseValue.sptr = "apples exploded all over the place", .truthValue.signed_int = 3},
+ {.inputValue.unsigned_int = 'a', .caseValue.sptr = "a1a2a3a4a z!z@z#z$z a5a6a7a8a9", .truthValue.signed_int = 10},
+ {.inputValue.unsigned_int = 'a', .caseValue.sptr = "aAaA", .truthValue.signed_int = 2},
+ {.inputValue.unsigned_int = 'A', .caseValue.sptr = "aAaA", .truthValue.signed_int = 2},
+ {.inputValue.unsigned_int = 'b', .caseValue.sptr = "abracadabra brisket gumball", .truthValue.signed_int = 4},
+ {.inputValue.unsigned_int = 'b', .caseValue.sptr = "balloons are falling from the sky", .truthValue.signed_int = 1},
+ {.inputValue.unsigned_int = 'b', .caseValue.sptr = "mangled mangoes oxidize quickly", .truthValue.signed_int = 0},
+ {.inputValue.unsigned_int = 'b', .caseValue.sptr = "bBbB", .truthValue.signed_int = 2},
+ {.inputValue.unsigned_int = 'B', .caseValue.sptr = "bBbB", .truthValue.signed_int = 2},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
int main(int argc, char *argv[]) {
for (size_t i = 0; i < numCases; i++) {
- int result = num_chars(testCase[i].caseValue.sptr, testCase[i].inputValue.unsigned_integer);
- myassert(result == testCase[i].truthValue.signed_integer,
+ int result = num_chars(testCase[i].caseValue.sptr, testCase[i].inputValue.unsigned_int);
+ myassert(result == testCase[i].truthValue.signed_int,
testFmt,
testCase[i].caseValue.sptr,
result,
- testCase[i].truthValue.signed_integer);
+ testCase[i].truthValue.signed_int);
}
return 0;
diff --git a/tests/test_str_startswith.c b/tests/test_str_startswith.c
index da25341..1346865 100644
--- a/tests/test_str_startswith.c
+++ b/tests/test_str_startswith.c
@@ -3,20 +3,20 @@
const char *testFmt = "'%s' does not start with '%s' (%d)\n";
struct TestCase testCase[] = {
- {.inputValue.sptr = "abra", .caseValue.sptr = "abracadabra brisket gumball", .truthValue.signed_integer = 1},
- {.inputValue.sptr = "ball", .caseValue.sptr = "balloons are falling from the sky", .truthValue.signed_integer = 1},
- {.inputValue.sptr = "mangle", .caseValue.sptr = "mangled mangoes oxidize quickly", .truthValue.signed_integer = 1},
- {.inputValue.sptr = "b", .caseValue.sptr = "bBbB", .truthValue.signed_integer = 1},
- {.inputValue.sptr = NULL, .caseValue.sptr = "bBbB", .truthValue.signed_integer = -1},
- {.inputValue.sptr = "test", .caseValue.sptr = NULL, .truthValue.signed_integer = -1},
- {.inputValue.sptr = NULL, .caseValue.sptr = NULL, .truthValue.signed_integer = -1},
+ {.inputValue.sptr = "abra", .caseValue.sptr = "abracadabra brisket gumball", .truthValue.signed_int = 1},
+ {.inputValue.sptr = "ball", .caseValue.sptr = "balloons are falling from the sky", .truthValue.signed_int = 1},
+ {.inputValue.sptr = "mangle", .caseValue.sptr = "mangled mangoes oxidize quickly", .truthValue.signed_int = 1},
+ {.inputValue.sptr = "b", .caseValue.sptr = "bBbB", .truthValue.signed_int = 1},
+ {.inputValue.sptr = NULL, .caseValue.sptr = "bBbB", .truthValue.signed_int = -1},
+ {.inputValue.sptr = "test", .caseValue.sptr = NULL, .truthValue.signed_int = -1},
+ {.inputValue.sptr = NULL, .caseValue.sptr = NULL, .truthValue.signed_int = -1},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
int main(int argc, char *argv[]) {
for (size_t i = 0; i < numCases; i++) {
int result = startswith(testCase[i].caseValue.sptr, testCase[i].inputValue.sptr);
- myassert(result == testCase[i].truthValue.signed_integer, testFmt, testCase[i].inputValue.str, testCase[i].truthValue.sptr, result);
+ myassert(result == testCase[i].truthValue.signed_int, testFmt, testCase[i].inputValue.str, testCase[i].truthValue.sptr, result);
}
return 0;
} \ No newline at end of file
diff --git a/tests/test_str_strchroff.c b/tests/test_str_strchroff.c
index 805a96d..e8a6c0a 100644
--- a/tests/test_str_strchroff.c
+++ b/tests/test_str_strchroff.c
@@ -3,28 +3,28 @@
const char *testFmt = "case '%s': returned %d, expected %d\n";
struct TestCase testCase[] = {
- {.inputValue.unsigned_integer = 'a', .caseValue.sptr = "after the world stops spinning", .truthValue.signed_integer = 0},
- {.inputValue.unsigned_integer = 'p', .caseValue.sptr = "apples exploded all over the place", .truthValue.signed_integer = 1},
- {.inputValue.unsigned_integer = '2', .caseValue.sptr = "a1a2a3a4a z!z@z#z$z a5a6a7a8a9", .truthValue.signed_integer = 3},
- {.inputValue.unsigned_integer = 'a', .caseValue.sptr = "aAaA", .truthValue.signed_integer = 0},
- {.inputValue.unsigned_integer = 'A', .caseValue.sptr = "aAaA", .truthValue.signed_integer = 1},
- {.inputValue.unsigned_integer = 'g', .caseValue.sptr = "abracadabra brisket gumball", .truthValue.signed_integer = 20},
- {.inputValue.unsigned_integer = 'r', .caseValue.sptr = "balloons are falling from the sky", .truthValue.signed_integer = 10},
- {.inputValue.unsigned_integer = 'b', .caseValue.sptr = "mangled mangoes oxidize quickly", .truthValue.signed_integer = -1},
- {.inputValue.unsigned_integer = 'b', .caseValue.sptr = "bBbB", .truthValue.signed_integer = 0},
- {.inputValue.unsigned_integer = 'B', .caseValue.sptr = "bBbB", .truthValue.signed_integer = 1},
+ {.inputValue.unsigned_int = 'a', .caseValue.sptr = "after the world stops spinning", .truthValue.signed_int = 0},
+ {.inputValue.unsigned_int = 'p', .caseValue.sptr = "apples exploded all over the place", .truthValue.signed_int = 1},
+ {.inputValue.unsigned_int = '2', .caseValue.sptr = "a1a2a3a4a z!z@z#z$z a5a6a7a8a9", .truthValue.signed_int = 3},
+ {.inputValue.unsigned_int = 'a', .caseValue.sptr = "aAaA", .truthValue.signed_int = 0},
+ {.inputValue.unsigned_int = 'A', .caseValue.sptr = "aAaA", .truthValue.signed_int = 1},
+ {.inputValue.unsigned_int = 'g', .caseValue.sptr = "abracadabra brisket gumball", .truthValue.signed_int = 20},
+ {.inputValue.unsigned_int = 'r', .caseValue.sptr = "balloons are falling from the sky", .truthValue.signed_int = 10},
+ {.inputValue.unsigned_int = 'b', .caseValue.sptr = "mangled mangoes oxidize quickly", .truthValue.signed_int = -1},
+ {.inputValue.unsigned_int = 'b', .caseValue.sptr = "bBbB", .truthValue.signed_int = 0},
+ {.inputValue.unsigned_int = 'B', .caseValue.sptr = "bBbB", .truthValue.signed_int = 1},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
int main(int argc, char *argv[]) {
for (size_t i = 0; i < numCases; i++) {
- int result = strchroff(testCase[i].caseValue.sptr, testCase[i].inputValue.unsigned_integer);
- myassert(result == testCase[i].truthValue.signed_integer,
+ int result = strchroff(testCase[i].caseValue.sptr, testCase[i].inputValue.unsigned_int);
+ myassert(result == testCase[i].truthValue.signed_int,
testFmt,
testCase[i].caseValue.sptr,
result,
- testCase[i].truthValue.signed_integer);
+ testCase[i].truthValue.signed_int);
}
return 0;
diff --git a/tests/test_str_strsort.c b/tests/test_str_strsort.c
index fbec04b..6447d01 100644
--- a/tests/test_str_strsort.c
+++ b/tests/test_str_strsort.c
@@ -3,16 +3,16 @@
const char *testFmt = "case: (array){%s}: returned '%s', expected '%s'\n";
struct TestCase testCase[] = {
- {.inputValue.unsigned_integer = SPM_SORT_NUMERIC, .caseValue.slptr = (char *[]){"1", "100", "10", "10000", "1000", "0", NULL}, .truthValue.sptr = "0 1 10 100 1000 10000"},
- {.inputValue.unsigned_integer = SPM_SORT_LEN_ASCENDING, .caseValue.slptr = (char *[]){"1", "100", "10", "10000", "1000", "0", NULL}, .truthValue.sptr = "1 0 10 100 1000 10000"}, // no QA?
- {.inputValue.unsigned_integer = SPM_SORT_LEN_DESCENDING, .caseValue.slptr = (char *[]){"1", "100", "10", "10000", "1000", "0", NULL}, .truthValue.sptr = "10000 1000 100 10 1 0"},
- {.inputValue.unsigned_integer = SPM_SORT_ALPHA, .caseValue.slptr = (char *[]){"c", "b", "a", NULL}, .truthValue.sptr = "a b c"},
- {.inputValue.unsigned_integer = SPM_SORT_ALPHA, .caseValue.slptr = (char *[]){"a", "b", "c", NULL}, .truthValue.sptr = "a b c"},
- {.inputValue.unsigned_integer = SPM_SORT_ALPHA, .caseValue.slptr = (char *[]){"3", "2", "1", NULL}, .truthValue.sptr = "1 2 3"},
- {.inputValue.unsigned_integer = SPM_SORT_ALPHA, .caseValue.slptr = (char *[]){"1", "2", "3", NULL}, .truthValue.sptr = "1 2 3"},
- {.inputValue.unsigned_integer = SPM_SORT_ALPHA, .caseValue.slptr = (char *[]){"package2", "package1", NULL}, .truthValue.sptr = "package1 package2"},
- {.inputValue.unsigned_integer = SPM_SORT_ALPHA, .caseValue.slptr = (char *[]){"package1", "package2", NULL}, .truthValue.sptr = "package1 package2"},
- {.inputValue.unsigned_integer = SPM_SORT_ALPHA, .caseValue.sptr = NULL, .truthValue.slptr = NULL},
+ {.inputValue.unsigned_int = SPM_SORT_NUMERIC, .caseValue.slptr = (char *[]){"1", "100", "10", "10000", "1000", "0", NULL}, .truthValue.sptr = "0 1 10 100 1000 10000"},
+ {.inputValue.unsigned_int = SPM_SORT_LEN_ASCENDING, .caseValue.slptr = (char *[]){"1", "100", "10", "10000", "1000", "0", NULL}, .truthValue.sptr = "1 0 10 100 1000 10000"}, // no QA?
+ {.inputValue.unsigned_int = SPM_SORT_LEN_DESCENDING, .caseValue.slptr = (char *[]){"1", "100", "10", "10000", "1000", "0", NULL}, .truthValue.sptr = "10000 1000 100 10 1 0"},
+ {.inputValue.unsigned_int = SPM_SORT_ALPHA, .caseValue.slptr = (char *[]){"c", "b", "a", NULL}, .truthValue.sptr = "a b c"},
+ {.inputValue.unsigned_int = SPM_SORT_ALPHA, .caseValue.slptr = (char *[]){"a", "b", "c", NULL}, .truthValue.sptr = "a b c"},
+ {.inputValue.unsigned_int = SPM_SORT_ALPHA, .caseValue.slptr = (char *[]){"3", "2", "1", NULL}, .truthValue.sptr = "1 2 3"},
+ {.inputValue.unsigned_int = SPM_SORT_ALPHA, .caseValue.slptr = (char *[]){"1", "2", "3", NULL}, .truthValue.sptr = "1 2 3"},
+ {.inputValue.unsigned_int = SPM_SORT_ALPHA, .caseValue.slptr = (char *[]){"package2", "package1", NULL}, .truthValue.sptr = "package1 package2"},
+ {.inputValue.unsigned_int = SPM_SORT_ALPHA, .caseValue.slptr = (char *[]){"package1", "package2", NULL}, .truthValue.sptr = "package1 package2"},
+ {.inputValue.unsigned_int = SPM_SORT_ALPHA, .caseValue.sptr = NULL, .truthValue.slptr = NULL},
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
@@ -21,7 +21,7 @@ int main(int argc, char *argv[]) {
char **array_orig = strdup_array(testCase[i].caseValue.slptr);
char **array_case = strdup_array(array_orig);
- strsort(array_case, testCase[i].inputValue.unsigned_integer);
+ strsort(array_case, testCase[i].inputValue.unsigned_int);
char *str_result = join(array_case, " ");
if (testCase[i].truthValue.sptr == NULL && str_result == NULL) {
diff --git a/tests/test_strlist.c b/tests/test_strlist.c
new file mode 100644
index 0000000..fc1ec4b
--- /dev/null
+++ b/tests/test_strlist.c
@@ -0,0 +1,182 @@
+#include "spm.h"
+#include "framework.h"
+
+#if !defined(MAXFLOAT)
+#define MAXFLOAT 3.40282347e+38F
+#endif
+
+static const char *story_truth = "The quick brown fox jumps over the lazy dog.";
+static const char *story_truth_rev = "dog. jumps over the lazy fox The quick brown";
+static const char *story_truth_sort_asc = "fox dog. The quick brown jumps over the lazy";
+static const char *story_truth_sort_dsc = "jumps over the lazy The quick brown dog. fox";
+
+static char *DATA[] = {
+ "The quick brown",
+ "fox",
+ "jumps over the lazy",
+ "dog.",
+ NULL,
+};
+
+long int MAX_INTS[] = {
+ INT8_MAX,
+ UINT8_MAX,
+ INT16_MAX,
+ UINT16_MAX,
+ INT32_MAX,
+ UINT32_MAX,
+ INT64_MAX,
+ UINT64_MAX,
+ 0,
+};
+
+enum truthValue {
+ int8_max = 0,
+ uint8_max,
+ int16_max,
+ uint16_max,
+ int32_max,
+ uint32_max,
+ int64_max,
+ uint64_max,
+};
+
+
+int main(int argc, char *argv[]) {
+ const char *storyFmt = "expected story: '%s', but got '%s'\n";
+ char *story = NULL;
+ union TestValue testValue = {0,};
+ StrList *strList = NULL;
+ StrList *strListCopy = NULL;
+ StrList *strListNumbers = NULL;
+ StrList truthInit = {1, 0, NULL};
+ size_t used = 0;
+ size_t allocated = 0;
+ char intStr[255];
+ const int DATA_SIZE = (sizeof(DATA) / sizeof(char *)) - 1;
+
+
+ // Initialize string list and check initial state
+ strList = strlist_init();
+ myassert(strList->num_inuse == 0, "strList has wrong number of records in use: %zu (expected %zu)\n", strList->num_inuse, truthInit.num_inuse);
+ myassert(strList->num_alloc == 1, "strList has wrong number of records allocated: %zu (expected %zu)\n", strList->num_alloc, truthInit.num_alloc);
+ myassert(strList->data != NULL, "strList was NULL");
+
+ ssize_t count = strlist_count(strList);
+ myassert(count == 0, "strlist_count returned wrong number of records in use: %zu (expected %zu)\n", count, strList->num_inuse);
+
+ // Populate list with strings
+ for (size_t i = 0; DATA[i] != NULL; i++) {
+ used = i + 1;
+ allocated = used + 1;
+
+ strlist_append(strList, DATA[i]);
+ myassert(strList->num_inuse == used, "incorrect used record count post-append\n");
+ myassert(strList->num_alloc == allocated, "incorrect allocated record count post-append\n");
+ }
+
+ // Is the data represented in the array as we expect it to be?
+ story = join(strList->data, " ");
+ myassert(strcmp(story, story_truth) == 0, storyFmt, story_truth, story);
+ free(story);
+ story = NULL;
+
+ // Copy the array (because we're about to modify it)
+ strListCopy = strlist_copy(strList);
+ myassert(strListCopy != NULL, "strlist_copy failed\n");
+
+ // Does reversing the array work correctly?
+ strlist_reverse(strListCopy);
+
+ story = join(strListCopy->data, " ");
+ // Copy the array (because we're about to modify it)
+ myassert(strcmp(story, story_truth_rev) == 0, storyFmt, story_truth, story);
+ free(story);
+ story = NULL;
+ strlist_free(strListCopy);
+ strListCopy = NULL;
+
+ // Copy the array (because we're about to modify it)
+ strListCopy = strlist_copy(strList);
+ myassert(strListCopy != NULL, "strlist_copy failed\n");
+
+ // Now compare the arrays to make sure they're identical
+ myassert(strlist_cmp(strList, strListCopy) == 0, "strlist_copy result does not match original StrList contents");
+
+ // Sort the array to see if it works.
+ strlist_sort(strListCopy, SPM_SORT_LEN_ASCENDING);
+
+ // The array just got modified, so check to make sure they are NOT identical
+ myassert(strlist_cmp(strList, strListCopy) == 1, "StrList data matches original StrList contents (after modification)");
+
+ story = join(strListCopy->data, " ");
+ myassert(strcmp(story, story_truth_sort_asc) == 0, storyFmt, story_truth_sort_asc, story);
+ free(story);
+ story = NULL;
+ strlist_free(strListCopy);
+ strListCopy = NULL;
+
+ // Copy the array (because we're about to modify it)
+ strListCopy = strlist_copy(strList);
+ myassert(strListCopy != NULL, "strlist_copy failed\n");
+
+ // Sort the array once more using a different comparator
+ strlist_sort(strListCopy, SPM_SORT_LEN_DESCENDING);
+
+ story = join(strListCopy->data, " ");
+ myassert(strcmp(story, story_truth_sort_dsc) == 0, storyFmt, story_truth_sort_dsc, story);
+ free(story);
+ story = NULL;
+ strlist_free(strListCopy);
+ strListCopy = NULL;
+
+ // Now append numerical values (as string) so we can start reading them back
+ for (size_t i = 0; MAX_INTS[i] != 0; i++) {
+ memset(intStr, '\0', sizeof(intStr));
+ sprintf(intStr, "%zu", MAX_INTS[i]);
+ strlist_append(strList, intStr);
+ }
+
+ memset(intStr, '\0', sizeof(intStr));
+ sprintf(intStr, "%lf", MAXFLOAT);
+ strlist_append(strList, intStr);
+
+ // Now make sure values derived from strlist_item_as_*() functions work properly
+ // NOTE: My focus is on 64-bit, so if you're compiling this on a 32-bit computer
+ // and these tests fail for you... That's a shame.
+ testValue.signed_char = strlist_item_as_char(strList, DATA_SIZE + int8_max);
+ myassert(testValue.signed_char == INT8_MAX, "int8_max incorrect: %d", testValue.signed_char);
+
+ testValue.unsigned_char = strlist_item_as_uchar(strList, DATA_SIZE + uint8_max);
+ myassert(testValue.unsigned_char == UINT8_MAX, "uint8_max incorrect: %d", testValue.unsigned_char);
+
+ testValue.signed_short = strlist_item_as_short(strList, DATA_SIZE + int16_max);
+ myassert(testValue.signed_short == INT16_MAX, "int16_max incorrect: %d", testValue.signed_short);
+
+ testValue.unsigned_short = strlist_item_as_ushort(strList, DATA_SIZE + uint16_max);
+ myassert(testValue.unsigned_short == UINT16_MAX, "uint16_max incorrect: %d", testValue.unsigned_short);
+
+ testValue.signed_int = strlist_item_as_int(strList, DATA_SIZE + int32_max);
+ myassert(testValue.signed_int == INT32_MAX, "int32_max incorrect: %d", testValue.signed_int);
+
+ testValue.unsigned_int = strlist_item_as_uint(strList, DATA_SIZE + uint32_max);
+ myassert(testValue.unsigned_int == UINT32_MAX, "uint32_max incorrect: %d", testValue.unsigned_int);
+
+ testValue.signed_long = strlist_item_as_long(strList, DATA_SIZE + int64_max);
+ myassert(testValue.signed_long == INT64_MAX, "int64_max (long) incorrect: %ld", testValue.signed_long);
+
+ testValue.unsigned_long = strlist_item_as_ulong(strList, DATA_SIZE + uint64_max);
+ myassert(testValue.unsigned_long == UINT64_MAX, "uint64_max (long) incorrect: %lu", testValue.unsigned_long);
+
+ testValue.signed_long_long = strlist_item_as_long_long(strList, DATA_SIZE + int64_max);
+ myassert(testValue.signed_long_long == INT64_MAX, "int64_max (long long) incorrect: %lld", testValue.signed_long_long);
+
+ testValue.unsigned_long_long = strlist_item_as_ulong_long(strList, DATA_SIZE + uint64_max);
+ myassert(testValue.unsigned_long_long == UINT64_MAX, "uint64_max (long long) incorrect: %llu", testValue.unsigned_long_long);
+
+ testValue.floating = strlist_item_as_float(strList, DATA_SIZE + uint64_max + 1);
+ myassert(testValue.floating == MAXFLOAT, "floating point maximum incorrect: %f", testValue.floating);
+
+ strlist_free(strList);
+ return 0;
+} \ No newline at end of file