46namespace gmock_matchers_test {
49typedef ::std::tuple<long, int> Tuple2;
53TEST(Eq2Test, MatchesEqualArguments) {
60TEST(Eq2Test, CanDescribeSelf) {
67TEST(Ge2Test, MatchesGreaterThanOrEqualArguments) {
75TEST(Ge2Test, CanDescribeSelf) {
82TEST(Gt2Test, MatchesGreaterThanArguments) {
90TEST(Gt2Test, CanDescribeSelf) {
97TEST(Le2Test, MatchesLessThanOrEqualArguments) {
105TEST(Le2Test, CanDescribeSelf) {
112TEST(Lt2Test, MatchesLessThanArguments) {
120TEST(Lt2Test, CanDescribeSelf) {
127TEST(Ne2Test, MatchesUnequalArguments) {
135TEST(Ne2Test, CanDescribeSelf) {
140TEST(PairMatchBaseTest, WorksWithMoveOnly) {
141 using Pointers = std::tuple<std::unique_ptr<int>, std::unique_ptr<int>>;
150TEST(IsNan, FloatMatchesNan) {
151 float quiet_nan = std::numeric_limits<float>::quiet_NaN();
152 float other_nan = std::nanf(
"1");
153 float real_value = 1.0f;
172TEST(IsNan, DoubleMatchesNan) {
173 double quiet_nan = std::numeric_limits<double>::quiet_NaN();
174 double other_nan = std::nan(
"1");
175 double real_value = 1.0;
194TEST(IsNan, LongDoubleMatchesNan) {
195 long double quiet_nan = std::numeric_limits<long double>::quiet_NaN();
196 long double other_nan = std::nan(
"1");
197 long double real_value = 1.0;
216TEST(IsNan, NotMatchesNan) {
218 EXPECT_FALSE(mf.Matches(std::numeric_limits<float>::quiet_NaN()));
223 EXPECT_FALSE(md.Matches(std::numeric_limits<double>::quiet_NaN()));
228 EXPECT_FALSE(mld.Matches(std::numeric_limits<long double>::quiet_NaN()));
234TEST(IsNan, CanDescribeSelf) {
246TEST(IsNan, CanDescribeSelfWithNot) {
259TEST(FloatEq2Test, MatchesEqualArguments) {
260 typedef ::std::tuple<float, float> Tpl;
263 EXPECT_TRUE(m.Matches(Tpl(0.3f, 0.1f + 0.1f + 0.1f)));
268TEST(FloatEq2Test, CanDescribeSelf) {
275TEST(NanSensitiveFloatEqTest, MatchesEqualArgumentsWithNaN) {
276 typedef ::std::tuple<float, float> Tpl;
279 EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits<float>::quiet_NaN(),
280 std::numeric_limits<float>::quiet_NaN())));
282 EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits<float>::quiet_NaN())));
283 EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits<float>::quiet_NaN(), 1.0f)));
287TEST(NanSensitiveFloatEqTest, CanDescribeSelfWithNaNs) {
294TEST(DoubleEq2Test, MatchesEqualArguments) {
295 typedef ::std::tuple<double, double> Tpl;
303TEST(DoubleEq2Test, CanDescribeSelf) {
310TEST(NanSensitiveDoubleEqTest, MatchesEqualArgumentsWithNaN) {
311 typedef ::std::tuple<double, double> Tpl;
314 EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits<double>::quiet_NaN(),
315 std::numeric_limits<double>::quiet_NaN())));
317 EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits<double>::quiet_NaN())));
318 EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits<double>::quiet_NaN(), 1.0f)));
322TEST(NanSensitiveDoubleEqTest, CanDescribeSelfWithNaNs) {
329TEST(FloatNear2Test, MatchesEqualArguments) {
330 typedef ::std::tuple<float, float> Tpl;
338TEST(FloatNear2Test, CanDescribeSelf) {
345TEST(NanSensitiveFloatNearTest, MatchesNearbyArgumentsWithNaN) {
346 typedef ::std::tuple<float, float> Tpl;
350 EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits<float>::quiet_NaN(),
351 std::numeric_limits<float>::quiet_NaN())));
353 EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits<float>::quiet_NaN())));
354 EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits<float>::quiet_NaN(), 1.0f)));
358TEST(NanSensitiveFloatNearTest, CanDescribeSelfWithNaNs) {
365TEST(DoubleNear2Test, MatchesEqualArguments) {
366 typedef ::std::tuple<double, double> Tpl;
374TEST(DoubleNear2Test, CanDescribeSelf) {
381TEST(NanSensitiveDoubleNearTest, MatchesNearbyArgumentsWithNaN) {
382 typedef ::std::tuple<double, double> Tpl;
386 EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits<double>::quiet_NaN(),
387 std::numeric_limits<double>::quiet_NaN())));
389 EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits<double>::quiet_NaN())));
390 EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits<double>::quiet_NaN(), 1.0f)));
394TEST(NanSensitiveDoubleNearTest, CanDescribeSelfWithNaNs) {
400TEST(NotTest, NegatesMatcher) {
408TEST(NotTest, CanDescribeSelf) {
414TEST(NotTest, NotMatcherSafelyCastsMonomorphicMatchers) {
427 for (
int i = 1;
i <= num; ++
i) {
437TEST(AllOfTest, MatchesWhenAllMatch) {
439 m = AllOf(Le(2), Ge(1));
445 m = AllOf(Gt(0), Ne(1), Ne(2));
451 m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3));
458 m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7));
467 AllOfMatches(2, AllOf(Ne(1), Ne(2)));
468 AllOfMatches(3, AllOf(Ne(1), Ne(2), Ne(3)));
469 AllOfMatches(4, AllOf(Ne(1), Ne(2), Ne(3), Ne(4)));
470 AllOfMatches(5, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5)));
471 AllOfMatches(6, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6)));
472 AllOfMatches(7, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7)));
474 AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8)));
476 9, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Ne(9)));
477 AllOfMatches(10, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8),
480 50, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Ne(9),
481 Ne(10), Ne(11), Ne(12), Ne(13), Ne(14), Ne(15), Ne(16), Ne(17),
482 Ne(18), Ne(19), Ne(20), Ne(21), Ne(22), Ne(23), Ne(24), Ne(25),
483 Ne(26), Ne(27), Ne(28), Ne(29), Ne(30), Ne(31), Ne(32), Ne(33),
484 Ne(34), Ne(35), Ne(36), Ne(37), Ne(38), Ne(39), Ne(40), Ne(41),
485 Ne(42), Ne(43), Ne(44), Ne(45), Ne(46), Ne(47), Ne(48), Ne(49),
490TEST(AllOfTest, CanDescribeSelf) {
492 m = AllOf(Le(2), Ge(1));
495 m = AllOf(Gt(0), Ne(1), Ne(2));
496 std::string expected_descr1 =
497 "(is > 0) and (isn't equal to 1) and (isn't equal to 2)";
500 m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3));
501 std::string expected_descr2 =
502 "(is > 0) and (isn't equal to 1) and (isn't equal to 2) and (isn't equal "
506 m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7));
507 std::string expected_descr3 =
508 "(is >= 0) and (is < 10) and (isn't equal to 3) and (isn't equal to 5) "
509 "and (isn't equal to 7)";
514TEST(AllOfTest, CanDescribeNegation) {
516 m = AllOf(Le(2), Ge(1));
517 std::string expected_descr4 =
"(isn't <= 2) or (isn't >= 1)";
520 m = AllOf(Gt(0), Ne(1), Ne(2));
521 std::string expected_descr5 =
522 "(isn't > 0) or (is equal to 1) or (is equal to 2)";
525 m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3));
526 std::string expected_descr6 =
527 "(isn't > 0) or (is equal to 1) or (is equal to 2) or (is equal to 3)";
530 m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7));
531 std::string expected_desr7 =
532 "(isn't >= 0) or (isn't < 10) or (is equal to 3) or (is equal to 5) or "
536 m = AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Ne(9),
538 AllOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
544TEST(AllOfTest, AllOfMatcherSafelyCastsMonomorphicMatchers) {
555 Matcher<int&> m5 = AllOf(greater_than_5, less_than_10, less_than_10);
558TEST_P(AllOfTestP, ExplainsResult) {
564 m = AllOf(GreaterThan(10), Lt(30));
568 m = AllOf(GreaterThan(10), GreaterThan(20));
569 EXPECT_EQ(
"which is 20 more than 10, and which is 10 more than 20",
574 m = AllOf(GreaterThan(10), Lt(30), GreaterThan(20));
575 EXPECT_EQ(
"which is 15 more than 10, and which is 5 more than 20",
579 m = AllOf(GreaterThan(10), GreaterThan(20), GreaterThan(30));
581 "which is 30 more than 10, and which is 20 more than 20, "
582 "and which is 10 more than 30",
587 m = AllOf(GreaterThan(10), GreaterThan(20));
593 m = AllOf(GreaterThan(10), Lt(30));
598 m = AllOf(GreaterThan(10), GreaterThan(20));
603static void AnyOfMatches(
int num,
const Matcher<int>& m) {
606 for (
int i = 1;
i <= num; ++
i) {
616 for (
int i = 1;
i <= num; ++
i) {
626TEST(AnyOfTest, MatchesWhenAnyMatches) {
628 m = AnyOf(Le(1), Ge(3));
633 m = AnyOf(Lt(0), Eq(1), Eq(2));
639 m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3));
646 m = AnyOf(Le(0), Gt(10), 3, 5, 7);
656 AnyOfMatches(2, AnyOf(1, 2));
657 AnyOfMatches(3, AnyOf(1, 2, 3));
658 AnyOfMatches(4, AnyOf(1, 2, 3, 4));
659 AnyOfMatches(5, AnyOf(1, 2, 3, 4, 5));
660 AnyOfMatches(6, AnyOf(1, 2, 3, 4, 5, 6));
661 AnyOfMatches(7, AnyOf(1, 2, 3, 4, 5, 6, 7));
662 AnyOfMatches(8, AnyOf(1, 2, 3, 4, 5, 6, 7, 8));
663 AnyOfMatches(9, AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9));
664 AnyOfMatches(10, AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
668TEST(AnyOfTest, VariadicMatchesWhenAnyMatches) {
671 Matcher<int> m = ::testing::AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
675 AnyOfMatches(50, AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
676 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
677 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
678 45, 46, 47, 48, 49, 50));
680 50, AnyOf(
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
681 "13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
682 "23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
"32",
683 "33",
"34",
"35",
"36",
"37",
"38",
"39",
"40",
"41",
"42",
684 "43",
"44",
"45",
"46",
"47",
"48",
"49",
"50"));
687TEST(ConditionalTest, MatchesFirstIfCondition) {
694 StringMatchResultListener listener;
695 StringMatchResultListener expected;
697 EXPECT_FALSE(eq_red.MatchAndExplain(
"green", &expected));
701TEST(ConditionalTest, MatchesSecondIfCondition) {
708 StringMatchResultListener listener;
709 StringMatchResultListener expected;
716TEST(AnyOfTest, CanDescribeSelf) {
718 m = AnyOf(Le(1), Ge(3));
722 m = AnyOf(Lt(0), Eq(1), Eq(2));
725 m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3));
726 EXPECT_EQ(
"(is < 0) or (is equal to 1) or (is equal to 2) or (is equal to 3)",
729 m = AnyOf(Le(0), Gt(10), 3, 5, 7);
731 "(is <= 0) or (is > 10) or (is equal to 3) or (is equal to 5) or (is "
737TEST(AnyOfTest, CanDescribeNegation) {
739 m = AnyOf(Le(1), Ge(3));
742 m = AnyOf(Lt(0), Eq(1), Eq(2));
743 EXPECT_EQ(
"(isn't < 0) and (isn't equal to 1) and (isn't equal to 2)",
746 m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3));
748 "(isn't < 0) and (isn't equal to 1) and (isn't equal to 2) and (isn't "
752 m = AnyOf(Le(0), Gt(10), 3, 5, 7);
754 "(isn't <= 0) and (isn't > 10) and (isn't equal to 3) and (isn't equal "
755 "to 5) and (isn't equal to 7)",
760TEST(AnyOfTest, AnyOfMatcherSafelyCastsMonomorphicMatchers) {
771 Matcher<int&> m5 = AnyOf(greater_than_5, less_than_10, less_than_10);
774TEST_P(AnyOfTestP, ExplainsResult) {
780 m = AnyOf(GreaterThan(10), Lt(0));
784 m = AnyOf(GreaterThan(10), GreaterThan(20));
785 EXPECT_EQ(
"which is 5 less than 10, and which is 15 less than 20",
790 m = AnyOf(GreaterThan(10), Gt(20), GreaterThan(30));
791 EXPECT_EQ(
"which is 5 less than 10, and which is 25 less than 30",
795 m = AnyOf(GreaterThan(10), GreaterThan(20), GreaterThan(30));
797 "which is 5 less than 10, and which is 15 less than 20, "
798 "and which is 25 less than 30",
803 m = AnyOf(GreaterThan(10), GreaterThan(20));
809 m = AnyOf(GreaterThan(10), Lt(30));
814 m = AnyOf(GreaterThan(30), GreaterThan(20));
825int IsPositive(
double x) {
return x > 0 ? 1 : 0; }
831 explicit IsGreaterThan(
int threshold) : threshold_(threshold) {}
833 bool operator()(
int n)
const {
return n > threshold_; }
844bool ReferencesFooAndIsZero(
const int& n) {
return (&n == &
foo) && (n == 0); }
848TEST(TrulyTest, MatchesWhatSatisfiesThePredicate) {
855TEST(TrulyTest, CanBeUsedWithFunctor) {
862class ConvertibleToBool {
864 explicit ConvertibleToBool(
int number) : number_(number) {}
865 operator bool()
const {
return number_ != 0; }
871ConvertibleToBool IsNotZero(
int number) {
return ConvertibleToBool(number); }
876TEST(TrulyTest, PredicateCanReturnAClassConvertibleToBool) {
883TEST(TrulyTest, CanDescribeSelf) {
890TEST(TrulyTest, WorksForByRefArguments) {
898TEST(TrulyTest, ExplainsFailures) {
899 StringMatchResultListener listener;
900 EXPECT_FALSE(ExplainMatchResult(Truly(IsPositive), -1, &listener));
901 EXPECT_EQ(listener.str(),
"didn't satisfy the given predicate");
906TEST(MatchesTest, IsSatisfiedByWhatMatchesTheMatcher) {
913TEST(MatchesTest, WorksOnByRefArguments) {
921TEST(MatchesTest, WorksWithMatcherOnNonRefType) {
930TEST(ValueTest, WorksWithPolymorphicMatcher) {
935TEST(ValueTest, WorksWithMonomorphicMatcher) {
946TEST(AllArgsTest, WorksForTuple) {
947 EXPECT_THAT(std::make_tuple(1, 2L), AllArgs(Lt()));
948 EXPECT_THAT(std::make_tuple(2L, 1), Not(AllArgs(Lt())));
951TEST(AllArgsTest, WorksForNonTuple) {
958 AllArgsHelper() =
default;
963 AllArgsHelper(
const AllArgsHelper&) =
delete;
964 AllArgsHelper& operator=(
const AllArgsHelper&) =
delete;
967TEST(AllArgsTest, WorksInWithClause) {
968 AllArgsHelper helper;
969 ON_CALL(helper, Helper(_, _)).With(AllArgs(Lt())).WillByDefault(Return(1));
971 EXPECT_CALL(helper, Helper(_, _)).With(AllArgs(Gt())).WillOnce(Return(2));
977class OptionalMatchersHelper {
979 OptionalMatchersHelper() =
default;
991 OptionalMatchersHelper(
const OptionalMatchersHelper&) =
delete;
992 OptionalMatchersHelper& operator=(
const OptionalMatchersHelper&) =
delete;
995TEST(AllArgsTest, WorksWithoutMatchers) {
996 OptionalMatchersHelper helper;
998 ON_CALL(helper, NoArgs).WillByDefault(Return(10));
999 ON_CALL(helper, OneArg).WillByDefault(Return(20));
1000 ON_CALL(helper, TwoArgs).WillByDefault(Return(30));
1007 EXPECT_CALL(helper, OneArg).WillOnce(Return(100));
1008 EXPECT_CALL(helper, OneArg(17)).WillOnce(Return(200));
1017template <
typename RawType>
1021 typedef typename Floating::Bits Bits;
1041 max_(std::numeric_limits<RawType>::max()),
1042 nan1_(Floating::ReinterpretBits(Floating::kExponentBitMask | 1)),
1043 nan2_(Floating::ReinterpretBits(Floating::kExponentBitMask | 200)) {}
1045 void TestSize() {
EXPECT_EQ(
sizeof(RawType),
sizeof(Bits)); }
1050 testing::internal::FloatingEqMatcher<RawType> (*matcher_maker)(RawType)) {
1124template <
typename RawType>
1125class FloatingPointNearTest :
public FloatingPointTest<RawType> {
1127 typedef FloatingPointTest<RawType> ParentType;
1131 void TestNearMatches(testing::internal::FloatingEqMatcher<RawType> (
1132 *matcher_maker)(RawType, RawType)) {
1133 Matcher<RawType> m1 = matcher_maker(0.0, 0.0);
1136 EXPECT_FALSE(m1.Matches(ParentType::close_to_positive_zero_));
1137 EXPECT_FALSE(m1.Matches(ParentType::close_to_negative_zero_));
1140 Matcher<RawType> m2 = matcher_maker(0.0, 1.0);
1150 Matcher<RawType> m3 = matcher_maker(ParentType::infinity_, 0.0);
1152 EXPECT_FALSE(m3.Matches(ParentType::close_to_infinity_));
1155 Matcher<RawType> m4 = matcher_maker(-ParentType::infinity_, 0.0);
1157 EXPECT_FALSE(m4.Matches(-ParentType::close_to_infinity_));
1161 Matcher<RawType> m5 = matcher_maker(ParentType::max_, ParentType::max_);
1165 Matcher<RawType> m6 = matcher_maker(-ParentType::max_, ParentType::max_);
1169 Matcher<RawType> m7 = matcher_maker(ParentType::max_, 0);
1173 Matcher<RawType> m8 = matcher_maker(-ParentType::max_, 0);
1179 Matcher<RawType> m9 =
1180 matcher_maker(ParentType::max_, ParentType::infinity_);
1185 Matcher<const RawType&> m10 = matcher_maker(0.0, 1.0);
1187 EXPECT_TRUE(m10.Matches(ParentType::close_to_positive_zero_));
1192 Matcher<RawType&> m11 = matcher_maker(0.0, 1.0);
1207typedef FloatingPointTest<float> FloatTest;
1209TEST_F(FloatTest, FloatEqApproximatelyMatchesFloats) { TestMatches(&FloatEq); }
1211TEST_F(FloatTest, NanSensitiveFloatEqApproximatelyMatchesFloats) {
1212 TestMatches(&NanSensitiveFloatEq);
1215TEST_F(FloatTest, FloatEqCannotMatchNaN) {
1217 Matcher<float> m = FloatEq(
nan1_);
1223TEST_F(FloatTest, NanSensitiveFloatEqCanMatchNaN) {
1225 Matcher<float> m = NanSensitiveFloatEq(
nan1_);
1231TEST_F(FloatTest, FloatEqCanDescribeSelf) {
1232 Matcher<float> m1 = FloatEq(2.0f);
1236 Matcher<float> m2 = FloatEq(0.5f);
1240 Matcher<float> m3 = FloatEq(
nan1_);
1245TEST_F(FloatTest, NanSensitiveFloatEqCanDescribeSelf) {
1246 Matcher<float> m1 = NanSensitiveFloatEq(2.0f);
1250 Matcher<float> m2 = NanSensitiveFloatEq(0.5f);
1254 Matcher<float> m3 = NanSensitiveFloatEq(
nan1_);
1261typedef FloatingPointNearTest<float> FloatNearTest;
1263TEST_F(FloatNearTest, FloatNearMatches) { TestNearMatches(&FloatNear); }
1265TEST_F(FloatNearTest, NanSensitiveFloatNearApproximatelyMatchesFloats) {
1266 TestNearMatches(&NanSensitiveFloatNear);
1269TEST_F(FloatNearTest, FloatNearCanDescribeSelf) {
1270 Matcher<float> m1 = FloatNear(2.0f, 0.5f);
1272 EXPECT_EQ(
"isn't approximately 2 (absolute error > 0.5)",
1275 Matcher<float> m2 = FloatNear(0.5f, 0.5f);
1277 EXPECT_EQ(
"isn't approximately 0.5 (absolute error > 0.5)",
1280 Matcher<float> m3 = FloatNear(
nan1_, 0.0);
1285TEST_F(FloatNearTest, NanSensitiveFloatNearCanDescribeSelf) {
1286 Matcher<float> m1 = NanSensitiveFloatNear(2.0f, 0.5f);
1288 EXPECT_EQ(
"isn't approximately 2 (absolute error > 0.5)",
1291 Matcher<float> m2 = NanSensitiveFloatNear(0.5f, 0.5f);
1293 EXPECT_EQ(
"isn't approximately 0.5 (absolute error > 0.5)",
1296 Matcher<float> m3 = NanSensitiveFloatNear(
nan1_, 0.1f);
1301TEST_F(FloatNearTest, FloatNearCannotMatchNaN) {
1303 Matcher<float> m = FloatNear(ParentType::nan1_, 0.1f);
1309TEST_F(FloatNearTest, NanSensitiveFloatNearCanMatchNaN) {
1311 Matcher<float> m = NanSensitiveFloatNear(
nan1_, 0.1f);
1318typedef FloatingPointTest<double> DoubleTest;
1320TEST_F(DoubleTest, DoubleEqApproximatelyMatchesDoubles) {
1321 TestMatches(&DoubleEq);
1324TEST_F(DoubleTest, NanSensitiveDoubleEqApproximatelyMatchesDoubles) {
1325 TestMatches(&NanSensitiveDoubleEq);
1328TEST_F(DoubleTest, DoubleEqCannotMatchNaN) {
1330 Matcher<double> m = DoubleEq(
nan1_);
1336TEST_F(DoubleTest, NanSensitiveDoubleEqCanMatchNaN) {
1338 Matcher<double> m = NanSensitiveDoubleEq(
nan1_);
1344TEST_F(DoubleTest, DoubleEqCanDescribeSelf) {
1345 Matcher<double> m1 = DoubleEq(2.0);
1349 Matcher<double> m2 = DoubleEq(0.5);
1353 Matcher<double> m3 = DoubleEq(
nan1_);
1358TEST_F(DoubleTest, NanSensitiveDoubleEqCanDescribeSelf) {
1359 Matcher<double> m1 = NanSensitiveDoubleEq(2.0);
1363 Matcher<double> m2 = NanSensitiveDoubleEq(0.5);
1367 Matcher<double> m3 = NanSensitiveDoubleEq(
nan1_);
1374typedef FloatingPointNearTest<double> DoubleNearTest;
1376TEST_F(DoubleNearTest, DoubleNearMatches) { TestNearMatches(&DoubleNear); }
1378TEST_F(DoubleNearTest, NanSensitiveDoubleNearApproximatelyMatchesDoubles) {
1379 TestNearMatches(&NanSensitiveDoubleNear);
1382TEST_F(DoubleNearTest, DoubleNearCanDescribeSelf) {
1383 Matcher<double> m1 = DoubleNear(2.0, 0.5);
1385 EXPECT_EQ(
"isn't approximately 2 (absolute error > 0.5)",
1388 Matcher<double> m2 = DoubleNear(0.5, 0.5);
1390 EXPECT_EQ(
"isn't approximately 0.5 (absolute error > 0.5)",
1393 Matcher<double> m3 = DoubleNear(
nan1_, 0.0);
1398TEST_F(DoubleNearTest, ExplainsResultWhenMatchFails) {
1403 const std::string explanation =
1404 Explain(DoubleNear(2.1, 1e-10), 2.1 + 1.2e-10);
1407 EXPECT_TRUE(explanation ==
"which is 1.2e-10 from 2.1" ||
1408 explanation ==
"which is 1.2e-010 from 2.1")
1409 <<
" where explanation is \"" << explanation <<
"\".";
1412TEST_F(DoubleNearTest, NanSensitiveDoubleNearCanDescribeSelf) {
1413 Matcher<double> m1 = NanSensitiveDoubleNear(2.0, 0.5);
1415 EXPECT_EQ(
"isn't approximately 2 (absolute error > 0.5)",
1418 Matcher<double> m2 = NanSensitiveDoubleNear(0.5, 0.5);
1420 EXPECT_EQ(
"isn't approximately 0.5 (absolute error > 0.5)",
1423 Matcher<double> m3 = NanSensitiveDoubleNear(
nan1_, 0.1);
1428TEST_F(DoubleNearTest, DoubleNearCannotMatchNaN) {
1430 Matcher<double> m = DoubleNear(ParentType::nan1_, 0.1);
1436TEST_F(DoubleNearTest, NanSensitiveDoubleNearCanMatchNaN) {
1438 Matcher<double> m = NanSensitiveDoubleNear(
nan1_, 0.1);
1444TEST(NotTest, WorksOnMoveOnlyType) {
1445 std::unique_ptr<int>
p(
new int(3));
1450TEST(AllOfTest, HugeMatcher) {
1453 EXPECT_THAT(0, testing::AllOf(_, _, _, _, _, _, _, _, _,
1454 testing::AllOf(_, _, _, _, _, _, _, _, _, _)));
1457TEST(AnyOfTest, HugeMatcher) {
1460 EXPECT_THAT(0, testing::AnyOf(_, _, _, _, _, _, _, _, _,
1461 testing::AnyOf(_, _, _, _, _, _, _, _, _, _)));
1478template <
typename T1,
typename T2>
1479bool AllOf(
const T1& ,
const T2& ) {
1483TEST(AllOfTest, DoesNotCallAllOfUnqualified) {
1485 testing::AllOf(M(), M(), M(), M(), M(), M(), M(), M(), M(), M()));
1488template <
typename T1,
typename T2>
1489bool AnyOf(
const T1&,
const T2&) {
1493TEST(AnyOfTest, DoesNotCallAnyOfUnqualified) {
1495 testing::AnyOf(M(), M(), M(), M(), M(), M(), M(), M(), M(), M()));
1500TEST(AllOfTest, WorksOnMoveOnlyType) {
1501 std::unique_ptr<int>
p(
new int(3));
1502 EXPECT_THAT(
p, AllOf(Pointee(Eq(3)), Pointee(Gt(0)), Pointee(Lt(5))));
1503 EXPECT_THAT(
p, Not(AllOf(Pointee(Eq(3)), Pointee(Gt(0)), Pointee(Lt(3)))));
1506TEST(AnyOfTest, WorksOnMoveOnlyType) {
1507 std::unique_ptr<int>
p(
new int(3));
1508 EXPECT_THAT(
p, AnyOf(Pointee(Eq(5)), Pointee(Lt(0)), Pointee(Lt(5))));
1509 EXPECT_THAT(
p, Not(AnyOf(Pointee(Eq(5)), Pointee(Lt(0)), Pointee(Gt(5)))));