diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2020-03-28 15:24:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-28 15:24:17 -0400 |
commit | 81a87ac139e26b1746c0370a4453bf5938e8eba9 (patch) | |
tree | 32774a6d5601a06557a862a2e223b3f0be4b3438 /tests/test_str_strdup_array.c | |
parent | 5048b9046afe0b48377a9862da9148165f7a0890 (diff) | |
parent | 04bfb70f4599c72f53406fd5fcfda570e30859fe (diff) | |
download | spmc-81a87ac139e26b1746c0370a4453bf5938e8eba9.tar.gz |
Merge pull request #7 from jhunkeler/strdup_array-test
strdup_array test
Diffstat (limited to 'tests/test_str_strdup_array.c')
-rw-r--r-- | tests/test_str_strdup_array.c | 30 |
1 files changed, 30 insertions, 0 deletions
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 |