From 35877b7967315f34fb77edd5077e3bc59eba4072 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 18 Sep 2013 17:51:08 +0000 Subject: [PATCH] avoids clash with the max() macro on Windows --- test/gmock-matchers_test.cc | 153 ++++++++++++++---------------------- 1 file changed, 59 insertions(+), 94 deletions(-) diff --git a/test/gmock-matchers_test.cc b/test/gmock-matchers_test.cc index 4644f91f..4ce1e4a5 100644 --- a/test/gmock-matchers_test.cc +++ b/test/gmock-matchers_test.cc @@ -2645,43 +2645,30 @@ TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) { template class FloatingPointTest : public testing::Test { protected: - typedef typename testing::internal::FloatingPoint Floating; + typedef testing::internal::FloatingPoint Floating; typedef typename Floating::Bits Bits; - virtual void SetUp() { - const size_t max_ulps = Floating::kMaxUlps; - - // The bits that represent 0.0. - const Bits zero_bits = Floating(0).bits(); - - // Makes some numbers close to 0.0. - close_to_positive_zero_ = Floating::ReinterpretBits(zero_bits + max_ulps/2); - close_to_negative_zero_ = -Floating::ReinterpretBits( - zero_bits + max_ulps - max_ulps/2); - further_from_negative_zero_ = -Floating::ReinterpretBits( - zero_bits + max_ulps + 1 - max_ulps/2); - - // The bits that represent 1.0. - const Bits one_bits = Floating(1).bits(); - - // Makes some numbers close to 1.0. - close_to_one_ = Floating::ReinterpretBits(one_bits + max_ulps); - further_from_one_ = Floating::ReinterpretBits(one_bits + max_ulps + 1); - - // +infinity. - infinity_ = Floating::Infinity(); - - // The bits that represent +infinity. - const Bits infinity_bits = Floating(infinity_).bits(); - - // Makes some numbers close to infinity. - close_to_infinity_ = Floating::ReinterpretBits(infinity_bits - max_ulps); - further_from_infinity_ = Floating::ReinterpretBits( - infinity_bits - max_ulps - 1); - - // Makes some NAN's. - nan1_ = Floating::ReinterpretBits(Floating::kExponentBitMask | 1); - nan2_ = Floating::ReinterpretBits(Floating::kExponentBitMask | 200); + FloatingPointTest() + : max_ulps_(Floating::kMaxUlps), + zero_bits_(Floating(0).bits()), + one_bits_(Floating(1).bits()), + infinity_bits_(Floating(Floating::Infinity()).bits()), + close_to_positive_zero_( + Floating::ReinterpretBits(zero_bits_ + max_ulps_/2)), + close_to_negative_zero_( + -Floating::ReinterpretBits(zero_bits_ + max_ulps_ - max_ulps_/2)), + further_from_negative_zero_(-Floating::ReinterpretBits( + zero_bits_ + max_ulps_ + 1 - max_ulps_/2)), + close_to_one_(Floating::ReinterpretBits(one_bits_ + max_ulps_)), + further_from_one_(Floating::ReinterpretBits(one_bits_ + max_ulps_ + 1)), + infinity_(Floating::Infinity()), + close_to_infinity_( + Floating::ReinterpretBits(infinity_bits_ - max_ulps_)), + further_from_infinity_( + Floating::ReinterpretBits(infinity_bits_ - max_ulps_ - 1)), + max_(Floating::Max()), + nan1_(Floating::ReinterpretBits(Floating::kExponentBitMask | 1)), + nan2_(Floating::ReinterpretBits(Floating::kExponentBitMask | 200)) { } void TestSize() { @@ -2736,51 +2723,34 @@ class FloatingPointTest : public testing::Test { // Pre-calculated numbers to be used by the tests. - static RawType close_to_positive_zero_; - static RawType close_to_negative_zero_; - static RawType further_from_negative_zero_; + const size_t max_ulps_; - static RawType close_to_one_; - static RawType further_from_one_; + const Bits zero_bits_; // The bits that represent 0.0. + const Bits one_bits_; // The bits that represent 1.0. + const Bits infinity_bits_; // The bits that represent +infinity. - static RawType infinity_; - static RawType close_to_infinity_; - static RawType further_from_infinity_; + // Some numbers close to 0.0. + const RawType close_to_positive_zero_; + const RawType close_to_negative_zero_; + const RawType further_from_negative_zero_; - static RawType nan1_; - static RawType nan2_; + // Some numbers close to 1.0. + const RawType close_to_one_; + const RawType further_from_one_; + + // Some numbers close to +infinity. + const RawType infinity_; + const RawType close_to_infinity_; + const RawType further_from_infinity_; + + // Maximum representable value that's not infinity. + const RawType max_; + + // Some NaNs. + const RawType nan1_; + const RawType nan2_; }; -template -RawType FloatingPointTest::close_to_positive_zero_; - -template -RawType FloatingPointTest::close_to_negative_zero_; - -template -RawType FloatingPointTest::further_from_negative_zero_; - -template -RawType FloatingPointTest::close_to_one_; - -template -RawType FloatingPointTest::further_from_one_; - -template -RawType FloatingPointTest::infinity_; - -template -RawType FloatingPointTest::close_to_infinity_; - -template -RawType FloatingPointTest::further_from_infinity_; - -template -RawType FloatingPointTest::nan1_; - -template -RawType FloatingPointTest::nan2_; - // Tests floating-point matchers with fixed epsilons. template class FloatingPointNearTest : public FloatingPointTest { @@ -2820,32 +2790,27 @@ class FloatingPointNearTest : public FloatingPointTest { EXPECT_FALSE(m4.Matches(ParentType::infinity_)); // Test various overflow scenarios. - Matcher m5 = matcher_maker( - std::numeric_limits::max(), - std::numeric_limits::max()); - EXPECT_TRUE(m5.Matches(std::numeric_limits::max())); - EXPECT_FALSE(m5.Matches(-std::numeric_limits::max())); + Matcher m5 = matcher_maker(ParentType::max_, ParentType::max_); + EXPECT_TRUE(m5.Matches(ParentType::max_)); + EXPECT_FALSE(m5.Matches(-ParentType::max_)); - Matcher m6 = matcher_maker( - -std::numeric_limits::max(), - std::numeric_limits::max()); - EXPECT_FALSE(m6.Matches(std::numeric_limits::max())); - EXPECT_TRUE(m6.Matches(-std::numeric_limits::max())); + Matcher m6 = matcher_maker(-ParentType::max_, ParentType::max_); + EXPECT_FALSE(m6.Matches(ParentType::max_)); + EXPECT_TRUE(m6.Matches(-ParentType::max_)); - Matcher m7 = matcher_maker(std::numeric_limits::max(), 0); - EXPECT_TRUE(m7.Matches(std::numeric_limits::max())); - EXPECT_FALSE(m7.Matches(-std::numeric_limits::max())); + Matcher m7 = matcher_maker(ParentType::max_, 0); + EXPECT_TRUE(m7.Matches(ParentType::max_)); + EXPECT_FALSE(m7.Matches(-ParentType::max_)); - Matcher m8 = matcher_maker( - -std::numeric_limits::max(), 0); - EXPECT_FALSE(m8.Matches(std::numeric_limits::max())); - EXPECT_TRUE(m8.Matches(-std::numeric_limits::max())); + Matcher m8 = matcher_maker(-ParentType::max_, 0); + EXPECT_FALSE(m8.Matches(ParentType::max_)); + EXPECT_TRUE(m8.Matches(-ParentType::max_)); // The difference between max() and -max() normally overflows to infinity, // but it should still match if the max_abs_error is also infinity. Matcher m9 = matcher_maker( - std::numeric_limits::max(), ParentType::infinity_); - EXPECT_TRUE(m8.Matches(-std::numeric_limits::max())); + ParentType::max_, ParentType::infinity_); + EXPECT_TRUE(m8.Matches(-ParentType::max_)); // matcher_maker can produce a Matcher, which is needed in // some cases.