48 namespace gmock_matchers_test {
51 typedef ::std::tuple<long, int> Tuple2;
55 TEST(Eq2Test, MatchesEqualArguments) {
62 TEST(Eq2Test, CanDescribeSelf) {
69 TEST(Ge2Test, MatchesGreaterThanOrEqualArguments) {
77 TEST(Ge2Test, CanDescribeSelf) {
84 TEST(Gt2Test, MatchesGreaterThanArguments) {
92 TEST(Gt2Test, CanDescribeSelf) {
99 TEST(Le2Test, MatchesLessThanOrEqualArguments) {
107 TEST(Le2Test, CanDescribeSelf) {
114 TEST(Lt2Test, MatchesLessThanArguments) {
122 TEST(Lt2Test, CanDescribeSelf) {
129 TEST(Ne2Test, MatchesUnequalArguments) {
137 TEST(Ne2Test, CanDescribeSelf) {
142 TEST(PairMatchBaseTest, WorksWithMoveOnly) {
143 using Pointers = std::tuple<std::unique_ptr<int>, std::unique_ptr<int>>;
152 TEST(IsNan, FloatMatchesNan) {
153 float quiet_nan = std::numeric_limits<float>::quiet_NaN();
154 float other_nan = std::nanf(
"1");
155 float real_value = 1.0f;
174 TEST(IsNan, DoubleMatchesNan) {
175 double quiet_nan = std::numeric_limits<double>::quiet_NaN();
176 double other_nan = std::nan(
"1");
177 double real_value = 1.0;
196 TEST(IsNan, LongDoubleMatchesNan) {
197 long double quiet_nan = std::numeric_limits<long double>::quiet_NaN();
198 long double other_nan = std::nan(
"1");
199 long double real_value = 1.0;
218 TEST(IsNan, NotMatchesNan) {
220 EXPECT_FALSE(mf.Matches(std::numeric_limits<float>::quiet_NaN()));
225 EXPECT_FALSE(md.Matches(std::numeric_limits<double>::quiet_NaN()));
230 EXPECT_FALSE(mld.Matches(std::numeric_limits<long double>::quiet_NaN()));
236 TEST(IsNan, CanDescribeSelf) {
248 TEST(IsNan, CanDescribeSelfWithNot) {
261 TEST(FloatEq2Test, MatchesEqualArguments) {
262 typedef ::std::tuple<float, float> Tpl;
270 TEST(FloatEq2Test, CanDescribeSelf) {
277 TEST(NanSensitiveFloatEqTest, MatchesEqualArgumentsWithNaN) {
278 typedef ::std::tuple<float, float> Tpl;
281 EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits<float>::quiet_NaN(),
282 std::numeric_limits<float>::quiet_NaN())));
284 EXPECT_FALSE(m.Matches(Tpl(1.0
f, std::numeric_limits<float>::quiet_NaN())));
285 EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits<float>::quiet_NaN(), 1.0
f)));
289 TEST(NanSensitiveFloatEqTest, CanDescribeSelfWithNaNs) {
296 TEST(DoubleEq2Test, MatchesEqualArguments) {
297 typedef ::std::tuple<double, double> Tpl;
305 TEST(DoubleEq2Test, CanDescribeSelf) {
312 TEST(NanSensitiveDoubleEqTest, MatchesEqualArgumentsWithNaN) {
313 typedef ::std::tuple<double, double> Tpl;
316 EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits<double>::quiet_NaN(),
317 std::numeric_limits<double>::quiet_NaN())));
319 EXPECT_FALSE(m.Matches(Tpl(1.0
f, std::numeric_limits<double>::quiet_NaN())));
320 EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits<double>::quiet_NaN(), 1.0
f)));
324 TEST(NanSensitiveDoubleEqTest, CanDescribeSelfWithNaNs) {
331 TEST(FloatNear2Test, MatchesEqualArguments) {
332 typedef ::std::tuple<float, float> Tpl;
340 TEST(FloatNear2Test, CanDescribeSelf) {
347 TEST(NanSensitiveFloatNearTest, MatchesNearbyArgumentsWithNaN) {
348 typedef ::std::tuple<float, float> Tpl;
352 EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits<float>::quiet_NaN(),
353 std::numeric_limits<float>::quiet_NaN())));
355 EXPECT_FALSE(m.Matches(Tpl(1.0
f, std::numeric_limits<float>::quiet_NaN())));
356 EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits<float>::quiet_NaN(), 1.0
f)));
360 TEST(NanSensitiveFloatNearTest, CanDescribeSelfWithNaNs) {
367 TEST(DoubleNear2Test, MatchesEqualArguments) {
368 typedef ::std::tuple<double, double> Tpl;
376 TEST(DoubleNear2Test, CanDescribeSelf) {
383 TEST(NanSensitiveDoubleNearTest, MatchesNearbyArgumentsWithNaN) {
384 typedef ::std::tuple<double, double> Tpl;
388 EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits<double>::quiet_NaN(),
389 std::numeric_limits<double>::quiet_NaN())));
391 EXPECT_FALSE(m.Matches(Tpl(1.0
f, std::numeric_limits<double>::quiet_NaN())));
392 EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits<double>::quiet_NaN(), 1.0
f)));
396 TEST(NanSensitiveDoubleNearTest, CanDescribeSelfWithNaNs) {
402 TEST(NotTest, NegatesMatcher) {
410 TEST(NotTest, CanDescribeSelf) {
416 TEST(NotTest, NotMatcherSafelyCastsMonomorphicMatchers) {
429 for (
int i = 1;
i <= num; ++
i) {
439 TEST(AllOfTest, MatchesWhenAllMatch) {
441 m = AllOf(Le(2), Ge(1));
447 m = AllOf(Gt(0), Ne(1), Ne(2));
453 m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3));
460 m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7));
469 AllOfMatches(2, AllOf(Ne(1), Ne(2)));
470 AllOfMatches(3, AllOf(Ne(1), Ne(2), Ne(3)));
471 AllOfMatches(4, AllOf(Ne(1), Ne(2), Ne(3), Ne(4)));
472 AllOfMatches(5, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5)));
473 AllOfMatches(6, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6)));
474 AllOfMatches(7, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7)));
476 AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8)));
478 9, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Ne(9)));
479 AllOfMatches(10, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8),
482 50, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Ne(9),
483 Ne(10), Ne(11), Ne(12), Ne(13), Ne(14), Ne(15), Ne(16), Ne(17),
484 Ne(18), Ne(19), Ne(20), Ne(21), Ne(22), Ne(23), Ne(24), Ne(25),
485 Ne(26), Ne(27), Ne(28), Ne(29), Ne(30), Ne(31), Ne(32), Ne(33),
486 Ne(34), Ne(35), Ne(36), Ne(37), Ne(38), Ne(39), Ne(40), Ne(41),
487 Ne(42), Ne(43), Ne(44), Ne(45), Ne(46), Ne(47), Ne(48), Ne(49),
492 TEST(AllOfTest, CanDescribeSelf) {
494 m = AllOf(Le(2), Ge(1));
497 m = AllOf(Gt(0), Ne(1), Ne(2));
498 std::string expected_descr1 =
499 "(is > 0) and (isn't equal to 1) and (isn't equal to 2)";
502 m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3));
503 std::string expected_descr2 =
504 "(is > 0) and (isn't equal to 1) and (isn't equal to 2) and (isn't equal "
508 m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7));
509 std::string expected_descr3 =
510 "(is >= 0) and (is < 10) and (isn't equal to 3) and (isn't equal to 5) "
511 "and (isn't equal to 7)";
516 TEST(AllOfTest, CanDescribeNegation) {
518 m = AllOf(Le(2), Ge(1));
519 std::string expected_descr4 =
"(isn't <= 2) or (isn't >= 1)";
522 m = AllOf(Gt(0), Ne(1), Ne(2));
523 std::string expected_descr5 =
524 "(isn't > 0) or (is equal to 1) or (is equal to 2)";
527 m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3));
528 std::string expected_descr6 =
529 "(isn't > 0) or (is equal to 1) or (is equal to 2) or (is equal to 3)";
532 m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7));
533 std::string expected_desr7 =
534 "(isn't >= 0) or (isn't < 10) or (is equal to 3) or (is equal to 5) or "
538 m = AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Ne(9),
540 AllOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
546 TEST(AllOfTest, AllOfMatcherSafelyCastsMonomorphicMatchers) {
557 Matcher<int&> m5 = AllOf(greater_than_5, less_than_10, less_than_10);
560 TEST_P(AllOfTestP, ExplainsResult) {
565 m = AllOf(GreaterThan(10), Lt(30));
569 m = AllOf(GreaterThan(10), GreaterThan(20));
570 EXPECT_EQ(
"which is 20 more than 10, and which is 10 more than 20",
575 m = AllOf(GreaterThan(10), Lt(30), GreaterThan(20));
577 "which is 15 more than 10, and is < 30, and which is 5 more than 20",
581 m = AllOf(GreaterThan(10), GreaterThan(20), GreaterThan(30));
583 "which is 30 more than 10, and which is 20 more than 20, "
584 "and which is 10 more than 30",
589 m = AllOf(GreaterThan(10), GreaterThan(20));
595 m = AllOf(GreaterThan(10), Lt(30));
600 m = AllOf(GreaterThan(10), GreaterThan(20));
605 static void AnyOfMatches(
int num,
const Matcher<int>& m) {
608 for (
int i = 1;
i <= num; ++
i) {
618 for (
int i = 1;
i <= num; ++
i) {
628 TEST(AnyOfTest, MatchesWhenAnyMatches) {
630 m = AnyOf(Le(1), Ge(3));
635 m = AnyOf(Lt(0), Eq(1), Eq(2));
641 m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3));
648 m = AnyOf(Le(0), Gt(10), 3, 5, 7);
658 AnyOfMatches(2, AnyOf(1, 2));
659 AnyOfMatches(3, AnyOf(1, 2, 3));
660 AnyOfMatches(4, AnyOf(1, 2, 3, 4));
661 AnyOfMatches(5, AnyOf(1, 2, 3, 4, 5));
662 AnyOfMatches(6, AnyOf(1, 2, 3, 4, 5, 6));
663 AnyOfMatches(7, AnyOf(1, 2, 3, 4, 5, 6, 7));
664 AnyOfMatches(8, AnyOf(1, 2, 3, 4, 5, 6, 7, 8));
665 AnyOfMatches(9, AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9));
666 AnyOfMatches(10, AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
670 TEST(AnyOfTest, VariadicMatchesWhenAnyMatches) {
673 Matcher<int> m = ::testing::AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
677 AnyOfMatches(50, AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
678 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
679 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
680 45, 46, 47, 48, 49, 50));
682 50, AnyOf(
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
683 "13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
684 "23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
"32",
685 "33",
"34",
"35",
"36",
"37",
"38",
"39",
"40",
"41",
"42",
686 "43",
"44",
"45",
"46",
"47",
"48",
"49",
"50"));
689 TEST(ConditionalTest, MatchesFirstIfCondition) {
696 StringMatchResultListener listener;
699 EXPECT_FALSE(eq_red.MatchAndExplain(
"green", &expected));
703 TEST(ConditionalTest, MatchesSecondIfCondition) {
710 StringMatchResultListener listener;
718 TEST(AnyOfTest, CanDescribeSelf) {
720 m = AnyOf(Le(1), Ge(3));
724 m = AnyOf(Lt(0), Eq(1), Eq(2));
727 m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3));
728 EXPECT_EQ(
"(is < 0) or (is equal to 1) or (is equal to 2) or (is equal to 3)",
731 m = AnyOf(Le(0), Gt(10), 3, 5, 7);
733 "(is <= 0) or (is > 10) or (is equal to 3) or (is equal to 5) or (is "
739 TEST(AnyOfTest, CanDescribeNegation) {
741 m = AnyOf(Le(1), Ge(3));
744 m = AnyOf(Lt(0), Eq(1), Eq(2));
745 EXPECT_EQ(
"(isn't < 0) and (isn't equal to 1) and (isn't equal to 2)",
748 m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3));
750 "(isn't < 0) and (isn't equal to 1) and (isn't equal to 2) and (isn't "
754 m = AnyOf(Le(0), Gt(10), 3, 5, 7);
756 "(isn't <= 0) and (isn't > 10) and (isn't equal to 3) and (isn't equal "
757 "to 5) and (isn't equal to 7)",
762 TEST(AnyOfTest, AnyOfMatcherSafelyCastsMonomorphicMatchers) {
773 Matcher<int&> m5 = AnyOf(greater_than_5, less_than_10, less_than_10);
776 TEST_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",
789 m = AnyOf(GreaterThan(10), Gt(20), GreaterThan(30));
791 "which is 5 less than 10, and isn't > 20, 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",
802 m = AnyOf(GreaterThan(10), GreaterThan(20));
806 m = AnyOf(GreaterThan(30), GreaterThan(20));
810 m = AnyOf(Gt(10), Lt(20));
814 m = AnyOf(Gt(30), Gt(20));
825 int IsPositive(
double x) {
return x > 0 ? 1 : 0; }
829 class IsGreaterThan {
831 explicit IsGreaterThan(
int threshold) :
threshold_(threshold) {}
833 bool operator()(
int n)
const {
return n >
threshold_; }
844 bool ReferencesFooAndIsZero(
const int& n) {
return (&n == &foo) && (n == 0); }
848 TEST(TrulyTest, MatchesWhatSatisfiesThePredicate) {
849 Matcher<double> m = Truly(IsPositive);
855 TEST(TrulyTest, CanBeUsedWithFunctor) {
856 Matcher<int> m = Truly(IsGreaterThan(5));
862 class ConvertibleToBool {
864 explicit ConvertibleToBool(
int number) :
number_(number) {}
865 operator bool()
const {
return number_ != 0; }
871 ConvertibleToBool IsNotZero(
int number) {
return ConvertibleToBool(number); }
876 TEST(TrulyTest, PredicateCanReturnAClassConvertibleToBool) {
877 Matcher<int> m = Truly(IsNotZero);
883 TEST(TrulyTest, CanDescribeSelf) {
884 Matcher<double> m = Truly(IsPositive);
890 TEST(TrulyTest, WorksForByRefArguments) {
891 Matcher<const int&> m = Truly(ReferencesFooAndIsZero);
898 TEST(TrulyTest, ExplainsFailures) {
899 StringMatchResultListener listener;
900 EXPECT_FALSE(ExplainMatchResult(Truly(IsPositive), -1, &listener));
901 EXPECT_EQ(listener.str(),
"didn't satisfy the given predicate");
906 TEST(MatchesTest, IsSatisfiedByWhatMatchesTheMatcher) {
913 TEST(MatchesTest, WorksOnByRefArguments) {
921 TEST(MatchesTest, WorksWithMatcherOnNonRefType) {
922 Matcher<int> eq5 = Eq(5);
930 TEST(ValueTest, WorksWithPolymorphicMatcher) {
935 TEST(ValueTest, WorksWithMonomorphicMatcher) {
936 const Matcher<int> is_zero = Eq(0);
941 const Matcher<const int&> ref_n = Ref(n);
946 TEST(AllArgsTest, WorksForTuple) {
947 EXPECT_THAT(std::make_tuple(1, 2L), AllArgs(Lt()));
948 EXPECT_THAT(std::make_tuple(2L, 1), Not(AllArgs(Lt())));
951 TEST(AllArgsTest, WorksForNonTuple) {
956 class AllArgsHelper {
958 AllArgsHelper() =
default;
963 AllArgsHelper(
const AllArgsHelper&) =
delete;
964 AllArgsHelper& operator=(
const AllArgsHelper&) =
delete;
967 TEST(AllArgsTest, WorksInWithClause) {
968 AllArgsHelper helper;
969 ON_CALL(helper, Helper(
_,
_)).With(AllArgs(Lt())).WillByDefault(
Return(1));
977 class OptionalMatchersHelper {
979 OptionalMatchersHelper() =
default;
991 OptionalMatchersHelper(
const OptionalMatchersHelper&) =
delete;
992 OptionalMatchersHelper& operator=(
const OptionalMatchersHelper&) =
delete;
995 TEST(AllArgsTest, WorksWithoutMatchers) {
996 OptionalMatchersHelper helper;
1017 template <
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)) {
1051 Matcher<RawType> m1 = matcher_maker(0.0);
1060 Matcher<RawType> m3 = matcher_maker(1.0);
1067 Matcher<RawType> m4 = matcher_maker(-
infinity_);
1070 Matcher<RawType> m5 = matcher_maker(
infinity_);
1079 Matcher<const RawType&> m6 = matcher_maker(0.0);
1086 Matcher<RawType&> m7 = matcher_maker(0.0);
1124 template <
typename RawType>
1125 class 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);
1140 Matcher<RawType> m2 = matcher_maker(0.0, 1.0);
1179 Matcher<RawType> m9 =
1185 Matcher<const RawType&> m10 = matcher_maker(0.0, 1.0);
1192 Matcher<RawType&> m11 = matcher_maker(0.0, 1.0);
1207 typedef FloatingPointTest<float> FloatTest;
1209 TEST_F(FloatTest, FloatEqApproximatelyMatchesFloats) { TestMatches(&FloatEq); }
1211 TEST_F(FloatTest, NanSensitiveFloatEqApproximatelyMatchesFloats) {
1212 TestMatches(&NanSensitiveFloatEq);
1215 TEST_F(FloatTest, FloatEqCannotMatchNaN) {
1217 Matcher<float> m = FloatEq(
nan1_);
1223 TEST_F(FloatTest, NanSensitiveFloatEqCanMatchNaN) {
1225 Matcher<float> m = NanSensitiveFloatEq(
nan1_);
1231 TEST_F(FloatTest, FloatEqCanDescribeSelf) {
1232 Matcher<float> m1 = FloatEq(2.0f);
1236 Matcher<float> m2 = FloatEq(0.5f);
1240 Matcher<float> m3 = FloatEq(
nan1_);
1245 TEST_F(FloatTest, NanSensitiveFloatEqCanDescribeSelf) {
1246 Matcher<float> m1 = NanSensitiveFloatEq(2.0f);
1250 Matcher<float> m2 = NanSensitiveFloatEq(0.5f);
1254 Matcher<float> m3 = NanSensitiveFloatEq(
nan1_);
1261 typedef FloatingPointNearTest<float> FloatNearTest;
1263 TEST_F(FloatNearTest, FloatNearMatches) { TestNearMatches(&FloatNear); }
1265 TEST_F(FloatNearTest, NanSensitiveFloatNearApproximatelyMatchesFloats) {
1266 TestNearMatches(&NanSensitiveFloatNear);
1269 TEST_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);
1285 TEST_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);
1301 TEST_F(FloatNearTest, FloatNearCannotMatchNaN) {
1309 TEST_F(FloatNearTest, NanSensitiveFloatNearCanMatchNaN) {
1311 Matcher<float> m = NanSensitiveFloatNear(
nan1_, 0.1f);
1318 typedef FloatingPointTest<double> DoubleTest;
1320 TEST_F(DoubleTest, DoubleEqApproximatelyMatchesDoubles) {
1321 TestMatches(&DoubleEq);
1324 TEST_F(DoubleTest, NanSensitiveDoubleEqApproximatelyMatchesDoubles) {
1325 TestMatches(&NanSensitiveDoubleEq);
1328 TEST_F(DoubleTest, DoubleEqCannotMatchNaN) {
1330 Matcher<double> m = DoubleEq(
nan1_);
1336 TEST_F(DoubleTest, NanSensitiveDoubleEqCanMatchNaN) {
1338 Matcher<double> m = NanSensitiveDoubleEq(
nan1_);
1344 TEST_F(DoubleTest, DoubleEqCanDescribeSelf) {
1345 Matcher<double> m1 = DoubleEq(2.0);
1349 Matcher<double> m2 = DoubleEq(0.5);
1353 Matcher<double> m3 = DoubleEq(
nan1_);
1358 TEST_F(DoubleTest, NanSensitiveDoubleEqCanDescribeSelf) {
1359 Matcher<double> m1 = NanSensitiveDoubleEq(2.0);
1363 Matcher<double> m2 = NanSensitiveDoubleEq(0.5);
1367 Matcher<double> m3 = NanSensitiveDoubleEq(
nan1_);
1374 typedef FloatingPointNearTest<double> DoubleNearTest;
1376 TEST_F(DoubleNearTest, DoubleNearMatches) { TestNearMatches(&DoubleNear); }
1378 TEST_F(DoubleNearTest, NanSensitiveDoubleNearApproximatelyMatchesDoubles) {
1379 TestNearMatches(&NanSensitiveDoubleNear);
1382 TEST_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);
1398 TEST_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 <<
"\".";
1412 TEST_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);
1428 TEST_F(DoubleNearTest, DoubleNearCannotMatchNaN) {
1436 TEST_F(DoubleNearTest, NanSensitiveDoubleNearCanMatchNaN) {
1438 Matcher<double> m = NanSensitiveDoubleNear(
nan1_, 0.1);
1444 TEST(NotTest, WorksOnMoveOnlyType) {
1445 std::unique_ptr<int>
p(
new int(3));
1450 TEST(AllOfTest, HugeMatcher) {
1453 EXPECT_THAT(0, testing::AllOf(
_,
_,
_,
_,
_,
_,
_,
_,
_,
1454 testing::AllOf(
_,
_,
_,
_,
_,
_,
_,
_,
_,
_)));
1457 TEST(AnyOfTest, HugeMatcher) {
1460 EXPECT_THAT(0, testing::AnyOf(
_,
_,
_,
_,
_,
_,
_,
_,
_,
1461 testing::AnyOf(
_,
_,
_,
_,
_,
_,
_,
_,
_,
_)));
1464 namespace adl_test {
1478 template <
typename T1,
typename T2>
1479 bool AllOf(
const T1& ,
const T2& ) {
1483 TEST(AllOfTest, DoesNotCallAllOfUnqualified) {
1485 testing::AllOf(M(), M(), M(), M(), M(), M(), M(), M(), M(), M()));
1488 template <
typename T1,
typename T2>
1489 bool AnyOf(
const T1&,
const T2&) {
1493 TEST(AnyOfTest, DoesNotCallAnyOfUnqualified) {
1495 testing::AnyOf(M(), M(), M(), M(), M(), M(), M(), M(), M(), M()));
1500 TEST(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)))));
1506 TEST(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)))));
constexpr bool StartsWith(const char(&prefix)[N], const char(&str)[M])
GTEST_DISABLE_MSC_WARNINGS_POP_() TEST(LinkTest
std::string Explain(const MatcherType &m, const Value &x)
constexpr bool EndsWith(const char(&suffix)[N], const char(&str)[M])
#define TEST_F(test_fixture, test_name)
#define MOCK_METHOD0(m,...)
#define TEST(test_suite_name, test_name)
#define ON_CALL(obj, call)
#define INSTANTIATE_GTEST_MATCHER_TEST_P(TestSuite)
#define MATCHER(name, description)
std::string Describe(const Matcher< T > &m)
#define MOCK_METHOD2(m,...)
const RawType close_to_negative_zero_
const Bits infinity_bits_
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
ADVar foo(double d, ADVar x, ADVar y)
#define MOCK_METHOD1(m,...)
const RawType close_to_one_
const RawType further_from_one_
const RawType close_to_infinity_
#define SCOPED_TRACE(message)
#define EXPECT_THAT(value, matcher)
internal::ReturnAction< R > Return(R value)
#define EXPECT_CALL(obj, call)
std::string DescribeNegation(const Matcher< T > &m)
#define EXPECT_EQ(val1, val2)
#define TEST_P(test_suite_name, test_name)
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
#define EXPECT_TRUE(condition)
const RawType close_to_positive_zero_
const RawType further_from_infinity_
#define EXPECT_FALSE(condition)
const RawType further_from_negative_zero_
static ExpectedAnswer expected[4]