1 // This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
3 // Copyright 2008, Google Inc.
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
16 // * Neither the name of Google Inc. nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 // Google Mock - a framework for writing C++ mock classes.
34 // This file implements some commonly used variadic matchers.
36 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
37 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
42 #include <gmock/gmock-matchers.h>
43 #include <gmock/gmock-printers.h>
48 // Implements ElementsAre() and ElementsAreArray().
49 template <typename Container>
50 class ElementsAreMatcherImpl : public MatcherInterface<Container> {
52 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) RawContainer;
53 typedef typename RawContainer::value_type Element;
55 // Constructs the matcher from a sequence of element values or
57 template <typename InputIter>
58 ElementsAreMatcherImpl(InputIter first, size_t count) {
59 matchers_.reserve(count);
61 for (size_t i = 0; i != count; ++i, ++it) {
62 matchers_.push_back(MatcherCast<const Element&>(*it));
66 // Returns true iff 'container' matches.
67 virtual bool Matches(Container container) const {
68 if (container.size() != count())
71 typename RawContainer::const_iterator container_iter = container.begin();
72 for (size_t i = 0; i != count(); ++container_iter, ++i) {
73 if (!matchers_[i].Matches(*container_iter))
80 // Describes what this matcher does.
81 virtual void DescribeTo(::std::ostream* os) const {
84 } else if (count() == 1) {
85 *os << "has 1 element that ";
86 matchers_[0].DescribeTo(os);
88 *os << "has " << Elements(count()) << " where\n";
89 for (size_t i = 0; i != count(); ++i) {
90 *os << "element " << i << " ";
91 matchers_[i].DescribeTo(os);
92 if (i + 1 < count()) {
99 // Describes what the negation of this matcher does.
100 virtual void DescribeNegationTo(::std::ostream* os) const {
102 *os << "is not empty";
106 *os << "does not have " << Elements(count()) << ", or\n";
107 for (size_t i = 0; i != count(); ++i) {
108 *os << "element " << i << " ";
109 matchers_[i].DescribeNegationTo(os);
110 if (i + 1 < count()) {
116 // Explains why 'container' matches, or doesn't match, this matcher.
117 virtual void ExplainMatchResultTo(Container container,
118 ::std::ostream* os) const {
119 if (Matches(container)) {
120 // We need to explain why *each* element matches (the obvious
121 // ones can be skipped).
123 bool reason_printed = false;
124 typename RawContainer::const_iterator container_iter = container.begin();
125 for (size_t i = 0; i != count(); ++container_iter, ++i) {
126 ::std::stringstream ss;
127 matchers_[i].ExplainMatchResultTo(*container_iter, &ss);
129 const string s = ss.str();
131 if (reason_printed) {
134 *os << "element " << i << " " << s;
135 reason_printed = true;
139 // We need to explain why the container doesn't match.
140 const size_t actual_count = container.size();
141 if (actual_count != count()) {
142 // The element count doesn't match. If the container is
143 // empty, there's no need to explain anything as Google Mock
144 // already prints the empty container. Otherwise we just need
145 // to show how many elements there actually are.
146 if (actual_count != 0) {
147 *os << "has " << Elements(actual_count);
152 // The container has the right size but at least one element
153 // doesn't match expectation. We need to find this element and
154 // explain why it doesn't match.
155 typename RawContainer::const_iterator container_iter = container.begin();
156 for (size_t i = 0; i != count(); ++container_iter, ++i) {
157 if (matchers_[i].Matches(*container_iter)) {
161 *os << "element " << i << " doesn't match";
163 ::std::stringstream ss;
164 matchers_[i].ExplainMatchResultTo(*container_iter, &ss);
165 const string s = ss.str();
167 *os << " (" << s << ")";
175 static Message Elements(size_t count) {
176 return Message() << count << (count == 1 ? " element" : " elements");
179 size_t count() const { return matchers_.size(); }
180 std::vector<Matcher<const Element&> > matchers_;
183 // Implements ElementsAre() of 0-10 arguments.
185 class ElementsAreMatcher0 {
187 ElementsAreMatcher0() {}
189 template <typename Container>
190 operator Matcher<Container>() const {
191 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))
193 typedef typename RawContainer::value_type Element;
195 const Matcher<const Element&>* const matchers = NULL;
196 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 0));
200 template <typename T1>
201 class ElementsAreMatcher1 {
203 explicit ElementsAreMatcher1(const T1& e1) : e1_(e1) {}
205 template <typename Container>
206 operator Matcher<Container>() const {
207 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))
209 typedef typename RawContainer::value_type Element;
211 const Matcher<const Element&> matchers[] = {
212 MatcherCast<const Element&>(e1_),
215 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 1));
222 template <typename T1, typename T2>
223 class ElementsAreMatcher2 {
225 ElementsAreMatcher2(const T1& e1, const T2& e2) : e1_(e1), e2_(e2) {}
227 template <typename Container>
228 operator Matcher<Container>() const {
229 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))
231 typedef typename RawContainer::value_type Element;
233 const Matcher<const Element&> matchers[] = {
234 MatcherCast<const Element&>(e1_),
235 MatcherCast<const Element&>(e2_),
238 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 2));
246 template <typename T1, typename T2, typename T3>
247 class ElementsAreMatcher3 {
249 ElementsAreMatcher3(const T1& e1, const T2& e2, const T3& e3) : e1_(e1),
252 template <typename Container>
253 operator Matcher<Container>() const {
254 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))
256 typedef typename RawContainer::value_type Element;
258 const Matcher<const Element&> matchers[] = {
259 MatcherCast<const Element&>(e1_),
260 MatcherCast<const Element&>(e2_),
261 MatcherCast<const Element&>(e3_),
264 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 3));
273 template <typename T1, typename T2, typename T3, typename T4>
274 class ElementsAreMatcher4 {
276 ElementsAreMatcher4(const T1& e1, const T2& e2, const T3& e3,
277 const T4& e4) : e1_(e1), e2_(e2), e3_(e3), e4_(e4) {}
279 template <typename Container>
280 operator Matcher<Container>() const {
281 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))
283 typedef typename RawContainer::value_type Element;
285 const Matcher<const Element&> matchers[] = {
286 MatcherCast<const Element&>(e1_),
287 MatcherCast<const Element&>(e2_),
288 MatcherCast<const Element&>(e3_),
289 MatcherCast<const Element&>(e4_),
292 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 4));
302 template <typename T1, typename T2, typename T3, typename T4, typename T5>
303 class ElementsAreMatcher5 {
305 ElementsAreMatcher5(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
306 const T5& e5) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5) {}
308 template <typename Container>
309 operator Matcher<Container>() const {
310 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))
312 typedef typename RawContainer::value_type Element;
314 const Matcher<const Element&> matchers[] = {
315 MatcherCast<const Element&>(e1_),
316 MatcherCast<const Element&>(e2_),
317 MatcherCast<const Element&>(e3_),
318 MatcherCast<const Element&>(e4_),
319 MatcherCast<const Element&>(e5_),
322 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 5));
333 template <typename T1, typename T2, typename T3, typename T4, typename T5,
335 class ElementsAreMatcher6 {
337 ElementsAreMatcher6(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
338 const T5& e5, const T6& e6) : e1_(e1), e2_(e2), e3_(e3), e4_(e4),
341 template <typename Container>
342 operator Matcher<Container>() const {
343 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))
345 typedef typename RawContainer::value_type Element;
347 const Matcher<const Element&> matchers[] = {
348 MatcherCast<const Element&>(e1_),
349 MatcherCast<const Element&>(e2_),
350 MatcherCast<const Element&>(e3_),
351 MatcherCast<const Element&>(e4_),
352 MatcherCast<const Element&>(e5_),
353 MatcherCast<const Element&>(e6_),
356 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 6));
368 template <typename T1, typename T2, typename T3, typename T4, typename T5,
369 typename T6, typename T7>
370 class ElementsAreMatcher7 {
372 ElementsAreMatcher7(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
373 const T5& e5, const T6& e6, const T7& e7) : e1_(e1), e2_(e2), e3_(e3),
374 e4_(e4), e5_(e5), e6_(e6), e7_(e7) {}
376 template <typename Container>
377 operator Matcher<Container>() const {
378 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))
380 typedef typename RawContainer::value_type Element;
382 const Matcher<const Element&> matchers[] = {
383 MatcherCast<const Element&>(e1_),
384 MatcherCast<const Element&>(e2_),
385 MatcherCast<const Element&>(e3_),
386 MatcherCast<const Element&>(e4_),
387 MatcherCast<const Element&>(e5_),
388 MatcherCast<const Element&>(e6_),
389 MatcherCast<const Element&>(e7_),
392 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 7));
405 template <typename T1, typename T2, typename T3, typename T4, typename T5,
406 typename T6, typename T7, typename T8>
407 class ElementsAreMatcher8 {
409 ElementsAreMatcher8(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
410 const T5& e5, const T6& e6, const T7& e7, const T8& e8) : e1_(e1),
411 e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6), e7_(e7), e8_(e8) {}
413 template <typename Container>
414 operator Matcher<Container>() const {
415 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))
417 typedef typename RawContainer::value_type Element;
419 const Matcher<const Element&> matchers[] = {
420 MatcherCast<const Element&>(e1_),
421 MatcherCast<const Element&>(e2_),
422 MatcherCast<const Element&>(e3_),
423 MatcherCast<const Element&>(e4_),
424 MatcherCast<const Element&>(e5_),
425 MatcherCast<const Element&>(e6_),
426 MatcherCast<const Element&>(e7_),
427 MatcherCast<const Element&>(e8_),
430 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 8));
444 template <typename T1, typename T2, typename T3, typename T4, typename T5,
445 typename T6, typename T7, typename T8, typename T9>
446 class ElementsAreMatcher9 {
448 ElementsAreMatcher9(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
449 const T5& e5, const T6& e6, const T7& e7, const T8& e8,
450 const T9& e9) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6),
451 e7_(e7), e8_(e8), e9_(e9) {}
453 template <typename Container>
454 operator Matcher<Container>() const {
455 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))
457 typedef typename RawContainer::value_type Element;
459 const Matcher<const Element&> matchers[] = {
460 MatcherCast<const Element&>(e1_),
461 MatcherCast<const Element&>(e2_),
462 MatcherCast<const Element&>(e3_),
463 MatcherCast<const Element&>(e4_),
464 MatcherCast<const Element&>(e5_),
465 MatcherCast<const Element&>(e6_),
466 MatcherCast<const Element&>(e7_),
467 MatcherCast<const Element&>(e8_),
468 MatcherCast<const Element&>(e9_),
471 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 9));
486 template <typename T1, typename T2, typename T3, typename T4, typename T5,
487 typename T6, typename T7, typename T8, typename T9, typename T10>
488 class ElementsAreMatcher10 {
490 ElementsAreMatcher10(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
491 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
492 const T10& e10) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6),
493 e7_(e7), e8_(e8), e9_(e9), e10_(e10) {}
495 template <typename Container>
496 operator Matcher<Container>() const {
497 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))
499 typedef typename RawContainer::value_type Element;
501 const Matcher<const Element&> matchers[] = {
502 MatcherCast<const Element&>(e1_),
503 MatcherCast<const Element&>(e2_),
504 MatcherCast<const Element&>(e3_),
505 MatcherCast<const Element&>(e4_),
506 MatcherCast<const Element&>(e5_),
507 MatcherCast<const Element&>(e6_),
508 MatcherCast<const Element&>(e7_),
509 MatcherCast<const Element&>(e8_),
510 MatcherCast<const Element&>(e9_),
511 MatcherCast<const Element&>(e10_),
514 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 10));
530 // Implements ElementsAreArray().
531 template <typename T>
532 class ElementsAreArrayMatcher {
534 ElementsAreArrayMatcher(const T* first, size_t count) :
535 first_(first), count_(count) {}
537 template <typename Container>
538 operator Matcher<Container>() const {
539 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))
541 typedef typename RawContainer::value_type Element;
543 return MakeMatcher(new ElementsAreMatcherImpl<Container>(first_, count_));
547 const T* const first_;
551 } // namespace internal
553 // ElementsAre(e0, e1, ..., e_n) matches an STL-style container with
554 // (n + 1) elements, where the i-th element in the container must
555 // match the i-th argument in the list. Each argument of
556 // ElementsAre() can be either a value or a matcher. We support up to
559 // NOTE: Since ElementsAre() cares about the order of the elements, it
560 // must not be used with containers whose elements's order is
561 // undefined (e.g. hash_map).
563 inline internal::ElementsAreMatcher0 ElementsAre() {
564 return internal::ElementsAreMatcher0();
567 template <typename T1>
568 inline internal::ElementsAreMatcher1<T1> ElementsAre(const T1& e1) {
569 return internal::ElementsAreMatcher1<T1>(e1);
572 template <typename T1, typename T2>
573 inline internal::ElementsAreMatcher2<T1, T2> ElementsAre(const T1& e1,
575 return internal::ElementsAreMatcher2<T1, T2>(e1, e2);
578 template <typename T1, typename T2, typename T3>
579 inline internal::ElementsAreMatcher3<T1, T2, T3> ElementsAre(const T1& e1,
580 const T2& e2, const T3& e3) {
581 return internal::ElementsAreMatcher3<T1, T2, T3>(e1, e2, e3);
584 template <typename T1, typename T2, typename T3, typename T4>
585 inline internal::ElementsAreMatcher4<T1, T2, T3, T4> ElementsAre(const T1& e1,
586 const T2& e2, const T3& e3, const T4& e4) {
587 return internal::ElementsAreMatcher4<T1, T2, T3, T4>(e1, e2, e3, e4);
590 template <typename T1, typename T2, typename T3, typename T4, typename T5>
591 inline internal::ElementsAreMatcher5<T1, T2, T3, T4,
592 T5> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
594 return internal::ElementsAreMatcher5<T1, T2, T3, T4, T5>(e1, e2, e3, e4, e5);
597 template <typename T1, typename T2, typename T3, typename T4, typename T5,
599 inline internal::ElementsAreMatcher6<T1, T2, T3, T4, T5,
600 T6> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
601 const T5& e5, const T6& e6) {
602 return internal::ElementsAreMatcher6<T1, T2, T3, T4, T5, T6>(e1, e2, e3, e4,
606 template <typename T1, typename T2, typename T3, typename T4, typename T5,
607 typename T6, typename T7>
608 inline internal::ElementsAreMatcher7<T1, T2, T3, T4, T5, T6,
609 T7> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
610 const T5& e5, const T6& e6, const T7& e7) {
611 return internal::ElementsAreMatcher7<T1, T2, T3, T4, T5, T6, T7>(e1, e2, e3,
615 template <typename T1, typename T2, typename T3, typename T4, typename T5,
616 typename T6, typename T7, typename T8>
617 inline internal::ElementsAreMatcher8<T1, T2, T3, T4, T5, T6, T7,
618 T8> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
619 const T5& e5, const T6& e6, const T7& e7, const T8& e8) {
620 return internal::ElementsAreMatcher8<T1, T2, T3, T4, T5, T6, T7, T8>(e1, e2,
621 e3, e4, e5, e6, e7, e8);
624 template <typename T1, typename T2, typename T3, typename T4, typename T5,
625 typename T6, typename T7, typename T8, typename T9>
626 inline internal::ElementsAreMatcher9<T1, T2, T3, T4, T5, T6, T7, T8,
627 T9> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
628 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) {
629 return internal::ElementsAreMatcher9<T1, T2, T3, T4, T5, T6, T7, T8, T9>(e1,
630 e2, e3, e4, e5, e6, e7, e8, e9);
633 template <typename T1, typename T2, typename T3, typename T4, typename T5,
634 typename T6, typename T7, typename T8, typename T9, typename T10>
635 inline internal::ElementsAreMatcher10<T1, T2, T3, T4, T5, T6, T7, T8, T9,
636 T10> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
637 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
639 return internal::ElementsAreMatcher10<T1, T2, T3, T4, T5, T6, T7, T8, T9,
640 T10>(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10);
643 // ElementsAreArray(array) and ElementAreArray(array, count) are like
644 // ElementsAre(), except that they take an array of values or
645 // matchers. The former form infers the size of 'array', which must
646 // be a static C-style array. In the latter form, 'array' can either
647 // be a static array or a pointer to a dynamically created array.
649 template <typename T>
650 inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
651 const T* first, size_t count) {
652 return internal::ElementsAreArrayMatcher<T>(first, count);
655 template <typename T, size_t N>
656 inline internal::ElementsAreArrayMatcher<T>
657 ElementsAreArray(const T (&array)[N]) {
658 return internal::ElementsAreArrayMatcher<T>(array, N);
661 } // namespace testing
663 // The MATCHER* family of macros can be used in a namespace scope to
664 // define custom matchers easily. The syntax:
666 // MATCHER(name, description_string) { statements; }
668 // will define a matcher with the given name that executes the
669 // statements, which must return a bool to indicate if the match
670 // succeeds. Inside the statements, you can refer to the value being
671 // matched by 'arg', and refer to its type by 'arg_type'.
673 // The description string documents what the matcher does, and is used
674 // to generate the failure message when the match fails. Since a
675 // MATCHER() is usually defined in a header file shared by multiple
676 // C++ source files, we require the description to be a C-string
677 // literal to avoid possible side effects. It can be empty, in which
678 // case we'll use the sequence of words in the matcher name as the
683 // MATCHER(IsEven, "") { return (arg % 2) == 0; }
685 // allows you to write
687 // // Expects mock_foo.Bar(n) to be called where n is even.
688 // EXPECT_CALL(mock_foo, Bar(IsEven()));
692 // // Verifies that the value of some_expression is even.
693 // EXPECT_THAT(some_expression, IsEven());
695 // If the above assertion fails, it will print something like:
697 // Value of: some_expression
701 // where the description "is even" is automatically calculated from the
702 // matcher name IsEven.
704 // Note that the type of the value being matched (arg_type) is
705 // determined by the context in which you use the matcher and is
706 // supplied to you by the compiler, so you don't need to worry about
707 // declaring it (nor can you). This allows the matcher to be
708 // polymorphic. For example, IsEven() can be used to match any type
709 // where the value of "(arg % 2) == 0" can be implicitly converted to
710 // a bool. In the "Bar(IsEven())" example above, if method Bar()
711 // takes an int, 'arg_type' will be int; if it takes an unsigned long,
712 // 'arg_type' will be unsigned long; and so on.
714 // Sometimes you'll want to parameterize the matcher. For that you
715 // can use another macro:
717 // MATCHER_P(name, param_name, description_string) { statements; }
721 // MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; }
723 // will allow you to write:
725 // EXPECT_THAT(Blah("a"), HasAbsoluteValue(n));
727 // which may lead to this message (assuming n is 10):
729 // Value of: Blah("a")
730 // Expected: has absolute value 10
733 // Note that both the matcher description and its parameter are
734 // printed, making the message human-friendly.
736 // In the matcher definition body, you can write 'foo_type' to
737 // reference the type of a parameter named 'foo'. For example, in the
738 // body of MATCHER_P(HasAbsoluteValue, value) above, you can write
739 // 'value_type' to refer to the type of 'value'.
741 // We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to
742 // support multi-parameter matchers.
744 // When defining a parameterized matcher, you can use Python-style
745 // interpolations in the description string to refer to the parameter
746 // values. We support the following syntax currently:
748 // %% a single '%' character
749 // %(*)s all parameters of the matcher printed as a tuple
750 // %(foo)s value of the matcher parameter named 'foo'
754 // MATCHER_P2(InClosedRange, low, hi, "is in range [%(low)s, %(hi)s]") {
755 // return low <= arg && arg <= hi;
758 // EXPECT_THAT(3, InClosedRange(4, 6));
760 // would generate a failure that contains the message:
762 // Expected: is in range [4, 6]
764 // If you specify "" as the description, the failure message will
765 // contain the sequence of words in the matcher name followed by the
766 // parameter values printed as a tuple. For example,
768 // MATCHER_P2(InClosedRange, low, hi, "") { ... }
770 // EXPECT_THAT(3, InClosedRange(4, 6));
772 // would generate a failure that contains the text:
774 // Expected: in closed range (4, 6)
776 // For the purpose of typing, you can view
778 // MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... }
782 // template <typename p1_type, ..., typename pk_type>
783 // FooMatcherPk<p1_type, ..., pk_type>
784 // Foo(p1_type p1, ..., pk_type pk) { ... }
786 // When you write Foo(v1, ..., vk), the compiler infers the types of
787 // the parameters v1, ..., and vk for you. If you are not happy with
788 // the result of the type inference, you can specify the types by
789 // explicitly instantiating the template, as in Foo<long, bool>(5,
790 // false). As said earlier, you don't get to (or need to) specify
791 // 'arg_type' as that's determined by the context in which the matcher
792 // is used. You can assign the result of expression Foo(p1, ..., pk)
793 // to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This
794 // can be useful when composing matchers.
796 // While you can instantiate a matcher template with reference types,
797 // passing the parameters by pointer usually makes your code more
798 // readable. If, however, you still want to pass a parameter by
799 // reference, be aware that in the failure message generated by the
800 // matcher you will see the value of the referenced object but not its
803 // You can overload matchers with different numbers of parameters:
805 // MATCHER_P(Blah, a, description_string1) { ... }
806 // MATCHER_P2(Blah, a, b, description_string2) { ... }
808 // While it's tempting to always use the MATCHER* macros when defining
809 // a new matcher, you should also consider implementing
810 // MatcherInterface or using MakePolymorphicMatcher() instead,
811 // especially if you need to use the matcher a lot. While these
812 // approaches require more work, they give you more control on the
813 // types of the value being matched and the matcher parameters, which
814 // in general leads to better compiler error messages that pay off in
815 // the long run. They also allow overloading matchers based on
816 // parameter types (as opposed to just based on the number of
821 // MATCHER*() can only be used in a namespace scope. The reason is
822 // that C++ doesn't yet allow function-local types to be used to
823 // instantiate templates. The up-coming C++0x standard will fix this.
824 // Once that's done, we'll consider supporting using MATCHER*() inside
829 // To learn more about using these macros, please search for 'MATCHER'
830 // on http://code.google.com/p/googlemock/wiki/CookBook.
835 // Constants denoting interpolations in a matcher description string.
836 const int kTupleInterpolation = -1; // "%(*)s"
837 const int kPercentInterpolation = -2; // "%%"
838 const int kInvalidInterpolation = -3; // "%" followed by invalid text
840 // Records the location and content of an interpolation.
841 struct Interpolation {
842 Interpolation(const char* start, const char* end, int param)
843 : start_pos(start), end_pos(end), param_index(param) {}
845 // Points to the start of the interpolation (the '%' character).
846 const char* start_pos;
847 // Points to the first character after the interpolation.
849 // 0-based index of the interpolated matcher parameter;
850 // kTupleInterpolation for "%(*)s"; kPercentInterpolation for "%%".
854 typedef ::std::vector<Interpolation> Interpolations;
856 // Parses a matcher description string and returns a vector of
857 // interpolations that appear in the string; generates non-fatal
858 // failures iff 'description' is an invalid matcher description.
859 // 'param_names' is a NULL-terminated array of parameter names in the
860 // order they appear in the MATCHER_P*() parameter list.
861 Interpolations ValidateMatcherDescription(
862 const char* param_names[], const char* description);
864 // Returns the actual matcher description, given the matcher name,
865 // user-supplied description template string, interpolations in the
866 // string, and the printed values of the matcher parameters.
867 string FormatMatcherDescription(
868 const char* matcher_name, const char* description,
869 const Interpolations& interp, const Strings& param_values);
871 } // namespace internal
872 } // namespace testing
874 #define MATCHER(name, description)\
875 class name##Matcher {\
877 template <typename arg_type>\
878 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
880 gmock_Impl(const ::testing::internal::Interpolations& gmock_interp)\
881 : gmock_interp_(gmock_interp) {}\
882 virtual bool Matches(arg_type arg) const;\
883 virtual void DescribeTo(::std::ostream* gmock_os) const {\
884 const ::testing::internal::Strings& gmock_printed_params = \
885 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
886 ::std::tr1::tuple<>());\
887 *gmock_os << ::testing::internal::FormatMatcherDescription(\
888 #name, description, gmock_interp_, gmock_printed_params);\
890 const ::testing::internal::Interpolations gmock_interp_;\
892 template <typename arg_type>\
893 operator ::testing::Matcher<arg_type>() const {\
894 return ::testing::Matcher<arg_type>(\
895 new gmock_Impl<arg_type>(gmock_interp_));\
898 const char* gmock_param_names[] = { NULL };\
899 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
900 gmock_param_names, ("" description ""));\
902 ::testing::internal::Interpolations gmock_interp_;\
904 inline name##Matcher name() {\
905 return name##Matcher();\
907 template <typename arg_type>\
908 bool name##Matcher::\
909 gmock_Impl<arg_type>::Matches(arg_type arg) const
911 #define MATCHER_P(name, p0, description)\
912 template <typename p0##_type>\
913 class name##MatcherP {\
915 template <typename arg_type>\
916 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
918 explicit gmock_Impl(p0##_type gmock_p0, \
919 const ::testing::internal::Interpolations& gmock_interp)\
920 : p0(gmock_p0), gmock_interp_(gmock_interp) {}\
921 virtual bool Matches(arg_type arg) const;\
922 virtual void DescribeTo(::std::ostream* gmock_os) const {\
923 const ::testing::internal::Strings& gmock_printed_params = \
924 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
925 ::std::tr1::tuple<p0##_type>(p0));\
926 *gmock_os << ::testing::internal::FormatMatcherDescription(\
927 #name, description, gmock_interp_, gmock_printed_params);\
930 const ::testing::internal::Interpolations gmock_interp_;\
932 template <typename arg_type>\
933 operator ::testing::Matcher<arg_type>() const {\
934 return ::testing::Matcher<arg_type>(\
935 new gmock_Impl<arg_type>(p0, gmock_interp_));\
937 name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\
938 const char* gmock_param_names[] = { #p0, NULL };\
939 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
940 gmock_param_names, ("" description ""));\
943 ::testing::internal::Interpolations gmock_interp_;\
945 template <typename p0##_type>\
946 inline name##MatcherP<p0##_type> name(p0##_type p0) {\
947 return name##MatcherP<p0##_type>(p0);\
949 template <typename p0##_type>\
950 template <typename arg_type>\
951 bool name##MatcherP<p0##_type>::\
952 gmock_Impl<arg_type>::Matches(arg_type arg) const
954 #define MATCHER_P2(name, p0, p1, description)\
955 template <typename p0##_type, typename p1##_type>\
956 class name##MatcherP2 {\
958 template <typename arg_type>\
959 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
961 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \
962 const ::testing::internal::Interpolations& gmock_interp)\
963 : p0(gmock_p0), p1(gmock_p1), gmock_interp_(gmock_interp) {}\
964 virtual bool Matches(arg_type arg) const;\
965 virtual void DescribeTo(::std::ostream* gmock_os) const {\
966 const ::testing::internal::Strings& gmock_printed_params = \
967 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
968 ::std::tr1::tuple<p0##_type, p1##_type>(p0, p1));\
969 *gmock_os << ::testing::internal::FormatMatcherDescription(\
970 #name, description, gmock_interp_, gmock_printed_params);\
974 const ::testing::internal::Interpolations gmock_interp_;\
976 template <typename arg_type>\
977 operator ::testing::Matcher<arg_type>() const {\
978 return ::testing::Matcher<arg_type>(\
979 new gmock_Impl<arg_type>(p0, p1, gmock_interp_));\
981 name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
983 const char* gmock_param_names[] = { #p0, #p1, NULL };\
984 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
985 gmock_param_names, ("" description ""));\
989 ::testing::internal::Interpolations gmock_interp_;\
991 template <typename p0##_type, typename p1##_type>\
992 inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \
994 return name##MatcherP2<p0##_type, p1##_type>(p0, p1);\
996 template <typename p0##_type, typename p1##_type>\
997 template <typename arg_type>\
998 bool name##MatcherP2<p0##_type, p1##_type>::\
999 gmock_Impl<arg_type>::Matches(arg_type arg) const
1001 #define MATCHER_P3(name, p0, p1, p2, description)\
1002 template <typename p0##_type, typename p1##_type, typename p2##_type>\
1003 class name##MatcherP3 {\
1005 template <typename arg_type>\
1006 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
1008 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1009 const ::testing::internal::Interpolations& gmock_interp)\
1010 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1011 gmock_interp_(gmock_interp) {}\
1012 virtual bool Matches(arg_type arg) const;\
1013 virtual void DescribeTo(::std::ostream* gmock_os) const {\
1014 const ::testing::internal::Strings& gmock_printed_params = \
1015 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
1016 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, \
1018 *gmock_os << ::testing::internal::FormatMatcherDescription(\
1019 #name, description, gmock_interp_, gmock_printed_params);\
1024 const ::testing::internal::Interpolations gmock_interp_;\
1026 template <typename arg_type>\
1027 operator ::testing::Matcher<arg_type>() const {\
1028 return ::testing::Matcher<arg_type>(\
1029 new gmock_Impl<arg_type>(p0, p1, p2, gmock_interp_));\
1031 name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \
1032 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\
1033 const char* gmock_param_names[] = { #p0, #p1, #p2, NULL };\
1034 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
1035 gmock_param_names, ("" description ""));\
1040 ::testing::internal::Interpolations gmock_interp_;\
1042 template <typename p0##_type, typename p1##_type, typename p2##_type>\
1043 inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
1044 p1##_type p1, p2##_type p2) {\
1045 return name##MatcherP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
1047 template <typename p0##_type, typename p1##_type, typename p2##_type>\
1048 template <typename arg_type>\
1049 bool name##MatcherP3<p0##_type, p1##_type, p2##_type>::\
1050 gmock_Impl<arg_type>::Matches(arg_type arg) const
1052 #define MATCHER_P4(name, p0, p1, p2, p3, description)\
1053 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1054 typename p3##_type>\
1055 class name##MatcherP4 {\
1057 template <typename arg_type>\
1058 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
1060 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1061 p3##_type gmock_p3, \
1062 const ::testing::internal::Interpolations& gmock_interp)\
1063 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
1064 gmock_interp_(gmock_interp) {}\
1065 virtual bool Matches(arg_type arg) const;\
1066 virtual void DescribeTo(::std::ostream* gmock_os) const {\
1067 const ::testing::internal::Strings& gmock_printed_params = \
1068 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
1069 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, \
1070 p3##_type>(p0, p1, p2, p3));\
1071 *gmock_os << ::testing::internal::FormatMatcherDescription(\
1072 #name, description, gmock_interp_, gmock_printed_params);\
1078 const ::testing::internal::Interpolations gmock_interp_;\
1080 template <typename arg_type>\
1081 operator ::testing::Matcher<arg_type>() const {\
1082 return ::testing::Matcher<arg_type>(\
1083 new gmock_Impl<arg_type>(p0, p1, p2, p3, gmock_interp_));\
1085 name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \
1086 p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
1087 p2(gmock_p2), p3(gmock_p3) {\
1088 const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, NULL };\
1089 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
1090 gmock_param_names, ("" description ""));\
1096 ::testing::internal::Interpolations gmock_interp_;\
1098 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1099 typename p3##_type>\
1100 inline name##MatcherP4<p0##_type, p1##_type, p2##_type, \
1101 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
1103 return name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \
1106 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1107 typename p3##_type>\
1108 template <typename arg_type>\
1109 bool name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>::\
1110 gmock_Impl<arg_type>::Matches(arg_type arg) const
1112 #define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\
1113 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1114 typename p3##_type, typename p4##_type>\
1115 class name##MatcherP5 {\
1117 template <typename arg_type>\
1118 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
1120 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1121 p3##_type gmock_p3, p4##_type gmock_p4, \
1122 const ::testing::internal::Interpolations& gmock_interp)\
1123 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
1124 p4(gmock_p4), gmock_interp_(gmock_interp) {}\
1125 virtual bool Matches(arg_type arg) const;\
1126 virtual void DescribeTo(::std::ostream* gmock_os) const {\
1127 const ::testing::internal::Strings& gmock_printed_params = \
1128 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
1129 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
1130 p4##_type>(p0, p1, p2, p3, p4));\
1131 *gmock_os << ::testing::internal::FormatMatcherDescription(\
1132 #name, description, gmock_interp_, gmock_printed_params);\
1139 const ::testing::internal::Interpolations gmock_interp_;\
1141 template <typename arg_type>\
1142 operator ::testing::Matcher<arg_type>() const {\
1143 return ::testing::Matcher<arg_type>(\
1144 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, gmock_interp_));\
1146 name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \
1147 p2##_type gmock_p2, p3##_type gmock_p3, \
1148 p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1149 p3(gmock_p3), p4(gmock_p4) {\
1150 const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, NULL };\
1151 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
1152 gmock_param_names, ("" description ""));\
1159 ::testing::internal::Interpolations gmock_interp_;\
1161 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1162 typename p3##_type, typename p4##_type>\
1163 inline name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
1164 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
1166 return name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
1167 p4##_type>(p0, p1, p2, p3, p4);\
1169 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1170 typename p3##_type, typename p4##_type>\
1171 template <typename arg_type>\
1172 bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type>::\
1173 gmock_Impl<arg_type>::Matches(arg_type arg) const
1175 #define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\
1176 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1177 typename p3##_type, typename p4##_type, typename p5##_type>\
1178 class name##MatcherP6 {\
1180 template <typename arg_type>\
1181 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
1183 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1184 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1185 const ::testing::internal::Interpolations& gmock_interp)\
1186 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
1187 p4(gmock_p4), p5(gmock_p5), gmock_interp_(gmock_interp) {}\
1188 virtual bool Matches(arg_type arg) const;\
1189 virtual void DescribeTo(::std::ostream* gmock_os) const {\
1190 const ::testing::internal::Strings& gmock_printed_params = \
1191 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
1192 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
1193 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5));\
1194 *gmock_os << ::testing::internal::FormatMatcherDescription(\
1195 #name, description, gmock_interp_, gmock_printed_params);\
1203 const ::testing::internal::Interpolations gmock_interp_;\
1205 template <typename arg_type>\
1206 operator ::testing::Matcher<arg_type>() const {\
1207 return ::testing::Matcher<arg_type>(\
1208 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, gmock_interp_));\
1210 name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \
1211 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
1212 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1213 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\
1214 const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, NULL };\
1215 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
1216 gmock_param_names, ("" description ""));\
1224 ::testing::internal::Interpolations gmock_interp_;\
1226 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1227 typename p3##_type, typename p4##_type, typename p5##_type>\
1228 inline name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
1229 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
1230 p3##_type p3, p4##_type p4, p5##_type p5) {\
1231 return name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
1232 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
1234 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1235 typename p3##_type, typename p4##_type, typename p5##_type>\
1236 template <typename arg_type>\
1237 bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
1239 gmock_Impl<arg_type>::Matches(arg_type arg) const
1241 #define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\
1242 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1243 typename p3##_type, typename p4##_type, typename p5##_type, \
1244 typename p6##_type>\
1245 class name##MatcherP7 {\
1247 template <typename arg_type>\
1248 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
1250 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1251 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1252 p6##_type gmock_p6, \
1253 const ::testing::internal::Interpolations& gmock_interp)\
1254 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
1255 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
1256 gmock_interp_(gmock_interp) {}\
1257 virtual bool Matches(arg_type arg) const;\
1258 virtual void DescribeTo(::std::ostream* gmock_os) const {\
1259 const ::testing::internal::Strings& gmock_printed_params = \
1260 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
1261 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
1262 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \
1264 *gmock_os << ::testing::internal::FormatMatcherDescription(\
1265 #name, description, gmock_interp_, gmock_printed_params);\
1274 const ::testing::internal::Interpolations gmock_interp_;\
1276 template <typename arg_type>\
1277 operator ::testing::Matcher<arg_type>() const {\
1278 return ::testing::Matcher<arg_type>(\
1279 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, gmock_interp_));\
1281 name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \
1282 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
1283 p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
1284 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
1286 const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, #p6, \
1288 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
1289 gmock_param_names, ("" description ""));\
1298 ::testing::internal::Interpolations gmock_interp_;\
1300 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1301 typename p3##_type, typename p4##_type, typename p5##_type, \
1302 typename p6##_type>\
1303 inline name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
1304 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
1305 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
1307 return name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
1308 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
1310 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1311 typename p3##_type, typename p4##_type, typename p5##_type, \
1312 typename p6##_type>\
1313 template <typename arg_type>\
1314 bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
1315 p5##_type, p6##_type>::\
1316 gmock_Impl<arg_type>::Matches(arg_type arg) const
1318 #define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\
1319 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1320 typename p3##_type, typename p4##_type, typename p5##_type, \
1321 typename p6##_type, typename p7##_type>\
1322 class name##MatcherP8 {\
1324 template <typename arg_type>\
1325 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
1327 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1328 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1329 p6##_type gmock_p6, p7##_type gmock_p7, \
1330 const ::testing::internal::Interpolations& gmock_interp)\
1331 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
1332 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
1333 gmock_interp_(gmock_interp) {}\
1334 virtual bool Matches(arg_type arg) const;\
1335 virtual void DescribeTo(::std::ostream* gmock_os) const {\
1336 const ::testing::internal::Strings& gmock_printed_params = \
1337 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
1338 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
1339 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \
1340 p3, p4, p5, p6, p7));\
1341 *gmock_os << ::testing::internal::FormatMatcherDescription(\
1342 #name, description, gmock_interp_, gmock_printed_params);\
1352 const ::testing::internal::Interpolations gmock_interp_;\
1354 template <typename arg_type>\
1355 operator ::testing::Matcher<arg_type>() const {\
1356 return ::testing::Matcher<arg_type>(\
1357 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, \
1360 name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \
1361 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
1362 p5##_type gmock_p5, p6##_type gmock_p6, \
1363 p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1364 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
1366 const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, #p6, \
1368 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
1369 gmock_param_names, ("" description ""));\
1379 ::testing::internal::Interpolations gmock_interp_;\
1381 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1382 typename p3##_type, typename p4##_type, typename p5##_type, \
1383 typename p6##_type, typename p7##_type>\
1384 inline name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
1385 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
1386 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
1387 p6##_type p6, p7##_type p7) {\
1388 return name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
1389 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
1392 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1393 typename p3##_type, typename p4##_type, typename p5##_type, \
1394 typename p6##_type, typename p7##_type>\
1395 template <typename arg_type>\
1396 bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
1397 p5##_type, p6##_type, p7##_type>::\
1398 gmock_Impl<arg_type>::Matches(arg_type arg) const
1400 #define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\
1401 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1402 typename p3##_type, typename p4##_type, typename p5##_type, \
1403 typename p6##_type, typename p7##_type, typename p8##_type>\
1404 class name##MatcherP9 {\
1406 template <typename arg_type>\
1407 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
1409 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1410 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1411 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
1412 const ::testing::internal::Interpolations& gmock_interp)\
1413 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
1414 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
1415 p8(gmock_p8), gmock_interp_(gmock_interp) {}\
1416 virtual bool Matches(arg_type arg) const;\
1417 virtual void DescribeTo(::std::ostream* gmock_os) const {\
1418 const ::testing::internal::Strings& gmock_printed_params = \
1419 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
1420 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
1421 p4##_type, p5##_type, p6##_type, p7##_type, \
1422 p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8));\
1423 *gmock_os << ::testing::internal::FormatMatcherDescription(\
1424 #name, description, gmock_interp_, gmock_printed_params);\
1435 const ::testing::internal::Interpolations gmock_interp_;\
1437 template <typename arg_type>\
1438 operator ::testing::Matcher<arg_type>() const {\
1439 return ::testing::Matcher<arg_type>(\
1440 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, \
1443 name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \
1444 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
1445 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
1446 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1447 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
1449 const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, #p6, \
1451 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
1452 gmock_param_names, ("" description ""));\
1463 ::testing::internal::Interpolations gmock_interp_;\
1465 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1466 typename p3##_type, typename p4##_type, typename p5##_type, \
1467 typename p6##_type, typename p7##_type, typename p8##_type>\
1468 inline name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
1469 p4##_type, p5##_type, p6##_type, p7##_type, \
1470 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
1471 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
1473 return name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
1474 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
1475 p3, p4, p5, p6, p7, p8);\
1477 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1478 typename p3##_type, typename p4##_type, typename p5##_type, \
1479 typename p6##_type, typename p7##_type, typename p8##_type>\
1480 template <typename arg_type>\
1481 bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
1482 p5##_type, p6##_type, p7##_type, p8##_type>::\
1483 gmock_Impl<arg_type>::Matches(arg_type arg) const
1485 #define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)\
1486 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1487 typename p3##_type, typename p4##_type, typename p5##_type, \
1488 typename p6##_type, typename p7##_type, typename p8##_type, \
1489 typename p9##_type>\
1490 class name##MatcherP10 {\
1492 template <typename arg_type>\
1493 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
1495 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1496 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1497 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
1498 p9##_type gmock_p9, \
1499 const ::testing::internal::Interpolations& gmock_interp)\
1500 : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
1501 p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
1502 p8(gmock_p8), p9(gmock_p9), gmock_interp_(gmock_interp) {}\
1503 virtual bool Matches(arg_type arg) const;\
1504 virtual void DescribeTo(::std::ostream* gmock_os) const {\
1505 const ::testing::internal::Strings& gmock_printed_params = \
1506 ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
1507 ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
1508 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
1509 p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\
1510 *gmock_os << ::testing::internal::FormatMatcherDescription(\
1511 #name, description, gmock_interp_, gmock_printed_params);\
1523 const ::testing::internal::Interpolations gmock_interp_;\
1525 template <typename arg_type>\
1526 operator ::testing::Matcher<arg_type>() const {\
1527 return ::testing::Matcher<arg_type>(\
1528 new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, \
1531 name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \
1532 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
1533 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
1534 p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
1535 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
1536 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\
1537 const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, #p6, \
1538 #p7, #p8, #p9, NULL };\
1539 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
1540 gmock_param_names, ("" description ""));\
1552 ::testing::internal::Interpolations gmock_interp_;\
1554 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1555 typename p3##_type, typename p4##_type, typename p5##_type, \
1556 typename p6##_type, typename p7##_type, typename p8##_type, \
1557 typename p9##_type>\
1558 inline name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
1559 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
1560 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
1561 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
1563 return name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
1564 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
1565 p1, p2, p3, p4, p5, p6, p7, p8, p9);\
1567 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1568 typename p3##_type, typename p4##_type, typename p5##_type, \
1569 typename p6##_type, typename p7##_type, typename p8##_type, \
1570 typename p9##_type>\
1571 template <typename arg_type>\
1572 bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
1573 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>::\
1574 gmock_Impl<arg_type>::Matches(arg_type arg) const
1577 namespace internal {
1579 // Returns true iff element is in the STL-style container.
1580 template <typename Container, typename Element>
1581 inline bool Contains(const Container& container, const Element& element) {
1582 return ::std::find(container.begin(), container.end(), element) !=
1586 // Returns true iff element is in the C-style array.
1587 template <typename ArrayElement, size_t N, typename Element>
1588 inline bool Contains(const ArrayElement (&array)[N], const Element& element) {
1589 return ::std::find(array, array + N, element) != array + N;
1592 } // namespace internal
1594 // Matches an STL-style container or a C-style array that contains the given
1598 // ::std::set<int> page_ids;
1599 // page_ids.insert(3);
1600 // page_ids.insert(1);
1601 // EXPECT_THAT(page_ids, Contains(1));
1602 // EXPECT_THAT(page_ids, Contains(3.0));
1603 // EXPECT_THAT(page_ids, Not(Contains(4)));
1605 // ::std::map<int, size_t> page_lengths;
1606 // page_lengths[1] = 100;
1607 // EXPECT_THAT(map_int, Contains(::std::pair<const int, size_t>(1, 100)));
1609 // const char* user_ids[] = { "joe", "mike", "tom" };
1610 // EXPECT_THAT(user_ids, Contains(::std::string("tom")));
1611 MATCHER_P(Contains, element, "") {
1612 return internal::Contains(arg, element);
1615 } // namespace testing
1617 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_