From 964056b457935bd9e3e124ce8d24991826b3a9b2 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Tue, 9 Jun 2009 05:42:12 +0000 Subject: Implements the Args(m) matcher. git-svn-id: http://googlemock.googlecode.com/svn/trunk@169 8415998a-534a-0410-bf83-d39667b30386 --- include/gmock/gmock-generated-matchers.h | 323 ++++++++++++++++++++++++++ include/gmock/gmock-generated-matchers.h.pump | 141 +++++++++++ include/gmock/gmock-matchers.h | 18 +- include/gmock/gmock-spec-builders.h | 4 +- test/gmock-generated-matchers_test.cc | 109 ++++++++- test/gmock-internal-utils_test.cc | 2 +- test/gmock-matchers_test.cc | 21 +- test/gmock_output_test_golden.txt | 8 +- 8 files changed, 597 insertions(+), 29 deletions(-) diff --git a/include/gmock/gmock-generated-matchers.h b/include/gmock/gmock-generated-matchers.h index f3484cb..1a3e60b 100644 --- a/include/gmock/gmock-generated-matchers.h +++ b/include/gmock/gmock-generated-matchers.h @@ -45,6 +45,251 @@ namespace testing { namespace internal { +// The type of the i-th (0-based) field of Tuple. +#define GMOCK_FIELD_TYPE_(Tuple, i) \ + typename ::std::tr1::tuple_element::type + +// TupleFields is for selecting fields from a +// tuple of type Tuple. It has two members: +// +// type: a tuple type whose i-th field is the ki-th field of Tuple. +// GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple. +// +// For example, in class TupleFields, 2, 0>, we have: +// +// type is tuple, and +// GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true). + +template +class TupleFields; + +// This generic version is used when there are 10 selectors. +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t), get(t), get(t), + get(t), get(t), get(t), get(t), get(t)); + } +}; + +// The following specialization is used for 0 ~ 9 selectors. + +template +class TupleFields { + public: + typedef ::std::tr1::tuple<> type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t), get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t), get(t), get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t), get(t), get(t), + get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t), get(t), get(t), + get(t), get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t), get(t), get(t), + get(t), get(t), get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t), get(t), get(t), + get(t), get(t), get(t), get(t)); + } +}; + +#undef GMOCK_FIELD_TYPE_ + +// Implements the Args() matcher. +template +class ArgsMatcherImpl : public MatcherInterface { + public: + // ArgsTuple may have top-level const or reference modifiers. + typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(ArgsTuple)) RawArgsTuple; + typedef typename internal::TupleFields::type SelectedArgs; + typedef Matcher MonomorphicInnerMatcher; + + template + explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher) + : inner_matcher_(SafeMatcherCast(inner_matcher)) {} + + virtual bool Matches(ArgsTuple args) const { + return inner_matcher_.Matches(GetSelectedArgs(args)); + } + + virtual void DescribeTo(::std::ostream* os) const { + PrintIndices(os); + inner_matcher_.DescribeTo(os); + } + + virtual void DescribeNegationTo(::std::ostream* os) const { + PrintIndices(os); + inner_matcher_.DescribeNegationTo(os); + } + + virtual void ExplainMatchResultTo(ArgsTuple args, + ::std::ostream* os) const { + inner_matcher_.ExplainMatchResultTo(GetSelectedArgs(args), os); + } + + private: + static SelectedArgs GetSelectedArgs(ArgsTuple args) { + return TupleFields::GetSelectedFields(args); + } + + // Prints the indices of the selected fields. + static void PrintIndices(::std::ostream* os) { + *os << "are a tuple whose fields ("; + const int indices[10] = { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9 }; + for (int i = 0; i < 10; i++) { + if (indices[i] < 0) + break; + + if (i >= 1) + *os << ", "; + + *os << "#" << indices[i]; + } + *os << ") "; + } + + const MonomorphicInnerMatcher inner_matcher_; +}; + +template +class ArgsMatcher { + public: + explicit ArgsMatcher(const InnerMatcher& inner_matcher) + : inner_matcher_(inner_matcher) {} + + template + operator Matcher() const { + return MakeMatcher(new ArgsMatcherImpl(inner_matcher_)); + } + + const InnerMatcher inner_matcher_; +}; + // Implements ElementsAre() and ElementsAreArray(). template class ElementsAreMatcherImpl : public MatcherInterface { @@ -567,6 +812,84 @@ class ElementsAreArrayMatcher { } // namespace internal +// Args(a_matcher) matches a tuple if the selected +// fields of it matches a_matcher. C++ doesn't support default +// arguments for function templates, so we have to overload it. +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + // ElementsAre(e0, e1, ..., e_n) matches an STL-style container with // (n + 1) elements, where the i-th element in the container must // match the i-th argument in the list. Each argument of diff --git a/include/gmock/gmock-generated-matchers.h.pump b/include/gmock/gmock-generated-matchers.h.pump index 4495547..653a2e8 100644 --- a/include/gmock/gmock-generated-matchers.h.pump +++ b/include/gmock/gmock-generated-matchers.h.pump @@ -3,6 +3,7 @@ $$ This is a Pump source file. Please use Pump to convert it to $$ gmock-generated-variadic-actions.h. $$ $var n = 10 $$ The maximum arity we support. +$$ }} This line fixes auto-indentation of the following code in Emacs. // Copyright 2008, Google Inc. // All rights reserved. // @@ -48,6 +49,130 @@ $var n = 10 $$ The maximum arity we support. namespace testing { namespace internal { +$range i 0..n-1 + +// The type of the i-th (0-based) field of Tuple. +#define GMOCK_FIELD_TYPE_(Tuple, i) \ + typename ::std::tr1::tuple_element::type + +// TupleFields is for selecting fields from a +// tuple of type Tuple. It has two members: +// +// type: a tuple type whose i-th field is the ki-th field of Tuple. +// GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple. +// +// For example, in class TupleFields, 2, 0>, we have: +// +// type is tuple, and +// GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true). + +template +class TupleFields; + +// This generic version is used when there are $n selectors. +template +class TupleFields { + public: + typedef ::std::tr1::tuple<$for i, [[GMOCK_FIELD_TYPE_(Tuple, k$i)]]> type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type($for i, [[get(t)]]); + } +}; + +// The following specialization is used for 0 ~ $(n-1) selectors. + +$for i [[ +$$ }}} +$range j 0..i-1 +$range k 0..n-1 + +template +class TupleFields { + public: + typedef ::std::tr1::tuple<$for j, [[GMOCK_FIELD_TYPE_(Tuple, k$j)]]> type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type($for j, [[get(t)]]); + } +}; + +]] + +#undef GMOCK_FIELD_TYPE_ + +// Implements the Args() matcher. + +$var ks = [[$for i, [[k$i]]]] +template +class ArgsMatcherImpl : public MatcherInterface { + public: + // ArgsTuple may have top-level const or reference modifiers. + typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(ArgsTuple)) RawArgsTuple; + typedef typename internal::TupleFields::type SelectedArgs; + typedef Matcher MonomorphicInnerMatcher; + + template + explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher) + : inner_matcher_(SafeMatcherCast(inner_matcher)) {} + + virtual bool Matches(ArgsTuple args) const { + return inner_matcher_.Matches(GetSelectedArgs(args)); + } + + virtual void DescribeTo(::std::ostream* os) const { + PrintIndices(os); + inner_matcher_.DescribeTo(os); + } + + virtual void DescribeNegationTo(::std::ostream* os) const { + PrintIndices(os); + inner_matcher_.DescribeNegationTo(os); + } + + virtual void ExplainMatchResultTo(ArgsTuple args, + ::std::ostream* os) const { + inner_matcher_.ExplainMatchResultTo(GetSelectedArgs(args), os); + } + + private: + static SelectedArgs GetSelectedArgs(ArgsTuple args) { + return TupleFields::GetSelectedFields(args); + } + + // Prints the indices of the selected fields. + static void PrintIndices(::std::ostream* os) { + *os << "are a tuple whose fields ("; + const int indices[$n] = { $ks }; + for (int i = 0; i < $n; i++) { + if (indices[i] < 0) + break; + + if (i >= 1) + *os << ", "; + + *os << "#" << indices[i]; + } + *os << ") "; + } + + const MonomorphicInnerMatcher inner_matcher_; +}; + +template +class ArgsMatcher { + public: + explicit ArgsMatcher(const InnerMatcher& inner_matcher) + : inner_matcher_(inner_matcher) {} + + template + operator Matcher() const { + return MakeMatcher(new ArgsMatcherImpl(inner_matcher_)); + } + + const InnerMatcher inner_matcher_; +}; + // Implements ElementsAre() and ElementsAreArray(). template class ElementsAreMatcherImpl : public MatcherInterface { @@ -268,6 +393,21 @@ class ElementsAreArrayMatcher { } // namespace internal +// Args(a_matcher) matches a tuple if the selected +// fields of it matches a_matcher. C++ doesn't support default +// arguments for function templates, so we have to overload it. + +$range i 0..n +$for i [[ +$range j 1..i +template <$for j [[int k$j, ]]typename InnerMatcher> +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + + +]] // ElementsAre(e0, e1, ..., e_n) matches an STL-style container with // (n + 1) elements, where the i-th element in the container must // match the i-th argument in the list. Each argument of @@ -282,6 +422,7 @@ inline internal::ElementsAreMatcher0 ElementsAre() { return internal::ElementsAreMatcher0(); } +$range i 1..n $for i [[ $range j 1..i diff --git a/include/gmock/gmock-matchers.h b/include/gmock/gmock-matchers.h index ce7a2fe..f4d5b0a 100644 --- a/include/gmock/gmock-matchers.h +++ b/include/gmock/gmock-matchers.h @@ -938,7 +938,7 @@ class MatchesRegexMatcher { // // We define this as a macro in order to eliminate duplicated source // code. -#define GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(name, op, relation) \ +#define GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(name, op) \ class name##2Matcher { \ public: \ template \ @@ -953,21 +953,21 @@ class MatchesRegexMatcher { return ::std::tr1::get<0>(args) op ::std::tr1::get<1>(args); \ } \ virtual void DescribeTo(::std::ostream* os) const { \ - *os << "argument #0 is " relation " argument #1"; \ + *os << "are a pair (x, y) where x " #op " y"; \ } \ virtual void DescribeNegationTo(::std::ostream* os) const { \ - *os << "argument #0 is not " relation " argument #1"; \ + *os << "are a pair (x, y) where x " #op " y is false"; \ } \ }; \ } // Implements Eq(), Ge(), Gt(), Le(), Lt(), and Ne() respectively. -GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Eq, ==, "equal to"); -GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Ge, >=, "greater than or equal to"); -GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Gt, >, "greater than"); -GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Le, <=, "less than or equal to"); -GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Lt, <, "less than"); -GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Ne, !=, "not equal to"); +GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Eq, ==); +GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Ge, >=); +GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Gt, >); +GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Le, <=); +GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Lt, <); +GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Ne, !=); #undef GMOCK_IMPLEMENT_COMPARISON2_MATCHER_ diff --git a/include/gmock/gmock-spec-builders.h b/include/gmock/gmock-spec-builders.h index d4578ac..c002ae7 100644 --- a/include/gmock/gmock-spec-builders.h +++ b/include/gmock/gmock-spec-builders.h @@ -795,9 +795,9 @@ class Expectation : public ExpectationBase { DescribeMatchFailureTupleTo(matchers_, args, os); } if (!extra_matcher_.Matches(args)) { - *os << " Expected: "; + *os << " Expected args: "; extra_matcher_.DescribeTo(os); - *os << "\n Actual: false"; + *os << "\n Actual: don't match"; internal::ExplainMatchResultAsNeededTo( extra_matcher_, args, os); diff --git a/test/gmock-generated-matchers_test.cc b/test/gmock-generated-matchers_test.cc index 2681446..7e71698 100644 --- a/test/gmock-generated-matchers_test.cc +++ b/test/gmock-generated-matchers_test.cc @@ -53,8 +53,11 @@ using std::pair; using std::set; using std::stringstream; using std::vector; +using std::tr1::get; using std::tr1::make_tuple; +using std::tr1::tuple; using testing::_; +using testing::Args; using testing::Contains; using testing::ElementsAre; using testing::ElementsAreArray; @@ -98,6 +101,107 @@ string Explain(const MatcherType& m, const Value& x) { return ss.str(); } +// Tests Args(m). + +TEST(ArgsTest, AcceptsZeroTemplateArg) { + const tuple t(5, true); + EXPECT_THAT(t, Args<>(Eq(tuple<>()))); + EXPECT_THAT(t, Not(Args<>(Ne(tuple<>())))); +} + +TEST(ArgsTest, AcceptsOneTemplateArg) { + const tuple t(5, true); + EXPECT_THAT(t, Args<0>(Eq(make_tuple(5)))); + EXPECT_THAT(t, Args<1>(Eq(make_tuple(true)))); + EXPECT_THAT(t, Not(Args<1>(Eq(make_tuple(false))))); +} + +TEST(ArgsTest, AcceptsTwoTemplateArgs) { + const tuple t(4, 5, 6L); // NOLINT + + EXPECT_THAT(t, (Args<0, 1>(Lt()))); + EXPECT_THAT(t, (Args<1, 2>(Lt()))); + EXPECT_THAT(t, Not(Args<0, 2>(Gt()))); +} + +TEST(ArgsTest, AcceptsRepeatedTemplateArgs) { + const tuple t(4, 5, 6L); // NOLINT + EXPECT_THAT(t, (Args<0, 0>(Eq()))); + EXPECT_THAT(t, Not(Args<1, 1>(Ne()))); +} + +TEST(ArgsTest, AcceptsDecreasingTemplateArgs) { + const tuple t(4, 5, 6L); // NOLINT + EXPECT_THAT(t, (Args<2, 0>(Gt()))); + EXPECT_THAT(t, Not(Args<2, 1>(Lt()))); +} + +MATCHER(SumIsZero, "") { + return get<0>(arg) + get<1>(arg) + get<2>(arg) == 0; +} + +TEST(ArgsTest, AcceptsMoreTemplateArgsThanArityOfOriginalTuple) { + EXPECT_THAT(make_tuple(-1, 2), (Args<0, 0, 1>(SumIsZero()))); + EXPECT_THAT(make_tuple(1, 2), Not(Args<0, 0, 1>(SumIsZero()))); +} + +TEST(ArgsTest, CanBeNested) { + const tuple t(4, 5, 6L, 6); // NOLINT + EXPECT_THAT(t, (Args<1, 2, 3>(Args<1, 2>(Eq())))); + EXPECT_THAT(t, (Args<0, 1, 3>(Args<0, 2>(Lt())))); +} + +TEST(ArgsTest, CanMatchTupleByValue) { + typedef tuple Tuple3; + const Matcher m = Args<1, 2>(Lt()); + EXPECT_TRUE(m.Matches(Tuple3('a', 1, 2))); + EXPECT_FALSE(m.Matches(Tuple3('b', 2, 2))); +} + +TEST(ArgsTest, CanMatchTupleByReference) { + typedef tuple Tuple3; + const Matcher m = Args<0, 1>(Lt()); + EXPECT_TRUE(m.Matches(Tuple3('a', 'b', 2))); + EXPECT_FALSE(m.Matches(Tuple3('b', 'b', 2))); +} + +// Validates that arg is printed as str. +MATCHER_P(PrintsAs, str, "") { + typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(arg_type)) RawTuple; + return + testing::internal::UniversalPrinter::PrintToString(arg) == str; +} + +TEST(ArgsTest, AcceptsTenTemplateArgs) { + EXPECT_THAT(make_tuple(0, 1L, 2, 3L, 4, 5, 6, 7, 8, 9), + (Args<9, 8, 7, 6, 5, 4, 3, 2, 1, 0>( + PrintsAs("(9, 8, 7, 6, 5, 4, 3, 2, 1, 0)")))); + EXPECT_THAT(make_tuple(0, 1L, 2, 3L, 4, 5, 6, 7, 8, 9), + Not(Args<9, 8, 7, 6, 5, 4, 3, 2, 1, 0>( + PrintsAs("(0, 8, 7, 6, 5, 4, 3, 2, 1, 0)")))); +} + +TEST(ArgsTest, DescirbesSelfCorrectly) { + const Matcher > m = Args<2, 0>(Lt()); + EXPECT_EQ("are a tuple whose fields (#2, #0) are a pair (x, y) where x < y", + Describe(m)); +} + +TEST(ArgsTest, DescirbesNestedArgsCorrectly) { + const Matcher&> m = + Args<0, 2, 3>(Args<2, 0>(Lt())); + EXPECT_EQ("are a tuple whose fields (#0, #2, #3) are a tuple " + "whose fields (#2, #0) are a pair (x, y) where x < y", + Describe(m)); +} + +TEST(ArgsTest, DescribesNegationCorrectly) { + const Matcher > m = Args<1, 0>(Gt()); + EXPECT_EQ("are a tuple whose fields (#1, #0) are a pair (x, y) " + "where x > y is false", + DescribeNegation(m)); +} + // For testing ExplainMatchResultTo(). class GreaterThanMatcher : public MatcherInterface { public: @@ -926,8 +1030,9 @@ TEST(ContainsTest, AcceptsMatcher) { TEST(ContainsTest, WorksForNativeArrayAsTuple) { const int a[] = { 1, 2 }; - EXPECT_THAT(make_tuple(a, 2), Contains(1)); - EXPECT_THAT(make_tuple(a, 2), Not(Contains(Gt(3)))); + const int* const pointer = a; + EXPECT_THAT(make_tuple(pointer, 2), Contains(1)); + EXPECT_THAT(make_tuple(pointer, 2), Not(Contains(Gt(3)))); } TEST(ContainsTest, WorksForTwoDimensionalNativeArray) { diff --git a/test/gmock-internal-utils_test.cc b/test/gmock-internal-utils_test.cc index 73960df..912ee35 100644 --- a/test/gmock-internal-utils_test.cc +++ b/test/gmock-internal-utils_test.cc @@ -941,7 +941,7 @@ TEST(StlContainerViewTest, WorksForDynamicNativeArray) { EXPECT_EQ(a1, a2.begin()); const NativeArray a3 = StlContainerView >:: - Copy(make_tuple(a1, 3)); + Copy(make_tuple(static_cast(a1), 3)); ASSERT_EQ(3, a3.size()); EXPECT_EQ(0, a3.begin()[0]); EXPECT_EQ(1, a3.begin()[1]); diff --git a/test/gmock-matchers_test.cc b/test/gmock-matchers_test.cc index 1226a1d..4ee6ea8 100644 --- a/test/gmock-matchers_test.cc +++ b/test/gmock-matchers_test.cc @@ -1335,7 +1335,7 @@ TEST(Eq2Test, MatchesEqualArguments) { // Tests that Eq() describes itself properly. TEST(Eq2Test, CanDescribeSelf) { Matcher m = Eq(); - EXPECT_EQ("argument #0 is equal to argument #1", Describe(m)); + EXPECT_EQ("are a pair (x, y) where x == y", Describe(m)); } // Tests that Ge() matches a 2-tuple where the first field >= the @@ -1350,8 +1350,7 @@ TEST(Ge2Test, MatchesGreaterThanOrEqualArguments) { // Tests that Ge() describes itself properly. TEST(Ge2Test, CanDescribeSelf) { Matcher m = Ge(); - EXPECT_EQ("argument #0 is greater than or equal to argument #1", - Describe(m)); + EXPECT_EQ("are a pair (x, y) where x >= y", Describe(m)); } // Tests that Gt() matches a 2-tuple where the first field > the @@ -1366,7 +1365,7 @@ TEST(Gt2Test, MatchesGreaterThanArguments) { // Tests that Gt() describes itself properly. TEST(Gt2Test, CanDescribeSelf) { Matcher m = Gt(); - EXPECT_EQ("argument #0 is greater than argument #1", Describe(m)); + EXPECT_EQ("are a pair (x, y) where x > y", Describe(m)); } // Tests that Le() matches a 2-tuple where the first field <= the @@ -1381,8 +1380,7 @@ TEST(Le2Test, MatchesLessThanOrEqualArguments) { // Tests that Le() describes itself properly. TEST(Le2Test, CanDescribeSelf) { Matcher m = Le(); - EXPECT_EQ("argument #0 is less than or equal to argument #1", - Describe(m)); + EXPECT_EQ("are a pair (x, y) where x <= y", Describe(m)); } // Tests that Lt() matches a 2-tuple where the first field < the @@ -1397,7 +1395,7 @@ TEST(Lt2Test, MatchesLessThanArguments) { // Tests that Lt() describes itself properly. TEST(Lt2Test, CanDescribeSelf) { Matcher m = Lt(); - EXPECT_EQ("argument #0 is less than argument #1", Describe(m)); + EXPECT_EQ("are a pair (x, y) where x < y", Describe(m)); } // Tests that Ne() matches a 2-tuple where the first field != the @@ -1412,7 +1410,7 @@ TEST(Ne2Test, MatchesUnequalArguments) { // Tests that Ne() describes itself properly. TEST(Ne2Test, CanDescribeSelf) { Matcher m = Ne(); - EXPECT_EQ("argument #0 is not equal to argument #1", Describe(m)); + EXPECT_EQ("are a pair (x, y) where x != y", Describe(m)); } // Tests that Not(m) matches any value that doesn't match m. @@ -2948,11 +2946,12 @@ TEST(ContainerEqExtraTest, WorksForNativeArrayAsTuple) { const int a2[] = { 1, 2, 3 }; const int b[] = { 1, 2, 3, 4 }; - EXPECT_THAT(make_tuple(a1, 3), ContainerEq(a2)); - EXPECT_THAT(make_tuple(a1, 3), Not(ContainerEq(b))); + const int* const p1 = a1; + EXPECT_THAT(make_tuple(p1, 3), ContainerEq(a2)); + EXPECT_THAT(make_tuple(p1, 3), Not(ContainerEq(b))); const int c[] = { 1, 3, 2 }; - EXPECT_THAT(make_tuple(a1, 3), Not(ContainerEq(c))); + EXPECT_THAT(make_tuple(p1, 3), Not(ContainerEq(c))); } TEST(ContainerEqExtraTest, CopiesNativeArrayParameter) { diff --git a/test/gmock_output_test_golden.txt b/test/gmock_output_test_golden.txt index 887b7be..b4d2ea0 100644 --- a/test/gmock_output_test_golden.txt +++ b/test/gmock_output_test_golden.txt @@ -183,8 +183,8 @@ Unexpected mock function call - returning default value. Google Mock tried the following 1 expectation, but it didn't match: FILE:#: - Expected: argument #0 is greater than or equal to argument #1 - Actual: false + Expected args: are a pair (x, y) where x >= y + Actual: don't match Expected: to be called once Actual: never called - unsatisfied and active [ FAILED ] GMockOutputTest.MismatchWithArguments @@ -199,8 +199,8 @@ Google Mock tried the following 1 expectation, but it didn't match: FILE:#: Expected arg #0: is greater than or equal to 2 Actual: 1 - Expected: argument #0 is greater than or equal to argument #1 - Actual: false + Expected args: are a pair (x, y) where x >= y + Actual: don't match Expected: to be called once Actual: never called - unsatisfied and active [ FAILED ] GMockOutputTest.MismatchArgumentsAndWithArguments -- cgit v1.2.1