From 55ea58ff5bcd0923627d5adead043c1aeefd0e3e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 3 Mar 2023 10:25:47 +1100 Subject: [PATCH] BLI_string: correct size for BLI_str_format_int_grouped, update tests Ensure the defines match the longest strings in tests. --- source/blender/blenlib/BLI_string.h | 3 +-- .../blender/blenlib/tests/BLI_string_test.cc | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index cef86539743..87749e90e77 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -17,12 +17,11 @@ extern "C" { #endif - /* Buffer size of maximum `uint64` plus commas and terminator. */ #define BLI_STR_FORMAT_UINT64_GROUPED_SIZE 27 /* Buffer size of maximum `int32` with commas and terminator. */ -#define BLI_STR_FORMAT_INT32_GROUPED_SIZE 16 +#define BLI_STR_FORMAT_INT32_GROUPED_SIZE 15 /* Buffer size of maximum `int64` formatted as byte size (with GiB for example). */ #define BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE 15 diff --git a/source/blender/blenlib/tests/BLI_string_test.cc b/source/blender/blenlib/tests/BLI_string_test.cc index 1c3859e3556..cd7dd503aeb 100644 --- a/source/blender/blenlib/tests/BLI_string_test.cc +++ b/source/blender/blenlib/tests/BLI_string_test.cc @@ -336,12 +336,6 @@ TEST(string, StrFormatIntGrouped) BLI_str_format_int_grouped(number_str, number = -1); EXPECT_STREQ("-1", number_str); - BLI_str_format_int_grouped(number_str, number = -2147483648); - EXPECT_STREQ("-2,147,483,648", number_str); - - BLI_str_format_int_grouped(number_str, number = 2147483647); - EXPECT_STREQ("2,147,483,647", number_str); - BLI_str_format_int_grouped(number_str, number = 1000); EXPECT_STREQ("1,000", number_str); @@ -353,6 +347,14 @@ TEST(string, StrFormatIntGrouped) BLI_str_format_int_grouped(number_str, number = -999); EXPECT_STREQ("-999", number_str); + + BLI_str_format_int_grouped(number_str, number = 2147483647); + EXPECT_STREQ("2,147,483,647", number_str); + + BLI_str_format_int_grouped(number_str, number = -2147483648); + EXPECT_STREQ("-2,147,483,648", number_str); + /* Ensure the limit is correct. */ + EXPECT_EQ(sizeof(number_str), strlen(number_str) + 1); } /* BLI_str_format_uint64_grouped */ @@ -375,6 +377,8 @@ TEST(string, StrFormatUint64Grouped) BLI_str_format_uint64_grouped(number_str, number = 18446744073709551615u); EXPECT_STREQ("18,446,744,073,709,551,615", number_str); + /* Ensure the limit is correct. */ + EXPECT_EQ(sizeof(number_str), strlen(number_str) + 1); } /* BLI_str_format_byte_unit */ @@ -440,6 +444,8 @@ TEST(string, StrFormatByteUnits) /* Test maximum string length. */ BLI_str_format_byte_unit(size_str, size = -9223200000000000000, false); EXPECT_STREQ("-8191.8472 PiB", size_str); + /* Ensure the limit is correct. */ + EXPECT_EQ(sizeof(size_str), strlen(size_str) + 1); } /* BLI_str_format_decimal_unit */