From 71d7a8218d46149de64c9490021691cc745fec41 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 27 Jun 2019 10:17:20 +0900 Subject: [PATCH 1/2] util,test: rename variable non_iec -> si --- src/basic/format-util.c | 6 +++--- src/test/test-format-util.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/basic/format-util.c b/src/basic/format-util.c index 4231fa8d3f..aec929a06a 100644 --- a/src/basic/format-util.c +++ b/src/basic/format-util.c @@ -23,7 +23,7 @@ char *format_bytes_full(char *buf, size_t l, uint64_t t, FormatBytesFlag flag) { { "G", UINT64_C(1024)*UINT64_C(1024)*UINT64_C(1024) }, { "M", UINT64_C(1024)*UINT64_C(1024) }, { "K", UINT64_C(1024) }, - }, table_non_iec[] = { + }, table_si[] = { { "E", UINT64_C(1000)*UINT64_C(1000)*UINT64_C(1000)*UINT64_C(1000)*UINT64_C(1000)*UINT64_C(1000) }, { "P", UINT64_C(1000)*UINT64_C(1000)*UINT64_C(1000)*UINT64_C(1000)*UINT64_C(1000) }, { "T", UINT64_C(1000)*UINT64_C(1000)*UINT64_C(1000)*UINT64_C(1000) }, @@ -34,12 +34,12 @@ char *format_bytes_full(char *buf, size_t l, uint64_t t, FormatBytesFlag flag) { const suffix_table *table; size_t n, i; - assert_cc(ELEMENTSOF(table_iec) == ELEMENTSOF(table_non_iec)); + assert_cc(ELEMENTSOF(table_iec) == ELEMENTSOF(table_si)); if (t == (uint64_t) -1) return NULL; - table = flag & FORMAT_BYTES_USE_IEC ? table_iec : table_non_iec; + table = flag & FORMAT_BYTES_USE_IEC ? table_iec : table_si; n = ELEMENTSOF(table_iec); for (i = 0; i < n; i++) diff --git a/src/test/test-format-util.c b/src/test/test-format-util.c index 2986b1bd8d..a60f9fe689 100644 --- a/src/test/test-format-util.c +++ b/src/test/test-format-util.c @@ -5,13 +5,13 @@ #include "string-util.h" static void test_format_bytes_one(size_t val, bool trailing_B, const char *iec_with_p, const char *iec_without_p, - const char *non_iec_with_p, const char *non_iec_without_p) { + const char *si_with_p, const char *si_without_p) { char buf[FORMAT_BYTES_MAX]; assert_se(streq_ptr(format_bytes_full(buf, sizeof buf, val, FORMAT_BYTES_USE_IEC | FORMAT_BYTES_BELOW_POINT | (trailing_B ? FORMAT_BYTES_TRAILING_B : 0)), iec_with_p)); assert_se(streq_ptr(format_bytes_full(buf, sizeof buf, val, FORMAT_BYTES_USE_IEC | (trailing_B ? FORMAT_BYTES_TRAILING_B : 0)), iec_without_p)); - assert_se(streq_ptr(format_bytes_full(buf, sizeof buf, val, FORMAT_BYTES_BELOW_POINT | (trailing_B ? FORMAT_BYTES_TRAILING_B : 0)), non_iec_with_p)); - assert_se(streq_ptr(format_bytes_full(buf, sizeof buf, val, trailing_B ? FORMAT_BYTES_TRAILING_B : 0), non_iec_without_p)); + assert_se(streq_ptr(format_bytes_full(buf, sizeof buf, val, FORMAT_BYTES_BELOW_POINT | (trailing_B ? FORMAT_BYTES_TRAILING_B : 0)), si_with_p)); + assert_se(streq_ptr(format_bytes_full(buf, sizeof buf, val, trailing_B ? FORMAT_BYTES_TRAILING_B : 0), si_without_p)); } static void test_format_bytes(void) { From fd8c6b46c9ab8fe65f160dc1a6e2fca9a9c33097 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 27 Jun 2019 10:20:18 +0900 Subject: [PATCH 2/2] test: fix argument type of test_format_bytes_one() Closes #12891. --- src/test/test-format-util.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/test/test-format-util.c b/src/test/test-format-util.c index a60f9fe689..6558ee2b0a 100644 --- a/src/test/test-format-util.c +++ b/src/test/test-format-util.c @@ -4,7 +4,7 @@ #include "macro.h" #include "string-util.h" -static void test_format_bytes_one(size_t val, bool trailing_B, const char *iec_with_p, const char *iec_without_p, +static void test_format_bytes_one(uint64_t val, bool trailing_B, const char *iec_with_p, const char *iec_without_p, const char *si_with_p, const char *si_without_p) { char buf[FORMAT_BYTES_MAX]; @@ -23,12 +23,13 @@ static void test_format_bytes(void) { test_format_bytes_one(1024, false, "1.0K", "1K", "1.0K", "1K"); test_format_bytes_one(1100, true, "1.0K", "1K", "1.1K", "1K"); test_format_bytes_one(1500, true, "1.4K", "1K", "1.5K", "1K"); - test_format_bytes_one((size_t) 3*1024*1024, true, "3.0M", "3M", "3.1M", "3M"); - test_format_bytes_one((size_t) 3*1024*1024*1024, true, "3.0G", "3G", "3.2G", "3G"); - test_format_bytes_one((size_t) 3*1024*1024*1024*1024, true, "3.0T", "3T", "3.2T", "3T"); - test_format_bytes_one((size_t) 3*1024*1024*1024*1024*1024, true, "3.0P", "3P", "3.3P", "3P"); - test_format_bytes_one((size_t) 3*1024*1024*1024*1024*1024*1024, true, "3.0E", "3E", "3.4E", "3E"); - test_format_bytes_one(SIZE_MAX, true, NULL, NULL, NULL, NULL); + test_format_bytes_one(UINT64_C(3)*1024*1024, true, "3.0M", "3M", "3.1M", "3M"); + test_format_bytes_one(UINT64_C(3)*1024*1024*1024, true, "3.0G", "3G", "3.2G", "3G"); + test_format_bytes_one(UINT64_C(3)*1024*1024*1024*1024, true, "3.0T", "3T", "3.2T", "3T"); + test_format_bytes_one(UINT64_C(3)*1024*1024*1024*1024*1024, true, "3.0P", "3P", "3.3P", "3P"); + test_format_bytes_one(UINT64_C(3)*1024*1024*1024*1024*1024*1024, true, "3.0E", "3E", "3.4E", "3E"); + test_format_bytes_one(UINT64_MAX, true, NULL, NULL, NULL, NULL); + test_format_bytes_one(UINT64_MAX, false, NULL, NULL, NULL, NULL); } int main(void) {