From 3fd134be035b1b4ac1a8f72bd36796fbb5c05ccb Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Wed, 8 May 2019 02:09:11 +0700 Subject: [PATCH] Move test_count_digits to format-impl-test and disable gtest warnings (#1147) * This translation unit includes `gtest.h` in which using something like `strncpy` Suppress MSVC warnings from `gtest.h` included. Warning sample: fmt-master\test\gtest\gtest.h(2873,10): warning: 'strncpy' is deprecated: This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [-Wdeprecated-declarations] * Moving `test_count_digits` to format-impl-test then count_digits<4>(internal::uintptr_t) shall not be exported * retaining _CRT_SECURE_NO_WARNINGS always defined should be no harms. --- test/custom-formatter-test.cc | 4 ++++ test/format-impl-test.cc | 16 ++++++++++++++++ test/format-test.cc | 16 ---------------- test/posix-mock-test.cc | 2 +- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/test/custom-formatter-test.cc b/test/custom-formatter-test.cc index d33b12f5..2fb64a83 100644 --- a/test/custom-formatter-test.cc +++ b/test/custom-formatter-test.cc @@ -5,6 +5,10 @@ // // For the license information refer to format.h. +#ifndef _CRT_SECURE_NO_WARNINGS +# define _CRT_SECURE_NO_WARNINGS +#endif + #include "fmt/format.h" #include "gtest-extra.h" diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index 33263aaa..d6f85a37 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -237,3 +237,19 @@ TEST(FormatTest, FormatErrorCode) { TEST(FormatTest, CountCodePoints) { EXPECT_EQ(4, fmt::internal::count_code_points(fmt::u8string_view("ёжик"))); } + +// Tests fmt::internal::count_digits for integer type Int. +template void test_count_digits() { + for (Int i = 0; i < 10; ++i) EXPECT_EQ(1u, fmt::internal::count_digits(i)); + for (Int i = 1, n = 1, end = std::numeric_limits::max() / 10; n <= end; + ++i) { + n *= 10; + EXPECT_EQ(i, fmt::internal::count_digits(n - 1)); + EXPECT_EQ(i + 1, fmt::internal::count_digits(n)); + } +} + +TEST(UtilTest, CountDigits) { + test_count_digits(); + test_count_digits(); +} diff --git a/test/format-test.cc b/test/format-test.cc index 6cd1b136..3321a552 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -140,22 +140,6 @@ template struct WriteChecker { EXPECT_PRED_FORMAT1(WriteChecker(), value) } // namespace -// Tests fmt::internal::count_digits for integer type Int. -template void test_count_digits() { - for (Int i = 0; i < 10; ++i) EXPECT_EQ(1u, fmt::internal::count_digits(i)); - for (Int i = 1, n = 1, end = std::numeric_limits::max() / 10; n <= end; - ++i) { - n *= 10; - EXPECT_EQ(i, fmt::internal::count_digits(n - 1)); - EXPECT_EQ(i + 1, fmt::internal::count_digits(n)); - } -} - -TEST(UtilTest, CountDigits) { - test_count_digits(); - test_count_digits(); -} - struct uint32_pair { uint32_t u[2]; }; diff --git a/test/posix-mock-test.cc b/test/posix-mock-test.cc index 87ac3982..75660ea5 100644 --- a/test/posix-mock-test.cc +++ b/test/posix-mock-test.cc @@ -6,7 +6,7 @@ // For the license information refer to format.h. // Disable bogus MSVC warnings. -#ifdef _MSC_VER +#ifndef _CRT_SECURE_NO_WARNINGS # define _CRT_SECURE_NO_WARNINGS #endif