aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/framework.h4
-rw-r--r--tests/test_fs_human_readable_size.c22
2 files changed, 26 insertions, 0 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_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