aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/framework.h4
-rw-r--r--tests/test_fs_get_file_size.c2
-rw-r--r--tests/test_fs_human_readable_size.c22
-rw-r--r--tests/test_fs_mkdirs.c43
4 files changed, 69 insertions, 2 deletions
diff --git a/tests/framework.h b/tests/framework.h
index c083b8a..2a7b268 100644
--- a/tests/framework.h
+++ b/tests/framework.h
@@ -10,6 +10,10 @@ union TestValue {
char character;
unsigned int unsigned_integer;
signed int signed_integer;
+ unsigned long unsigned_long;
+ signed long signed_long;
+ unsigned long long unsigned_long_long;
+ signed long long signed_long_long;
float floating;
char str[PATH_MAX];
};
diff --git a/tests/test_fs_get_file_size.c b/tests/test_fs_get_file_size.c
index ce93b13..fa38b8f 100644
--- a/tests/test_fs_get_file_size.c
+++ b/tests/test_fs_get_file_size.c
@@ -3,8 +3,6 @@
#define KILOBYTE 1024
-
-
const char *testFmt = "returned '%zu', expected '%zu'\n";
struct TestCase testCase[] = {
{.caseValue.unsigned_integer = 0, .truthValue.unsigned_integer = 0},
diff --git a/tests/test_fs_human_readable_size.c b/tests/test_fs_human_readable_size.c
new file mode 100644
index 0000000..7509bfe
--- /dev/null
+++ b/tests/test_fs_human_readable_size.c
@@ -0,0 +1,22 @@
+#include "spm.h"
+#include "framework.h"
+
+const char *testFmt = "returned '%s', expected '%s'\n";
+struct TestCase testCase[] = {
+ {.caseValue.unsigned_long = 1L, .truthValue.sptr = "1B"},
+ {.caseValue.unsigned_long = 1L * 1024, .truthValue.sptr = "1.00K"},
+ {.caseValue.unsigned_long = 1L * 1024 * 1024, .truthValue.sptr = "1.00M"},
+ {.caseValue.unsigned_long = 1L * 1024 * 1024 * 1024, .truthValue.sptr = "1.00G"},
+ {.caseValue.unsigned_long = 1L * 1024 * 1024 * 1024 * 1024, .truthValue.sptr = "1.00T"},
+ {.caseValue.unsigned_long = 1L * 1024 * 1024 * 1024 * 1024 * 1024, .truthValue.sptr = "1.00P"},
+ {.caseValue.unsigned_long = 1L * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, .truthValue.sptr = "1.00E"},
+};
+size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
+
+int main(int argc, char *argv[]) {
+ for (size_t i = 0; i < numCases; i++) {
+ char *result = human_readable_size(testCase[i].caseValue.unsigned_long);
+ myassert(strcmp(result, testCase[i].truthValue.sptr) == 0, testFmt, result, testCase[i].truthValue.sptr);
+ }
+ return 0;
+} \ No newline at end of file
diff --git a/tests/test_fs_mkdirs.c b/tests/test_fs_mkdirs.c
new file mode 100644
index 0000000..5229769
--- /dev/null
+++ b/tests/test_fs_mkdirs.c
@@ -0,0 +1,43 @@
+#include "spm.h"
+#include "framework.h"
+
+const char *testFmt = "returned '%d', expected '%d'\n";
+struct TestCase testCase[] = {
+ {.arg[0].str = "one", .truthValue.signed_integer = 0},
+ {.arg[0].str = "one/two", .truthValue.signed_integer = 0},
+ {.arg[0].str = "one/two/three", .truthValue.signed_integer = 0},
+ {.arg[0].str = "one/two/three/four", .truthValue.signed_integer = 0},
+ {.arg[0].str = "one/two/three/four/five", .truthValue.signed_integer = 0},
+};
+size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
+
+int main(int argc, char *argv[]) {
+ for (size_t i = 0; i < numCases; i++) {
+ int present = 0;
+ int result = 0;
+ char path_root[PATH_MAX] = {"test_fs_mkdirs_XXXXXX"};
+ char *path = NULL;
+
+ if (mkdtemp(path_root) == NULL) {
+ perror("mkdtemp failed to create temporary directory");
+ exit(errno);
+ }
+
+ path = join((char *[]){path_root, testCase[i].caseValue.str, NULL}, DIRSEPS);
+
+ if ((result = mkdirs(path, 0755)) < 0) {
+ perror(path);
+ exit(1);
+ }
+ present = access(path, X_OK);
+
+ myassert(result == 0, testFmt, result, testCase[i].truthValue.signed_integer);
+ myassert(present == 0, testFmt, result, testCase[i].truthValue.signed_integer);
+
+ rmdirs(path);
+
+ present = access(path, X_OK);
+ myassert(present != 0, testFmt, result, testCase[i].truthValue.signed_integer);
+ }
+ return 0;
+} \ No newline at end of file