aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386>2013-09-18 17:51:08 +0000
committerzhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386>2013-09-18 17:51:08 +0000
commit35877b7967315f34fb77edd5077e3bc59eba4072 (patch)
treeca658f980710f83bbd42e4f91b83d174e037c367 /test
parent6e0fba4de0c506dff05598799fcc56fccfdcc669 (diff)
downloadgoogletest-35877b7967315f34fb77edd5077e3bc59eba4072.tar.gz
googletest-35877b7967315f34fb77edd5077e3bc59eba4072.tar.bz2
googletest-35877b7967315f34fb77edd5077e3bc59eba4072.zip
avoids clash with the max() macro on Windows
Diffstat (limited to 'test')
-rw-r--r--test/gmock-matchers_test.cc155
1 files changed, 60 insertions, 95 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 <typename RawType>
class FloatingPointTest : public testing::Test {
protected:
- typedef typename testing::internal::FloatingPoint<RawType> Floating;
+ typedef testing::internal::FloatingPoint<RawType> 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,50 +2723,33 @@ 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_;
-
- static RawType close_to_one_;
- static RawType further_from_one_;
-
- static RawType infinity_;
- static RawType close_to_infinity_;
- static RawType further_from_infinity_;
-
- static RawType nan1_;
- static RawType nan2_;
-};
-
-template <typename RawType>
-RawType FloatingPointTest<RawType>::close_to_positive_zero_;
-
-template <typename RawType>
-RawType FloatingPointTest<RawType>::close_to_negative_zero_;
-
-template <typename RawType>
-RawType FloatingPointTest<RawType>::further_from_negative_zero_;
+ const size_t max_ulps_;
-template <typename RawType>
-RawType FloatingPointTest<RawType>::close_to_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.
-template <typename RawType>
-RawType FloatingPointTest<RawType>::further_from_one_;
+ // Some numbers close to 0.0.
+ const RawType close_to_positive_zero_;
+ const RawType close_to_negative_zero_;
+ const RawType further_from_negative_zero_;
-template <typename RawType>
-RawType FloatingPointTest<RawType>::infinity_;
+ // Some numbers close to 1.0.
+ const RawType close_to_one_;
+ const RawType further_from_one_;
-template <typename RawType>
-RawType FloatingPointTest<RawType>::close_to_infinity_;
+ // Some numbers close to +infinity.
+ const RawType infinity_;
+ const RawType close_to_infinity_;
+ const RawType further_from_infinity_;
-template <typename RawType>
-RawType FloatingPointTest<RawType>::further_from_infinity_;
+ // Maximum representable value that's not infinity.
+ const RawType max_;
-template <typename RawType>
-RawType FloatingPointTest<RawType>::nan1_;
-
-template <typename RawType>
-RawType FloatingPointTest<RawType>::nan2_;
+ // Some NaNs.
+ const RawType nan1_;
+ const RawType nan2_;
+};
// Tests floating-point matchers with fixed epsilons.
template <typename RawType>
@@ -2820,32 +2790,27 @@ class FloatingPointNearTest : public FloatingPointTest<RawType> {
EXPECT_FALSE(m4.Matches(ParentType::infinity_));
// Test various overflow scenarios.
- Matcher<RawType> m5 = matcher_maker(
- std::numeric_limits<RawType>::max(),
- std::numeric_limits<RawType>::max());
- EXPECT_TRUE(m5.Matches(std::numeric_limits<RawType>::max()));
- EXPECT_FALSE(m5.Matches(-std::numeric_limits<RawType>::max()));
-
- Matcher<RawType> m6 = matcher_maker(
- -std::numeric_limits<RawType>::max(),
- std::numeric_limits<RawType>::max());
- EXPECT_FALSE(m6.Matches(std::numeric_limits<RawType>::max()));
- EXPECT_TRUE(m6.Matches(-std::numeric_limits<RawType>::max()));
-
- Matcher<RawType> m7 = matcher_maker(std::numeric_limits<RawType>::max(), 0);
- EXPECT_TRUE(m7.Matches(std::numeric_limits<RawType>::max()));
- EXPECT_FALSE(m7.Matches(-std::numeric_limits<RawType>::max()));
-
- Matcher<RawType> m8 = matcher_maker(
- -std::numeric_limits<RawType>::max(), 0);
- EXPECT_FALSE(m8.Matches(std::numeric_limits<RawType>::max()));
- EXPECT_TRUE(m8.Matches(-std::numeric_limits<RawType>::max()));
+ Matcher<RawType> m5 = matcher_maker(ParentType::max_, ParentType::max_);
+ EXPECT_TRUE(m5.Matches(ParentType::max_));
+ EXPECT_FALSE(m5.Matches(-ParentType::max_));
+
+ Matcher<RawType> m6 = matcher_maker(-ParentType::max_, ParentType::max_);
+ EXPECT_FALSE(m6.Matches(ParentType::max_));
+ EXPECT_TRUE(m6.Matches(-ParentType::max_));
+
+ Matcher<RawType> m7 = matcher_maker(ParentType::max_, 0);
+ EXPECT_TRUE(m7.Matches(ParentType::max_));
+ EXPECT_FALSE(m7.Matches(-ParentType::max_));
+
+ Matcher<RawType> 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<RawType> m9 = matcher_maker(
- std::numeric_limits<RawType>::max(), ParentType::infinity_);
- EXPECT_TRUE(m8.Matches(-std::numeric_limits<RawType>::max()));
+ ParentType::max_, ParentType::infinity_);
+ EXPECT_TRUE(m8.Matches(-ParentType::max_));
// matcher_maker can produce a Matcher<const RawType&>, which is needed in
// some cases.