aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2020-03-28 15:24:17 -0400
committerGitHub <noreply@github.com>2020-03-28 15:24:17 -0400
commit81a87ac139e26b1746c0370a4453bf5938e8eba9 (patch)
tree32774a6d5601a06557a862a2e223b3f0be4b3438 /tests
parent5048b9046afe0b48377a9862da9148165f7a0890 (diff)
parent04bfb70f4599c72f53406fd5fcfda570e30859fe (diff)
downloadspmc-81a87ac139e26b1746c0370a4453bf5938e8eba9.tar.gz
Merge pull request #7 from jhunkeler/strdup_array-test
strdup_array test
Diffstat (limited to 'tests')
-rw-r--r--tests/framework.h1
-rw-r--r--tests/test_str_strdup_array.c30
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/framework.h b/tests/framework.h
index 1e5adaa..d317005 100644
--- a/tests/framework.h
+++ b/tests/framework.h
@@ -6,6 +6,7 @@
union TestValue {
const char *sptr;
char **slptr;
+ const char **cslptr;
char character;
unsigned int unsigned_integer;
signed int signed_integer;
diff --git a/tests/test_str_strdup_array.c b/tests/test_str_strdup_array.c
new file mode 100644
index 0000000..5590a74
--- /dev/null
+++ b/tests/test_str_strdup_array.c
@@ -0,0 +1,30 @@
+#include "spm.h"
+#include "framework.h"
+
+const char *testFmt = "case: (array){%s} expected (array){%s}, returned (array){%s} \n";
+struct TestCase testCase[] = {
+ {.caseValue.slptr = (char *[]){"a", "a", "c", "d", "e", NULL}, .truthValue.slptr = (char *[]){"a", "a", "c", "d", "e", NULL}},
+ {.caseValue.slptr = (char *[]){"e", "d", "c", "b", "a", NULL}, .truthValue.slptr = (char *[]){"e", "d", "c", "b", "a", NULL}},
+ {.caseValue.slptr = (char *[]){"ha", "haha", "hahaha", "hahahaha", "hahahahaha", NULL}, .truthValue.slptr = (char *[]){"ha", "haha", "hahaha", "hahahaha", "hahahahaha", NULL}},
+ {.caseValue.slptr = NULL, .truthValue.sptr = NULL},
+};
+size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
+
+int main(int argc, char *argv[]) {
+ for (size_t i = 0; i < numCases; i++) {
+ char **result = strdup_array(testCase[i].caseValue.slptr);
+ myassert(strcmp_array(result, testCase[i].truthValue.slptr) == 0,
+ testFmt,
+ array_to_string(testCase[i].caseValue.slptr, ", "),
+ array_to_string(testCase[i].truthValue.slptr, ", "),
+ array_to_string(result, ", "));
+
+ if (result != NULL) {
+ for (size_t r = 0; result[r] != NULL; r++) {
+ free(result[r]);
+ }
+ free(result);
+ }
+ }
+ return 0;
+} \ No newline at end of file