45#include "gtest/gtest.h"
46#include "gtest/gtest-spi.h"
54using std::stringstream;
57using testing::make_tuple;
86string Describe(
const Matcher<T>& m) {
96 m.DescribeNegationTo(&ss);
101template <
typename MatcherType,
typename Value>
104 m.ExplainMatchResultTo(x, &ss);
110TEST(ArgsTest, AcceptsZeroTemplateArg) {
111 const tuple<int, bool>
t(5,
true);
116TEST(ArgsTest, AcceptsOneTemplateArg) {
117 const tuple<int, bool>
t(5,
true);
120 EXPECT_THAT(t, Not(Args<1>(Eq(make_tuple(
false)))));
123TEST(ArgsTest, AcceptsTwoTemplateArgs) {
124 const tuple<short, int, long>
t(4, 5, 6L);
131TEST(ArgsTest, AcceptsRepeatedTemplateArgs) {
132 const tuple<short, int, long>
t(4, 5, 6L);
137TEST(ArgsTest, AcceptsDecreasingTemplateArgs) {
138 const tuple<short, int, long>
t(4, 5, 6L);
149# pragma warning(push)
150# pragma warning(disable:4100)
154 return get<0>(arg) + get<1>(arg) + get<2>(arg) == 0;
157TEST(ArgsTest, AcceptsMoreTemplateArgsThanArityOfOriginalTuple) {
158 EXPECT_THAT(make_tuple(-1, 2), (Args<0, 0, 1>(SumIsZero())));
159 EXPECT_THAT(make_tuple(1, 2), Not(Args<0, 0, 1>(SumIsZero())));
162TEST(ArgsTest, CanBeNested) {
163 const tuple<short, int, long, int>
t(4, 5, 6L, 6);
168TEST(ArgsTest, CanMatchTupleByValue) {
169 typedef tuple<char, int, int> Tuple3;
170 const Matcher<Tuple3> m = Args<1, 2>(Lt());
175TEST(ArgsTest, CanMatchTupleByReference) {
176 typedef tuple<char, char, int> Tuple3;
177 const Matcher<const Tuple3&> m = Args<0, 1>(Lt());
187TEST(ArgsTest, AcceptsTenTemplateArgs) {
188 EXPECT_THAT(make_tuple(0, 1L, 2, 3L, 4, 5, 6, 7, 8, 9),
189 (Args<9, 8, 7, 6, 5, 4, 3, 2, 1, 0>(
190 PrintsAs(
"(9, 8, 7, 6, 5, 4, 3, 2, 1, 0)"))));
191 EXPECT_THAT(make_tuple(0, 1L, 2, 3L, 4, 5, 6, 7, 8, 9),
192 Not(Args<9, 8, 7, 6, 5, 4, 3, 2, 1, 0>(
193 PrintsAs(
"(0, 8, 7, 6, 5, 4, 3, 2, 1, 0)"))));
196TEST(ArgsTest, DescirbesSelfCorrectly) {
197 const Matcher<tuple<int, bool, char> > m = Args<2, 0>(Lt());
198 EXPECT_EQ(
"are a tuple whose fields (#2, #0) are a pair where "
199 "the first < the second",
203TEST(ArgsTest, DescirbesNestedArgsCorrectly) {
204 const Matcher<const tuple<int, bool, char, int>&> m =
205 Args<0, 2, 3>(Args<2, 0>(Lt()));
206 EXPECT_EQ(
"are a tuple whose fields (#0, #2, #3) are a tuple "
207 "whose fields (#2, #0) are a pair where the first < the second",
211TEST(ArgsTest, DescribesNegationCorrectly) {
212 const Matcher<tuple<int, char> > m = Args<1, 0>(Gt());
213 EXPECT_EQ(
"are a tuple whose fields (#1, #0) aren't a pair "
214 "where the first > the second",
218TEST(ArgsTest, ExplainsMatchResultWithoutInnerExplanation) {
219 const Matcher<tuple<bool, int, int> > m = Args<1, 2>(Eq());
220 EXPECT_EQ(
"whose fields (#1, #2) are (42, 42)",
221 Explain(m, make_tuple(
false, 42, 42)));
222 EXPECT_EQ(
"whose fields (#1, #2) are (42, 43)",
223 Explain(m, make_tuple(
false, 42, 43)));
227class LessThanMatcher :
public MatcherInterface<tuple<char, int> > {
229 virtual void DescribeTo(::std::ostream* os)
const {}
231 virtual bool MatchAndExplain(tuple<char, int>
value,
232 MatchResultListener* listener)
const {
235 *listener <<
"where the first value is " <<
diff
236 <<
" more than the second";
242Matcher<tuple<char, int> > LessThan() {
243 return MakeMatcher(
new LessThanMatcher);
246TEST(ArgsTest, ExplainsMatchResultWithInnerExplanation) {
247 const Matcher<tuple<char, int, int> > m = Args<0, 2>(LessThan());
248 EXPECT_EQ(
"whose fields (#0, #2) are ('a' (97, 0x61), 42), "
249 "where the first value is 55 more than the second",
250 Explain(m, make_tuple(
'a', 42, 42)));
251 EXPECT_EQ(
"whose fields (#0, #2) are ('\\0', 43)",
252 Explain(m, make_tuple(
'\0', 42, 43)));
256class GreaterThanMatcher :
public MatcherInterface<int> {
258 explicit GreaterThanMatcher(
int rhs) : rhs_(rhs) {}
260 virtual void DescribeTo(::std::ostream* os)
const {
261 *os <<
"is greater than " << rhs_;
264 virtual bool MatchAndExplain(
int lhs,
265 MatchResultListener* listener)
const {
266 const int diff = lhs - rhs_;
268 *listener <<
"which is " <<
diff <<
" more than " << rhs_;
269 }
else if (diff == 0) {
270 *listener <<
"which is the same as " << rhs_;
272 *listener <<
"which is " << -
diff <<
" less than " << rhs_;
283 return MakeMatcher(
new GreaterThanMatcher(n));
288TEST(ElementsAreTest, CanDescribeExpectingNoElement) {
289 Matcher<const vector<int>&> m = ElementsAre();
293TEST(ElementsAreTest, CanDescribeExpectingOneElement) {
294 Matcher<vector<int> > m = ElementsAre(Gt(5));
298TEST(ElementsAreTest, CanDescribeExpectingManyElements) {
299 Matcher<list<string> > m = ElementsAre(StrEq(
"one"),
"two");
301 "element #0 is equal to \"one\",\n"
302 "element #1 is equal to \"two\"",
Describe(m));
305TEST(ElementsAreTest, CanDescribeNegationOfExpectingNoElement) {
306 Matcher<vector<int> > m = ElementsAre();
310TEST(ElementsAreTest, CanDescribeNegationOfExpectingOneElment) {
311 Matcher<const list<int>& > m = ElementsAre(Gt(5));
316TEST(ElementsAreTest, CanDescribeNegationOfExpectingManyElements) {
317 Matcher<const list<string>& > m = ElementsAre(
"one",
"two");
318 EXPECT_EQ(
"doesn't have 2 elements, or\n"
319 "element #0 isn't equal to \"one\", or\n"
323TEST(ElementsAreTest, DoesNotExplainTrivialMatch) {
324 Matcher<const list<int>& > m = ElementsAre(1, Ne(2));
332TEST(ElementsAreTest, ExplainsNonTrivialMatch) {
333 Matcher<const vector<int>& > m =
336 const int a[] = { 10, 0, 100 };
338 EXPECT_EQ(
"whose element #0 matches, which is 9 more than 1,\n"
339 "and whose element #2 matches, which is 98 more than 2",
343TEST(ElementsAreTest, CanExplainMismatchWrongSize) {
344 Matcher<const list<int>& > m = ElementsAre(1, 3);
354TEST(ElementsAreTest, CanExplainMismatchRightSize) {
355 Matcher<const vector<int>& > m = ElementsAre(1,
GreaterThan(5));
363 EXPECT_EQ(
"whose element #1 doesn't match, which is 4 less than 5",
367TEST(ElementsAreTest, MatchesOneElementVector) {
368 vector<string> test_vector;
369 test_vector.push_back(
"test string");
371 EXPECT_THAT(test_vector, ElementsAre(StrEq(
"test string")));
374TEST(ElementsAreTest, MatchesOneElementList) {
378 EXPECT_THAT(test_list, ElementsAre(
"test string"));
381TEST(ElementsAreTest, MatchesThreeElementVector) {
382 vector<string> test_vector;
383 test_vector.push_back(
"one");
384 test_vector.push_back(
"two");
385 test_vector.push_back(
"three");
387 EXPECT_THAT(test_vector, ElementsAre(
"one", StrEq(
"two"), _));
390TEST(ElementsAreTest, MatchesOneElementEqMatcher) {
391 vector<int> test_vector;
392 test_vector.push_back(4);
397TEST(ElementsAreTest, MatchesOneElementAnyMatcher) {
398 vector<int> test_vector;
399 test_vector.push_back(4);
404TEST(ElementsAreTest, MatchesOneElementValue) {
405 vector<int> test_vector;
406 test_vector.push_back(4);
411TEST(ElementsAreTest, MatchesThreeElementsMixedMatchers) {
412 vector<int> test_vector;
413 test_vector.push_back(1);
414 test_vector.push_back(2);
415 test_vector.push_back(3);
417 EXPECT_THAT(test_vector, ElementsAre(1, Eq(2), _));
420TEST(ElementsAreTest, MatchesTenElementVector) {
421 const int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
427 ElementsAre(0, Ge(0), _, 3, 4, Ne(2), Eq(6), 7, 8, _));
430TEST(ElementsAreTest, DoesNotMatchWrongSize) {
431 vector<string> test_vector;
432 test_vector.push_back(
"test string");
433 test_vector.push_back(
"test string");
435 Matcher<vector<string> > m = ElementsAre(StrEq(
"test string"));
439TEST(ElementsAreTest, DoesNotMatchWrongValue) {
440 vector<string> test_vector;
441 test_vector.push_back(
"other string");
443 Matcher<vector<string> > m = ElementsAre(StrEq(
"test string"));
447TEST(ElementsAreTest, DoesNotMatchWrongOrder) {
448 vector<string> test_vector;
449 test_vector.push_back(
"one");
450 test_vector.push_back(
"three");
451 test_vector.push_back(
"two");
453 Matcher<vector<string> > m = ElementsAre(
454 StrEq(
"one"), StrEq(
"two"), StrEq(
"three"));
458TEST(ElementsAreTest, WorksForNestedContainer) {
459 const char* strings[] = {
464 vector<list<char> > nested;
466 nested.push_back(list<char>(strings[i], strings[i] + strlen(strings[i])));
469 EXPECT_THAT(nested, ElementsAre(ElementsAre(
'H', Ne(
'e')),
470 ElementsAre(
'w',
'o', _, _,
'd')));
471 EXPECT_THAT(nested, Not(ElementsAre(ElementsAre(
'H',
'e'),
472 ElementsAre(
'w',
'o', _, _,
'd'))));
475TEST(ElementsAreTest, WorksWithByRefElementMatchers) {
476 int a[] = { 0, 1, 2 };
479 EXPECT_THAT(v, ElementsAre(Ref(v[0]), Ref(v[1]), Ref(v[2])));
480 EXPECT_THAT(v, Not(ElementsAre(Ref(v[0]), Ref(v[1]), Ref(
a[2]))));
483TEST(ElementsAreTest, WorksWithContainerPointerUsingPointee) {
484 int a[] = { 0, 1, 2 };
488 EXPECT_THAT(&v, Not(Pointee(ElementsAre(0, _, 3))));
491TEST(ElementsAreTest, WorksWithNativeArrayPassedByReference) {
492 int array[] = { 0, 1, 2 };
498class NativeArrayPassedAsPointerAndSize {
500 NativeArrayPassedAsPointerAndSize() {}
508TEST(ElementsAreTest, WorksWithNativeArrayPassedAsPointerAndSize) {
509 int array[] = { 0, 1 };
510 ::testing::tuple<int*, size_t> array_as_tuple(array, 2);
514 NativeArrayPassedAsPointerAndSize helper;
516 .With(ElementsAre(0, 1));
517 helper.Helper(array, 2);
520TEST(ElementsAreTest, WorksWithTwoDimensionalNativeArray) {
521 const char a2[][3] = {
"hi",
"lo" };
522 EXPECT_THAT(a2, ElementsAre(ElementsAre(
'h',
'i',
'\0'),
523 ElementsAre(
'l',
'o',
'\0')));
524 EXPECT_THAT(a2, ElementsAre(StrEq(
"hi"), StrEq(
"lo")));
525 EXPECT_THAT(a2, ElementsAre(Not(ElementsAre(
'h',
'o',
'\0')),
526 ElementsAre(
'l',
'o',
'\0')));
529TEST(ElementsAreTest, AcceptsStringLiteral) {
530 string array[] = {
"hi",
"one",
"two" };
531 EXPECT_THAT(array, ElementsAre(
"hi",
"one",
"two"));
532 EXPECT_THAT(array, Not(ElementsAre(
"hi",
"one",
"too")));
543extern const char kHi[];
545TEST(ElementsAreTest, AcceptsArrayWithUnknownSize) {
549 string array1[] = {
"hi" };
552 string array2[] = {
"ho" };
556const char kHi[] =
"hi";
560TEST(ElementsAreTest, MakesCopyOfArguments) {
565 polymorphic_matcher = ElementsAre(x, y);
568 const int array1[] = { 1, 2 };
570 const int array2[] = { 0, 0 };
579TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) {
580 const int a[] = { 1, 2, 3 };
589TEST(ElementsAreArrayTest, CanBeCreatedWithArraySize) {
590 const char*
a[] = {
"one",
"two",
"three" };
596 test_vector[0] =
"1";
600TEST(ElementsAreArrayTest, CanBeCreatedWithoutArraySize) {
601 const char*
a[] = {
"one",
"two",
"three" };
606 test_vector[0] =
"1";
610TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherArray) {
611 const Matcher<string> kMatcherArray[] =
612 { StrEq(
"one"), StrEq(
"two"), StrEq(
"three") };
614 vector<string> test_vector;
615 test_vector.push_back(
"one");
616 test_vector.push_back(
"two");
617 test_vector.push_back(
"three");
618 EXPECT_THAT(test_vector, ElementsAreArray(kMatcherArray));
620 test_vector.push_back(
"three");
621 EXPECT_THAT(test_vector, Not(ElementsAreArray(kMatcherArray)));
624TEST(ElementsAreArrayTest, CanBeCreatedWithVector) {
625 const int a[] = { 1, 2, 3 };
628 EXPECT_THAT(test_vector, ElementsAreArray(expected));
629 test_vector.push_back(4);
630 EXPECT_THAT(test_vector, Not(ElementsAreArray(expected)));
633#if GTEST_HAS_STD_INITIALIZER_LIST_
635TEST(ElementsAreArrayTest, TakesInitializerList) {
636 const int a[5] = { 1, 2, 3, 4, 5 };
638 EXPECT_THAT(
a, Not(ElementsAreArray({ 1, 2, 3, 5, 4 })));
639 EXPECT_THAT(
a, Not(ElementsAreArray({ 1, 2, 3, 4, 6 })));
642TEST(ElementsAreArrayTest, TakesInitializerListOfCStrings) {
643 const string a[5] = {
"a",
"b",
"c",
"d",
"e" };
644 EXPECT_THAT(
a, ElementsAreArray({
"a",
"b",
"c",
"d",
"e" }));
645 EXPECT_THAT(
a, Not(ElementsAreArray({
"a",
"b",
"c",
"e",
"d" })));
646 EXPECT_THAT(
a, Not(ElementsAreArray({
"a",
"b",
"c",
"d",
"ef" })));
649TEST(ElementsAreArrayTest, TakesInitializerListOfSameTypedMatchers) {
650 const int a[5] = { 1, 2, 3, 4, 5 };
652 { Eq(1), Eq(2), Eq(3), Eq(4), Eq(5) }));
654 { Eq(1), Eq(2), Eq(3), Eq(4), Eq(6) })));
657TEST(ElementsAreArrayTest,
658 TakesInitializerListOfDifferentTypedMatchers) {
659 const int a[5] = { 1, 2, 3, 4, 5 };
664 { Eq(1), Ne(-2), Ge(3), Le(4), Eq(5) }));
666 { Eq(1), Ne(-2), Ge(3), Le(4), Eq(6) })));
671TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherVector) {
672 const int a[] = { 1, 2, 3 };
673 const Matcher<int> kMatchers[] = { Eq(1), Eq(2), Eq(3) };
675 const vector<Matcher<int> > expected(
677 EXPECT_THAT(test_vector, ElementsAreArray(expected));
678 test_vector.push_back(4);
679 EXPECT_THAT(test_vector, Not(ElementsAreArray(expected)));
682TEST(ElementsAreArrayTest, CanBeCreatedWithIteratorRange) {
683 const int a[] = { 1, 2, 3 };
686 EXPECT_THAT(test_vector, ElementsAreArray(expected.begin(), expected.end()));
690 int*
const null_int = NULL;
691 EXPECT_THAT(test_vector, Not(ElementsAreArray(null_int, null_int)));
692 EXPECT_THAT((vector<int>()), ElementsAreArray(null_int, null_int));
697TEST(ElementsAreArrayTest, WorksWithNativeArray) {
698 ::std::string
a[] = {
"hi",
"ho" };
699 ::std::string
b[] = {
"hi",
"ho" };
706TEST(ElementsAreArrayTest, SourceLifeSpan) {
707 const int a[] = { 1, 2, 3 };
710 ElementsAreArrayMatcher<int> matcher_maker =
715 typedef vector<int>::iterator
Iter;
716 for (Iter it =
expect.begin(); it !=
expect.end(); ++it) { *it += 10; }
718 test_vector.push_back(3);
726MATCHER(IsEven,
"") {
return (arg % 2) == 0; }
728TEST(MatcherMacroTest, Works) {
729 const Matcher<int> m = IsEven();
740MATCHER(IsEven2, negation ?
"is odd" :
"is even") {
741 if ((arg % 2) == 0) {
744 *result_listener <<
"OK";
747 *result_listener <<
"% 2 == " << (arg % 2);
755 string(negation ?
"doesn't equal" :
"equals") +
" the sum of " +
756 PrintToString(x) +
" and " + PrintToString(y)) {
757 if (arg == (x + y)) {
758 *result_listener <<
"OK";
763 if (result_listener->stream() != NULL) {
764 *result_listener->stream() <<
"diff == " << (x + y - arg);
772TEST(MatcherMacroTest, DescriptionCanReferenceNegationAndParameters) {
773 const Matcher<int> m1 = IsEven2();
777 const Matcher<int> m2 = EqSumOf(5, 9);
783TEST(MatcherMacroTest, CanExplainMatchResult) {
784 const Matcher<int> m1 = IsEven2();
788 const Matcher<int> m2 = EqSumOf(1, 2);
797 StaticAssertTypeEq< ::std::string, arg_type>();
801MATCHER(IsEmptyStringByRef,
"") {
802 StaticAssertTypeEq<const ::std::string&, arg_type>();
806TEST(MatcherMacroTest, CanReferenceArgType) {
807 const Matcher< ::std::string> m1 = IsEmptyString();
810 const Matcher<const ::std::string&> m2 = IsEmptyStringByRef();
817MATCHER(IsOdd,
"") {
return (arg % 2) != 0; }
820TEST(MatcherMacroTest, WorksInNamespace) {
821 Matcher<int> m = matcher_test::IsOdd();
828 return Value(arg, matcher_test::IsOdd()) && arg > 0;
831TEST(MatcherMacroTest, CanBeComposedUsingValue) {
839MATCHER_P(IsGreaterThan32And, n,
"") {
return arg > 32 && arg > n; }
841TEST(MatcherPMacroTest, Works) {
842 const Matcher<int> m = IsGreaterThan32And(5);
853MATCHER_P(_is_Greater_Than32and_, n,
"") {
return arg > 32 && arg > n; }
855TEST(MatcherPMacroTest, GeneratesCorrectDescription) {
856 const Matcher<int> m = _is_Greater_Than32and_(5);
869 explicit UncopyableFoo(
char value) : value_(
value) {}
871 UncopyableFoo(
const UncopyableFoo&);
872 void operator=(
const UncopyableFoo&);
877MATCHER_P(ReferencesUncopyable, variable,
"") {
return &arg == &variable; }
879TEST(MatcherPMacroTest, WorksWhenExplicitlyInstantiatedWithReference) {
880 UncopyableFoo foo1(
'1'), foo2(
'2');
881 const Matcher<const UncopyableFoo&> m =
882 ReferencesUncopyable<const UncopyableFoo&>(foo1);
899 StaticAssertTypeEq<int, foo_type>();
900 StaticAssertTypeEq<long, bar_type>();
901 StaticAssertTypeEq<char, baz_type>();
905TEST(MatcherPnMacroTest, CanReferenceParamTypes) {
906 EXPECT_THAT(0, ParamTypesAreIntLongAndChar(10, 20L,
'a'));
912MATCHER_P2(ReferencesAnyOf, variable1, variable2,
"") {
913 return &arg == &variable1 || &arg == &variable2;
916TEST(MatcherPnMacroTest, WorksWhenExplicitlyInstantiatedWithReferences) {
917 UncopyableFoo foo1(
'1'), foo2(
'2'), foo3(
'3');
918 const Matcher<const UncopyableFoo&> m =
919 ReferencesAnyOf<const UncopyableFoo&, const UncopyableFoo&>(foo1, foo2);
926TEST(MatcherPnMacroTest,
927 GeneratesCorretDescriptionWhenExplicitlyInstantiatedWithReferences) {
928 UncopyableFoo foo1(
'1'), foo2(
'2');
929 const Matcher<const UncopyableFoo&> m =
930 ReferencesAnyOf<const UncopyableFoo&, const UncopyableFoo&>(foo1, foo2);
936 EXPECT_EQ(
"references any of (1-byte object <31>, 1-byte object <32>)",
942MATCHER_P2(IsNotInClosedRange, low, hi,
"") {
return arg < low || arg > hi; }
944TEST(MatcherPnMacroTest, Works) {
945 const Matcher<const long&> m = IsNotInClosedRange(10, 20);
958MATCHER(EqualsSumOf,
"") {
return arg == 0; }
965 return arg ==
a +
b +
c +
d +
e + f;
968 return arg ==
a +
b +
c +
d +
e + f + g;
971 return arg ==
a +
b +
c +
d +
e + f + g +
h;
973MATCHER_P9(EqualsSumOf,
a,
b, c,
d, e, f, g,
h, i,
"") {
974 return arg ==
a +
b +
c +
d +
e + f + g +
h +
i;
976MATCHER_P10(EqualsSumOf,
a,
b, c,
d, e, f, g,
h, i, j,
"") {
977 return arg ==
a +
b +
c +
d +
e + f + g +
h +
i + j;
980TEST(MatcherPnMacroTest, CanBeOverloadedOnNumberOfParameters) {
986 EXPECT_THAT(12345, EqualsSumOf(10000, 2000, 300, 40, 5));
988 EqualsSumOf(::std::string(
"a"),
'b',
'c',
"d",
"e",
'f'));
990 EqualsSumOf(::std::string(
"a"),
'b',
'c',
"d",
"e",
'f',
'g'));
992 EqualsSumOf(::std::string(
"a"),
'b',
'c',
"d",
"e",
'f',
'g',
995 EqualsSumOf(::std::string(
"a"),
'b',
'c',
"d",
"e",
'f',
'g',
998 EqualsSumOf(::std::string(
"a"),
'b',
'c',
"d",
"e",
'f',
'g',
999 "h",
'i', ::std::string(
"j")));
1005 EXPECT_THAT(-1234, Not(EqualsSumOf(1000, 200, 30, 4)));
1006 EXPECT_THAT(-12345, Not(EqualsSumOf(10000, 2000, 300, 40, 5)));
1008 Not(EqualsSumOf(::std::string(
"a"),
'b',
'c',
"d",
"e",
'f')));
1010 Not(EqualsSumOf(::std::string(
"a"),
'b',
'c',
"d",
"e",
'f',
1013 Not(EqualsSumOf(::std::string(
"a"),
'b',
'c',
"d",
"e",
'f',
'g',
1016 Not(EqualsSumOf(::std::string(
"a"),
'b',
'c',
"d",
"e",
'f',
'g',
1019 Not(EqualsSumOf(::std::string(
"a"),
'b',
'c',
"d",
"e",
'f',
'g',
1020 "h",
'i', ::std::string(
"j"))));
1025TEST(MatcherPnMacroTest, WorksForDifferentParameterTypes) {
1026 EXPECT_THAT(123, EqualsSumOf(100L, 20,
static_cast<char>(3)));
1027 EXPECT_THAT(
"abcd", EqualsSumOf(::std::string(
"a"),
"b",
'c',
"d"));
1029 EXPECT_THAT(124, Not(EqualsSumOf(100L, 20,
static_cast<char>(3))));
1030 EXPECT_THAT(
"abcde", Not(EqualsSumOf(::std::string(
"a"),
"b",
'c',
"d")));
1037 std::string prefix_str(prefix);
1038 char suffix_char =
static_cast<char>(suffix);
1039 return arg == prefix_str + suffix_char;
1042TEST(MatcherPnMacroTest, SimpleTypePromotion) {
1043 Matcher<std::string> no_promo =
1044 EqConcat(std::string(
"foo"),
't');
1045 Matcher<const std::string&> promo =
1046 EqConcat(
"foo",
static_cast<int>(
't'));
1055TEST(MatcherPnMacroTest, TypesAreCorrect) {
1057 EqualsSumOfMatcher a0 = EqualsSumOf();
1060 EqualsSumOfMatcherP<int> a1 = EqualsSumOf(1);
1064 EqualsSumOfMatcherP2<int, char> a2 = EqualsSumOf(1,
'2');
1065 EqualsSumOfMatcherP3<int, int, char> a3 = EqualsSumOf(1, 2,
'3');
1066 EqualsSumOfMatcherP4<int, int, int, char> a4 = EqualsSumOf(1, 2, 3,
'4');
1067 EqualsSumOfMatcherP5<int, int, int, int, char> a5 =
1068 EqualsSumOf(1, 2, 3, 4,
'5');
1069 EqualsSumOfMatcherP6<int, int, int, int, int, char> a6 =
1070 EqualsSumOf(1, 2, 3, 4, 5,
'6');
1071 EqualsSumOfMatcherP7<int, int, int, int, int, int, char> a7 =
1072 EqualsSumOf(1, 2, 3, 4, 5, 6,
'7');
1073 EqualsSumOfMatcherP8<int, int, int, int, int, int, int, char> a8 =
1074 EqualsSumOf(1, 2, 3, 4, 5, 6, 7,
'8');
1075 EqualsSumOfMatcherP9<int, int, int, int, int, int, int, int, char> a9 =
1076 EqualsSumOf(1, 2, 3, 4, 5, 6, 7, 8,
'9');
1077 EqualsSumOfMatcherP10<int, int, int, int, int, int, int, int, int, char> a10 =
1078 EqualsSumOf(1, 2, 3, 4, 5, 6, 7, 8, 9,
'0');
1099 const int count =
static_cast<int>(
Value(arg, m1))
1100 +
static_cast<int>(
Value(arg, m2)) +
static_cast<int>(
Value(arg, m3));
1104TEST(MatcherPnMacroTest, CanUseMatcherTypedParameterInValue) {
1111TEST(ContainsTest, ListMatchesWhenElementIsInContainer) {
1112 list<int> some_list;
1113 some_list.push_back(3);
1114 some_list.push_back(1);
1115 some_list.push_back(2);
1120 list<string> another_list;
1121 another_list.push_back(
"fee");
1122 another_list.push_back(
"fie");
1123 another_list.push_back(
"foe");
1124 another_list.push_back(
"fum");
1125 EXPECT_THAT(another_list, Contains(
string(
"fee")));
1128TEST(ContainsTest, ListDoesNotMatchWhenElementIsNotInContainer) {
1129 list<int> some_list;
1130 some_list.push_back(3);
1131 some_list.push_back(1);
1135TEST(ContainsTest, SetMatchesWhenElementIsInContainer) {
1144 set<const char*> another_set;
1145 another_set.insert(
"fee");
1146 another_set.insert(
"fie");
1147 another_set.insert(
"foe");
1148 another_set.insert(
"fum");
1149 EXPECT_THAT(another_set, Contains(Eq(
string(
"fum"))));
1152TEST(ContainsTest, SetDoesNotMatchWhenElementIsNotInContainer) {
1158 set<const char*> c_string_set;
1159 c_string_set.insert(
"hello");
1160 EXPECT_THAT(c_string_set, Not(Contains(
string(
"hello").c_str())));
1163TEST(ContainsTest, ExplainsMatchResultCorrectly) {
1164 const int a[2] = { 1, 2 };
1165 Matcher<
const int (&)[2]> m = Contains(2);
1178TEST(ContainsTest, DescribesItselfCorrectly) {
1179 Matcher<vector<int> > m = Contains(1);
1182 Matcher<vector<int> > m2 = Not(m);
1186TEST(ContainsTest, MapMatchesWhenElementIsInContainer) {
1187 map<const char*, int> my_map;
1188 const char*
bar =
"a string";
1190 EXPECT_THAT(my_map, Contains(pair<const char* const, int>(
bar, 2)));
1192 map<string, int> another_map;
1193 another_map[
"fee"] = 1;
1194 another_map[
"fie"] = 2;
1195 another_map[
"foe"] = 3;
1196 another_map[
"fum"] = 4;
1197 EXPECT_THAT(another_map, Contains(pair<const string, int>(
string(
"fee"), 1)));
1198 EXPECT_THAT(another_map, Contains(pair<const string, int>(
"fie", 2)));
1201TEST(ContainsTest, MapDoesNotMatchWhenElementIsNotInContainer) {
1202 map<int, int> some_map;
1205 EXPECT_THAT(some_map, Not(Contains(pair<const int, int>(2, 23))));
1208TEST(ContainsTest, ArrayMatchesWhenElementIsInContainer) {
1209 const char* string_array[] = {
"fee",
"fie",
"foe",
"fum" };
1210 EXPECT_THAT(string_array, Contains(Eq(
string(
"fum"))));
1213TEST(ContainsTest, ArrayDoesNotMatchWhenElementIsNotInContainer) {
1214 int int_array[] = { 1, 2, 3, 4 };
1218TEST(ContainsTest, AcceptsMatcher) {
1219 const int a[] = { 1, 2, 3 };
1224TEST(ContainsTest, WorksForNativeArrayAsTuple) {
1225 const int a[] = { 1, 2 };
1231TEST(ContainsTest, WorksForTwoDimensionalNativeArray) {
1232 int a[][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
1239TEST(AllOfTest, HugeMatcher) {
1242 EXPECT_THAT(0,
testing::AllOf(_, _, _, _, _, _, _, _, _,
1246TEST(AnyOfTest, HugeMatcher) {
1249 EXPECT_THAT(0,
testing::AnyOf(_, _, _, _, _, _, _, _, _,
1264template <
typename T1,
typename T2>
1265bool AllOf(
const T1&
t1,
const T2&
t2) {
return true; }
1267TEST(AllOfTest, DoesNotCallAllOfUnqualified) {
1269 M(),
M(),
M(),
M(),
M(),
M(),
M(),
M(),
M(),
M()));
1272template <
typename T1,
typename T2>
bool
1273AnyOf(
const T1&
t1,
const T2&
t2) {
return true; }
1275TEST(AnyOfTest, DoesNotCallAnyOfUnqualified) {
1277 M(),
M(),
M(),
M(),
M(),
M(),
M(),
M(),
M(),
M()));
1283# pragma warning(pop)
cryptonote::block b
Definition block.cpp:40
static uint64_t h
Definition blockchain_stats.cpp:55
Definition gmock-matchers.h:80
Definition gmock-matchers.h:143
Definition gmock-matchers.h:319
Definition gmock-matchers.h:3525
Definition gmock-matchers.h:3477
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition document.h:2116
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1922
#define EXPECT_TRUE(condition)
Definition gtest.h:1859
#define TEST(test_case_name, test_name)
Definition gtest.h:2187
#define EXPECT_FALSE(condition)
Definition gtest.h:1862
#define GTEST_ARRAY_SIZE_(array)
Definition gtest-port.h:1092
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition gtest-port.h:874
#define MOCK_METHOD2(m,...)
Definition gmock-generated-function-mockers.h:677
#define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)
Definition gmock-generated-matchers.h:1814
#define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)
Definition gmock-generated-matchers.h:1987
#define MATCHER_P5(name, p0, p1, p2, p3, p4, description)
Definition gmock-generated-matchers.h:1666
#define MATCHER_P3(name, p0, p1, p2, description)
Definition gmock-generated-matchers.h:1537
#define MATCHER_P4(name, p0, p1, p2, p3, description)
Definition gmock-generated-matchers.h:1597
#define MATCHER_P2(name, p0, p1, description)
Definition gmock-generated-matchers.h:1480
#define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)
Definition gmock-generated-matchers.h:2080
#define MATCHER_P(name, p0, description)
Definition gmock-generated-matchers.h:1428
#define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)
Definition gmock-generated-matchers.h:1739
#define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)
Definition gmock-generated-matchers.h:1898
#define MATCHER(name, description)
<< DiffStrings(str, arg);
Definition gmock-generated-matchers.h:1381
#define EXPECT_THAT(value, matcher)
Definition gmock-matchers.h:4390
#define EXPECT_CALL(obj, call)
Definition gmock-spec-builders.h:1845
int * count
Definition gmock_stress_test.cc:176
Definition gmock-generated-matchers_test.cc:1253
Definition gtest_output_test_.cc:549
t
Definition console.py:33
Definition gtest-printers_test.cc:126
Iter(n, format, sep='')
Definition gen_gtest_pred_impl.py:189
diff
Definition gen_wide_data.py:42
test_list
Definition gtest_output_test.py:248
Definition gmock-generated-matchers_test.cc:816
c
Definition pymoduletest.py:79
int i
Definition pymoduletest.py:23
e
Definition pymoduletest.py:79
int
Definition pymoduletest.py:17
p
Definition pymoduletest.py:75
string Describe(const Matcher< T > &m)
Definition gmock-matchers_test.cc:202
Matcher< int > GreaterThan(int n)
Definition gmock-matchers_test.cc:188
string Explain(const MatcherType &m, const Value &x)
Definition gmock-matchers_test.cc:218
string DescribeNegation(const Matcher< T > &m)
Definition gmock-matchers_test.cc:210
::std::string string
Definition gtest-port.h:1097
internal::NotMatcher< InnerMatcher > Not(InnerMatcher m)
Definition gmock-matchers.h:4107
internal::Le2Matcher Le()
Definition gmock-matchers.h:4094
internal::Ne2Matcher Ne()
Definition gmock-matchers.h:4102
internal::Lt2Matcher Lt()
Definition gmock-matchers.h:4098
internal::Gt2Matcher Gt()
Definition gmock-matchers.h:4090
const internal::AnythingMatcher _
Definition gmock-matchers.h:3729
internal::AllOfResult2< M1, M2 >::type AllOf(M1 m1, M2 m2)
Definition gmock-generated-matchers.h:1002
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
Definition gmock-generated-matchers.h:481
bool StaticAssertTypeEq()
Definition gtest.h:2150
internal::ElementsAreArrayMatcher< typename ::std::iterator_traits< Iter >::value_type > ElementsAreArray(Iter first, Iter last)
Definition gmock-matchers.h:3646
internal::ElementsAreMatcher< ::testing::tuple<> > ElementsAre()
Definition gmock-generated-matchers.h:570
internal::Ge2Matcher Ge()
Definition gmock-matchers.h:4086
::std::string PrintToString(const T &value)
Definition gtest-printers.h:980
internal::ContainsMatcher< M > Contains(M matcher)
Definition gmock-matchers.h:4282
internal::Eq2Matcher Eq()
Definition gmock-matchers.h:4082
Matcher< T > MakeMatcher(const MatcherInterface< T > *impl)
Definition gmock-matchers.h:484
internal::AnyOfResult2< M1, M2 >::type AnyOf(M1 m1, M2 m2)
Definition gmock-generated-matchers.h:1085
bool Value(const T &value, M matcher)
Definition gmock-matchers.h:4347
internal::RefMatcher< T & > Ref(T &x)
Definition gmock-matchers.h:3809
internal::PointeeMatcher< InnerMatcher > Pointee(const InnerMatcher &inner_matcher)
Definition gmock-matchers.h:3872
PolymorphicMatcher< internal::StrEqualityMatcher< internal::string > > StrEq(const internal::string &str)
Definition gmock-matchers.h:3955
const GenericPointer< typename T::ValueType > T2 value
Definition pointer.h:1225
const GenericPointer< typename T::ValueType > & pointer
Definition pointer.h:1124
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
const char *const str
Definition portlistingparse.c:23
t2
Definition pow22523.h:103
t1
Definition pow22523.h:58
#define M(w0, w14, w9, w1)
Definition sha512-blocks.c:41