67namespace gmock_matchers_test {
79using std::stringstream;
99using testing::IsEmpty;
157using testing::make_tuple;
166 *
os <<
"is > " << rhs_;
171 const int diff = lhs - rhs_;
173 *listener <<
"which is " <<
diff <<
" more than " << rhs_;
174 }
else if (
diff == 0) {
175 *listener <<
"which is the same as " << rhs_;
177 *listener <<
"which is " << -
diff <<
" less than " << rhs_;
191std::string
OfType(
const std::string& type_name) {
193 return " (of type " + type_name +
")";
212template <
typename MatcherType,
typename Value>
213std::string
Explain(
const MatcherType& m,
const Value& x) {
216 return listener.
str();
219TEST(MonotonicMatcherTest, IsPrintable) {
225TEST(MatchResultListenerTest, StreamingWorks) {
227 listener <<
"hi" << 5;
241TEST(MatchResultListenerTest, CanAccessUnderlyingStream) {
248TEST(MatchResultListenerTest, IsInterestedWorks) {
266 *
os <<
"is an even number";
275TEST(MatcherInterfaceTest, CanBeImplementedUsingPublishedAPI) {
284 const bool match = x % 2 == 0;
286 *listener <<
"value % " << 2;
287 if (listener->
stream() != NULL) {
290 *listener->
stream() <<
" == " << (x % 2);
296 *
os <<
"is an even number";
300TEST(MatcherInterfaceTest, CanBeImplementedUsingNewAPI) {
309TEST(MatcherTest, CanBeDefaultConstructed) {
314TEST(MatcherTest, CanBeConstructedFromMatcherInterface) {
322TEST(MatcherTest, CanBeImplicitlyConstructedFromValue) {
329TEST(MatcherTest, CanBeImplicitlyConstructedFromNULL) {
343TEST(MatcherTest, CanBeConstructedFromUndefinedVariable) {
367TEST(MatcherTest, CanDescribeItself) {
373TEST(MatcherTest, MatchAndExplain) {
386TEST(StringMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) {
398TEST(StringMatcherTest, CanBeImplicitlyConstructedFromString) {
408#if GTEST_HAS_GLOBAL_STRING
411TEST(StringMatcherTest, CanBeImplicitlyConstructedFromGlobalString) {
422#if GTEST_HAS_GLOBAL_STRING
425TEST(GlobalStringMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) {
426 Matcher< ::string> m1 =
"hi";
430 Matcher<const ::string&> m2 =
"hi";
437TEST(GlobalStringMatcherTest, CanBeImplicitlyConstructedFromString) {
438 Matcher< ::string> m1 = std::string(
"hi");
442 Matcher<const ::string&> m2 = std::string(
"hi");
449TEST(GlobalStringMatcherTest, CanBeImplicitlyConstructedFromGlobalString) {
450 Matcher< ::string> m1 =
::string(
"hi");
454 Matcher<const ::string&> m2 =
::string(
"hi");
463TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) {
464 Matcher<absl::string_view> m1 =
"cats";
468 Matcher<const absl::string_view&> m2 =
"cats";
475TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromString) {
476 Matcher<absl::string_view> m1 = std::string(
"cats");
480 Matcher<const absl::string_view&> m2 = std::string(
"cats");
485#if GTEST_HAS_GLOBAL_STRING
488TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromGlobalString) {
489 Matcher<absl::string_view> m1 =
::string(
"cats");
493 Matcher<const absl::string_view&> m2 =
::string(
"cats");
501TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromStringView) {
502 Matcher<absl::string_view> m1 = absl::string_view(
"cats");
506 Matcher<const absl::string_view&> m2 = absl::string_view(
"cats");
515TEST(MakeMatcherTest, ConstructsMatcherFromMatcherInterface) {
525 template <
typename T>
529 return p == &
g_bar || x == 0;
535 *
os <<
"doesn't reference g_bar and is not zero";
545TEST(MakePolymorphicMatcherTest, ConstructsMatcherUsingOldAPI) {
571 template <
typename T>
574 *listener <<
"% " << 2;
575 if (listener->
stream() != NULL) {
578 *listener->
stream() <<
" == " << (x % 2);
588TEST(MakePolymorphicMatcherTest, ConstructsMatcherUsingNewAPI) {
613TEST(MatcherCastTest, FromPolymorphicMatcher) {
624 explicit IntValue(
int a_value) : value_(a_value) {}
626 int value()
const {
return value_; }
633 return foo.value() > 0;
638TEST(MatcherCastTest, FromCompatibleType) {
654TEST(MatcherCastTest, FromConstReferenceToNonReference) {
662TEST(MatcherCastTest, FromReferenceToNonReference) {
670TEST(MatcherCastTest, FromNonReferenceToConstReference) {
678TEST(MatcherCastTest, FromNonReferenceToReference) {
688TEST(MatcherCastTest, FromSameType) {
697TEST(MatcherCastTest, FromAValue) {
705TEST(MatcherCastTest, FromAnImplicitlyConvertibleValue) {
706 const int kExpected =
'c';
759namespace convertible_from_any {
763 template <
typename T>
771 return a.value == b.
value;
775 return os <<
a.value;
778TEST(MatcherCastTest, ConversionConstructorIsUsed) {
784TEST(MatcherCastTest, FromConvertibleFromAny) {
800 return a.value == b.
value;
803TEST(MatcherCastTest, ValueIsNotCopied) {
827TEST(SafeMatcherCastTest, FromPolymorphicMatcher) {
836TEST(SafeMatcherCastTest, FromLosslesslyConvertibleArithmeticType) {
849TEST(SafeMatcherCastTest, FromBaseClass) {
863TEST(SafeMatcherCastTest, FromConstReferenceToReference) {
873TEST(SafeMatcherCastTest, FromNonReferenceToConstReference) {
881TEST(SafeMatcherCastTest, FromNonReferenceToReference) {
891TEST(SafeMatcherCastTest, FromSameType) {
900namespace convertible_from_any {
901TEST(SafeMatcherCastTest, ConversionConstructorIsUsed) {
907TEST(SafeMatcherCastTest, FromConvertibleFromAny) {
917TEST(SafeMatcherCastTest, ValueIsNotCopied) {
924TEST(ExpectThat, TakesLiterals) {
930TEST(ExpectThat, TakesFunctions) {
932 static void Func() {}
934 void (*func)() = Helper::Func;
954TEST(ATest, WorksForDerivedClass) {
990TEST(UnderscoreTest, MatchesAnyValue) {
1005TEST(UnderscoreTest, CanDescribeSelf) {
1013 const char a1[] =
"hi";
1014 const char a2[] =
"hi";
1050TEST(TypedEqTest, ChecksEqualityForGivenType) {
1061TEST(TypedEqTest, CanDescribeSelf) {
1071template <
typename T>
1075 template <
typename T2>
1079TEST(TypedEqTest, HasSpecifiedType) {
1086TEST(GeTest, ImplementsGreaterThanOrEqual) {
1100TEST(GtTest, ImplementsGreaterThan) {
1114TEST(LeTest, ImplementsLessThanOrEqual) {
1156TEST(IsNullTest, MatchesNullPointer) {
1164 const char* p2 = NULL;
1168#if !GTEST_OS_SYMBIAN
1193TEST(IsNullTest, ReferenceToConstLinkedPtr) {
1203TEST(IsNullTest, StdFunction) {
1219TEST(NotNullTest, MatchesNonNullPointer) {
1227 const char* p2 = NULL;
1241TEST(NotNullTest, ReferenceToConstLinkedPtr) {
1251TEST(NotNullTest, StdFunction) {
1260TEST(NotNullTest, CanDescribeSelf) {
1267TEST(RefTest, MatchesSameVariable) {
1280 ss <<
"references the variable @" << &n <<
" 5";
1286TEST(RefTest, CanBeUsedAsMatcherForConstReference) {
1324TEST(StrEqTest, MatchesEqualString) {
1344 EXPECT_EQ(
"is equal to \"Hi-\'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\\xD3\"",
1347 std::string str(
"01204500800");
1351 str[0] = str[6] = str[7] = str[9] = str[10] =
'\0';
1356TEST(StrNeTest, MatchesUnequalString) {
1379TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) {
1399TEST(StrCaseEqTest, MatchesEqualStringWith0IgnoringCase) {
1400 std::string str1(
"oabocdooeoo");
1401 std::string str2(
"OABOCDOOEOO");
1405 str1[3] = str2[3] =
'\0';
1409 str1[0] = str1[6] = str1[7] = str1[10] =
'\0';
1410 str2[0] = str2[6] = str2[7] = str2[10] =
'\0';
1412 str1[9] = str2[9] =
'\0';
1419 str2.append(1,
'\0');
1424TEST(StrCaseEqTest, CanDescribeSelf) {
1429TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) {
1449TEST(StrCaseNeTest, CanDescribeSelf) {
1455TEST(HasSubstrTest, WorksForStringClasses) {
1466TEST(HasSubstrTest, WorksForCStrings) {
1480TEST(HasSubstrTest, WorksForStringViewClasses) {
1498TEST(HasSubstrTest, CanDescribeSelf) {
1511 EXPECT_EQ(
"whose first field is a value which is 5 less than 10",
1512 Explain(m, make_pair(5,
true)));
1513 EXPECT_EQ(
"whose first field is a value which is 5 more than 10",
1514 Explain(m, make_pair(15,
true)));
1518 pair<int, std::string>
p(25,
"foo");
1532 using first_type = int;
1533 using second_type = string;
1535 const int& GetImpl(Tag<0>)
const {
return member_1; }
1536 const string& GetImpl(Tag<1>)
const {
return member_2; }
1539auto get(
const PairWithGet&
value) ->
decltype(
value.GetImpl(Tag<I>())) {
1540 return value.GetImpl(Tag<I>());
1542TEST(PairTest, MatchesPairWithGetCorrectly) {
1543 PairWithGet
p{25,
"foo"};
1549 std::vector<PairWithGet> v = {{11,
"Foo"}, {29,
"gMockIsBestMock"}};
1554TEST(KeyTest, SafelyCastsInnerMatcher) {
1557 pair<char, bool>
p(
'a',
true);
1562TEST(KeyTest, InsideContainsUsingMap) {
1563 map<int, char> container;
1564 container.insert(make_pair(1,
'a'));
1565 container.insert(make_pair(2,
'b'));
1566 container.insert(make_pair(4,
'c'));
1571TEST(KeyTest, InsideContainsUsingMultimap) {
1572 multimap<int, char> container;
1573 container.insert(make_pair(1,
'a'));
1574 container.insert(make_pair(2,
'b'));
1575 container.insert(make_pair(4,
'c'));
1578 container.insert(make_pair(25,
'd'));
1580 container.insert(make_pair(25,
'e'));
1599 EXPECT_EQ(
"has a first field that is equal to \"foo\""
1600 ", and has a second field that is equal to 42",
1602 EXPECT_EQ(
"has a first field that isn't equal to \"foo\""
1603 ", or has a second field that isn't equal to 42",
1607 EXPECT_EQ(
"has a first field that isn't equal to 13"
1608 ", and has a second field that is equal to 42",
1612TEST(PairTest, CanExplainMatchResultTo) {
1616 EXPECT_EQ(
"whose first field does not match, which is 1 less than 0",
1617 Explain(m, make_pair(-1, -2)));
1621 EXPECT_EQ(
"whose second field does not match, which is 2 less than 0",
1622 Explain(m, make_pair(1, -2)));
1626 EXPECT_EQ(
"whose first field does not match, which is 1 less than 0",
1627 Explain(m, make_pair(-1, 2)));
1630 EXPECT_EQ(
"whose both fields match, where the first field is a value "
1631 "which is 1 more than 0, and the second field is a value "
1632 "which is 2 more than 0",
1638 EXPECT_EQ(
"whose both fields match, where the first field is a value "
1639 "which is 1 more than 0",
1640 Explain(explain_first, make_pair(1, 0)));
1645 EXPECT_EQ(
"whose both fields match, where the second field is a value "
1646 "which is 1 more than 0",
1647 Explain(explain_second, make_pair(0, 1)));
1651 pair<int, std::string>
p(25,
"foo");
1670TEST(PairTest, SafelyCastsInnerMatchers) {
1673 pair<char, bool>
p(
'a',
true);
1680TEST(PairTest, InsideContainsUsingMap) {
1681 map<int, char> container;
1682 container.insert(make_pair(1,
'a'));
1683 container.insert(make_pair(2,
'b'));
1684 container.insert(make_pair(4,
'c'));
1692TEST(PairTest, UseGetInsteadOfMembers) {
1693 PairWithGet pair{7,
"ABC"};
1698 std::vector<PairWithGet> v = {{11,
"Foo"}, {29,
"gMockIsBestMock"}};
1705TEST(StartsWithTest, MatchesStringWithGivenPrefix) {
1719TEST(StartsWithTest, CanDescribeSelf) {
1726TEST(EndsWithTest, MatchesStringWithGivenSuffix) {
1739#if GTEST_HAS_GLOBAL_STRING
1758TEST(EndsWithTest, CanDescribeSelf) {
1765TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) {
1789TEST(MatchesRegexTest, CanDescribeSelf) {
1804TEST(ContainsRegexTest, MatchesStringContainingGivenRegex) {
1828TEST(ContainsRegexTest, CanDescribeSelf) {
1842#if GTEST_HAS_STD_WSTRING
1843TEST(StdWideStrEqTest, MatchesEqual) {
1857 ::std::wstring str(L
"01204500800");
1861 str[0] = str[6] = str[7] = str[9] = str[10] = L
'\0';
1866TEST(StdWideStrEqTest, CanDescribeSelf) {
1867 Matcher< ::std::wstring> m =
StrEq(L
"Hi-\'\"?\\\a\b\f\n\r\t\v");
1868 EXPECT_EQ(
"is equal to L\"Hi-\'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\"",
1871 Matcher< ::std::wstring> m2 =
StrEq(L
"\xD3\x576\x8D3\xC74D");
1872 EXPECT_EQ(
"is equal to L\"\\xD3\\x576\\x8D3\\xC74D\"",
1875 ::std::wstring str(L
"01204500800");
1877 Matcher<const ::std::wstring&> m4 =
StrEq(str);
1879 str[0] = str[6] = str[7] = str[9] = str[10] = L
'\0';
1880 Matcher<const ::std::wstring&> m5 =
StrEq(str);
1884TEST(StdWideStrNeTest, MatchesUnequalString) {
1885 Matcher<const wchar_t*> m =
StrNe(L
"Hello");
1890 Matcher< ::std::wstring> m2 =
StrNe(::std::wstring(L
"Hello"));
1895TEST(StdWideStrNeTest, CanDescribeSelf) {
1896 Matcher<const wchar_t*> m =
StrNe(L
"Hi");
1900TEST(StdWideStrCaseEqTest, MatchesEqualStringIgnoringCase) {
1901 Matcher<const wchar_t*> m =
StrCaseEq(::std::wstring(L
"Hello"));
1907 Matcher<const ::std::wstring&> m2 =
StrCaseEq(L
"Hello");
1912TEST(StdWideStrCaseEqTest, MatchesEqualStringWith0IgnoringCase) {
1913 ::std::wstring str1(L
"oabocdooeoo");
1914 ::std::wstring str2(L
"OABOCDOOEOO");
1915 Matcher<const ::std::wstring&> m0 =
StrCaseEq(str1);
1916 EXPECT_FALSE(m0.Matches(str2 + ::std::wstring(1, L
'\0')));
1918 str1[3] = str2[3] = L
'\0';
1919 Matcher<const ::std::wstring&> m1 =
StrCaseEq(str1);
1922 str1[0] = str1[6] = str1[7] = str1[10] = L
'\0';
1923 str2[0] = str2[6] = str2[7] = str2[10] = L
'\0';
1924 Matcher<const ::std::wstring&> m2 =
StrCaseEq(str1);
1925 str1[9] = str2[9] = L
'\0';
1928 Matcher<const ::std::wstring&> m3 =
StrCaseEq(str1);
1932 str2.append(1, L
'\0');
1937TEST(StdWideStrCaseEqTest, CanDescribeSelf) {
1938 Matcher< ::std::wstring> m =
StrCaseEq(L
"Hi");
1942TEST(StdWideStrCaseNeTest, MatchesUnequalStringIgnoringCase) {
1943 Matcher<const wchar_t*> m =
StrCaseNe(L
"Hello");
1949 Matcher< ::std::wstring> m2 =
StrCaseNe(::std::wstring(L
"Hello"));
1954TEST(StdWideStrCaseNeTest, CanDescribeSelf) {
1955 Matcher<const wchar_t*> m =
StrCaseNe(L
"Hi");
1960TEST(StdWideHasSubstrTest, WorksForStringClasses) {
1961 const Matcher< ::std::wstring> m1 =
HasSubstr(L
"foo");
1962 EXPECT_TRUE(m1.Matches(::std::wstring(L
"I love food.")));
1965 const Matcher<const ::std::wstring&> m2 =
HasSubstr(L
"foo");
1966 EXPECT_TRUE(m2.Matches(::std::wstring(L
"I love food.")));
1971TEST(StdWideHasSubstrTest, WorksForCStrings) {
1972 const Matcher<wchar_t*> m1 =
HasSubstr(L
"foo");
1973 EXPECT_TRUE(m1.Matches(
const_cast<wchar_t*
>(L
"I love food.")));
1974 EXPECT_FALSE(m1.Matches(
const_cast<wchar_t*
>(L
"tofo")));
1977 const Matcher<const wchar_t*> m2 =
HasSubstr(L
"foo");
1984TEST(StdWideHasSubstrTest, CanDescribeSelf) {
1985 Matcher< ::std::wstring> m =
HasSubstr(L
"foo\n\"");
1991TEST(StdWideStartsWithTest, MatchesStringWithGivenPrefix) {
1992 const Matcher<const wchar_t*> m1 =
StartsWith(::std::wstring(L
""));
1997 const Matcher<const ::std::wstring&> m2 =
StartsWith(L
"Hi");
2005TEST(StdWideStartsWithTest, CanDescribeSelf) {
2006 Matcher<const ::std::wstring> m =
StartsWith(L
"Hi");
2012TEST(StdWideEndsWithTest, MatchesStringWithGivenSuffix) {
2013 const Matcher<const wchar_t*> m1 =
EndsWith(L
"");
2018 const Matcher<const ::std::wstring&> m2 =
EndsWith(::std::wstring(L
"Hi"));
2026TEST(StdWideEndsWithTest, CanDescribeSelf) {
2027 Matcher<const ::std::wstring> m =
EndsWith(L
"Hi");
2033#if GTEST_HAS_GLOBAL_WSTRING
2034TEST(GlobalWideStrEqTest, MatchesEqual) {
2035 Matcher<const wchar_t*> m =
StrEq(::wstring(L
"Hello"));
2040 Matcher<const ::wstring&> m2 =
StrEq(L
"Hello");
2044 Matcher<const ::wstring&> m3 =
StrEq(L
"\xD3\x576\x8D3\xC74D");
2048 ::wstring
str(L
"01204500800");
2050 Matcher<const ::wstring&> m4 =
StrEq(str);
2053 Matcher<const ::wstring&> m5 =
StrEq(str);
2057TEST(GlobalWideStrEqTest, CanDescribeSelf) {
2058 Matcher< ::wstring> m =
StrEq(L
"Hi-\'\"?\\\a\b\f\n\r\t\v");
2059 EXPECT_EQ(
"is equal to L\"Hi-\'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\"",
2062 Matcher< ::wstring> m2 =
StrEq(L
"\xD3\x576\x8D3\xC74D");
2063 EXPECT_EQ(
"is equal to L\"\\xD3\\x576\\x8D3\\xC74D\"",
2066 ::wstring
str(L
"01204500800");
2068 Matcher<const ::wstring&> m4 =
StrEq(str);
2071 Matcher<const ::wstring&> m5 =
StrEq(str);
2075TEST(GlobalWideStrNeTest, MatchesUnequalString) {
2076 Matcher<const wchar_t*> m =
StrNe(L
"Hello");
2081 Matcher< ::wstring> m2 =
StrNe(::wstring(L
"Hello"));
2086TEST(GlobalWideStrNeTest, CanDescribeSelf) {
2087 Matcher<const wchar_t*> m =
StrNe(L
"Hi");
2091TEST(GlobalWideStrCaseEqTest, MatchesEqualStringIgnoringCase) {
2092 Matcher<const wchar_t*> m =
StrCaseEq(::wstring(L
"Hello"));
2098 Matcher<const ::wstring&> m2 =
StrCaseEq(L
"Hello");
2103TEST(GlobalWideStrCaseEqTest, MatchesEqualStringWith0IgnoringCase) {
2104 ::wstring str1(L
"oabocdooeoo");
2105 ::wstring str2(L
"OABOCDOOEOO");
2106 Matcher<const ::wstring&> m0 =
StrCaseEq(str1);
2109 str1[3] = str2[3] = L
'\0';
2110 Matcher<const ::wstring&> m1 =
StrCaseEq(str1);
2113 str1[0] = str1[6] = str1[7] = str1[10] = L
'\0';
2114 str2[0] = str2[6] = str2[7] = str2[10] = L
'\0';
2115 Matcher<const ::wstring&> m2 =
StrCaseEq(str1);
2116 str1[9] = str2[9] = L
'\0';
2119 Matcher<const ::wstring&> m3 =
StrCaseEq(str1);
2123 str2.append(1, L
'\0');
2128TEST(GlobalWideStrCaseEqTest, CanDescribeSelf) {
2129 Matcher< ::wstring> m =
StrCaseEq(L
"Hi");
2133TEST(GlobalWideStrCaseNeTest, MatchesUnequalStringIgnoringCase) {
2134 Matcher<const wchar_t*> m =
StrCaseNe(L
"Hello");
2140 Matcher< ::wstring> m2 =
StrCaseNe(::wstring(L
"Hello"));
2145TEST(GlobalWideStrCaseNeTest, CanDescribeSelf) {
2146 Matcher<const wchar_t*> m =
StrCaseNe(L
"Hi");
2151TEST(GlobalWideHasSubstrTest, WorksForStringClasses) {
2152 const Matcher< ::wstring> m1 =
HasSubstr(L
"foo");
2153 EXPECT_TRUE(m1.Matches(::wstring(L
"I love food.")));
2156 const Matcher<const ::wstring&> m2 =
HasSubstr(L
"foo");
2157 EXPECT_TRUE(m2.Matches(::wstring(L
"I love food.")));
2162TEST(GlobalWideHasSubstrTest, WorksForCStrings) {
2163 const Matcher<wchar_t*> m1 =
HasSubstr(L
"foo");
2164 EXPECT_TRUE(m1.Matches(
const_cast<wchar_t*
>(L
"I love food.")));
2165 EXPECT_FALSE(m1.Matches(
const_cast<wchar_t*
>(L
"tofo")));
2168 const Matcher<const wchar_t*> m2 =
HasSubstr(L
"foo");
2175TEST(GlobalWideHasSubstrTest, CanDescribeSelf) {
2176 Matcher< ::wstring> m =
HasSubstr(L
"foo\n\"");
2182TEST(GlobalWideStartsWithTest, MatchesStringWithGivenPrefix) {
2183 const Matcher<const wchar_t*> m1 =
StartsWith(::wstring(L
""));
2188 const Matcher<const ::wstring&> m2 =
StartsWith(L
"Hi");
2196TEST(GlobalWideStartsWithTest, CanDescribeSelf) {
2197 Matcher<const ::wstring> m =
StartsWith(L
"Hi");
2203TEST(GlobalWideEndsWithTest, MatchesStringWithGivenSuffix) {
2204 const Matcher<const wchar_t*> m1 =
EndsWith(L
"");
2209 const Matcher<const ::wstring&> m2 =
EndsWith(::wstring(L
"Hi"));
2217TEST(GlobalWideEndsWithTest, CanDescribeSelf) {
2218 Matcher<const ::wstring> m =
EndsWith(L
"Hi");
2229TEST(Eq2Test, MatchesEqualArguments) {
2243TEST(Ge2Test, MatchesGreaterThanOrEqualArguments) {
2258TEST(Gt2Test, MatchesGreaterThanArguments) {
2273TEST(Le2Test, MatchesLessThanOrEqualArguments) {
2288TEST(Lt2Test, MatchesLessThanArguments) {
2303TEST(Ne2Test, MatchesUnequalArguments) {
2318TEST(FloatEq2Test, MatchesEqualArguments) {
2319 typedef ::testing::tuple<float, float> Tpl;
2327TEST(FloatEq2Test, CanDescribeSelf) {
2334TEST(NanSensitiveFloatEqTest, MatchesEqualArgumentsWithNaN) {
2335 typedef ::testing::tuple<float, float> Tpl;
2339 std::numeric_limits<float>::quiet_NaN())));
2346TEST(NanSensitiveFloatEqTest, CanDescribeSelfWithNaNs) {
2353TEST(DoubleEq2Test, MatchesEqualArguments) {
2354 typedef ::testing::tuple<double, double> Tpl;
2362TEST(DoubleEq2Test, CanDescribeSelf) {
2369TEST(NanSensitiveDoubleEqTest, MatchesEqualArgumentsWithNaN) {
2370 typedef ::testing::tuple<double, double> Tpl;
2374 std::numeric_limits<double>::quiet_NaN())));
2381TEST(NanSensitiveDoubleEqTest, CanDescribeSelfWithNaNs) {
2388TEST(FloatNear2Test, MatchesEqualArguments) {
2389 typedef ::testing::tuple<float, float> Tpl;
2397TEST(FloatNear2Test, CanDescribeSelf) {
2404TEST(NanSensitiveFloatNearTest, MatchesNearbyArgumentsWithNaN) {
2405 typedef ::testing::tuple<float, float> Tpl;
2410 std::numeric_limits<float>::quiet_NaN())));
2417TEST(NanSensitiveFloatNearTest, CanDescribeSelfWithNaNs) {
2425TEST(DoubleNear2Test, MatchesEqualArguments) {
2426 typedef ::testing::tuple<double, double> Tpl;
2434TEST(DoubleNear2Test, CanDescribeSelf) {
2441TEST(NanSensitiveDoubleNearTest, MatchesNearbyArgumentsWithNaN) {
2442 typedef ::testing::tuple<double, double> Tpl;
2447 std::numeric_limits<double>::quiet_NaN())));
2454TEST(NanSensitiveDoubleNearTest, CanDescribeSelfWithNaNs) {
2475TEST(NotTest, NotMatcherSafelyCastsMonomorphicMatchers) {
2488 for (
int i = 1; i <= num; ++i) {
2496TEST(AllOfTest, MatchesWhenAllMatch) {
2542TEST(AllOfTest, VariadicMatchesWhenAllMatch) {
2545 ::testing::AllOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
2570 "((isn't equal to 1) and "
2571 "(isn't equal to 2))",
2577 "(isn't equal to 1)) and "
2578 "((isn't equal to 2) and "
2579 "(isn't equal to 3))",
2586 "((isn't equal to 3) and "
2587 "((isn't equal to 5) and "
2588 "(isn't equal to 7)))",
2593TEST(AllOfTest, CanDescribeNegation) {
2602 "((is equal to 1) or "
2609 "(is equal to 1)) or "
2610 "((is equal to 2) or "
2618 "((is equal to 3) or "
2619 "((is equal to 5) or "
2620 "(is equal to 7)))",
2625TEST(AllOfTest, AllOfMatcherSafelyCastsMonomorphicMatchers) {
2650 EXPECT_EQ(
"which is 20 more than 10, and which is 10 more than 20",
2656 EXPECT_EQ(
"which is 15 more than 10, and which is 5 more than 20",
2661 EXPECT_EQ(
"which is 30 more than 10, and which is 20 more than 20, "
2662 "and which is 10 more than 30",
2686 for (
int i = 1; i <= num; ++i) {
2694TEST(AnyOfTest, MatchesWhenAnyMatches) {
2732 AnyOfMatches(10,
AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
2737TEST(AnyOfTest, VariadicMatchesWhenAnyMatches) {
2740 Matcher<int> m =
::testing::AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
2744 AnyOfMatches(50,
AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
2745 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
2746 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
2747 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
2748 41, 42, 43, 44, 45, 46, 47, 48, 49, 50));
2752TEST(ElementsAreTest, HugeMatcher) {
2753 vector<int> test_vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
2761TEST(ElementsAreTest, HugeMatcherStr) {
2762 vector<string> test_vector{
2763 "literal_string",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""};
2770TEST(ElementsAreTest, HugeMatcherUnordered) {
2771 vector<int> test_vector{2, 1, 8, 5, 4, 6, 7, 3, 9, 12, 11, 10};
2789 "((is equal to 1) or (is equal to 2))",
2794 "(is equal to 1)) or "
2795 "((is equal to 2) or "
2802 "((is equal to 3) or "
2803 "((is equal to 5) or "
2804 "(is equal to 7)))",
2809TEST(AnyOfTest, CanDescribeNegation) {
2812 EXPECT_EQ(
"(isn't <= 1) and (isn't >= 3)",
2817 "((isn't equal to 1) and (isn't equal to 2))",
2822 "(isn't equal to 1)) and "
2823 "((isn't equal to 2) and "
2824 "(isn't equal to 3))",
2829 "(isn't > 10)) and "
2830 "((isn't equal to 3) and "
2831 "((isn't equal to 5) and "
2832 "(isn't equal to 7)))",
2837TEST(AnyOfTest, AnyOfMatcherSafelyCastsMonomorphicMatchers) {
2862 EXPECT_EQ(
"which is 5 less than 10, and which is 15 less than 20",
2868 EXPECT_EQ(
"which is 5 less than 10, and which is 25 less than 30",
2873 EXPECT_EQ(
"which is 5 less than 10, and which is 15 less than 20, "
2874 "and which is 25 less than 30",
2902 return x > 0 ? 1 : 0;
2923 return (&n == &
foo) && (n == 0);
2928TEST(TrulyTest, MatchesWhatSatisfiesThePredicate) {
2935TEST(TrulyTest, CanBeUsedWithFunctor) {
2945 operator bool()
const {
return number_ != 0; }
2958TEST(TrulyTest, PredicateCanReturnAClassConvertibleToBool) {
2967 EXPECT_EQ(
"satisfies the given predicate",
2973TEST(TrulyTest, WorksForByRefArguments) {
2982TEST(MatchesTest, IsSatisfiedByWhatMatchesTheMatcher) {
2989TEST(MatchesTest, WorksOnByRefArguments) {
2997TEST(MatchesTest, WorksWithMatcherOnNonRefType) {
3006TEST(ValueTest, WorksWithPolymorphicMatcher) {
3011TEST(ValueTest, WorksWithMonomorphicMatcher) {
3022TEST(ExplainMatchResultTest, WorksWithPolymorphicMatcher) {
3032TEST(ExplainMatchResultTest, WorksWithMonomorphicMatcher) {
3048TEST(ExplainMatchResultTest, WorksInsideMATCHER) {
3052TEST(DescribeMatcherTest, WorksWithValue) {
3057TEST(DescribeMatcherTest, WorksWithMonomorphicMatcher) {
3063TEST(DescribeMatcherTest, WorksWithPolymorphicMatcher) {
3073TEST(AllArgsTest, WorksForNonTuple) {
3088TEST(AllArgsTest, WorksInWithClause) {
3092 .WillByDefault(
Return(1));
3119TEST(AllArgsTest, WorksWithoutMatchers) {
3142TEST(MatcherAssertionTest, WorksWhenMatcherIsSatisfied) {
3151TEST(MatcherAssertionTest, WorksWhenMatcherIsNotSatisfied) {
3154 static unsigned short n;
3164 "Expected: is > 10\n"
3165 " Actual: 5" +
OfType(
"unsigned short"));
3170 "Expected: (is <= 7) and (is >= 5)\n"
3171 " Actual: 0" +
OfType(
"unsigned short"));
3176TEST(MatcherAssertionTest, WorksForByRefArguments) {
3184 "Expected: does not reference the variable @");
3187 "Actual: 0" +
OfType(
"int") +
", which is located @");
3190#if !GTEST_OS_SYMBIAN
3204TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) {
3210 const std::string bad =
"bad";
3213 "Expected: ends with \"ok\"\n"
3214 " Actual: \"bad\"");
3218 "Expected: is > 5\n"
3219 " Actual: 5" +
OfType(
"int"));
3224template <
typename RawType>
3334template <
typename RawType>
3343 (*matcher_maker)(RawType, RawType)) {
3421 TestMatches(&FloatEq);
3425 TestMatches(&NanSensitiveFloatEq);
3477 TestNearMatches(&FloatNear);
3481 TestNearMatches(&NanSensitiveFloatNear);
3536 TestMatches(&DoubleEq);
3540 TestMatches(&NanSensitiveDoubleEq);
3592 TestNearMatches(&DoubleNear);
3596 TestNearMatches(&NanSensitiveDoubleNear);
3620 const std::string explanation =
3624 EXPECT_TRUE(explanation ==
"which is 1.2e-10 from 2.1" ||
3625 explanation ==
"which is 1.2e-010 from 2.1")
3626 <<
" where explanation is \"" << explanation <<
"\".";
3671TEST(PointeeTest, RawPointerToConst) {
3681TEST(PointeeTest, ReferenceToConstRawPointer) {
3691TEST(PointeeTest, ReferenceToNonConstRawPointer) {
3708TEST(WhenDynamicCastToTest, SameType) {
3713 Base* as_base_ptr = &derived;
3717 Not(WhenDynamicCastTo<Derived*>(
Pointee(FieldIIs(5)))));
3720TEST(WhenDynamicCastToTest, WrongTypes) {
3723 OtherDerived other_derived;
3728 Base* as_base_ptr = &derived;
3731 as_base_ptr = &other_derived;
3736TEST(WhenDynamicCastToTest, AlreadyNull) {
3738 Base* as_base_ptr = NULL;
3742struct AmbiguousCastTypes {
3743 class VirtualDerived :
public virtual Base {};
3744 class DerivedSub1 :
public VirtualDerived {};
3745 class DerivedSub2 :
public VirtualDerived {};
3746 class ManyDerivedInHierarchy :
public DerivedSub1,
public DerivedSub2 {};
3749TEST(WhenDynamicCastToTest, AmbiguousCast) {
3750 AmbiguousCastTypes::DerivedSub1 sub1;
3751 AmbiguousCastTypes::ManyDerivedInHierarchy many_derived;
3754 static_cast<AmbiguousCastTypes::DerivedSub1*
>(&many_derived);
3756 WhenDynamicCastTo<AmbiguousCastTypes::VirtualDerived*>(
IsNull()));
3757 as_base_ptr = &sub1;
3760 WhenDynamicCastTo<AmbiguousCastTypes::VirtualDerived*>(
Not(
IsNull())));
3764 Matcher<Base*> matcher = WhenDynamicCastTo<Derived*>(
Pointee(_));
3765 const std::string prefix =
3768 EXPECT_EQ(prefix +
"does not point to a value that is anything",
3773 Matcher<Base*> matcher = WhenDynamicCastTo<Derived*>(
Pointee(_));
3781 Matcher<const Base&> ref_matcher = WhenDynamicCastTo<const OtherDerived&>(_);
3783 HasSubstr(
"which cannot be dynamic_cast"));
3786TEST(WhenDynamicCastToTest, GoodReference) {
3789 Base& as_base_ref = derived;
3790 EXPECT_THAT(as_base_ref, WhenDynamicCastTo<const Derived&>(FieldIIs(4)));
3791 EXPECT_THAT(as_base_ref, WhenDynamicCastTo<const Derived&>(
Not(FieldIIs(5))));
3794TEST(WhenDynamicCastToTest, BadReference) {
3796 Base& as_base_ref = derived;
3797 EXPECT_THAT(as_base_ref,
Not(WhenDynamicCastTo<const OtherDerived&>(_)));
3802template <
typename T>
3814 const T*
get()
const {
return val_; }
3821TEST(PointeeTest, WorksWithConstPropagatingPointers) {
3833TEST(PointeeTest, NeverMatchesNull) {
3839TEST(PointeeTest, MatchesAgainstAValue) {
3849TEST(PointeeTest, CanDescribeSelf) {
3852 EXPECT_EQ(
"does not point to a value that is > 3",
3856TEST(PointeeTest, CanExplainMatchResult) {
3863 EXPECT_EQ(
"which points to 3" +
OfType(
"long") +
", which is 2 more than 1",
3867TEST(PointeeTest, AlwaysExplainsPointee) {
3918TEST(FieldTest, WorksForNonConstField) {
3931TEST(FieldTest, WorksForConstField) {
3945TEST(FieldTest, WorksForUncopyableField) {
3955TEST(FieldTest, WorksForPointerField) {
3972TEST(FieldTest, WorksForByRefArgument) {
3983TEST(FieldTest, WorksForArgumentOfSubType) {
3996TEST(FieldTest, WorksForCompatibleMatcherType) {
4015TEST(FieldTest, CanDescribeSelfWithFieldName) {
4019 EXPECT_EQ(
"is an object whose field `field_name` isn't >= 0",
4024TEST(FieldTest, CanExplainMatchResult) {
4033 "whose given field is 1" +
OfType(
"int") +
", which is 1 more than 0",
4037TEST(FieldTest, CanExplainMatchResultWithFieldName) {
4046 ", which is 1 more than 0",
4051TEST(FieldForPointerTest, WorksForPointerToConst) {
4061TEST(FieldForPointerTest, WorksForPointerToNonConst) {
4071TEST(FieldForPointerTest, WorksForReferenceToConstPointer) {
4081TEST(FieldForPointerTest, DoesNotMatchNull) {
4088TEST(FieldForPointerTest, WorksForArgumentOfSubType) {
4100TEST(FieldForPointerTest, CanDescribeSelf) {
4107TEST(FieldForPointerTest, CanDescribeSelfWithFieldName) {
4111 EXPECT_EQ(
"is an object whose field `field_name` isn't >= 0",
4116TEST(FieldForPointerTest, CanExplainMatchResult) {
4122 EXPECT_EQ(
"which points to an object whose given field is 1" +
OfType(
"int"),
4126 EXPECT_EQ(
"which points to an object whose given field is 1" +
OfType(
"int") +
4127 ", which is 1 more than 0",
Explain(m, &
a));
4130TEST(FieldForPointerTest, CanExplainMatchResultWithFieldName) {
4137 "which points to an object whose field `field_name` is 1" +
OfType(
"int"),
4141 EXPECT_EQ(
"which points to an object whose field `field_name` is 1" +
4142 OfType(
"int") +
", which is 1 more than 0",
4152 int n()
const {
return n_; }
4157 const std::string&
s()
const {
return s_; }
4160 const std::string& s_ref() const & {
return s_; }
4163 void set_s(
const std::string& new_s) { s_ = new_s; }
4166 double&
x()
const {
return x_; }
4175double AClass::x_ = 0.0;
4180 int k()
const {
return k_; }
4187TEST(PropertyTest, WorksForNonReferenceProperty) {
4203TEST(PropertyTest, WorksForReferenceToConstProperty) {
4221TEST(PropertyTest, WorksForRefQualifiedProperty) {
4235TEST(PropertyTest, WorksForReferenceToNonConstProperty) {
4248TEST(PropertyTest, WorksForByValueArgument) {
4261TEST(PropertyTest, WorksForArgumentOfSubType) {
4276TEST(PropertyTest, WorksForCompatibleMatcherType) {
4293TEST(PropertyTest, CanDescribeSelf) {
4297 EXPECT_EQ(
"is an object whose given property isn't >= 0",
4301TEST(PropertyTest, CanDescribeSelfWithPropertyName) {
4305 EXPECT_EQ(
"is an object whose property `fancy_name` isn't >= 0",
4310TEST(PropertyTest, CanExplainMatchResult) {
4319 "whose given property is 1" +
OfType(
"int") +
", which is 1 more than 0",
4323TEST(PropertyTest, CanExplainMatchResultWithPropertyName) {
4332 ", which is 1 more than 0",
4337TEST(PropertyForPointerTest, WorksForPointerToConst) {
4349TEST(PropertyForPointerTest, WorksForPointerToNonConst) {
4362TEST(PropertyForPointerTest, WorksForReferenceToConstPointer) {
4374TEST(PropertyForPointerTest, WorksForReferenceToNonConstProperty) {
4381TEST(PropertyForPointerTest, WorksForArgumentOfSubType) {
4395TEST(PropertyForPointerTest, CanDescribeSelf) {
4399 EXPECT_EQ(
"is an object whose given property isn't >= 0",
4403TEST(PropertyForPointerTest, CanDescribeSelfWithPropertyDescription) {
4407 EXPECT_EQ(
"is an object whose property `fancy_name` isn't >= 0",
4412TEST(PropertyForPointerTest, CanExplainMatchResult) {
4419 "which points to an object whose given property is 1" +
OfType(
"int"),
4423 EXPECT_EQ(
"which points to an object whose given property is 1" +
4424 OfType(
"int") +
", which is 1 more than 0",
4428TEST(PropertyForPointerTest, CanExplainMatchResultWithPropertyName) {
4434 EXPECT_EQ(
"which points to an object whose property `fancy_name` is 1" +
4439 EXPECT_EQ(
"which points to an object whose property `fancy_name` is 1" +
4440 OfType(
"int") +
", which is 1 more than 0",
4449 return input == 1 ?
"foo" :
"bar";
4452TEST(ResultOfTest, WorksForFunctionPointers) {
4460TEST(ResultOfTest, CanDescribeItself) {
4463 EXPECT_EQ(
"is mapped by the given callable to a value that "
4464 "is equal to \"foo\"",
Describe(matcher));
4465 EXPECT_EQ(
"is mapped by the given callable to a value that "
4472TEST(ResultOfTest, CanExplainMatchResult) {
4474 EXPECT_EQ(
"which is mapped by the given callable to 90" +
OfType(
"int"),
4478 EXPECT_EQ(
"which is mapped by the given callable to 90" +
OfType(
"int") +
4479 ", which is 5 more than 85",
Explain(matcher, 36));
4484TEST(ResultOfTest, WorksForNonReferenceResults) {
4499TEST(ResultOfTest, WorksForReferenceToNonConstResults) {
4521TEST(ResultOfTest, WorksForReferenceToConstResults) {
4522 std::string
s =
"foo";
4532TEST(ResultOfTest, WorksForCompatibleMatcherTypes) {
4542TEST(ResultOfDeathTest, DiesOnNullFunctionPointers) {
4544 ResultOf(
static_cast<std::string (*)(
int dummy)
>(NULL),
4545 Eq(std::string(
"foo"))),
4546 "NULL function pointer is passed into ResultOf\\(\\)\\.");
4551TEST(ResultOfTest, WorksForFunctionReferences) {
4559struct Functor :
public ::std::unary_function<int, std::string> {
4565TEST(ResultOfTest, WorksForFunctors) {
4581TEST(ResultOfTest, WorksForPolymorphicFunctors) {
4600TEST(ResultOfTest, WorksForReferencingCallables) {
4617 template <
typename T>
4619 *listener <<
"which is " << (n % divider_) <<
" modulo "
4621 return (n % divider_) == 0;
4625 *
os <<
"is divisible by " << divider_;
4629 *
os <<
"is not divisible by " << divider_;
4645TEST(ExplainMatchResultTest, AllOf_False_False) {
4652TEST(ExplainMatchResultTest, AllOf_False_True) {
4659TEST(ExplainMatchResultTest, AllOf_True_False) {
4666TEST(ExplainMatchResultTest, AllOf_True_True) {
4671TEST(ExplainMatchResultTest, AllOf_True_True_2) {
4676TEST(ExplainmatcherResultTest, MonomorphicMatcher) {
4704TEST(ByRefTest, AllowsNotCopyableConstValueInMatchers) {
4713TEST(ByRefTest, AllowsNotCopyableValueInMatchers) {
4722TEST(IsEmptyTest, ImplementsIsEmpty) {
4723 vector<int> container;
4725 container.push_back(0);
4727 container.push_back(1);
4731TEST(IsEmptyTest, WorksWithString) {
4736 text = std::string(
"\0", 1);
4740TEST(IsEmptyTest, CanDescribeSelf) {
4748 vector<int> container;
4750 container.push_back(0);
4783 std::unique_ptr<int> null_unique;
4784 std::unique_ptr<int> nonnull_unique(
new int(0));
4792TEST(SizeIsTest, ImplementsSizeIs) {
4793 vector<int> container;
4796 container.push_back(0);
4799 container.push_back(0);
4805 map<std::string, int> container;
4808 container.insert(make_pair(
"foo", 1));
4811 container.insert(make_pair(
"bar", 2));
4816TEST(SizeIsTest, WorksWithReferences) {
4817 vector<int> container;
4820 container.push_back(0);
4835 vector<int> container;
4839 EXPECT_EQ(
"whose size 0 doesn't match, which is 1 less than 1",
4841 container.push_back(0);
4842 container.push_back(0);
4846 EXPECT_EQ(
"whose size 2 matches, which is 1 more than 1",
4850#if GTEST_HAS_TYPED_TEST
4854template <
typename T>
4857typedef testing::Types<
4862 ContainerEqTestTypes;
4868 static const int vals[] = {1, 1, 2, 3, 5, 8};
4869 TypeParam my_set(vals, vals + 6);
4877 static const int vals[] = {1, 1, 2, 3, 5, 8};
4878 static const int test_vals[] = {2, 1, 8, 5};
4879 TypeParam my_set(vals, vals + 6);
4880 TypeParam test_set(test_vals, test_vals + 4);
4883 EXPECT_EQ(
"which doesn't have these expected elements: 3",
4889 static const int vals[] = {1, 1, 2, 3, 5, 8};
4890 static const int test_vals[] = {1, 2, 3, 5, 8, 46};
4891 TypeParam my_set(vals, vals + 6);
4892 TypeParam test_set(test_vals, test_vals + 6);
4893 const Matcher<const TypeParam&> m =
ContainerEq(my_set);
4895 EXPECT_EQ(
"which has these unexpected elements: 46",
Explain(m, test_set));
4899TYPED_TEST(ContainerEqTest, ValueAddedAndRemoved) {
4900 static const int vals[] = {1, 1, 2, 3, 5, 8};
4901 static const int test_vals[] = {1, 2, 3, 8, 46};
4902 TypeParam my_set(vals, vals + 6);
4903 TypeParam test_set(test_vals, test_vals + 5);
4906 EXPECT_EQ(
"which has these unexpected elements: 46,\n"
4907 "and doesn't have these expected elements: 5",
4912TYPED_TEST(ContainerEqTest, DuplicateDifference) {
4913 static const int vals[] = {1, 1, 2, 3, 5, 8};
4914 static const int test_vals[] = {1, 2, 3, 5, 8};
4915 TypeParam my_set(vals, vals + 6);
4916 TypeParam test_set(test_vals, test_vals + 5);
4917 const Matcher<const TypeParam&> m =
ContainerEq(my_set);
4926TEST(ContainerEqExtraTest, MultipleValuesMissing) {
4927 static const int vals[] = {1, 1, 2, 3, 5, 8};
4928 static const int test_vals[] = {2, 1, 5};
4929 vector<int> my_set(vals, vals + 6);
4930 vector<int> test_set(test_vals, test_vals + 3);
4933 EXPECT_EQ(
"which doesn't have these expected elements: 3, 8",
4939TEST(ContainerEqExtraTest, MultipleValuesAdded) {
4940 static const int vals[] = {1, 1, 2, 3, 5, 8};
4941 static const int test_vals[] = {1, 2, 92, 3, 5, 8, 46};
4942 list<size_t> my_set(vals, vals + 6);
4943 list<size_t> test_set(test_vals, test_vals + 7);
4946 EXPECT_EQ(
"which has these unexpected elements: 92, 46",
4951TEST(ContainerEqExtraTest, MultipleValuesAddedAndRemoved) {
4952 static const int vals[] = {1, 1, 2, 3, 5, 8};
4953 static const int test_vals[] = {1, 2, 3, 92, 46};
4954 list<size_t> my_set(vals, vals + 6);
4955 list<size_t> test_set(test_vals, test_vals + 5);
4958 EXPECT_EQ(
"which has these unexpected elements: 92, 46,\n"
4959 "and doesn't have these expected elements: 5, 8",
4965TEST(ContainerEqExtraTest, MultiSetOfIntDuplicateDifference) {
4966 static const int vals[] = {1, 1, 2, 3, 5, 8};
4967 static const int test_vals[] = {1, 2, 3, 5, 8};
4968 vector<int> my_set(vals, vals + 6);
4969 vector<int> test_set(test_vals, test_vals + 5);
4979TEST(ContainerEqExtraTest, WorksForMaps) {
4980 map<int, std::string> my_map;
4984 map<int, std::string> test_map;
4992 EXPECT_EQ(
"which has these unexpected elements: (0, \"aa\"),\n"
4993 "and doesn't have these expected elements: (0, \"a\")",
4997TEST(ContainerEqExtraTest, WorksForNativeArray) {
4998 int a1[] = {1, 2, 3};
4999 int a2[] = {1, 2, 3};
5000 int b[] = {1, 2, 4};
5006TEST(ContainerEqExtraTest, WorksForTwoDimensionalNativeArray) {
5007 const char a1[][3] = {
"hi",
"lo"};
5008 const char a2[][3] = {
"hi",
"lo"};
5009 const char b[][3] = {
"lo",
"hi"};
5020TEST(ContainerEqExtraTest, WorksForNativeArrayAsTuple) {
5021 const int a1[] = {1, 2, 3};
5022 const int a2[] = {1, 2, 3};
5023 const int b[] = {1, 2, 3, 4};
5025 const int*
const p1 = a1;
5029 const int c[] = {1, 3, 2};
5033TEST(ContainerEqExtraTest, CopiesNativeArrayParameter) {
5034 std::string a1[][3] = {
5035 {
"hi",
"hello",
"ciao"},
5036 {
"bye",
"see you",
"ciao"}
5039 std::string a2[][3] = {
5040 {
"hi",
"hello",
"ciao"},
5041 {
"bye",
"see you",
"ciao"}
5051TEST(WhenSortedByTest, WorksForEmptyContainer) {
5052 const vector<int> numbers;
5057TEST(WhenSortedByTest, WorksForNonEmptyContainer) {
5058 vector<unsigned> numbers;
5059 numbers.push_back(3);
5060 numbers.push_back(1);
5061 numbers.push_back(2);
5062 numbers.push_back(2);
5069TEST(WhenSortedByTest, WorksForNonVectorContainer) {
5070 list<std::string> words;
5071 words.push_back(
"say");
5072 words.push_back(
"hello");
5073 words.push_back(
"world");
5080TEST(WhenSortedByTest, WorksForNativeArray) {
5081 const int numbers[] = {1, 3, 2, 4};
5082 const int sorted_numbers[] = {1, 2, 3, 4};
5089TEST(WhenSortedByTest, CanDescribeSelf) {
5091 EXPECT_EQ(
"(when sorted) has 2 elements where\n"
5092 "element #0 is equal to 1,\n"
5093 "element #1 is equal to 2",
5095 EXPECT_EQ(
"(when sorted) doesn't have 2 elements, or\n"
5096 "element #0 isn't equal to 1, or\n"
5097 "element #1 isn't equal to 2",
5101TEST(WhenSortedByTest, ExplainsMatchResult) {
5102 const int a[] = {2, 1};
5103 EXPECT_EQ(
"which is { 1, 2 } when sorted, whose element #0 doesn't match",
5105 EXPECT_EQ(
"which is { 1, 2 } when sorted",
5112TEST(WhenSortedTest, WorksForEmptyContainer) {
5113 const vector<int> numbers;
5118TEST(WhenSortedTest, WorksForNonEmptyContainer) {
5119 list<std::string> words;
5120 words.push_back(
"3");
5121 words.push_back(
"1");
5122 words.push_back(
"2");
5123 words.push_back(
"2");
5128TEST(WhenSortedTest, WorksForMapTypes) {
5129 map<std::string, int> word_counts;
5130 word_counts[
"and"] = 1;
5131 word_counts[
"the"] = 1;
5132 word_counts[
"buffalo"] = 2;
5138 Pair(
"buffalo", 2)))));
5141TEST(WhenSortedTest, WorksForMultiMapTypes) {
5142 multimap<int, int> ifib;
5143 ifib.insert(make_pair(8, 6));
5144 ifib.insert(make_pair(2, 3));
5145 ifib.insert(make_pair(1, 1));
5146 ifib.insert(make_pair(3, 4));
5147 ifib.insert(make_pair(1, 2));
5148 ifib.insert(make_pair(5, 5));
5163TEST(WhenSortedTest, WorksForPolymorphicMatcher) {
5171TEST(WhenSortedTest, WorksForVectorConstRefMatcher) {
5183template <
typename T>
5191 template <
typename InIter>
5192 Streamlike(InIter first, InIter last) : remainder_(first, last) {}
5202 class ConstIter :
public std::iterator<std::input_iterator_tag,
5206 const value_type&> {
5209 typename std::list<value_type>::iterator pos)
5210 : s_(
s), pos_(pos) {}
5212 const value_type& operator*()
const {
return *pos_; }
5213 const value_type* operator->()
const {
return &*pos_; }
5214 ConstIter& operator++() {
5215 s_->remainder_.erase(pos_++);
5228 PostIncrProxy operator++(
int) {
5229 PostIncrProxy proxy(**
this);
5234 friend bool operator==(
const ConstIter&
a,
const ConstIter& b) {
5235 return a.s_ == b.s_ &&
a.pos_ == b.pos_;
5237 friend bool operator!=(
const ConstIter&
a,
const ConstIter& b) {
5243 typename std::list<value_type>::iterator pos_;
5248 typedef typename std::list<value_type>::const_iterator Iter;
5249 const char* sep =
"";
5250 for (Iter it =
s.remainder_.begin(); it !=
s.remainder_.end(); ++it) {
5258 mutable std::list<value_type> remainder_;
5262 const int a[5] = {2, 1, 4, 5, 3};
5266 while (it !=
s.end()) {
5272#if GTEST_HAS_STD_FORWARD_LIST_
5273TEST(BeginEndDistanceIsTest, WorksWithForwardList) {
5274 std::forward_list<int> container;
5277 container.push_front(0);
5280 container.push_front(0);
5286TEST(BeginEndDistanceIsTest, WorksWithNonStdList) {
5287 const int a[5] = {1, 2, 3, 4, 5};
5292TEST(BeginEndDistanceIsTest, CanDescribeSelf) {
5295 EXPECT_EQ(
"distance between begin() and end() isn't equal to 2",
5299TEST(BeginEndDistanceIsTest, ExplainsResult) {
5304 vector<int> container;
5305 EXPECT_EQ(
"whose distance between begin() and end() 0 doesn't match",
5307 EXPECT_EQ(
"whose distance between begin() and end() 0 matches",
5309 EXPECT_EQ(
"whose distance between begin() and end() 0 matches",
5312 "whose distance between begin() and end() 0 doesn't match, which is 1 "
5315 container.push_back(0);
5316 container.push_back(0);
5317 EXPECT_EQ(
"whose distance between begin() and end() 2 matches",
5319 EXPECT_EQ(
"whose distance between begin() and end() 2 doesn't match",
5321 EXPECT_EQ(
"whose distance between begin() and end() 2 doesn't match",
5324 "whose distance between begin() and end() 2 matches, which is 1 more "
5329TEST(WhenSortedTest, WorksForStreamlike) {
5332 const int a[5] = {2, 1, 4, 5, 3};
5338TEST(WhenSortedTest, WorksForVectorConstRefMatcherOnStreamlike) {
5339 const int a[] = {2, 1, 4, 5, 3};
5346TEST(IsSupersetOfTest, WorksForNativeArray) {
5347 const int subset[] = {1, 4};
5348 const int superset[] = {1, 2, 4};
5349 const int disjoint[] = {1, 0, 3};
5357TEST(IsSupersetOfTest, WorksWithDuplicates) {
5358 const int not_enough[] = {1, 2};
5359 const int enough[] = {1, 1, 2};
5360 const int expected[] = {1, 1};
5365TEST(IsSupersetOfTest, WorksForEmpty) {
5366 vector<int> numbers;
5367 vector<int> expected;
5369 expected.push_back(1);
5372 numbers.push_back(1);
5373 numbers.push_back(2);
5375 expected.push_back(1);
5377 expected.push_back(2);
5379 expected.push_back(3);
5383TEST(IsSupersetOfTest, WorksForStreamlike) {
5384 const int a[5] = {1, 2, 3, 4, 5};
5387 vector<int> expected;
5388 expected.push_back(1);
5389 expected.push_back(2);
5390 expected.push_back(5);
5393 expected.push_back(0);
5397TEST(IsSupersetOfTest, TakesStlContainer) {
5398 const int actual[] = {3, 1, 2};
5400 ::std::list<int> expected;
5401 expected.push_back(1);
5402 expected.push_back(3);
5405 expected.push_back(4);
5410 typedef std::vector<int> IntVec;
5412 expected.push_back(111);
5413 expected.push_back(222);
5414 expected.push_back(333);
5417 Eq(
"a surjection from elements to requirements exists such that:\n"
5418 " - an element is equal to 111\n"
5419 " - an element is equal to 222\n"
5420 " - an element is equal to 333"));
5424 typedef std::vector<int> IntVec;
5426 expected.push_back(111);
5427 expected.push_back(222);
5428 expected.push_back(333);
5431 Eq(
"no surjection from elements to requirements exists such that:\n"
5432 " - an element is equal to 111\n"
5433 " - an element is equal to 222\n"
5434 " - an element is equal to 333"));
5437TEST(IsSupersetOfTest, MatchAndExplain) {
5441 std::vector<int> expected;
5442 expected.push_back(1);
5443 expected.push_back(2);
5448 Eq(
"where the following matchers don't match any elements:\n"
5449 "matcher #0: is equal to 1"));
5456 " - element #0 is matched by matcher #1,\n"
5457 " - element #2 is matched by matcher #0"));
5460#if GTEST_HAS_STD_INITIALIZER_LIST_
5461TEST(IsSupersetOfTest, WorksForRhsInitializerList) {
5462 const int numbers[] = {1, 3, 6, 2, 4, 5};
5468TEST(IsSubsetOfTest, WorksForNativeArray) {
5469 const int subset[] = {1, 4};
5470 const int superset[] = {1, 2, 4};
5471 const int disjoint[] = {1, 0, 3};
5479TEST(IsSubsetOfTest, WorksWithDuplicates) {
5480 const int not_enough[] = {1, 2};
5481 const int enough[] = {1, 1, 2};
5482 const int actual[] = {1, 1};
5487TEST(IsSubsetOfTest, WorksForEmpty) {
5488 vector<int> numbers;
5489 vector<int> expected;
5491 expected.push_back(1);
5494 numbers.push_back(1);
5495 numbers.push_back(2);
5497 expected.push_back(1);
5499 expected.push_back(2);
5501 expected.push_back(3);
5505TEST(IsSubsetOfTest, WorksForStreamlike) {
5506 const int a[5] = {1, 2};
5509 vector<int> expected;
5510 expected.push_back(1);
5512 expected.push_back(2);
5513 expected.push_back(5);
5517TEST(IsSubsetOfTest, TakesStlContainer) {
5518 const int actual[] = {3, 1, 2};
5520 ::std::list<int> expected;
5521 expected.push_back(1);
5522 expected.push_back(3);
5525 expected.push_back(2);
5526 expected.push_back(4);
5531 typedef std::vector<int> IntVec;
5533 expected.push_back(111);
5534 expected.push_back(222);
5535 expected.push_back(333);
5539 Eq(
"an injection from elements to requirements exists such that:\n"
5540 " - an element is equal to 111\n"
5541 " - an element is equal to 222\n"
5542 " - an element is equal to 333"));
5546 typedef std::vector<int> IntVec;
5548 expected.push_back(111);
5549 expected.push_back(222);
5550 expected.push_back(333);
5553 Eq(
"no injection from elements to requirements exists such that:\n"
5554 " - an element is equal to 111\n"
5555 " - an element is equal to 222\n"
5556 " - an element is equal to 333"));
5559TEST(IsSubsetOfTest, MatchAndExplain) {
5563 std::vector<int> expected;
5564 expected.push_back(1);
5565 expected.push_back(2);
5570 Eq(
"where the following elements don't match any matchers:\n"
5573 expected.push_back(3);
5578 " - element #0 is matched by matcher #1,\n"
5579 " - element #1 is matched by matcher #2"));
5582#if GTEST_HAS_STD_INITIALIZER_LIST_
5583TEST(IsSubsetOfTest, WorksForRhsInitializerList) {
5584 const int numbers[] = {1, 2, 3};
5593TEST(ElemensAreStreamTest, WorksForStreamlike) {
5594 const int a[5] = {1, 2, 3, 4, 5};
5600TEST(ElemensAreArrayStreamTest, WorksForStreamlike) {
5601 const int a[5] = {1, 2, 3, 4, 5};
5604 vector<int> expected;
5605 expected.push_back(1);
5606 expected.push_back(2);
5607 expected.push_back(3);
5608 expected.push_back(4);
5609 expected.push_back(5);
5616TEST(ElementsAreTest, WorksWithUncopyable) {
5623TEST(ElementsAreTest, TakesStlContainer) {
5624 const int actual[] = {3, 1, 2};
5626 ::std::list<int> expected;
5627 expected.push_back(3);
5628 expected.push_back(1);
5629 expected.push_back(2);
5632 expected.push_back(4);
5638TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) {
5639 const int a[] = {0, 1, 2, 3, 4};
5644 s, &listener)) << listener.
str();
5645 }
while (std::next_permutation(
s.begin(),
s.end()));
5648TEST(UnorderedElementsAreArrayTest, VectorBool) {
5649 const bool a[] = {0, 1, 0, 1, 1};
5650 const bool b[] = {1, 0, 1, 1, 0};
5655 actual, &listener)) << listener.
str();
5658TEST(UnorderedElementsAreArrayTest, WorksForStreamlike) {
5662 const int a[5] = {2, 1, 4, 5, 3};
5665 ::std::vector<int> expected;
5666 expected.push_back(1);
5667 expected.push_back(2);
5668 expected.push_back(3);
5669 expected.push_back(4);
5670 expected.push_back(5);
5673 expected.push_back(6);
5677TEST(UnorderedElementsAreArrayTest, TakesStlContainer) {
5678 const int actual[] = {3, 1, 2};
5680 ::std::list<int> expected;
5681 expected.push_back(1);
5682 expected.push_back(2);
5683 expected.push_back(3);
5686 expected.push_back(4);
5690#if GTEST_HAS_STD_INITIALIZER_LIST_
5692TEST(UnorderedElementsAreArrayTest, TakesInitializerList) {
5693 const int a[5] = {2, 1, 4, 5, 3};
5698TEST(UnorderedElementsAreArrayTest, TakesInitializerListOfCStrings) {
5699 const std::string
a[5] = {
"a",
"b",
"c",
"d",
"e"};
5704TEST(UnorderedElementsAreArrayTest, TakesInitializerListOfSameTypedMatchers) {
5705 const int a[5] = {2, 1, 4, 5, 3};
5712TEST(UnorderedElementsAreArrayTest,
5713 TakesInitializerListOfDifferentTypedMatchers) {
5714 const int a[5] = {2, 1, 4, 5, 3};
5740 const int a[] = {1, 2, 3};
5745 s, &listener)) << listener.
str();
5746 }
while (std::next_permutation(
s.begin(),
s.end()));
5750 const int a[] = {1, 2, 3};
5752 std::vector<Matcher<int> > mv;
5759 s, &listener)) << listener.
str();
5766 const int a[5] = {2, 1, 4, 5, 3};
5781 std::vector<Matcher<int> > mv;
5782 for (
int i = 0; i < 100; ++i) {
5789 s, &listener)) << listener.
str();
5797 std::vector<Matcher<int> > mv;
5798 for (
int i = 0; i < 100; ++i) {
5808 s, &listener)) << listener.
str();
5816 v, &listener)) << listener.
str();
5824 v, &listener)) << listener.
str();
5834 v, &listener)) << listener.
str();
5837 Eq(
"where the following matchers don't match any elements:\n"
5838 "matcher #1: is equal to 2"));
5847 v, &listener)) << listener.
str();
5850 Eq(
"where the following elements don't match any matchers:\n"
5860 v, &listener)) << listener.
str();
5864 " the following matchers don't match any elements:\n"
5865 "matcher #0: is equal to 1\n"
5868 " the following elements don't match any matchers:\n"
5873static std::string EMString(
int element,
int matcher) {
5875 ss <<
"(element #" << element <<
", matcher #" << matcher <<
")";
5882 std::vector<std::string> v;
5891 std::string prefix =
5892 "where no permutation of the elements can satisfy all matchers, "
5893 "and the closest match is 2 of 3 matchers with the "
5899 AnyOf(prefix +
"{\n " + EMString(0, 0) +
5900 ",\n " + EMString(1, 2) +
"\n}",
5901 prefix +
"{\n " + EMString(0, 1) +
5902 ",\n " + EMString(1, 2) +
"\n}",
5903 prefix +
"{\n " + EMString(0, 0) +
5904 ",\n " + EMString(2, 2) +
"\n}",
5905 prefix +
"{\n " + EMString(0, 1) +
5906 ",\n " + EMString(2, 2) +
"\n}"));
5914 Eq(
"has 1 element and that element is equal to 345"));
5917 Eq(
"has 3 elements and there exists some permutation "
5918 "of elements such that:\n"
5919 " - element #0 is equal to 111, and\n"
5920 " - element #1 is equal to 222, and\n"
5921 " - element #2 is equal to 333"));
5929 Eq(
"doesn't have 1 element, or has 1 element that isn't equal to 345"));
5932 Eq(
"doesn't have 3 elements, or there exists no permutation "
5933 "of elements such that:\n"
5934 " - element #0 is equal to 123, and\n"
5935 " - element #1 is equal to 234, and\n"
5936 " - element #2 is equal to 345"));
5945template <
typename Graph>
5946class BacktrackingMaxBPMState {
5949 explicit BacktrackingMaxBPMState(
const Graph* g) : graph_(g) { }
5952 if (graph_->LhsSize() == 0 || graph_->RhsSize() == 0) {
5953 return best_so_far_;
5955 lhs_used_.assign(graph_->LhsSize(), kUnused);
5956 rhs_used_.assign(graph_->RhsSize(), kUnused);
5957 for (
size_t irhs = 0; irhs < graph_->RhsSize(); ++irhs) {
5960 if (best_so_far_.size() == graph_->RhsSize())
5963 return best_so_far_;
5967 static const size_t kUnused =
static_cast<size_t>(-1);
5969 void PushMatch(
size_t lhs,
size_t rhs) {
5971 lhs_used_[lhs] = rhs;
5972 rhs_used_[rhs] = lhs;
5973 if (matches_.size() > best_so_far_.size()) {
5974 best_so_far_ = matches_;
5980 lhs_used_[back.first] = kUnused;
5981 rhs_used_[back.second] = kUnused;
5982 matches_.pop_back();
5985 bool RecurseInto(
size_t irhs) {
5986 if (rhs_used_[irhs] != kUnused) {
5989 for (
size_t ilhs = 0; ilhs < graph_->LhsSize(); ++ilhs) {
5990 if (lhs_used_[ilhs] != kUnused) {
5993 if (!graph_->HasEdge(ilhs, irhs)) {
5996 PushMatch(ilhs, irhs);
5997 if (best_so_far_.size() == graph_->RhsSize()) {
6000 for (
size_t mi = irhs + 1; mi < graph_->RhsSize(); ++mi) {
6001 if (!RecurseInto(mi))
return false;
6008 const Graph* graph_;
6009 std::vector<size_t> lhs_used_;
6010 std::vector<size_t> rhs_used_;
6015template <
typename Graph>
6016const size_t BacktrackingMaxBPMState<Graph>::kUnused;
6022template <
typename Graph>
6025 return BacktrackingMaxBPMState<Graph>(&g).Compute();
6036 int nodes = GetParam();
6045 std::vector<bool> seen_element(graph.
LhsSize());
6046 std::vector<bool> seen_matcher(graph.
RhsSize());
6048 for (
size_t i = 0; i < matches.size(); ++i) {
6049 size_t ilhs = matches[i].first;
6050 size_t irhs = matches[i].second;
6054 seen_element[ilhs] =
true;
6055 seen_matcher[irhs] =
true;
6077 static const int kEdges[][2] = {{0, 2}, {1, 1}, {2, 1}, {3, 0}};
6079 g.
SetEdge(kEdges[i][0], kEdges[i][1],
true);
6089 size_t nlhs = GetParam().first;
6090 size_t nrhs = GetParam().second;
6096 <<
"\nbacktracking: "
6105 std::make_pair(1, 2),
6106 std::make_pair(2, 1),
6107 std::make_pair(3, 2),
6108 std::make_pair(2, 3),
6109 std::make_pair(4, 1),
6110 std::make_pair(1, 4),
6111 std::make_pair(4, 3),
6112 std::make_pair(3, 4)));
6120 int nodes = GetParam().first;
6121 int iters = GetParam().second;
6129 for (; iters > 0; --iters, ++seed) {
6130 srand(
static_cast<int>(seed));
6135 <<
"\nTo reproduce the failure, rerun the test with the flag"
6143 std::make_pair(5, 10000),
6144 std::make_pair(6, 5000),
6145 std::make_pair(7, 2000),
6146 std::make_pair(8, 500),
6147 std::make_pair(9, 100)));
6151TEST(IsReadableTypeNameTest, ReturnsTrueForShortNames) {
6153 EXPECT_TRUE(IsReadableTypeName(
"const unsigned char*"));
6154 EXPECT_TRUE(IsReadableTypeName(
"MyMap<int, void*>"));
6155 EXPECT_TRUE(IsReadableTypeName(
"void (*)(int, bool)"));
6158TEST(IsReadableTypeNameTest, ReturnsTrueForLongNonTemplateNonFunctionNames) {
6159 EXPECT_TRUE(IsReadableTypeName(
"my_long_namespace::MyClassName"));
6160 EXPECT_TRUE(IsReadableTypeName(
"int [5][6][7][8][9][10][11]"));
6161 EXPECT_TRUE(IsReadableTypeName(
"my_namespace::MyOuterClass::MyInnerClass"));
6164TEST(IsReadableTypeNameTest, ReturnsFalseForLongTemplateNames) {
6166 IsReadableTypeName(
"basic_string<char, std::char_traits<char> >"));
6167 EXPECT_FALSE(IsReadableTypeName(
"std::vector<int, std::alloc_traits<int> >"));
6170TEST(IsReadableTypeNameTest, ReturnsFalseForLongFunctionTypeNames) {
6171 EXPECT_FALSE(IsReadableTypeName(
"void (&)(int, bool, char, float)"));
6176TEST(FormatMatcherDescriptionTest, WorksForEmptyDescription) {
6178 FormatMatcherDescription(
false,
"IsEven",
Strings()));
6180 FormatMatcherDescription(
true,
"IsEven",
Strings()));
6182 const char*
params[] = {
"5"};
6184 FormatMatcherDescription(
false,
"Equals",
6187 const char* params2[] = {
"5",
"8"};
6189 FormatMatcherDescription(
false,
"IsInRange",
6190 Strings(params2, params2 + 2)));
6194TEST(PolymorphicMatcherTest, CanAccessMutableImpl) {
6199 impl.set_divider(0);
6204TEST(PolymorphicMatcherTest, CanAccessImpl) {
6210TEST(MatcherTupleTest, ExplainsMatchFailure) {
6213 make_tuple(
'a', 10), &ss1);
6218 make_tuple(2,
'b'), &ss2);
6220 " Actual: 2, which is 3 less than 5\n"
6221 " Expected arg #1: is equal to 'a' (97, 0x61)\n"
6222 " Actual: 'b' (98, 0x62)\n",
6227 make_tuple(2,
'a'), &ss3);
6229 " Actual: 2, which is 3 less than 5\n",
6236TEST(EachTest, ExplainsMatchResultCorrectly) {
6244 const int b[1] = {1};
6257 EXPECT_EQ(
"whose element #0 doesn't match, which is 9 less than 10",
6261TEST(EachTest, DescribesItselfCorrectly) {
6269TEST(EachTest, MatchesVectorWhenAllElementsMatch) {
6270 vector<int> some_vector;
6272 some_vector.push_back(3);
6275 some_vector.push_back(1);
6276 some_vector.push_back(2);
6280 vector<std::string> another_vector;
6281 another_vector.push_back(
"fee");
6283 another_vector.push_back(
"fie");
6284 another_vector.push_back(
"foe");
6285 another_vector.push_back(
"fum");
6289TEST(EachTest, MatchesMapWhenAllElementsMatch) {
6290 map<const char*, int> my_map;
6291 const char*
bar =
"a string";
6295 map<std::string, int> another_map;
6297 another_map[
"fee"] = 1;
6299 another_map[
"fie"] = 2;
6300 another_map[
"foe"] = 3;
6301 another_map[
"fum"] = 4;
6308 const int a[] = {1, 2, 3};
6313TEST(EachTest, WorksForNativeArrayAsTuple) {
6314 const int a[] = {1, 2};
6323 template <
typename T1,
typename T2>
6326 if (get<0>(a_pair) == get<1>(a_pair)/2) {
6327 *listener <<
"where the second is " << get<1>(a_pair);
6330 *listener <<
"where the second/2 is " << get<1>(a_pair)/2;
6336 *
os <<
"are a pair where the first is half of the second";
6340 *
os <<
"are a pair where the first isn't half of the second";
6348TEST(PointwiseTest, DescribesSelf) {
6354 EXPECT_EQ(
"contains 3 values, where each value and its corresponding value "
6355 "in { 1, 2, 3 } are a pair where the first is half of the second",
6357 EXPECT_EQ(
"doesn't contain exactly 3 values, or contains a value x at some "
6358 "index i where x and the i-th value of { 1, 2, 3 } are a pair "
6359 "where the first isn't half of the second",
6363TEST(PointwiseTest, MakesCopyOfRhs) {
6364 list<signed char> rhs;
6377TEST(PointwiseTest, WorksForLhsNativeArray) {
6378 const int lhs[] = {1, 2, 3};
6387TEST(PointwiseTest, WorksForRhsNativeArray) {
6388 const int rhs[] = {1, 2, 3};
6398TEST(PointwiseTest, WorksForVectorOfBool) {
6399 vector<bool> rhs(3,
false);
6401 vector<bool> lhs = rhs;
6407#if GTEST_HAS_STD_INITIALIZER_LIST_
6409TEST(PointwiseTest, WorksForRhsInitializerList) {
6410 const vector<int> lhs{2, 4, 6};
6417TEST(PointwiseTest, RejectsWrongSize) {
6418 const double lhs[2] = {1, 2};
6419 const int rhs[1] = {0};
6424 const int rhs2[3] = {0, 1, 2};
6428TEST(PointwiseTest, RejectsWrongContent) {
6429 const double lhs[3] = {1, 2, 3};
6430 const int rhs[3] = {2, 6, 4};
6432 EXPECT_EQ(
"where the value pair (2, 6) at index #1 don't match, "
6433 "where the second/2 is 3",
6437TEST(PointwiseTest, AcceptsCorrectContent) {
6438 const double lhs[3] = {1, 2, 3};
6439 const int rhs[3] = {2, 4, 6};
6444TEST(PointwiseTest, AllowsMonomorphicInnerMatcher) {
6445 const double lhs[3] = {1, 2, 3};
6446 const int rhs[3] = {2, 4, 6};
6458TEST(UnorderedPointwiseTest, DescribesSelf) {
6465 "has 3 elements and there exists some permutation of elements such "
6467 " - element #0 and 1 are a pair where the first is half of the second, "
6469 " - element #1 and 2 are a pair where the first is half of the second, "
6471 " - element #2 and 3 are a pair where the first is half of the second",
6474 "doesn't have 3 elements, or there exists no permutation of elements "
6476 " - element #0 and 1 are a pair where the first is half of the second, "
6478 " - element #1 and 2 are a pair where the first is half of the second, "
6480 " - element #2 and 3 are a pair where the first is half of the second",
6484TEST(UnorderedPointwiseTest, MakesCopyOfRhs) {
6485 list<signed char> rhs;
6498TEST(UnorderedPointwiseTest, WorksForLhsNativeArray) {
6499 const int lhs[] = {1, 2, 3};
6508TEST(UnorderedPointwiseTest, WorksForRhsNativeArray) {
6509 const int rhs[] = {1, 2, 3};
6518#if GTEST_HAS_STD_INITIALIZER_LIST_
6520TEST(UnorderedPointwiseTest, WorksForRhsInitializerList) {
6521 const vector<int> lhs{2, 4, 6};
6528TEST(UnorderedPointwiseTest, RejectsWrongSize) {
6529 const double lhs[2] = {1, 2};
6530 const int rhs[1] = {0};
6535 const int rhs2[3] = {0, 1, 2};
6539TEST(UnorderedPointwiseTest, RejectsWrongContent) {
6540 const double lhs[3] = {1, 2, 3};
6541 const int rhs[3] = {2, 6, 6};
6543 EXPECT_EQ(
"where the following elements don't match any matchers:\n"
6548TEST(UnorderedPointwiseTest, AcceptsCorrectContentInSameOrder) {
6549 const double lhs[3] = {1, 2, 3};
6550 const int rhs[3] = {2, 4, 6};
6554TEST(UnorderedPointwiseTest, AcceptsCorrectContentInDifferentOrder) {
6555 const double lhs[3] = {1, 2, 3};
6556 const int rhs[3] = {6, 4, 2};
6560TEST(UnorderedPointwiseTest, AllowsMonomorphicInnerMatcher) {
6561 const double lhs[3] = {1, 2, 3};
6562 const int rhs[3] = {4, 6, 2};
6579 operator bool()
const {
6601TEST(OptionalTest, MatchesNonEmptyOptional) {
6611TEST(OptionalTest, DoesNotMatchNullopt) {
6622 template <
typename T>
6627 template <
typename T>
6629 return value.get_impl(
static_cast<T*
>(NULL));
6633 const int& get_impl(
int*)
const {
return i_; }
6634 const std::string& get_impl(std::string*)
const {
return s_; }
6644 "'.*' and the value is equal to 1"));
6652 HasSubstr(
"whose value is not of type '"));
6654 "whose value 2 doesn't match");
6665TEST(VariantTest, TypeDoesNotMatch) {
6673TEST(VariantTest, InnerDoesNotMatch) {
6686 template <
typename T>
6688 return any->get_impl(
static_cast<T*
>(NULL));
6696 const int* get_impl(
int*)
const {
return index_ == 0 ? &i_ : NULL; }
6697 const std::string* get_impl(std::string*)
const {
6698 return index_ == 1 ? &s_ : NULL;
6707TEST(AnyWithTest, TestBadCastType) {
6713TEST(AnyWithTest, TestUseInContainers) {
6714 std::vector<SampleAnyType>
a;
6721 std::vector<SampleAnyType> b;
6722 b.emplace_back(
"hello");
6723 b.emplace_back(
"merhaba");
6724 b.emplace_back(
"salut");
6737 "'.*' and the value is equal to 1"));
6745 HasSubstr(
"whose value is not of type '"));
6751TEST(PointeeTest, WorksOnMoveOnlyType) {
6752 std::unique_ptr<int>
p(
new int(3));
6757TEST(NotTest, WorksOnMoveOnlyType) {
6758 std::unique_ptr<int>
p(
new int(3));