diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-04-10 00:40:52 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-04-10 00:40:52 -0400 |
commit | 941893c1f6070b789c5ddf8376cc7abfe0dddd0a (patch) | |
tree | 20794d6ef64459dd0a1a8009670902d0c9b358e8 /tests | |
parent | 0f0dd17bc5a2c3149684f2a50fbefae09e49be72 (diff) | |
download | spmc-941893c1f6070b789c5ddf8376cc7abfe0dddd0a.tar.gz |
Add test_human_readable_size
* Add additional integer types to TestCase union
Diffstat (limited to 'tests')
-rw-r--r-- | tests/framework.h | 4 | ||||
-rw-r--r-- | tests/test_fs_human_readable_size.c | 22 |
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 |