aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-04-09 01:27:45 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-04-09 01:27:45 -0400
commit1e185a60f7213dd31b9b96127719e3ef735627d4 (patch)
tree59f91d9fcf512cba02324810fd555b94d35ae9b1
parent3ff0e986bee05be4abb3c49d2fddec0fa8ccfc59 (diff)
downloadspmc-1e185a60f7213dd31b9b96127719e3ef735627d4.tar.gz
Add test_fs_expandpath
-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