53 #include "gmock/gmock.h" 54 #include "gtest/gtest.h" 55 #include "gtest/gtest-spi.h" 63 namespace gmock_matchers_test {
75 using std::stringstream;
98 using testing::IsEmpty;
155 #define GMOCK_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0])) 163 *os <<
"is > " << rhs_;
168 const int diff = lhs - rhs_;
170 *listener <<
"which is " << diff <<
" more than " << rhs_;
171 }
else if (diff == 0) {
172 *listener <<
"which is the same as " << rhs_;
174 *listener <<
"which is " << -diff <<
" less than " << rhs_;
190 return " (of type " + type_name +
")";
197 template <
typename T>
205 template <
typename T>
213 template <
typename MatcherType,
typename Value>
217 return listener.
str();
220 TEST(MatchResultListenerTest, StreamingWorks) {
222 listener <<
"hi" << 5;
236 TEST(MatchResultListenerTest, CanAccessUnderlyingStream) {
243 TEST(MatchResultListenerTest, IsInterestedWorks) {
261 *os <<
"is an even number";
270 TEST(MatcherInterfaceTest, CanBeImplementedUsingPublishedAPI) {
279 const bool match = x % 2 == 0;
281 *listener <<
"value % " << 2;
282 if (listener->
stream() != NULL) {
285 *listener->
stream() <<
" == " << (x % 2);
291 *os <<
"is an even number";
295 TEST(MatcherInterfaceTest, CanBeImplementedUsingNewAPI) {
304 TEST(MatcherTest, CanBeDefaultConstructed) {
309 TEST(MatcherTest, CanBeConstructedFromMatcherInterface) {
317 TEST(MatcherTest, CanBeImplicitlyConstructedFromValue) {
324 TEST(MatcherTest, CanBeImplicitlyConstructedFromNULL) {
332 TEST(MatcherTest, IsCopyable) {
346 TEST(MatcherTest, CanDescribeItself) {
352 TEST(MatcherTest, MatchAndExplain) {
360 EXPECT_EQ(
"which is 9 less than 0", listener2.str());
365 TEST(StringMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) {
377 TEST(StringMatcherTest, CanBeImplicitlyConstructedFromString) {
387 #if GTEST_HAS_STRING_PIECE_ 390 TEST(StringPieceMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) {
402 TEST(StringPieceMatcherTest, CanBeImplicitlyConstructedFromString) {
414 TEST(StringPieceMatcherTest, CanBeImplicitlyConstructedFromStringPiece) {
423 #endif // GTEST_HAS_STRING_PIECE_ 428 TEST(MakeMatcherTest, ConstructsMatcherFromMatcherInterface) {
438 template <
typename T>
442 return p == &g_bar || x == 0;
445 void DescribeTo(ostream* os)
const { *os <<
"g_bar or zero"; }
448 *os <<
"doesn't reference g_bar and is not zero";
458 TEST(MakePolymorphicMatcherTest, ConstructsMatcherUsingOldAPI) {
484 template <
typename T>
487 *listener <<
"% " << 2;
488 if (listener->
stream() != NULL) {
491 *listener->
stream() <<
" == " << (x % 2);
501 TEST(MakePolymorphicMatcherTest, ConstructsMatcherUsingNewAPI) {
526 TEST(MatcherCastTest, FromPolymorphicMatcher) {
537 explicit IntValue(
int a_value) : value_(a_value) {}
539 int value()
const {
return value_; }
546 return foo.
value() > 0;
551 TEST(MatcherCastTest, FromCompatibleType) {
567 TEST(MatcherCastTest, FromConstReferenceToNonReference) {
575 TEST(MatcherCastTest, FromReferenceToNonReference) {
583 TEST(MatcherCastTest, FromNonReferenceToConstReference) {
591 TEST(MatcherCastTest, FromNonReferenceToReference) {
601 TEST(MatcherCastTest, FromSameType) {
611 template <
typename T>
623 return os << a.
value;
626 TEST(MatcherCastTest, ConversionConstructorIsUsed) {
632 TEST(MatcherCastTest, FromConvertibleFromAny) {
643 TEST(SafeMatcherCastTest, FromPolymorphicMatcher) {
652 TEST(SafeMatcherCastTest, FromLosslesslyConvertibleArithmeticType) {
665 TEST(SafeMatcherCastTest, FromBaseClass) {
679 TEST(SafeMatcherCastTest, FromConstReferenceToReference) {
689 TEST(SafeMatcherCastTest, FromNonReferenceToConstReference) {
697 TEST(SafeMatcherCastTest, FromNonReferenceToReference) {
707 TEST(SafeMatcherCastTest, FromSameType) {
714 TEST(SafeMatcherCastTest, ConversionConstructorIsUsed) {
720 TEST(SafeMatcherCastTest, FromConvertibleFromAny) {
742 TEST(ATest, WorksForDerivedClass) {
757 TEST(AnTest, MatchesAnyValue) {
772 TEST(AnTest, CanDescribeSelf) {
778 TEST(UnderscoreTest, MatchesAnyValue) {
793 TEST(UnderscoreTest, CanDescribeSelf) {
799 TEST(EqTest, MatchesEqualValue) {
801 const char a1[] =
"hi";
802 const char a2[] =
"hi";
820 TEST(EqTest, CanDescribeSelf) {
838 TEST(TypedEqTest, ChecksEqualityForGivenType) {
849 TEST(TypedEqTest, CanDescribeSelf) {
859 template <
typename T>
863 template <
typename T2>
864 static void IsTypeOf(T2 v);
867 TEST(TypedEqTest, HasSpecifiedType) {
874 TEST(GeTest, ImplementsGreaterThanOrEqual) {
882 TEST(GeTest, CanDescribeSelf) {
888 TEST(GtTest, ImplementsGreaterThan) {
896 TEST(GtTest, CanDescribeSelf) {
902 TEST(LeTest, ImplementsLessThanOrEqual) {
910 TEST(LeTest, CanDescribeSelf) {
916 TEST(LtTest, ImplementsLessThan) {
924 TEST(LtTest, CanDescribeSelf) {
930 TEST(NeTest, ImplementsNotEqual) {
938 TEST(NeTest, CanDescribeSelf) {
944 TEST(IsNullTest, MatchesNullPointer) {
952 const char* p2 = NULL;
956 #if !GTEST_OS_SYMBIAN 968 EXPECT_FALSE(m3.Matches(reinterpret_cast<void*>(0xbeef)));
981 TEST(IsNullTest, ReferenceToConstLinkedPtr) {
990 TEST(IsNullTest, ReferenceToConstScopedPtr) {
1000 TEST(IsNullTest, CanDescribeSelf) {
1007 TEST(NotNullTest, MatchesNonNullPointer) {
1015 const char* p2 = NULL;
1029 TEST(NotNullTest, ReferenceToConstLinkedPtr) {
1038 TEST(NotNullTest, ReferenceToConstScopedPtr) {
1048 TEST(NotNullTest, CanDescribeSelf) {
1055 TEST(RefTest, MatchesSameVariable) {
1068 ss <<
"references the variable @" << &n <<
" 5";
1074 TEST(RefTest, CanBeUsedAsMatcherForConstReference) {
1112 TEST(StrEqTest, MatchesEqualString) {
1125 EXPECT_EQ(
"is equal to \"Hi-\'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\\xD3\"",
1128 string str(
"01204500800");
1132 str[0] = str[6] = str[7] = str[9] = str[10] =
'\0';
1137 TEST(StrNeTest, MatchesUnequalString) {
1153 TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) {
1165 TEST(StrCaseEqTest, MatchesEqualStringWith0IgnoringCase) {
1166 string str1(
"oabocdooeoo");
1167 string str2(
"OABOCDOOEOO");
1171 str1[3] = str2[3] =
'\0';
1175 str1[0] = str1[6] = str1[7] = str1[10] =
'\0';
1176 str2[0] = str2[6] = str2[7] = str2[10] =
'\0';
1178 str1[9] = str2[9] =
'\0';
1185 str2.append(1,
'\0');
1190 TEST(StrCaseEqTest, CanDescribeSelf) {
1195 TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) {
1207 TEST(StrCaseNeTest, CanDescribeSelf) {
1213 TEST(HasSubstrTest, WorksForStringClasses) {
1224 TEST(HasSubstrTest, WorksForCStrings) {
1237 TEST(HasSubstrTest, CanDescribeSelf) {
1250 EXPECT_EQ(
"whose first field is a value which is 5 less than 10",
1251 Explain(m, make_pair(5,
true)));
1252 EXPECT_EQ(
"whose first field is a value which is 5 more than 10",
1253 Explain(m, make_pair(15,
true)));
1257 pair<int, std::string> p(25,
"foo");
1264 TEST(KeyTest, SafelyCastsInnerMatcher) {
1267 pair<char, bool> p(
'a',
true);
1272 TEST(KeyTest, InsideContainsUsingMap) {
1273 map<int, char> container;
1274 container.insert(make_pair(1,
'a'));
1275 container.insert(make_pair(2,
'b'));
1276 container.insert(make_pair(4,
'c'));
1281 TEST(KeyTest, InsideContainsUsingMultimap) {
1282 multimap<int, char> container;
1283 container.insert(make_pair(1,
'a'));
1284 container.insert(make_pair(2,
'b'));
1285 container.insert(make_pair(4,
'c'));
1288 container.insert(make_pair(25,
'd'));
1290 container.insert(make_pair(25,
'e'));
1309 EXPECT_EQ(
"has a first field that is equal to \"foo\"" 1310 ", and has a second field that is equal to 42",
1312 EXPECT_EQ(
"has a first field that isn't equal to \"foo\"" 1313 ", or has a second field that isn't equal to 42",
1317 EXPECT_EQ(
"has a first field that isn't equal to 13" 1318 ", and has a second field that is equal to 42",
1322 TEST(PairTest, CanExplainMatchResultTo) {
1326 EXPECT_EQ(
"whose first field does not match, which is 1 less than 0",
1327 Explain(m, make_pair(-1, -2)));
1331 EXPECT_EQ(
"whose second field does not match, which is 2 less than 0",
1332 Explain(m, make_pair(1, -2)));
1336 EXPECT_EQ(
"whose first field does not match, which is 1 less than 0",
1337 Explain(m, make_pair(-1, 2)));
1340 EXPECT_EQ(
"whose both fields match, where the first field is a value " 1341 "which is 1 more than 0, and the second field is a value " 1342 "which is 2 more than 0",
1348 EXPECT_EQ(
"whose both fields match, where the first field is a value " 1349 "which is 1 more than 0",
1350 Explain(explain_first, make_pair(1, 0)));
1355 EXPECT_EQ(
"whose both fields match, where the second field is a value " 1356 "which is 1 more than 0",
1357 Explain(explain_second, make_pair(0, 1)));
1361 pair<int, std::string> p(25,
"foo");
1380 TEST(PairTest, SafelyCastsInnerMatchers) {
1383 pair<char, bool> p(
'a',
true);
1390 TEST(PairTest, InsideContainsUsingMap) {
1391 map<int, char> container;
1392 container.insert(make_pair(1,
'a'));
1393 container.insert(make_pair(2,
'b'));
1394 container.insert(make_pair(4,
'c'));
1403 TEST(StartsWithTest, MatchesStringWithGivenPrefix) {
1417 TEST(StartsWithTest, CanDescribeSelf) {
1424 TEST(EndsWithTest, MatchesStringWithGivenSuffix) {
1438 TEST(EndsWithTest, CanDescribeSelf) {
1445 TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) {
1457 TEST(MatchesRegexTest, CanDescribeSelf) {
1467 TEST(ContainsRegexTest, MatchesStringContainingGivenRegex) {
1479 TEST(ContainsRegexTest, CanDescribeSelf) {
1488 #if GTEST_HAS_STD_WSTRING 1489 TEST(StdWideStrEqTest, MatchesEqual) {
1507 str[0] = str[6] = str[7] = str[9] = str[10] = L
'\0';
1512 TEST(StdWideStrEqTest, CanDescribeSelf) {
1514 EXPECT_EQ(
"is equal to L\"Hi-\'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\"",
1518 EXPECT_EQ(
"is equal to L\"\\xD3\\x576\\x8D3\\xC74D\"",
1525 str[0] = str[6] = str[7] = str[9] = str[10] = L
'\0';
1530 TEST(StdWideStrNeTest, MatchesUnequalString) {
1541 TEST(StdWideStrNeTest, CanDescribeSelf) {
1546 TEST(StdWideStrCaseEqTest, MatchesEqualStringIgnoringCase) {
1558 TEST(StdWideStrCaseEqTest, MatchesEqualStringWith0IgnoringCase) {
1564 str1[3] = str2[3] = L
'\0';
1568 str1[0] = str1[6] = str1[7] = str1[10] = L
'\0';
1569 str2[0] = str2[6] = str2[7] = str2[10] = L
'\0';
1571 str1[9] = str2[9] = L
'\0';
1578 str2.append(1, L
'\0');
1583 TEST(StdWideStrCaseEqTest, CanDescribeSelf) {
1588 TEST(StdWideStrCaseNeTest, MatchesUnequalStringIgnoringCase) {
1600 TEST(StdWideStrCaseNeTest, CanDescribeSelf) {
1606 TEST(StdWideHasSubstrTest, WorksForStringClasses) {
1617 TEST(StdWideHasSubstrTest, WorksForCStrings) {
1630 TEST(StdWideHasSubstrTest, CanDescribeSelf) {
1637 TEST(StdWideStartsWithTest, MatchesStringWithGivenPrefix) {
1651 TEST(StdWideStartsWithTest, CanDescribeSelf) {
1658 TEST(StdWideEndsWithTest, MatchesStringWithGivenSuffix) {
1672 TEST(StdWideEndsWithTest, CanDescribeSelf) {
1677 #endif // GTEST_HAS_STD_WSTRING 1679 #if GTEST_HAS_GLOBAL_WSTRING 1680 TEST(GlobalWideStrEqTest, MatchesEqual) {
1698 str[0] = str[6] = str[7] = str[9] = str[10] = L
'\0';
1703 TEST(GlobalWideStrEqTest, CanDescribeSelf) {
1705 EXPECT_EQ(
"is equal to L\"Hi-\'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\"",
1709 EXPECT_EQ(
"is equal to L\"\\xD3\\x576\\x8D3\\xC74D\"",
1716 str[0] = str[6] = str[7] = str[9] = str[10] = L
'\0';
1721 TEST(GlobalWideStrNeTest, MatchesUnequalString) {
1732 TEST(GlobalWideStrNeTest, CanDescribeSelf) {
1737 TEST(GlobalWideStrCaseEqTest, MatchesEqualStringIgnoringCase) {
1749 TEST(GlobalWideStrCaseEqTest, MatchesEqualStringWith0IgnoringCase) {
1755 str1[3] = str2[3] = L
'\0';
1759 str1[0] = str1[6] = str1[7] = str1[10] = L
'\0';
1760 str2[0] = str2[6] = str2[7] = str2[10] = L
'\0';
1762 str1[9] = str2[9] = L
'\0';
1769 str2.append(1, L
'\0');
1774 TEST(GlobalWideStrCaseEqTest, CanDescribeSelf) {
1779 TEST(GlobalWideStrCaseNeTest, MatchesUnequalStringIgnoringCase) {
1791 TEST(GlobalWideStrCaseNeTest, CanDescribeSelf) {
1797 TEST(GlobalWideHasSubstrTest, WorksForStringClasses) {
1808 TEST(GlobalWideHasSubstrTest, WorksForCStrings) {
1821 TEST(GlobalWideHasSubstrTest, CanDescribeSelf) {
1828 TEST(GlobalWideStartsWithTest, MatchesStringWithGivenPrefix) {
1842 TEST(GlobalWideStartsWithTest, CanDescribeSelf) {
1849 TEST(GlobalWideEndsWithTest, MatchesStringWithGivenSuffix) {
1863 TEST(GlobalWideEndsWithTest, CanDescribeSelf) {
1868 #endif // GTEST_HAS_GLOBAL_WSTRING 1875 TEST(Eq2Test, MatchesEqualArguments) {
1889 TEST(Ge2Test, MatchesGreaterThanOrEqualArguments) {
1904 TEST(Gt2Test, MatchesGreaterThanArguments) {
1919 TEST(Le2Test, MatchesLessThanOrEqualArguments) {
1934 TEST(Lt2Test, MatchesLessThanArguments) {
1949 TEST(Ne2Test, MatchesUnequalArguments) {
1977 TEST(NotTest, NotMatcherSafelyCastsMonomorphicMatchers) {
1990 for (
int i = 1; i <= num; ++i) {
1998 TEST(AllOfTest, MatchesWhenAllMatch) {
2042 #if GTEST_LANG_CXX11 2044 TEST(AllOfTest, VariadicMatchesWhenAllMatch) {
2047 ::testing::AllOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
2062 #endif // GTEST_LANG_CXX11 2072 "((isn't equal to 1) and " 2073 "(isn't equal to 2))",
2079 "(isn't equal to 1)) and " 2080 "((isn't equal to 2) and " 2081 "(isn't equal to 3))",
2088 "((isn't equal to 3) and " 2089 "((isn't equal to 5) and " 2090 "(isn't equal to 7)))",
2095 TEST(AllOfTest, CanDescribeNegation) {
2104 "((is equal to 1) or " 2111 "(is equal to 1)) or " 2112 "((is equal to 2) or " 2120 "((is equal to 3) or " 2121 "((is equal to 5) or " 2122 "(is equal to 7)))",
2127 TEST(AllOfTest, AllOfMatcherSafelyCastsMonomorphicMatchers) {
2152 EXPECT_EQ(
"which is 20 more than 10, and which is 10 more than 20",
2158 EXPECT_EQ(
"which is 15 more than 10, and which is 5 more than 20",
2163 EXPECT_EQ(
"which is 30 more than 10, and which is 20 more than 20, " 2164 "and which is 10 more than 30",
2188 for (
int i = 1; i <= num; ++i) {
2196 TEST(AnyOfTest, MatchesWhenAnyMatches) {
2234 AnyOfMatches(10,
AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
2237 #if GTEST_LANG_CXX11 2239 TEST(AnyOfTest, VariadicMatchesWhenAnyMatches) {
2242 Matcher<int> m =
::testing::AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
2246 AnyOfMatches(50,
AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
2247 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
2248 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
2249 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
2250 41, 42, 43, 44, 45, 46, 47, 48, 49, 50));
2253 #endif // GTEST_LANG_CXX11 2264 "((is equal to 1) or (is equal to 2))",
2269 "(is equal to 1)) or " 2270 "((is equal to 2) or " 2277 "((is equal to 3) or " 2278 "((is equal to 5) or " 2279 "(is equal to 7)))",
2284 TEST(AnyOfTest, CanDescribeNegation) {
2287 EXPECT_EQ(
"(isn't <= 1) and (isn't >= 3)",
2292 "((isn't equal to 1) and (isn't equal to 2))",
2297 "(isn't equal to 1)) and " 2298 "((isn't equal to 2) and " 2299 "(isn't equal to 3))",
2304 "(isn't > 10)) and " 2305 "((isn't equal to 3) and " 2306 "((isn't equal to 5) and " 2307 "(isn't equal to 7)))",
2312 TEST(AnyOfTest, AnyOfMatcherSafelyCastsMonomorphicMatchers) {
2337 EXPECT_EQ(
"which is 5 less than 10, and which is 15 less than 20",
2343 EXPECT_EQ(
"which is 5 less than 10, and which is 25 less than 30",
2348 EXPECT_EQ(
"which is 5 less than 10, and which is 15 less than 20, " 2349 "and which is 25 less than 30",
2377 return x > 0 ? 1 : 0;
2398 return (&n == &foo) && (n == 0);
2403 TEST(TrulyTest, MatchesWhatSatisfiesThePredicate) {
2410 TEST(TrulyTest, CanBeUsedWithFunctor) {
2420 operator bool()
const {
return number_ != 0; }
2433 TEST(TrulyTest, PredicateCanReturnAClassConvertibleToBool) {
2442 EXPECT_EQ(
"satisfies the given predicate",
2448 TEST(TrulyTest, WorksForByRefArguments) {
2457 TEST(MatchesTest, IsSatisfiedByWhatMatchesTheMatcher) {
2464 TEST(MatchesTest, WorksOnByRefArguments) {
2472 TEST(MatchesTest, WorksWithMatcherOnNonRefType) {
2481 TEST(ValueTest, WorksWithPolymorphicMatcher) {
2486 TEST(ValueTest, WorksWithMonomorphicMatcher) {
2497 TEST(ExplainMatchResultTest, WorksWithPolymorphicMatcher) {
2507 TEST(ExplainMatchResultTest, WorksWithMonomorphicMatcher) {
2523 TEST(ExplainMatchResultTest, WorksInsideMATCHER) {
2532 TEST(AllArgsTest, WorksForNonTuple) {
2547 TEST(AllArgsTest, WorksInWithClause) {
2551 .WillByDefault(
Return(1));
2563 TEST(MatcherAssertionTest, WorksWhenMatcherIsSatisfied) {
2572 TEST(MatcherAssertionTest, WorksWhenMatcherIsNotSatisfied) {
2575 static unsigned short n;
2585 "Expected: is > 10\n" 2586 " Actual: 5" +
OfType(
"unsigned short"));
2591 "Expected: (is <= 7) and (is >= 5)\n" 2592 " Actual: 0" +
OfType(
"unsigned short"));
2597 TEST(MatcherAssertionTest, WorksForByRefArguments) {
2605 "Expected: does not reference the variable @");
2608 "Actual: 0" +
OfType(
"int") +
", which is located @");
2611 #if !GTEST_OS_SYMBIAN 2625 TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) {
2631 const string bad =
"bad";
2634 "Expected: ends with \"ok\"\n" 2635 " Actual: \"bad\"");
2639 "Expected: is > 5\n" 2640 " Actual: 5" +
OfType(
"int"));
2642 #endif // !GTEST_OS_SYMBIAN 2645 template <
typename RawType>
2652 : max_ulps_(Floating::kMaxUlps),
2653 zero_bits_(Floating(0).bits()),
2654 one_bits_(Floating(1).bits()),
2655 infinity_bits_(Floating(Floating::Infinity()).bits()),
2656 close_to_positive_zero_(
2657 Floating::ReinterpretBits(zero_bits_ + max_ulps_/2)),
2658 close_to_negative_zero_(
2659 -Floating::ReinterpretBits(zero_bits_ + max_ulps_ - max_ulps_/2)),
2660 further_from_negative_zero_(-Floating::ReinterpretBits(
2661 zero_bits_ + max_ulps_ + 1 - max_ulps_/2)),
2662 close_to_one_(Floating::ReinterpretBits(one_bits_ + max_ulps_)),
2663 further_from_one_(Floating::ReinterpretBits(one_bits_ + max_ulps_ + 1)),
2664 infinity_(Floating::Infinity()),
2666 Floating::ReinterpretBits(infinity_bits_ - max_ulps_)),
2667 further_from_infinity_(
2668 Floating::ReinterpretBits(infinity_bits_ - max_ulps_ - 1)),
2669 max_(Floating::Max()),
2670 nan1_(Floating::ReinterpretBits(Floating::kExponentBitMask | 1)),
2671 nan2_(Floating::ReinterpretBits(Floating::kExponentBitMask | 200)) {
2675 EXPECT_EQ(
sizeof(RawType),
sizeof(Bits));
2755 template <
typename RawType>
2764 (*matcher_maker)(RawType, RawType)) {
2784 EXPECT_FALSE(m3.Matches(ParentType::close_to_infinity_));
2789 EXPECT_FALSE(m4.Matches(-ParentType::close_to_infinity_));
2819 EXPECT_TRUE(m10.Matches(ParentType::close_to_positive_zero_));
2841 TEST_F(FloatTest, FloatEqApproximatelyMatchesFloats) {
2845 TEST_F(FloatTest, NanSensitiveFloatEqApproximatelyMatchesFloats) {
2857 TEST_F(FloatTest, NanSensitiveFloatEqCanMatchNaN) {
2879 TEST_F(FloatTest, NanSensitiveFloatEqCanDescribeSelf) {
2901 TEST_F(FloatNearTest, NanSensitiveFloatNearApproximatelyMatchesFloats) {
2905 TEST_F(FloatNearTest, FloatNearCanDescribeSelf) {
2921 TEST_F(FloatNearTest, NanSensitiveFloatNearCanDescribeSelf) {
2937 TEST_F(FloatNearTest, FloatNearCannotMatchNaN) {
2945 TEST_F(FloatNearTest, NanSensitiveFloatNearCanMatchNaN) {
2956 TEST_F(DoubleTest, DoubleEqApproximatelyMatchesDoubles) {
2960 TEST_F(DoubleTest, NanSensitiveDoubleEqApproximatelyMatchesDoubles) {
2972 TEST_F(DoubleTest, NanSensitiveDoubleEqCanMatchNaN) {
2980 TEST_F(DoubleTest, DoubleEqCanDescribeSelf) {
2994 TEST_F(DoubleTest, NanSensitiveDoubleEqCanDescribeSelf) {
3016 TEST_F(DoubleNearTest, NanSensitiveDoubleNearApproximatelyMatchesDoubles) {
3020 TEST_F(DoubleNearTest, DoubleNearCanDescribeSelf) {
3036 TEST_F(DoubleNearTest, NanSensitiveDoubleNearCanDescribeSelf) {
3052 TEST_F(DoubleNearTest, DoubleNearCannotMatchNaN) {
3060 TEST_F(DoubleNearTest, NanSensitiveDoubleNearCanMatchNaN) {
3078 TEST(PointeeTest, RawPointerToConst) {
3088 TEST(PointeeTest, ReferenceToConstRawPointer) {
3098 TEST(PointeeTest, ReferenceToNonConstRawPointer) {
3111 template <
typename T>
3120 T*
get() {
return val_; }
3123 const T*
get()
const {
return val_; }
3130 TEST(PointeeTest, WorksWithConstPropagatingPointers) {
3142 TEST(PointeeTest, NeverMatchesNull) {
3148 TEST(PointeeTest, MatchesAgainstAValue) {
3158 TEST(PointeeTest, CanDescribeSelf) {
3161 EXPECT_EQ(
"does not point to a value that is > 3",
3165 TEST(PointeeTest, CanExplainMatchResult) {
3172 EXPECT_EQ(
"which points to 3" +
OfType(
"long") +
", which is 2 more than 1",
3176 TEST(PointeeTest, AlwaysExplainsPointee) {
3200 : x(rhs.x), y(rhs.y), z(rhs.z.value()), p(rhs.p) {}
3220 TEST(FieldTest, WorksForNonConstField) {
3230 TEST(FieldTest, WorksForConstField) {
3235 m =
Field(&AStruct::y,
Le(0.0));
3240 TEST(FieldTest, WorksForUncopyableField) {
3250 TEST(FieldTest, WorksForPointerField) {
3267 TEST(FieldTest, WorksForByRefArgument) {
3278 TEST(FieldTest, WorksForArgumentOfSubType) {
3291 TEST(FieldTest, WorksForCompatibleMatcherType) {
3311 TEST(FieldTest, CanExplainMatchResult) {
3320 "whose given field is 1" +
OfType(
"int") +
", which is 1 more than 0",
3325 TEST(FieldForPointerTest, WorksForPointerToConst) {
3335 TEST(FieldForPointerTest, WorksForPointerToNonConst) {
3345 TEST(FieldForPointerTest, WorksForReferenceToConstPointer) {
3355 TEST(FieldForPointerTest, DoesNotMatchNull) {
3362 TEST(FieldForPointerTest, WorksForArgumentOfSubType) {
3374 TEST(FieldForPointerTest, CanDescribeSelf) {
3382 TEST(FieldForPointerTest, CanExplainMatchResult) {
3388 EXPECT_EQ(
"which points to an object whose given field is 1" +
OfType(
"int"),
3392 EXPECT_EQ(
"which points to an object whose given field is 1" +
OfType(
"int") +
3393 ", which is 1 more than 0",
Explain(m, &a));
3402 int n()
const {
return n_; }
3407 const string&
s()
const {
return s_; }
3409 void set_s(
const string& new_s) { s_ = new_s; }
3412 double&
x()
const {
return x_; }
3430 TEST(PropertyTest, WorksForNonReferenceProperty) {
3443 TEST(PropertyTest, WorksForReferenceToConstProperty) {
3456 TEST(PropertyTest, WorksForReferenceToNonConstProperty) {
3469 TEST(PropertyTest, WorksForByValueArgument) {
3482 TEST(PropertyTest, WorksForArgumentOfSubType) {
3497 TEST(PropertyTest, WorksForCompatibleMatcherType) {
3509 TEST(PropertyTest, CanDescribeSelf) {
3513 EXPECT_EQ(
"is an object whose given property isn't >= 0",
3518 TEST(PropertyTest, CanExplainMatchResult) {
3527 "whose given property is 1" +
OfType(
"int") +
", which is 1 more than 0",
3532 TEST(PropertyForPointerTest, WorksForPointerToConst) {
3544 TEST(PropertyForPointerTest, WorksForPointerToNonConst) {
3557 TEST(PropertyForPointerTest, WorksForReferenceToConstPointer) {
3569 TEST(PropertyForPointerTest, WorksForReferenceToNonConstProperty) {
3576 TEST(PropertyForPointerTest, WorksForArgumentOfSubType) {
3590 TEST(PropertyForPointerTest, CanDescribeSelf) {
3594 EXPECT_EQ(
"is an object whose given property isn't >= 0",
3599 TEST(PropertyForPointerTest, CanExplainMatchResult) {
3606 "which points to an object whose given property is 1" +
OfType(
"int"),
3610 EXPECT_EQ(
"which points to an object whose given property is 1" +
3611 OfType(
"int") +
", which is 1 more than 0",
3621 TEST(ResultOfTest, WorksForFunctionPointers) {
3629 TEST(ResultOfTest, CanDescribeItself) {
3632 EXPECT_EQ(
"is mapped by the given callable to a value that " 3633 "is equal to \"foo\"",
Describe(matcher));
3634 EXPECT_EQ(
"is mapped by the given callable to a value that " 3641 TEST(ResultOfTest, CanExplainMatchResult) {
3643 EXPECT_EQ(
"which is mapped by the given callable to 90" +
OfType(
"int"),
3647 EXPECT_EQ(
"which is mapped by the given callable to 90" +
OfType(
"int") +
3648 ", which is 5 more than 85",
Explain(matcher, 36));
3653 TEST(ResultOfTest, WorksForNonReferenceResults) {
3668 TEST(ResultOfTest, WorksForReferenceToNonConstResults) {
3690 TEST(ResultOfTest, WorksForReferenceToConstResults) {
3701 TEST(ResultOfTest, WorksForCompatibleMatcherTypes) {
3711 TEST(ResultOfDeathTest, DiesOnNullFunctionPointers) {
3713 ResultOf(
static_cast<string(*)(
int dummy)
>(NULL),
Eq(
string(
"foo"))),
3714 "NULL function pointer is passed into ResultOf\\(\\)\\.");
3719 TEST(ResultOfTest, WorksForFunctionReferences) {
3727 struct Functor :
public ::std::unary_function<int, string> {
3733 TEST(ResultOfTest, WorksForFunctors) {
3746 int operator()(
const char* s) {
return static_cast<int>(strlen(s)); }
3749 TEST(ResultOfTest, WorksForPolymorphicFunctors) {
3757 EXPECT_TRUE(matcher_string.Matches(
"long string"));
3768 TEST(ResultOfTest, WorksForReferencingCallables) {
3785 template <
typename T>
3787 *listener <<
"which is " << (n % divider_) <<
" modulo " 3789 return (n % divider_) == 0;
3793 *os <<
"is divisible by " << divider_;
3797 *os <<
"is not divisible by " << divider_;
3813 TEST(ExplainMatchResultTest, AllOf_False_False) {
3820 TEST(ExplainMatchResultTest, AllOf_False_True) {
3827 TEST(ExplainMatchResultTest, AllOf_True_False) {
3834 TEST(ExplainMatchResultTest, AllOf_True_True) {
3839 TEST(ExplainMatchResultTest, AllOf_True_True_2) {
3844 TEST(ExplainmatcherResultTest, MonomorphicMatcher) {
3860 return value() == rhs.
value();
3864 return value() >= rhs.
value();
3872 TEST(ByRefTest, AllowsNotCopyableConstValueInMatchers) {
3881 TEST(ByRefTest, AllowsNotCopyableValueInMatchers) {
3890 TEST(IsEmptyTest, ImplementsIsEmpty) {
3891 vector<int> container;
3893 container.push_back(0);
3895 container.push_back(1);
3899 TEST(IsEmptyTest, WorksWithString) {
3908 TEST(IsEmptyTest, CanDescribeSelf) {
3914 TEST(IsEmptyTest, ExplainsResult) {
3916 vector<int> container;
3918 container.push_back(0);
3922 TEST(SizeIsTest, ImplementsSizeIs) {
3923 vector<int> container;
3926 container.push_back(0);
3929 container.push_back(0);
3935 map<string, int> container;
3938 container.insert(make_pair(
"foo", 1));
3941 container.insert(make_pair(
"bar", 2));
3946 TEST(SizeIsTest, WorksWithReferences) {
3947 vector<int> container;
3950 container.push_back(0);
3954 TEST(SizeIsTest, CanDescribeSelf) {
3965 vector<int> container;
3969 EXPECT_EQ(
"whose size 0 doesn't match, which is 1 less than 1",
3971 container.push_back(0);
3972 container.push_back(0);
3976 EXPECT_EQ(
"whose size 2 matches, which is 1 more than 1",
3980 #if GTEST_HAS_TYPED_TEST 3984 template <
typename T>
3992 ContainerEqTestTypes;
3998 static const int vals[] = {1, 1, 2, 3, 5, 8};
3999 TypeParam my_set(vals, vals + 6);
4007 static const int vals[] = {1, 1, 2, 3, 5, 8};
4008 static const int test_vals[] = {2, 1, 8, 5};
4009 TypeParam my_set(vals, vals + 6);
4010 TypeParam test_set(test_vals, test_vals + 4);
4013 EXPECT_EQ(
"which doesn't have these expected elements: 3",
4019 static const int vals[] = {1, 1, 2, 3, 5, 8};
4020 static const int test_vals[] = {1, 2, 3, 5, 8, 46};
4021 TypeParam my_set(vals, vals + 6);
4022 TypeParam test_set(test_vals, test_vals + 6);
4025 EXPECT_EQ(
"which has these unexpected elements: 46",
Explain(m, test_set));
4029 TYPED_TEST(ContainerEqTest, ValueAddedAndRemoved) {
4030 static const int vals[] = {1, 1, 2, 3, 5, 8};
4031 static const int test_vals[] = {1, 2, 3, 8, 46};
4032 TypeParam my_set(vals, vals + 6);
4033 TypeParam test_set(test_vals, test_vals + 5);
4036 EXPECT_EQ(
"which has these unexpected elements: 46,\n" 4037 "and doesn't have these expected elements: 5",
4042 TYPED_TEST(ContainerEqTest, DuplicateDifference) {
4043 static const int vals[] = {1, 1, 2, 3, 5, 8};
4044 static const int test_vals[] = {1, 2, 3, 5, 8};
4045 TypeParam my_set(vals, vals + 6);
4046 TypeParam test_set(test_vals, test_vals + 5);
4052 #endif // GTEST_HAS_TYPED_TEST 4056 TEST(ContainerEqExtraTest, MultipleValuesMissing) {
4057 static const int vals[] = {1, 1, 2, 3, 5, 8};
4058 static const int test_vals[] = {2, 1, 5};
4059 vector<int> my_set(vals, vals + 6);
4060 vector<int> test_set(test_vals, test_vals + 3);
4063 EXPECT_EQ(
"which doesn't have these expected elements: 3, 8",
4069 TEST(ContainerEqExtraTest, MultipleValuesAdded) {
4070 static const int vals[] = {1, 1, 2, 3, 5, 8};
4071 static const int test_vals[] = {1, 2, 92, 3, 5, 8, 46};
4072 list<size_t> my_set(vals, vals + 6);
4073 list<size_t> test_set(test_vals, test_vals + 7);
4076 EXPECT_EQ(
"which has these unexpected elements: 92, 46",
4081 TEST(ContainerEqExtraTest, MultipleValuesAddedAndRemoved) {
4082 static const int vals[] = {1, 1, 2, 3, 5, 8};
4083 static const int test_vals[] = {1, 2, 3, 92, 46};
4084 list<size_t> my_set(vals, vals + 6);
4085 list<size_t> test_set(test_vals, test_vals + 5);
4088 EXPECT_EQ(
"which has these unexpected elements: 92, 46,\n" 4089 "and doesn't have these expected elements: 5, 8",
4095 TEST(ContainerEqExtraTest, MultiSetOfIntDuplicateDifference) {
4096 static const int vals[] = {1, 1, 2, 3, 5, 8};
4097 static const int test_vals[] = {1, 2, 3, 5, 8};
4098 vector<int> my_set(vals, vals + 6);
4099 vector<int> test_set(test_vals, test_vals + 5);
4109 TEST(ContainerEqExtraTest, WorksForMaps) {
4110 map<int, std::string> my_map;
4114 map<int, std::string> test_map;
4122 EXPECT_EQ(
"which has these unexpected elements: (0, \"aa\"),\n" 4123 "and doesn't have these expected elements: (0, \"a\")",
4127 TEST(ContainerEqExtraTest, WorksForNativeArray) {
4128 int a1[] = { 1, 2, 3 };
4129 int a2[] = { 1, 2, 3 };
4130 int b[] = { 1, 2, 4 };
4136 TEST(ContainerEqExtraTest, WorksForTwoDimensionalNativeArray) {
4137 const char a1[][3] = {
"hi",
"lo" };
4138 const char a2[][3] = {
"hi",
"lo" };
4139 const char b[][3] = {
"lo",
"hi" };
4150 TEST(ContainerEqExtraTest, WorksForNativeArrayAsTuple) {
4151 const int a1[] = { 1, 2, 3 };
4152 const int a2[] = { 1, 2, 3 };
4153 const int b[] = { 1, 2, 3, 4 };
4155 const int*
const p1 = a1;
4159 const int c[] = { 1, 3, 2 };
4163 TEST(ContainerEqExtraTest, CopiesNativeArrayParameter) {
4165 {
"hi",
"hello",
"ciao" },
4166 {
"bye",
"see you",
"ciao" }
4170 {
"hi",
"hello",
"ciao" },
4171 {
"bye",
"see you",
"ciao" }
4181 TEST(WhenSortedByTest, WorksForEmptyContainer) {
4182 const vector<int> numbers;
4187 TEST(WhenSortedByTest, WorksForNonEmptyContainer) {
4188 vector<unsigned> numbers;
4189 numbers.push_back(3);
4190 numbers.push_back(1);
4191 numbers.push_back(2);
4192 numbers.push_back(2);
4199 TEST(WhenSortedByTest, WorksForNonVectorContainer) {
4201 words.push_back(
"say");
4202 words.push_back(
"hello");
4203 words.push_back(
"world");
4210 TEST(WhenSortedByTest, WorksForNativeArray) {
4211 const int numbers[] = { 1, 3, 2, 4 };
4212 const int sorted_numbers[] = { 1, 2, 3, 4 };
4219 TEST(WhenSortedByTest, CanDescribeSelf) {
4221 EXPECT_EQ(
"(when sorted) has 2 elements where\n" 4222 "element #0 is equal to 1,\n" 4223 "element #1 is equal to 2",
4225 EXPECT_EQ(
"(when sorted) doesn't have 2 elements, or\n" 4226 "element #0 isn't equal to 1, or\n" 4227 "element #1 isn't equal to 2",
4231 TEST(WhenSortedByTest, ExplainsMatchResult) {
4232 const int a[] = { 2, 1 };
4233 EXPECT_EQ(
"which is { 1, 2 } when sorted, whose element #0 doesn't match",
4235 EXPECT_EQ(
"which is { 1, 2 } when sorted",
4242 TEST(WhenSortedTest, WorksForEmptyContainer) {
4243 const vector<int> numbers;
4248 TEST(WhenSortedTest, WorksForNonEmptyContainer) {
4250 words.push_back(
"3");
4251 words.push_back(
"1");
4252 words.push_back(
"2");
4253 words.push_back(
"2");
4258 TEST(WhenSortedTest, WorksForMapTypes) {
4259 map<string, int> word_counts;
4260 word_counts[
"and"] = 1;
4261 word_counts[
"the"] = 1;
4262 word_counts[
"buffalo"] = 2;
4266 Pair(
"and", 1),
Pair(
"the", 1),
Pair(
"buffalo", 2)))));
4269 TEST(WhenSortedTest, WorksForMultiMapTypes) {
4270 multimap<int, int> ifib;
4271 ifib.insert(make_pair(8, 6));
4272 ifib.insert(make_pair(2, 3));
4273 ifib.insert(make_pair(1, 1));
4274 ifib.insert(make_pair(3, 4));
4275 ifib.insert(make_pair(1, 2));
4276 ifib.insert(make_pair(5, 5));
4291 TEST(WhenSortedTest, WorksForPolymorphicMatcher) {
4299 TEST(WhenSortedTest, WorksForVectorConstRefMatcher) {
4311 template <
typename T>
4319 template <
typename InIter>
4320 Streamlike(InIter first, InIter last) : remainder_(first, last) {}
4323 return const_iterator(
this, remainder_.begin());
4326 return const_iterator(
this, remainder_.end());
4330 class ConstIter :
public std::iterator<std::input_iterator_tag,
4334 const value_type*> {
4337 typename std::list<value_type>::iterator pos)
4338 : s_(s), pos_(pos) {}
4343 s_->remainder_.erase(pos_++);
4371 typename std::list<value_type>::iterator
pos_;
4376 typedef typename std::list<value_type>::const_iterator
Iter;
4377 const char* sep =
"";
4390 const int a[5] = { 2, 1, 4, 5, 3 };
4394 while (it != s.
end()) {
4400 TEST(WhenSortedTest, WorksForStreamlike) {
4403 const int a[5] = { 2, 1, 4, 5, 3 };
4409 TEST(WhenSortedTest, WorksForVectorConstRefMatcherOnStreamlike) {
4410 const int a[] = { 2, 1, 4, 5, 3 };
4420 TEST(ElemensAreStreamTest, WorksForStreamlike) {
4421 const int a[5] = { 1, 2, 3, 4, 5 };
4427 TEST(ElemensAreArrayStreamTest, WorksForStreamlike) {
4428 const int a[5] = { 1, 2, 3, 4, 5 };
4431 vector<int> expected;
4432 expected.push_back(1);
4433 expected.push_back(2);
4434 expected.push_back(3);
4435 expected.push_back(4);
4436 expected.push_back(5);
4445 TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) {
4446 const int a[] = { 0, 1, 2, 3, 4 };
4451 s, &listener)) << listener.
str();
4452 }
while (std::next_permutation(s.begin(), s.end()));
4455 TEST(UnorderedElementsAreArrayTest, VectorBool) {
4456 const bool a[] = { 0, 1, 0, 1, 1 };
4457 const bool b[] = { 1, 0, 1, 1, 0 };
4462 actual, &listener)) << listener.
str();
4465 TEST(UnorderedElementsAreArrayTest, WorksForStreamlike) {
4469 const int a[5] = { 2, 1, 4, 5, 3 };
4472 ::std::vector<int> expected;
4473 expected.push_back(1);
4474 expected.push_back(2);
4475 expected.push_back(3);
4476 expected.push_back(4);
4477 expected.push_back(5);
4480 expected.push_back(6);
4484 #if GTEST_LANG_CXX11 4486 TEST(UnorderedElementsAreArrayTest, TakesInitializerList) {
4487 const int a[5] = { 2, 1, 4, 5, 3 };
4492 TEST(UnorderedElementsAreArrayTest, TakesInitializerListOfCStrings) {
4493 const string a[5] = {
"a",
"b",
"c",
"d",
"e" };
4498 TEST(UnorderedElementsAreArrayTest, TakesInitializerListOfSameTypedMatchers) {
4499 const int a[5] = { 2, 1, 4, 5, 3 };
4506 TEST(UnorderedElementsAreArrayTest,
4507 TakesInitializerListOfDifferentTypedMatchers) {
4508 const int a[5] = { 2, 1, 4, 5, 3 };
4518 #endif // GTEST_LANG_CXX11 4526 const int a[] = { 1, 2, 3 };
4531 s, &listener)) << listener.
str();
4532 }
while (std::next_permutation(s.begin(), s.end()));
4536 const int a[] = { 1, 2, 3 };
4538 std::vector<Matcher<int> > mv;
4545 s, &listener)) << listener.
str();
4552 const int a[5] = { 2, 1, 4, 5, 3 };
4567 std::vector<Matcher<int> > mv;
4568 for (
int i = 0; i < 100; ++i) {
4575 s, &listener)) << listener.
str();
4583 std::vector<Matcher<int> > mv;
4584 for (
int i = 0; i < 100; ++i) {
4594 s, &listener)) << listener.
str();
4602 v, &listener)) << listener.
str();
4610 v, &listener)) << listener.
str();
4620 v, &listener)) << listener.
str();
4623 Eq(
"where the following matchers don't match any elements:\n" 4624 "matcher #1: is equal to 2"));
4633 v, &listener)) << listener.
str();
4636 Eq(
"where the following elements don't match any matchers:\n" 4646 v, &listener)) << listener.
str();
4650 " the following matchers don't match any elements:\n" 4651 "matcher #0: is equal to 1\n" 4654 " the following elements don't match any matchers:\n" 4661 ss <<
"(element #" << element <<
", matcher #" << matcher <<
")";
4668 std::vector<string> v;
4678 "where no permutation of the elements can satisfy all matchers, " 4679 "and the closest match is 2 of 3 matchers with the " 4700 Eq(
"has 1 element and that element is equal to 345"));
4703 Eq(
"has 3 elements and there exists some permutation " 4704 "of elements such that:\n" 4705 " - element #0 is equal to 111, and\n" 4706 " - element #1 is equal to 222, and\n" 4707 " - element #2 is equal to 333"));
4715 Eq(
"doesn't have 1 element, or has 1 element that isn't equal to 345"));
4718 Eq(
"doesn't have 3 elements, or there exists no permutation " 4719 "of elements such that:\n" 4720 " - element #0 is equal to 123, and\n" 4721 " - element #1 is equal to 234, and\n" 4722 " - element #2 is equal to 345"));
4731 template <
typename Graph>
4732 class BacktrackingMaxBPMState {
4735 explicit BacktrackingMaxBPMState(
const Graph* g) :
graph_(g) { }
4738 if (
graph_->LhsSize() == 0 ||
graph_->RhsSize() == 0) {
4743 for (
size_t irhs = 0; irhs <
graph_->RhsSize(); ++irhs) {
4753 static const size_t kUnused =
static_cast<size_t>(-1);
4755 void PushMatch(
size_t lhs,
size_t rhs) {
4771 bool RecurseInto(
size_t irhs) {
4775 for (
size_t ilhs = 0; ilhs <
graph_->LhsSize(); ++ilhs) {
4779 if (!
graph_->HasEdge(ilhs, irhs)) {
4782 PushMatch(ilhs, irhs);
4786 for (
size_t mi = irhs + 1; mi <
graph_->RhsSize(); ++mi) {
4787 if (!RecurseInto(mi))
return false;
4801 template <
typename Graph>
4808 template <
typename Graph>
4811 return BacktrackingMaxBPMState<Graph>(&g).Compute();
4822 int nodes = GetParam();
4831 std::vector<bool> seen_element(graph.
LhsSize());
4832 std::vector<bool> seen_matcher(graph.
RhsSize());
4834 for (
size_t i = 0; i < matches.size(); ++i) {
4835 size_t ilhs = matches[i].first;
4836 size_t irhs = matches[i].second;
4840 seen_element[ilhs] =
true;
4841 seen_matcher[irhs] =
true;
4863 static const int kEdges[][2] = { {0, 2}, {1, 1}, {2, 1}, {3, 0} };
4865 g.
SetEdge(kEdges[i][0], kEdges[i][1],
true);
4875 size_t nlhs = GetParam().first;
4876 size_t nrhs = GetParam().second;
4882 <<
"\nbacktracking: " 4891 std::make_pair(1, 2),
4892 std::make_pair(2, 1),
4893 std::make_pair(3, 2),
4894 std::make_pair(2, 3),
4895 std::make_pair(4, 1),
4896 std::make_pair(1, 4),
4897 std::make_pair(4, 3),
4898 std::make_pair(3, 4)));
4906 int nodes = GetParam().first;
4907 int iters = GetParam().second;
4915 for (; iters > 0; --iters, ++seed) {
4916 srand(static_cast<int>(seed));
4921 <<
"\nTo reproduce the failure, rerun the test with the flag" 4929 std::make_pair(5, 10000),
4930 std::make_pair(6, 5000),
4931 std::make_pair(7, 2000),
4932 std::make_pair(8, 500),
4933 std::make_pair(9, 100)));
4937 TEST(IsReadableTypeNameTest, ReturnsTrueForShortNames) {
4944 TEST(IsReadableTypeNameTest, ReturnsTrueForLongNonTemplateNonFunctionNames) {
4950 TEST(IsReadableTypeNameTest, ReturnsFalseForLongTemplateNames) {
4956 TEST(IsReadableTypeNameTest, ReturnsFalseForLongFunctionTypeNames) {
4962 TEST(JoinAsTupleTest, JoinsEmptyTuple) {
4966 TEST(JoinAsTupleTest, JoinsOneTuple) {
4967 const char* fields[] = {
"1" };
4971 TEST(JoinAsTupleTest, JoinsTwoTuple) {
4972 const char* fields[] = {
"1",
"a" };
4976 TEST(JoinAsTupleTest, JoinsTenTuple) {
4977 const char* fields[] = {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10" };
4978 EXPECT_EQ(
"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)",
4984 TEST(FormatMatcherDescriptionTest, WorksForEmptyDescription) {
4990 const char* params[] = {
"5" };
4993 Strings(params, params + 1)));
4995 const char* params2[] = {
"5",
"8" };
4998 Strings(params2, params2 + 2)));
5002 TEST(PolymorphicMatcherTest, CanAccessMutableImpl) {
5012 TEST(PolymorphicMatcherTest, CanAccessImpl) {
5018 TEST(MatcherTupleTest, ExplainsMatchFailure) {
5028 " Actual: 2, which is 3 less than 5\n" 5029 " Expected arg #1: is equal to 'a' (97, 0x61)\n" 5030 " Actual: 'b' (98, 0x62)\n",
5037 " Actual: 2, which is 3 less than 5\n",
5044 TEST(EachTest, ExplainsMatchResultCorrectly) {
5052 const int b[1] = { 1 };
5065 EXPECT_EQ(
"whose element #0 doesn't match, which is 9 less than 10",
5069 TEST(EachTest, DescribesItselfCorrectly) {
5077 TEST(EachTest, MatchesVectorWhenAllElementsMatch) {
5078 vector<int> some_vector;
5080 some_vector.push_back(3);
5083 some_vector.push_back(1);
5084 some_vector.push_back(2);
5088 vector<string> another_vector;
5089 another_vector.push_back(
"fee");
5091 another_vector.push_back(
"fie");
5092 another_vector.push_back(
"foe");
5093 another_vector.push_back(
"fum");
5097 TEST(EachTest, MatchesMapWhenAllElementsMatch) {
5098 map<const char*, int> my_map;
5099 const char*
bar =
"a string";
5103 map<string, int> another_map;
5105 another_map[
"fee"] = 1;
5107 another_map[
"fie"] = 2;
5108 another_map[
"foe"] = 3;
5109 another_map[
"fum"] = 4;
5116 const int a[] = { 1, 2, 3 };
5121 TEST(EachTest, WorksForNativeArrayAsTuple) {
5122 const int a[] = { 1, 2 };
5123 const int*
const pointer = a;
5131 template <
typename T1,
typename T2>
5134 if (get<0>(a_pair) == get<1>(a_pair)/2) {
5135 *listener <<
"where the second is " << get<1>(a_pair);
5138 *listener <<
"where the second/2 is " << get<1>(a_pair)/2;
5144 *os <<
"are a pair where the first is half of the second";
5148 *os <<
"are a pair where the first isn't half of the second";
5156 TEST(PointwiseTest, DescribesSelf) {
5162 EXPECT_EQ(
"contains 3 values, where each value and its corresponding value " 5163 "in { 1, 2, 3 } are a pair where the first is half of the second",
5165 EXPECT_EQ(
"doesn't contain exactly 3 values, or contains a value x at some " 5166 "index i where x and the i-th value of { 1, 2, 3 } are a pair " 5167 "where the first isn't half of the second",
5171 TEST(PointwiseTest, MakesCopyOfRhs) {
5172 list<signed char> rhs;
5176 int lhs[] = { 1, 2 };
5185 TEST(PointwiseTest, WorksForLhsNativeArray) {
5186 const int lhs[] = { 1, 2, 3 };
5195 TEST(PointwiseTest, WorksForRhsNativeArray) {
5196 const int rhs[] = { 1, 2, 3 };
5205 TEST(PointwiseTest, RejectsWrongSize) {
5206 const double lhs[2] = { 1, 2 };
5207 const int rhs[1] = { 0 };
5212 const int rhs2[3] = { 0, 1, 2 };
5216 TEST(PointwiseTest, RejectsWrongContent) {
5217 const double lhs[3] = { 1, 2, 3 };
5218 const int rhs[3] = { 2, 6, 4 };
5220 EXPECT_EQ(
"where the value pair (2, 6) at index #1 don't match, " 5221 "where the second/2 is 3",
5225 TEST(PointwiseTest, AcceptsCorrectContent) {
5226 const double lhs[3] = { 1, 2, 3 };
5227 const int rhs[3] = { 2, 4, 6 };
5232 TEST(PointwiseTest, AllowsMonomorphicInnerMatcher) {
5233 const double lhs[3] = { 1, 2, 3 };
5234 const int rhs[3] = { 2, 4, 6 };
const RawType further_from_negative_zero_
PolymorphicMatcher< internal::IsNullMatcher > IsNull()
string Describe(const Matcher< T > &m)
void DescribeTo(ostream *os) const
internal::GtMatcher< Rhs > Gt(Rhs x)
bool MatchAndExplain(const tuple< T1, T2 > &a_pair, MatchResultListener *listener) const
PolymorphicMatcher< internal::MatchesRegexMatcher > MatchesRegex(const internal::RE *regex)
const_iterator begin() const
static bool IsTypeOf(const T &)
internal::NeMatcher< Rhs > Ne(Rhs x)
PostIncrProxy(const value_type &value)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
bool is_negative(T value)
#define EXPECT_FATAL_FAILURE(statement, substr)
PolymorphicMatcher< internal::NotNullMatcher > NotNull()
virtual bool MatchAndExplain(int x, MatchResultListener *) const
PolymorphicMatcher< internal::StartsWithMatcher< internal::string > > StartsWith(const internal::string &prefix)
void TestMatches(testing::internal::FloatingEqMatcher< RawType >(*matcher_maker)(RawType))
#define EXPECT_NONFATAL_FAILURE(statement, substr)
PolymorphicMatcher< ReferencesBarOrIsZeroImpl > ReferencesBarOrIsZero()
void TestNearMatches(testing::internal::FloatingEqMatcher< RawType >(*matcher_maker)(RawType, RawType))
bool MatchAndExplain(const T &x, MatchResultListener *listener) const
bool MatchAndExplain(const T &n, MatchResultListener *listener) const
internal::EqMatcher< T > Eq(T x)
::std::string PrintToString(const T &value)
::std::ostream * stream()
TypeWithSize< 4 >::Int Int32
const_iterator end() const
internal::SizeIsMatcher< SizeMatcher > SizeIs(const SizeMatcher &size_matcher)
#define EXPECT_THAT(value, matcher)
Matcher< int > GreaterThan(int n)
bool IsPositiveIntValue(const IntValue &foo)
PolymorphicMatcher< internal::MatchesRegexMatcher > ContainsRegex(const internal::RE *regex)
internal::KeyMatcher< M > Key(M inner_matcher)
FloatingPointTest< double > DoubleTest
bool operator==(T *ptr, const linked_ptr< T > &x)
bool HasEdge(size_t ilhs, size_t irhs) const
const int * ReferencingFunction(const int &n)
internal::string str() const
PolymorphicMatcher< IsHalfOfMatcher > IsHalfOf()
const RawType further_from_infinity_
ConvertibleToBool(int number)
InnerMatcher AllArgs(const InnerMatcher &matcher)
double & DoubleFunction(double &input)
internal::PointwiseMatcher< TupleMatcher, GTEST_REMOVE_CONST_(Container)> Pointwise(const TupleMatcher &tuple_matcher, const Container &rhs)
string Explain(const MatcherType &m, const Value &x)
ConvertibleFromAny(int a_value)
ElementMatcherPairs FindBacktrackingMaxBPM(const Graph &g)
internal::FloatingEqMatcher< double > NanSensitiveDoubleEq(double rhs)
internal::ParamGenerator< T > Range(T start, T end, IncrementT step)
PolymorphicMatcher< internal::EndsWithMatcher< internal::string > > EndsWith(const internal::string &suffix)
internal::UnorderedElementsAreArrayMatcher< typename::std::iterator_traits< Iter >::value_type > UnorderedElementsAreArray(Iter first, Iter last)
void set_divider(int a_divider)
PolymorphicMatcher< DivisibleByImpl > DivisibleBy(int n)
const RawType close_to_one_
const value_type * operator->() const
#define EXPECT_TRUE(condition)
void DescribeNegationTo(ostream *os) const
const Impl & impl() const
ConstPropagatingPtr(T *t)
PolymorphicMatcher< internal::ContainerEqMatcher< GTEST_REMOVE_CONST_(Container)> > ContainerEq(const Container &rhs)
virtual bool MatchAndExplain(int lhs, MatchResultListener *listener) const
void DescribeNegationTo(ostream *os) const
virtual void DescribeTo(ostream *os) const
void DescribeNegationTo(ostream *os) const
std::ostream & operator<<(std::ostream &os, const TestPartResult &result)
#define ON_CALL(obj, call)
ConstIter(const Streamlike *s, typename std::list< value_type >::iterator pos)
bool operator==(const Unprintable &)
TYPED_TEST_CASE(TypedTest, MyTypes)
PostIncrProxy operator++(int)
string DescribeNegation(const Matcher< T > &m)
internal::AllOfResult2< M1, M2 >::type AllOf(M1 m1, M2 m2)
internal::RefMatcher< T & > Ref(T &x)
virtual void DescribeTo(ostream *os) const
void AllOfMatches(int num, const Matcher< int > &m)
PolymorphicMatcher< internal::StrEqualityMatcher< internal::string > > StrEq(const internal::string &str)
GTEST_API_ string JoinAsTuple(const Strings &fields)
::std::vector< ElementMatcherPair > ElementMatcherPairs
void DescribeTo(ostream *os) const
internal::LtMatcher< Rhs > Lt(Rhs x)
internal::FloatingEqMatcher< double > DoubleNear(double rhs, double max_abs_error)
bool MatchAndExplain(T x, MatchResultListener *listener) const
TEST_F(ListenerTest, DoesFoo)
internal::FloatingEqMatcher< double > DoubleEq(double rhs)
#define MOCK_METHOD2(m,...)
MATCHER_P(Really, inner_matcher,"")
internal::UnorderedElementsAreMatcher< std::tr1::tuple<> > UnorderedElementsAre()
GreaterThanMatcher(int rhs)
TEST_P(BipartiteRandomTest, LargerNets)
internal::LeMatcher< Rhs > Le(Rhs x)
internal::ElementsAreMatcher< std::tr1::tuple<> > ElementsAre()
PolymorphicMatcher< Impl > MakePolymorphicMatcher(const Impl &impl)
testing::internal::FloatingPoint< RawType > Floating
PolymorphicMatcher< internal::StrEqualityMatcher< internal::string > > StrCaseNe(const internal::string &str)
def Iter(n, format, sep='')
void DescribeTo(::std::ostream *os) const
internal::ElementsAreArrayMatcher< typename::std::iterator_traits< Iter >::value_type > ElementsAreArray(Iter first, Iter last)
const RawType close_to_negative_zero_
FloatingPointTest< float > FloatTest
int operator()(const char *s)
PolymorphicMatcher< internal::HasSubstrMatcher< internal::string > > HasSubstr(const internal::string &substring)
#define EXPECT_FALSE(condition)
bool MatchAndExplain(const T &x, MatchResultListener *) const
bool Value(const T &value, M matcher)
std::vector< size_t > rhs_used_
internal::PairMatcher< FirstMatcher, SecondMatcher > Pair(FirstMatcher first_matcher, SecondMatcher second_matcher)
const RawType further_from_one_
void DescribeTo(ostream *os) const
internal::NotMatcher< InnerMatcher > Not(InnerMatcher m)
const string & StringFunction(const string &input)
ConstPropagatingPtr(const ConstPropagatingPtr &other)
internal::AnyOfResult2< M1, M2 >::type AnyOf(M1 m1, M2 m2)
internal::MatcherAsPredicate< M > Matches(M matcher)
Matcher< T > MakeMatcher(const MatcherInterface< T > *impl)
ConvertibleToBool IsNotZero(int number)
int IntFunction(int input)
Streamlike(InIter first, InIter last)
::std::pair< size_t, size_t > ElementMatcherPair
internal::FloatingEqMatcher< float > NanSensitiveFloatEq(float rhs)
#define GTEST_DISALLOW_ASSIGN_(type)
virtual bool MatchAndExplain(int x, MatchResultListener *listener) const
bool ValueIsPositive(const Uncopyable &x)
value_type operator*() const
std::vector< int > IntVec
GTEST_API_ string FormatMatcherDescription(bool negation, const char *matcher_name, const Strings ¶m_values)
#define ASSERT_THAT(value, matcher)
internal::PointeeMatcher< InnerMatcher > Pointee(const InnerMatcher &inner_matcher)
FloatingPointNearTest< double > DoubleNearTest
result_type operator()(argument_type input) const
const RawType close_to_infinity_
PolymorphicMatcher< internal::FieldMatcher< Class, FieldType > > Field(FieldType Class::*field, const FieldMatcher &matcher)
friend std::ostream & operator<<(std::ostream &os, const Streamlike &s)
FloatingPointTest< RawType > ParentType
const RawType close_to_positive_zero_
string IntToStringFunction(int input)
internal::FloatingEqMatcher< float > NanSensitiveFloatNear(float rhs, float max_abs_error)
PolymorphicMatcher< internal::StrEqualityMatcher< internal::string > > StrNe(const internal::string &str)
PolymorphicMatcher< internal::PropertyMatcher< Class, PropertyType > > Property(PropertyType(Class::*property)() const, const PropertyMatcher &matcher)
bool operator()(int n) const
Uncopyable & RefUncopyableFunction(Uncopyable &obj)
void ExplainMatchFailureTupleTo(const MatcherTuple &matchers, const ValueTuple &values,::std::ostream *os)
void DescribeNegationTo(ostream *os) const
PolymorphicMatcher< PolymorphicIsEvenImpl > PolymorphicIsEven()
void SetEdge(size_t ilhs, size_t irhs, bool b)
Matcher< Lhs > TypedEq(const Rhs &rhs)
std::list< value_type >::iterator pos_
friend bool operator==(const ConstIter &a, const ConstIter &b)
friend bool operator!=(const ConstIter &a, const ConstIter &b)
const T & operator*() const
internal::WhenSortedByMatcher< internal::LessComparator, ContainerMatcher > WhenSorted(const ContainerMatcher &container_matcher)
internal::FloatingEqMatcher< double > NanSensitiveDoubleNear(double rhs, double max_abs_error)
internal::NamedArg< char > arg(StringRef name, const T &arg)
bool ExplainMatchResult(M matcher, const T &value, MatchResultListener *listener)
ElementMatcherPairs best_so_far_
string DebugString() const
Matcher< T > MatcherCast(M matcher)
#define GMOCK_ARRAY_SIZE_(array)
string OfType(const string &type_name)
bool ReferencesFooAndIsZero(const int &n)
TYPED_TEST(TypedTest, TestA)
IsGreaterThan(int threshold)
#define EXPECT_CALL(obj, call)
result_type operator()(const int &n)
GTEST_API_ ElementMatcherPairs FindMaxBipartiteMatching(const MatchMatrix &g)
internal::EachMatcher< M > Each(M matcher)
bool IsReadableTypeName(const string &type_name)
::std::tr1::tuple< long, int > Tuple2
::std::vector< string > Strings
TypeWithSize< sizeof(RawType)>::UInt Bits
internal::ReferenceWrapper< T > ByRef(T &l_value)
bool operator==(const NotCopyable &rhs) const
internal::FloatingEqMatcher< float > FloatEq(float rhs)
#define GTEST_FLAG_PREFIX_
const Bits infinity_bits_
void DescribeNegationTo(::std::ostream *os) const
const internal::AnythingMatcher _
DivisibleByImpl(int a_divider)
FloatingPointNearTest< float > FloatNearTest
INSTANTIATE_TEST_CASE_P(Samples, BipartiteRandomTest, testing::Values(std::make_pair(5, 10000), std::make_pair(6, 5000), std::make_pair(7, 2000), std::make_pair(8, 500), std::make_pair(9, 100)))
ConvertibleFromAny(const T &a_value)
internal::ValueArray1< T1 > Values(T1 v1)
ElementMatcherPairs matches_
internal::GeMatcher< Rhs > Ge(Rhs x)
PolymorphicMatcher< internal::StrEqualityMatcher< internal::string > > StrCaseEq(const internal::string &str)
void AnyOfMatches(int num, const Matcher< int > &m)
#define SCOPED_TRACE(message)
internal::ContainsMatcher< M > Contains(M matcher)
bool operator>=(const NotCopyable &rhs) const
AStruct(const AStruct &rhs)
void DescribeTo(ostream *os) const
AssertionResult IsNull(const char *str)
virtual void DescribeTo(ostream *os) const
internal::ResultOfMatcher< Callable > ResultOf(Callable callable, const ResultOfMatcher &matcher)
static const size_t kUnused
#define EXPECT_EQ(expected, actual)
PolymorphicMatcher< internal::TrulyMatcher< Predicate > > Truly(Predicate pred)
std::vector< size_t > lhs_used_
std::list< value_type > remainder_
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
void set_s(const string &new_s)
internal::ReturnAction< R > Return(R value)
internal::WhenSortedByMatcher< Comparator, ContainerMatcher > WhenSortedBy(const Comparator &comparator, const ContainerMatcher &container_matcher)
static string EMString(int element, int matcher)
TEST(IsXDigitTest, WorksForNarrowAscii)
const value_type & operator*() const
internal::FloatingEqMatcher< float > FloatNear(float rhs, float max_abs_error)