From 5ea5c5a94a3b95fe1d7f6fa144001f3f62c075c1 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sat, 28 Mar 2020 15:18:49 -0400 Subject: Add `const char **` type to TestValue union --- tests/framework.h | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') 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; -- cgit From 04bfb70f4599c72f53406fd5fcfda570e30859fe Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sat, 28 Mar 2020 15:19:31 -0400 Subject: Add strdup_array() test --- tests/test_str_strdup_array.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/test_str_strdup_array.c (limited to 'tests') 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 -- cgit