diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-24 12:27:33 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-24 12:27:33 -0400 |
commit | ad07c35f12ca10bd3dfea50aaf8a9db8dcc9f630 (patch) | |
tree | 4b31aa43dcb942611fef8699bc96d166cf63b68e /tests/test_str_strdeldup.c | |
parent | ccaeb7092b5ad40b1b3833c987ba3ec4d47f0bb8 (diff) | |
download | spmc-ad07c35f12ca10bd3dfea50aaf8a9db8dcc9f630.tar.gz |
Initial commit of tests
Diffstat (limited to 'tests/test_str_strdeldup.c')
-rw-r--r-- | tests/test_str_strdeldup.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_str_strdeldup.c b/tests/test_str_strdeldup.c new file mode 100644 index 0000000..1efdeb7 --- /dev/null +++ b/tests/test_str_strdeldup.c @@ -0,0 +1,31 @@ +#include "spm.h" +#include "framework.h" + +const char *testFmt = "case: (array){%s} expected '%s', returned '%s' \n"; +struct TestCase testCase[] = { + {.caseValue.slptr = (char *[]){"a", "a", "c", "d", "e", NULL}, .truthValue.sptr = "acde"}, + {.caseValue.slptr = (char *[]){"a", "b", "b", "d", "e", NULL}, .truthValue.sptr = "abde"}, + {.caseValue.slptr = (char *[]){"a", "b", "c", "c", "e", NULL}, .truthValue.sptr = "abce"}, + {.caseValue.slptr = (char *[]){"a", "b", "c", "d", "e", NULL}, .truthValue.sptr = "abcde"}, + {.caseValue.slptr = (char *[]){"e", "d", "c", "b", "a", NULL}, .truthValue.sptr = "edcba"}, + {.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 = strdeldup(testCase[i].caseValue.slptr); + if (testCase[i].truthValue.sptr == NULL && result == NULL) { + continue; + } else if (testCase[i].truthValue.sptr == NULL && result != NULL) { + fprintf(stderr, testFmt, array_to_string(testCase[i].caseValue.slptr, ", "), testCase[i].truthValue.sptr, array_to_string(result, "")); + return 1; + } + char *str_result = join(result, ""); + + myassert(strcmp(str_result, testCase[i].truthValue.sptr) == 0, testFmt, array_to_string(testCase[i].caseValue.slptr, ", "), testCase[i].truthValue.sptr, str_result); + + free(str_result); + } + return 0; +}
\ No newline at end of file |