From 1e185a60f7213dd31b9b96127719e3ef735627d4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 9 Apr 2020 01:27:45 -0400 Subject: Add test_fs_expandpath --- tests/test_fs_expandpath.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_fs_expandpath.c (limited to 'tests/test_fs_expandpath.c') diff --git a/tests/test_fs_expandpath.c b/tests/test_fs_expandpath.c new file mode 100644 index 0000000..7c54780 --- /dev/null +++ b/tests/test_fs_expandpath.c @@ -0,0 +1,35 @@ +#include "spm.h" +#include "framework.h" + +const char *testFmt = "returned '%s', expected '%s'\n"; +struct TestCase testCase[] = { + {.caseValue.sptr = "~", .truthValue.sptr = NULL}, + {.caseValue.sptr = "/dev/winning", .truthValue.sptr = "/dev/winning"}, + {.caseValue.sptr = "", .truthValue.sptr = ""}, + {.caseValue.sptr = NULL, .truthValue.sptr = NULL}, +}; +size_t numCases = sizeof(testCase) / sizeof(struct TestCase); + +int main(int argc, char *argv[]) { +#if !defined(_WIN32) + testCase[0].truthValue.sptr = getenv("HOME"); +#else + testcase[0].truthValue.sptr = getenv("USERPROFILE"); +#endif + + for (size_t i = 0; i < numCases; i++) { + char *result = expandpath(testCase[i].caseValue.sptr); + + + if (result == NULL && testCase[i].caseValue.sptr == NULL && testCase[i].truthValue.sptr == NULL) { + continue; + } + + myassert(strcmp(result, testCase[i].truthValue.sptr) == 0, testFmt, result, testCase[i].truthValue.sptr); + + if (result != NULL) { + free(result); + } + } + return 0; +} \ No newline at end of file -- cgit