Split uc_human_bytesz in uc_human_bytesz_dec/uc_human_bytesz_bin, for

decimal and binary conversion (http://en.wikipedia.org/wiki/Megabyte)
This commit is contained in:
Nils O. Selåsdal
2013-11-19 11:33:43 +01:00
parent ac95b1002c
commit 8083fa54cf
3 changed files with 61 additions and 10 deletions
+35 -7
View File
@@ -6,7 +6,11 @@ START_TEST (test_human_bytesz_bytes)
char result[128];
char *rc;
rc = uc_human_bytesz(999, result, sizeof result);
rc = uc_human_bytesz_dec(999, result, sizeof result);
fail_if(rc == NULL);
ck_assert_str_eq(result, "999 b");
rc = uc_human_bytesz_bin(999, result, sizeof result);
fail_if(rc == NULL);
ck_assert_str_eq(result, "999 b");
END_TEST
@@ -15,7 +19,11 @@ START_TEST (test_human_bytesz_bytes_0)
char result[128];
char *rc;
rc = uc_human_bytesz(0, result, sizeof result);
rc = uc_human_bytesz_dec(0, result, sizeof result);
fail_if(rc == NULL);
ck_assert_str_eq(result, "0 b");
rc = uc_human_bytesz_bin(0, result, sizeof result);
fail_if(rc == NULL);
ck_assert_str_eq(result, "0 b");
END_TEST
@@ -24,45 +32,65 @@ START_TEST (test_human_bytesz_kilobytes)
char result[128];
char *rc;
rc = uc_human_bytesz(64000, result, sizeof result);
rc = uc_human_bytesz_dec(64000, result, sizeof result);
fail_if(rc == NULL);
ck_assert_str_eq(result, "64.00 kB");
rc = uc_human_bytesz_bin(64000, result, sizeof result);
fail_if(rc == NULL);
ck_assert_str_eq(result, "62.50 KiB");
END_TEST
START_TEST (test_human_bytesz_megabytes)
char result[128];
char *rc;
rc = uc_human_bytesz(6409000, result, sizeof result);
rc = uc_human_bytesz_dec(6409000, result, sizeof result);
fail_if(rc == NULL);
ck_assert_str_eq(result, "6.41 MB");
rc = uc_human_bytesz_bin(6409000, result, sizeof result);
fail_if(rc == NULL);
ck_assert_str_eq(result, "6.11 MiB");
END_TEST
START_TEST (test_human_bytesz_gigabytes)
char result[128];
char *rc;
rc = uc_human_bytesz(126999400000, result, sizeof result);
rc = uc_human_bytesz_dec(126999400000, result, sizeof result);
fail_if(rc == NULL);
ck_assert_str_eq(result, "127.00 GB");
rc = uc_human_bytesz_bin(126999400000, result, sizeof result);
fail_if(rc == NULL);
ck_assert_str_eq(result, "118.28 GiB");
END_TEST
START_TEST (test_human_bytesz_terrabytes)
char result[128];
char *rc;
rc = uc_human_bytesz(12453400030000, result, sizeof result);
rc = uc_human_bytesz_dec(12453400030000, result, sizeof result);
fail_if(rc == NULL);
ck_assert_str_eq(result, "12.45 TB");
rc = uc_human_bytesz_bin(12453400030000, result, sizeof result);
fail_if(rc == NULL);
ck_assert_str_eq(result, "11.33 TiB");
END_TEST
START_TEST (test_human_bytesz_petabytes)
char result[128];
char *rc;
rc = uc_human_bytesz(~0LL, result, sizeof result);
rc = uc_human_bytesz_dec(~0LL, result, sizeof result);
fail_if(rc == NULL);
ck_assert_str_eq(result, "18446.74 PB");
rc = uc_human_bytesz_bin(~0ULL, result, sizeof result);
fail_if(rc == NULL);
ck_assert_str_eq(result, "16384.00 PiB");
END_TEST