aboutsummaryrefslogtreecommitdiff
path: root/tests/test_fs_expandpath.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2020-04-09 01:32:39 -0400
committerGitHub <noreply@github.com>2020-04-09 01:32:39 -0400
commitbda58bb6886c1fa49a4ecfc5812f38921fb9e7f4 (patch)
tree25fd27d8c32751720c8f24916365f1fcd37d5c3b /tests/test_fs_expandpath.c
parentd36652a97046e7c5a626cb39e39f83172a85ff3e (diff)
parent1e185a60f7213dd31b9b96127719e3ef735627d4 (diff)
downloadspmc-bda58bb6886c1fa49a4ecfc5812f38921fb9e7f4.tar.gz
Merge pull request #16 from jhunkeler/test-expandpath
Add test_fs_expandpath
Diffstat (limited to 'tests/test_fs_expandpath.c')
-rw-r--r--tests/test_fs_expandpath.c35
1 files changed, 35 insertions, 0 deletions
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