From 06da826131ba1c5e28731fc9bae975fc21b13da1 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 6 Apr 2020 02:01:35 -0400 Subject: Test replace_text (#13) * Add test boilerplate * Add replace_text test * Redo replace_text --- tests/test_relocation_replace_text.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/test_relocation_replace_text.c (limited to 'tests/test_relocation_replace_text.c') diff --git a/tests/test_relocation_replace_text.c b/tests/test_relocation_replace_text.c new file mode 100644 index 0000000..c0dc42f --- /dev/null +++ b/tests/test_relocation_replace_text.c @@ -0,0 +1,26 @@ +#include "spm.h" +#include "framework.h" + +const char *testFmt = "case '%s': returned '%s', expected '%s'\n"; +struct TestCase testCase[] = { + {.caseValue.sptr = "This is a test... Happy friend.", .arg[0].sptr = "...", .arg[1].sptr = ".", .truthValue.sptr = "This is a test. Happy friend."}, + {.caseValue.sptr = "This is a test... Happy friend.", .arg[0].sptr = "test", .arg[1].sptr = "win", .truthValue.sptr = "This is a win... Happy friend."}, + {.caseValue.sptr = "This is a test... Happy friend.", .arg[0].sptr = "This is a test", .arg[1].sptr = "Meow cat", .truthValue.sptr = "Meow cat... Happy friend."}, + {.caseValue.sptr = "This is a test... Happy friend.", .arg[0].sptr = "T", .arg[1].sptr = "#", .truthValue.sptr = "#his is a test... Happy friend."}, + {.caseValue.sptr = "This is a test... Happy friend.", .arg[0].sptr = "", .arg[1].sptr = "#", .truthValue.sptr = "This is a test... Happy friend."}, + {.caseValue.sptr = "This is a test... Happy friend.", .arg[0].sptr = "#", .arg[1].sptr = "", .truthValue.sptr = "This is a test... Happy friend."}, + {.caseValue.sptr = "This is a test... Happy friend.", .arg[0].sptr = "", .arg[1].sptr = "", .truthValue.sptr = "This is a test... Happy friend."}, +}; +size_t numCases = sizeof(testCase) / sizeof(struct TestCase); + +int main(int argc, char *argv[]) { + for (size_t i = 0; i < numCases; i++) { + char *caseValue = strdup(testCase[i].caseValue.sptr); + + replace_text(caseValue, testCase[i].arg[0].sptr, testCase[i].arg[1].sptr); + myassert(strcmp(caseValue, testCase[i].truthValue.sptr) == 0, testFmt, testCase[i].caseValue.sptr, caseValue, testCase[i].truthValue.sptr); + + free(caseValue); + } + return 0; +} \ No newline at end of file -- cgit