Add test for human_bytesz
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
#include <check.h>
|
||||
#include <ucore/string.h>
|
||||
|
||||
|
||||
START_TEST (test_human_bytesz_bytes)
|
||||
char result[128];
|
||||
char *rc;
|
||||
|
||||
rc = uc_human_bytesz(999, result, sizeof result);
|
||||
fail_if(rc == NULL);
|
||||
ck_assert_str_eq(result, "999 b");
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_human_bytesz_bytes_0)
|
||||
char result[128];
|
||||
char *rc;
|
||||
|
||||
rc = uc_human_bytesz(0, result, sizeof result);
|
||||
fail_if(rc == NULL);
|
||||
ck_assert_str_eq(result, "0 b");
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_human_bytesz_kilobytes)
|
||||
char result[128];
|
||||
char *rc;
|
||||
|
||||
rc = uc_human_bytesz(64000, result, sizeof result);
|
||||
fail_if(rc == NULL);
|
||||
ck_assert_str_eq(result, "64.00 kB");
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_human_bytesz_megabytes)
|
||||
char result[128];
|
||||
char *rc;
|
||||
|
||||
rc = uc_human_bytesz(6409000, result, sizeof result);
|
||||
fail_if(rc == NULL);
|
||||
ck_assert_str_eq(result, "6.41 MB");
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_human_bytesz_gigabytes)
|
||||
char result[128];
|
||||
char *rc;
|
||||
|
||||
rc = uc_human_bytesz(126999400000, result, sizeof result);
|
||||
fail_if(rc == NULL);
|
||||
ck_assert_str_eq(result, "127.00 GB");
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_human_bytesz_terrabytes)
|
||||
char result[128];
|
||||
char *rc;
|
||||
|
||||
rc = uc_human_bytesz(12453400030000, result, sizeof result);
|
||||
fail_if(rc == NULL);
|
||||
ck_assert_str_eq(result, "12.45 TB");
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_human_bytesz_petabytes)
|
||||
char result[128];
|
||||
char *rc;
|
||||
|
||||
rc = uc_human_bytesz(~0LL, result, sizeof result);
|
||||
fail_if(rc == NULL);
|
||||
ck_assert_str_eq(result, "18446.74 PB");
|
||||
END_TEST
|
||||
|
||||
|
||||
Suite *human_bytesz_suite(void)
|
||||
{
|
||||
Suite *s = suite_create("human_bytesz");
|
||||
TCase *tc = tcase_create("human_bytesz tests");
|
||||
tcase_add_test(tc, test_human_bytesz_bytes);
|
||||
tcase_add_test(tc, test_human_bytesz_bytes_0);
|
||||
tcase_add_test(tc, test_human_bytesz_kilobytes);
|
||||
tcase_add_test(tc, test_human_bytesz_megabytes);
|
||||
tcase_add_test(tc, test_human_bytesz_terrabytes);
|
||||
tcase_add_test(tc, test_human_bytesz_petabytes);
|
||||
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
+3
-1
@@ -19,6 +19,7 @@ extern Suite *clock_suite(void);
|
||||
extern Suite *seq_suite(void);
|
||||
extern Suite *sat_math_suite(void);
|
||||
extern Suite *timers_suite(void);
|
||||
extern Suite *human_bytesz_suite(void);
|
||||
|
||||
static suite_func suites[] = {
|
||||
bitvec_suite,
|
||||
@@ -33,7 +34,8 @@ static suite_func suites[] = {
|
||||
clock_suite,
|
||||
seq_suite,
|
||||
sat_math_suite,
|
||||
timers_suite
|
||||
timers_suite,
|
||||
human_bytesz_suite
|
||||
};
|
||||
|
||||
int
|
||||
|
||||
Reference in New Issue
Block a user