blob: f8cbf49e9bf820a66d815253402b2c9398fe335f [file] [log] [blame]
shiqiane35fdd92008-12-10 05:08:54 +00001// This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
2
3// Copyright 2008, Google Inc.
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are
8// met:
9//
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
15// distribution.
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.
19//
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.
31
32// Google Mock - a framework for writing C++ mock classes.
33//
34// This file implements some commonly used variadic matchers.
35
36#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
37#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
38
39#include <sstream>
40#include <string>
41#include <vector>
42#include <gmock/gmock-matchers.h>
43
44namespace testing {
45namespace internal {
46
zhanyong.wance198ff2009-02-12 01:34:27 +000047// Generates a non-fatal failure iff 'description' is not a valid
48// matcher description.
49inline void ValidateMatcherDescription(const char* description) {
50 EXPECT_STREQ("", description)
51 << "The description string in a MATCHER*() macro must be \"\" "
52 "at this moment. We will implement custom description string soon.";
53}
54
shiqiane35fdd92008-12-10 05:08:54 +000055// Implements ElementsAre() and ElementsAreArray().
56template <typename Container>
57class ElementsAreMatcherImpl : public MatcherInterface<Container> {
58 public:
59 typedef GMOCK_REMOVE_CONST(GMOCK_REMOVE_REFERENCE(Container)) RawContainer;
60 typedef typename RawContainer::value_type Element;
61
62 // Constructs the matcher from a sequence of element values or
63 // element matchers.
64 template <typename InputIter>
65 ElementsAreMatcherImpl(InputIter first, size_t count) {
66 matchers_.reserve(count);
67 InputIter it = first;
68 for (size_t i = 0; i != count; ++i, ++it) {
69 matchers_.push_back(MatcherCast<const Element&>(*it));
70 }
71 }
72
73 // Returns true iff 'container' matches.
74 virtual bool Matches(Container container) const {
75 if (container.size() != count())
76 return false;
77
78 typename RawContainer::const_iterator container_iter = container.begin();
79 for (size_t i = 0; i != count(); ++container_iter, ++i) {
80 if (!matchers_[i].Matches(*container_iter))
81 return false;
82 }
83
84 return true;
85 }
86
87 // Describes what this matcher does.
88 virtual void DescribeTo(::std::ostream* os) const {
89 if (count() == 0) {
90 *os << "is empty";
91 } else if (count() == 1) {
92 *os << "has 1 element that ";
93 matchers_[0].DescribeTo(os);
94 } else {
95 *os << "has " << Elements(count()) << " where\n";
96 for (size_t i = 0; i != count(); ++i) {
97 *os << "element " << i << " ";
98 matchers_[i].DescribeTo(os);
99 if (i + 1 < count()) {
100 *os << ",\n";
101 }
102 }
103 }
104 }
105
106 // Describes what the negation of this matcher does.
107 virtual void DescribeNegationTo(::std::ostream* os) const {
108 if (count() == 0) {
109 *os << "is not empty";
110 return;
111 }
112
113 *os << "does not have " << Elements(count()) << ", or\n";
114 for (size_t i = 0; i != count(); ++i) {
115 *os << "element " << i << " ";
116 matchers_[i].DescribeNegationTo(os);
117 if (i + 1 < count()) {
118 *os << ", or\n";
119 }
120 }
121 }
122
123 // Explains why 'container' matches, or doesn't match, this matcher.
124 virtual void ExplainMatchResultTo(Container container,
125 ::std::ostream* os) const {
126 if (Matches(container)) {
127 // We need to explain why *each* element matches (the obvious
128 // ones can be skipped).
129
130 bool reason_printed = false;
131 typename RawContainer::const_iterator container_iter = container.begin();
132 for (size_t i = 0; i != count(); ++container_iter, ++i) {
133 ::std::stringstream ss;
134 matchers_[i].ExplainMatchResultTo(*container_iter, &ss);
135
136 const string s = ss.str();
137 if (!s.empty()) {
138 if (reason_printed) {
139 *os << ",\n";
140 }
141 *os << "element " << i << " " << s;
142 reason_printed = true;
143 }
144 }
145 } else {
146 // We need to explain why the container doesn't match.
147 const size_t actual_count = container.size();
148 if (actual_count != count()) {
149 // The element count doesn't match. If the container is
150 // empty, there's no need to explain anything as Google Mock
151 // already prints the empty container. Otherwise we just need
152 // to show how many elements there actually are.
153 if (actual_count != 0) {
154 *os << "has " << Elements(actual_count);
155 }
156 return;
157 }
158
159 // The container has the right size but at least one element
160 // doesn't match expectation. We need to find this element and
161 // explain why it doesn't match.
162 typename RawContainer::const_iterator container_iter = container.begin();
163 for (size_t i = 0; i != count(); ++container_iter, ++i) {
164 if (matchers_[i].Matches(*container_iter)) {
165 continue;
166 }
167
168 *os << "element " << i << " doesn't match";
169
170 ::std::stringstream ss;
171 matchers_[i].ExplainMatchResultTo(*container_iter, &ss);
172 const string s = ss.str();
173 if (!s.empty()) {
174 *os << " (" << s << ")";
175 }
176 return;
177 }
178 }
179 }
180
181 private:
182 static Message Elements(size_t count) {
183 return Message() << count << (count == 1 ? " element" : " elements");
184 }
185
186 size_t count() const { return matchers_.size(); }
187 std::vector<Matcher<const Element&> > matchers_;
188};
189
190// Implements ElementsAre() of 0-10 arguments.
191
192class ElementsAreMatcher0 {
193 public:
194 ElementsAreMatcher0() {}
195
196 template <typename Container>
197 operator Matcher<Container>() const {
198 typedef GMOCK_REMOVE_CONST(GMOCK_REMOVE_REFERENCE(Container)) RawContainer;
199 typedef typename RawContainer::value_type Element;
200
201 const Matcher<const Element&>* const matchers = NULL;
202 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 0));
203 }
204};
205
206template <typename T1>
207class ElementsAreMatcher1 {
208 public:
209 explicit ElementsAreMatcher1(const T1& e1) : e1_(e1) {}
210
211 template <typename Container>
212 operator Matcher<Container>() const {
213 typedef GMOCK_REMOVE_CONST(GMOCK_REMOVE_REFERENCE(Container)) RawContainer;
214 typedef typename RawContainer::value_type Element;
215
216 const Matcher<const Element&> matchers[] = {
217 MatcherCast<const Element&>(e1_),
218 };
219
220 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 1));
221 }
222
223 private:
224 const T1& e1_;
225};
226
227template <typename T1, typename T2>
228class ElementsAreMatcher2 {
229 public:
230 ElementsAreMatcher2(const T1& e1, const T2& e2) : e1_(e1), e2_(e2) {}
231
232 template <typename Container>
233 operator Matcher<Container>() const {
234 typedef GMOCK_REMOVE_CONST(GMOCK_REMOVE_REFERENCE(Container)) RawContainer;
235 typedef typename RawContainer::value_type Element;
236
237 const Matcher<const Element&> matchers[] = {
238 MatcherCast<const Element&>(e1_),
239 MatcherCast<const Element&>(e2_),
240 };
241
242 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 2));
243 }
244
245 private:
246 const T1& e1_;
247 const T2& e2_;
248};
249
250template <typename T1, typename T2, typename T3>
251class ElementsAreMatcher3 {
252 public:
253 ElementsAreMatcher3(const T1& e1, const T2& e2, const T3& e3) : e1_(e1),
254 e2_(e2), e3_(e3) {}
255
256 template <typename Container>
257 operator Matcher<Container>() const {
258 typedef GMOCK_REMOVE_CONST(GMOCK_REMOVE_REFERENCE(Container)) RawContainer;
259 typedef typename RawContainer::value_type Element;
260
261 const Matcher<const Element&> matchers[] = {
262 MatcherCast<const Element&>(e1_),
263 MatcherCast<const Element&>(e2_),
264 MatcherCast<const Element&>(e3_),
265 };
266
267 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 3));
268 }
269
270 private:
271 const T1& e1_;
272 const T2& e2_;
273 const T3& e3_;
274};
275
276template <typename T1, typename T2, typename T3, typename T4>
277class ElementsAreMatcher4 {
278 public:
279 ElementsAreMatcher4(const T1& e1, const T2& e2, const T3& e3,
280 const T4& e4) : e1_(e1), e2_(e2), e3_(e3), e4_(e4) {}
281
282 template <typename Container>
283 operator Matcher<Container>() const {
284 typedef GMOCK_REMOVE_CONST(GMOCK_REMOVE_REFERENCE(Container)) RawContainer;
285 typedef typename RawContainer::value_type Element;
286
287 const Matcher<const Element&> matchers[] = {
288 MatcherCast<const Element&>(e1_),
289 MatcherCast<const Element&>(e2_),
290 MatcherCast<const Element&>(e3_),
291 MatcherCast<const Element&>(e4_),
292 };
293
294 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 4));
295 }
296
297 private:
298 const T1& e1_;
299 const T2& e2_;
300 const T3& e3_;
301 const T4& e4_;
302};
303
304template <typename T1, typename T2, typename T3, typename T4, typename T5>
305class ElementsAreMatcher5 {
306 public:
307 ElementsAreMatcher5(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
308 const T5& e5) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5) {}
309
310 template <typename Container>
311 operator Matcher<Container>() const {
312 typedef GMOCK_REMOVE_CONST(GMOCK_REMOVE_REFERENCE(Container)) RawContainer;
313 typedef typename RawContainer::value_type Element;
314
315 const Matcher<const Element&> matchers[] = {
316 MatcherCast<const Element&>(e1_),
317 MatcherCast<const Element&>(e2_),
318 MatcherCast<const Element&>(e3_),
319 MatcherCast<const Element&>(e4_),
320 MatcherCast<const Element&>(e5_),
321 };
322
323 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 5));
324 }
325
326 private:
327 const T1& e1_;
328 const T2& e2_;
329 const T3& e3_;
330 const T4& e4_;
331 const T5& e5_;
332};
333
334template <typename T1, typename T2, typename T3, typename T4, typename T5,
335 typename T6>
336class ElementsAreMatcher6 {
337 public:
338 ElementsAreMatcher6(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
339 const T5& e5, const T6& e6) : e1_(e1), e2_(e2), e3_(e3), e4_(e4),
340 e5_(e5), e6_(e6) {}
341
342 template <typename Container>
343 operator Matcher<Container>() const {
344 typedef GMOCK_REMOVE_CONST(GMOCK_REMOVE_REFERENCE(Container)) RawContainer;
345 typedef typename RawContainer::value_type Element;
346
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_),
354 };
355
356 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 6));
357 }
358
359 private:
360 const T1& e1_;
361 const T2& e2_;
362 const T3& e3_;
363 const T4& e4_;
364 const T5& e5_;
365 const T6& e6_;
366};
367
368template <typename T1, typename T2, typename T3, typename T4, typename T5,
369 typename T6, typename T7>
370class ElementsAreMatcher7 {
371 public:
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) {}
375
376 template <typename Container>
377 operator Matcher<Container>() const {
378 typedef GMOCK_REMOVE_CONST(GMOCK_REMOVE_REFERENCE(Container)) RawContainer;
379 typedef typename RawContainer::value_type Element;
380
381 const Matcher<const Element&> matchers[] = {
382 MatcherCast<const Element&>(e1_),
383 MatcherCast<const Element&>(e2_),
384 MatcherCast<const Element&>(e3_),
385 MatcherCast<const Element&>(e4_),
386 MatcherCast<const Element&>(e5_),
387 MatcherCast<const Element&>(e6_),
388 MatcherCast<const Element&>(e7_),
389 };
390
391 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 7));
392 }
393
394 private:
395 const T1& e1_;
396 const T2& e2_;
397 const T3& e3_;
398 const T4& e4_;
399 const T5& e5_;
400 const T6& e6_;
401 const T7& e7_;
402};
403
404template <typename T1, typename T2, typename T3, typename T4, typename T5,
405 typename T6, typename T7, typename T8>
406class ElementsAreMatcher8 {
407 public:
408 ElementsAreMatcher8(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
409 const T5& e5, const T6& e6, const T7& e7, const T8& e8) : e1_(e1),
410 e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6), e7_(e7), e8_(e8) {}
411
412 template <typename Container>
413 operator Matcher<Container>() const {
414 typedef GMOCK_REMOVE_CONST(GMOCK_REMOVE_REFERENCE(Container)) RawContainer;
415 typedef typename RawContainer::value_type Element;
416
417 const Matcher<const Element&> matchers[] = {
418 MatcherCast<const Element&>(e1_),
419 MatcherCast<const Element&>(e2_),
420 MatcherCast<const Element&>(e3_),
421 MatcherCast<const Element&>(e4_),
422 MatcherCast<const Element&>(e5_),
423 MatcherCast<const Element&>(e6_),
424 MatcherCast<const Element&>(e7_),
425 MatcherCast<const Element&>(e8_),
426 };
427
428 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 8));
429 }
430
431 private:
432 const T1& e1_;
433 const T2& e2_;
434 const T3& e3_;
435 const T4& e4_;
436 const T5& e5_;
437 const T6& e6_;
438 const T7& e7_;
439 const T8& e8_;
440};
441
442template <typename T1, typename T2, typename T3, typename T4, typename T5,
443 typename T6, typename T7, typename T8, typename T9>
444class ElementsAreMatcher9 {
445 public:
446 ElementsAreMatcher9(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
447 const T5& e5, const T6& e6, const T7& e7, const T8& e8,
448 const T9& e9) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6),
449 e7_(e7), e8_(e8), e9_(e9) {}
450
451 template <typename Container>
452 operator Matcher<Container>() const {
453 typedef GMOCK_REMOVE_CONST(GMOCK_REMOVE_REFERENCE(Container)) RawContainer;
454 typedef typename RawContainer::value_type Element;
455
456 const Matcher<const Element&> matchers[] = {
457 MatcherCast<const Element&>(e1_),
458 MatcherCast<const Element&>(e2_),
459 MatcherCast<const Element&>(e3_),
460 MatcherCast<const Element&>(e4_),
461 MatcherCast<const Element&>(e5_),
462 MatcherCast<const Element&>(e6_),
463 MatcherCast<const Element&>(e7_),
464 MatcherCast<const Element&>(e8_),
465 MatcherCast<const Element&>(e9_),
466 };
467
468 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 9));
469 }
470
471 private:
472 const T1& e1_;
473 const T2& e2_;
474 const T3& e3_;
475 const T4& e4_;
476 const T5& e5_;
477 const T6& e6_;
478 const T7& e7_;
479 const T8& e8_;
480 const T9& e9_;
481};
482
483template <typename T1, typename T2, typename T3, typename T4, typename T5,
484 typename T6, typename T7, typename T8, typename T9, typename T10>
485class ElementsAreMatcher10 {
486 public:
487 ElementsAreMatcher10(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
488 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
489 const T10& e10) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6),
490 e7_(e7), e8_(e8), e9_(e9), e10_(e10) {}
491
492 template <typename Container>
493 operator Matcher<Container>() const {
494 typedef GMOCK_REMOVE_CONST(GMOCK_REMOVE_REFERENCE(Container)) RawContainer;
495 typedef typename RawContainer::value_type Element;
496
497 const Matcher<const Element&> matchers[] = {
498 MatcherCast<const Element&>(e1_),
499 MatcherCast<const Element&>(e2_),
500 MatcherCast<const Element&>(e3_),
501 MatcherCast<const Element&>(e4_),
502 MatcherCast<const Element&>(e5_),
503 MatcherCast<const Element&>(e6_),
504 MatcherCast<const Element&>(e7_),
505 MatcherCast<const Element&>(e8_),
506 MatcherCast<const Element&>(e9_),
507 MatcherCast<const Element&>(e10_),
508 };
509
510 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 10));
511 }
512
513 private:
514 const T1& e1_;
515 const T2& e2_;
516 const T3& e3_;
517 const T4& e4_;
518 const T5& e5_;
519 const T6& e6_;
520 const T7& e7_;
521 const T8& e8_;
522 const T9& e9_;
523 const T10& e10_;
524};
525
526// Implements ElementsAreArray().
527template <typename T>
528class ElementsAreArrayMatcher {
529 public:
530 ElementsAreArrayMatcher(const T* first, size_t count) :
531 first_(first), count_(count) {}
532
533 template <typename Container>
534 operator Matcher<Container>() const {
535 typedef GMOCK_REMOVE_CONST(GMOCK_REMOVE_REFERENCE(Container)) RawContainer;
536 typedef typename RawContainer::value_type Element;
537
538 return MakeMatcher(new ElementsAreMatcherImpl<Container>(first_, count_));
539 }
540
541 private:
542 const T* const first_;
543 const size_t count_;
544};
545
546} // namespace internal
547
548// ElementsAre(e0, e1, ..., e_n) matches an STL-style container with
549// (n + 1) elements, where the i-th element in the container must
550// match the i-th argument in the list. Each argument of
551// ElementsAre() can be either a value or a matcher. We support up to
552// 10 arguments.
553//
554// NOTE: Since ElementsAre() cares about the order of the elements, it
555// must not be used with containers whose elements's order is
556// undefined (e.g. hash_map).
557
558inline internal::ElementsAreMatcher0 ElementsAre() {
559 return internal::ElementsAreMatcher0();
560}
561
562template <typename T1>
563inline internal::ElementsAreMatcher1<T1> ElementsAre(const T1& e1) {
564 return internal::ElementsAreMatcher1<T1>(e1);
565}
566
567template <typename T1, typename T2>
568inline internal::ElementsAreMatcher2<T1, T2> ElementsAre(const T1& e1,
569 const T2& e2) {
570 return internal::ElementsAreMatcher2<T1, T2>(e1, e2);
571}
572
573template <typename T1, typename T2, typename T3>
574inline internal::ElementsAreMatcher3<T1, T2, T3> ElementsAre(const T1& e1,
575 const T2& e2, const T3& e3) {
576 return internal::ElementsAreMatcher3<T1, T2, T3>(e1, e2, e3);
577}
578
579template <typename T1, typename T2, typename T3, typename T4>
580inline internal::ElementsAreMatcher4<T1, T2, T3, T4> ElementsAre(const T1& e1,
581 const T2& e2, const T3& e3, const T4& e4) {
582 return internal::ElementsAreMatcher4<T1, T2, T3, T4>(e1, e2, e3, e4);
583}
584
585template <typename T1, typename T2, typename T3, typename T4, typename T5>
586inline internal::ElementsAreMatcher5<T1, T2, T3, T4,
587 T5> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
588 const T5& e5) {
589 return internal::ElementsAreMatcher5<T1, T2, T3, T4, T5>(e1, e2, e3, e4, e5);
590}
591
592template <typename T1, typename T2, typename T3, typename T4, typename T5,
593 typename T6>
594inline internal::ElementsAreMatcher6<T1, T2, T3, T4, T5,
595 T6> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
596 const T5& e5, const T6& e6) {
597 return internal::ElementsAreMatcher6<T1, T2, T3, T4, T5, T6>(e1, e2, e3, e4,
598 e5, e6);
599}
600
601template <typename T1, typename T2, typename T3, typename T4, typename T5,
602 typename T6, typename T7>
603inline internal::ElementsAreMatcher7<T1, T2, T3, T4, T5, T6,
604 T7> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
605 const T5& e5, const T6& e6, const T7& e7) {
606 return internal::ElementsAreMatcher7<T1, T2, T3, T4, T5, T6, T7>(e1, e2, e3,
607 e4, e5, e6, e7);
608}
609
610template <typename T1, typename T2, typename T3, typename T4, typename T5,
611 typename T6, typename T7, typename T8>
612inline internal::ElementsAreMatcher8<T1, T2, T3, T4, T5, T6, T7,
613 T8> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
614 const T5& e5, const T6& e6, const T7& e7, const T8& e8) {
615 return internal::ElementsAreMatcher8<T1, T2, T3, T4, T5, T6, T7, T8>(e1, e2,
616 e3, e4, e5, e6, e7, e8);
617}
618
619template <typename T1, typename T2, typename T3, typename T4, typename T5,
620 typename T6, typename T7, typename T8, typename T9>
621inline internal::ElementsAreMatcher9<T1, T2, T3, T4, T5, T6, T7, T8,
622 T9> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
623 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) {
624 return internal::ElementsAreMatcher9<T1, T2, T3, T4, T5, T6, T7, T8, T9>(e1,
625 e2, e3, e4, e5, e6, e7, e8, e9);
626}
627
628template <typename T1, typename T2, typename T3, typename T4, typename T5,
629 typename T6, typename T7, typename T8, typename T9, typename T10>
630inline internal::ElementsAreMatcher10<T1, T2, T3, T4, T5, T6, T7, T8, T9,
631 T10> ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
632 const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
633 const T10& e10) {
634 return internal::ElementsAreMatcher10<T1, T2, T3, T4, T5, T6, T7, T8, T9,
635 T10>(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10);
636}
637
638// ElementsAreArray(array) and ElementAreArray(array, count) are like
639// ElementsAre(), except that they take an array of values or
640// matchers. The former form infers the size of 'array', which must
641// be a static C-style array. In the latter form, 'array' can either
642// be a static array or a pointer to a dynamically created array.
643
644template <typename T>
645inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
646 const T* first, size_t count) {
647 return internal::ElementsAreArrayMatcher<T>(first, count);
648}
649
650template <typename T, size_t N>
651inline internal::ElementsAreArrayMatcher<T>
652ElementsAreArray(const T (&array)[N]) {
653 return internal::ElementsAreArrayMatcher<T>(array, N);
654}
655
656} // namespace testing
657
zhanyong.wance198ff2009-02-12 01:34:27 +0000658// The MATCHER* family of macros can be used in a namespace scope to
659// define custom matchers easily. The syntax:
660//
661// MATCHER(name, description_string) { statements; }
662//
663// will define a matcher with the given name that executes the
664// statements, which must return a bool to indicate if the match
665// succeeds. For now, the description_string must be "", but we'll
666// allow other values soon. Inside the statements, you can refer to
667// the value being matched by 'arg', and refer to its type by
668// 'arg_type'. For example:
669//
670// MATCHER(IsEven, "") { return (arg % 2) == 0; }
671//
672// allows you to write
673//
674// // Expects mock_foo.Bar(n) to be called where n is even.
675// EXPECT_CALL(mock_foo, Bar(IsEven()));
676//
677// or,
678//
679// // Verifies that the value of some_expression is even.
680// EXPECT_THAT(some_expression, IsEven());
681//
682// If the above assertion fails, it will print something like:
683//
684// Value of: some_expression
685// Expected: is even
686// Actual: 7
687//
688// where the description "is even" is automatically calculated from the
689// matcher name IsEven.
690//
691// Note that the type of the value being matched (arg_type) is
692// determined by the context in which you use the matcher and is
693// supplied to you by the compiler, so you don't need to worry about
694// declaring it (nor can you). This allows the matcher to be
695// polymorphic. For example, IsEven() can be used to match any type
696// where the value of "(arg % 2) == 0" can be implicitly converted to
697// a bool. In the "Bar(IsEven())" example above, if method Bar()
698// takes an int, 'arg_type' will be int; if it takes an unsigned long,
699// 'arg_type' will be unsigned long; and so on.
700//
701// Sometimes you'll want to parameterize the matcher. For that you
702// can use another macro:
703//
704// MATCHER_P(name, param_name, description_string) { statements; }
705//
706// For example:
707//
708// MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; }
709//
710// will allow you to write:
711//
712// EXPECT_THAT(Blah("a"), HasAbsoluteValue(n));
713//
714// which may lead to this message (assuming n is 10):
715//
716// Value of: Blah("a")
717// Expected: has absolute value 10
718// Actual: -9
719//
720// Note that both the matcher description and its parameter are
721// printed, making the message human-friendly.
722//
723// In the matcher definition body, you can write 'foo_type' to
724// reference the type of a parameter named 'foo'. For example, in the
725// body of MATCHER_P(HasAbsoluteValue, value) above, you can write
726// 'value_type' to refer to the type of 'value'.
727//
728// We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to
729// support multi-parameter matchers.
730//
731// For the purpose of typing, you can view
732//
733// MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... }
734//
735// as shorthand for
736//
737// template <typename p1_type, ..., typename pk_type>
738// FooMatcherPk<p1_type, ..., pk_type>
739// Foo(p1_type p1, ..., pk_type pk) { ... }
740//
741// When you write Foo(v1, ..., vk), the compiler infers the types of
742// the parameters v1, ..., and vk for you. If you are not happy with
743// the result of the type inference, you can specify the types by
744// explicitly instantiating the template, as in Foo<long, bool>(5,
745// false). As said earlier, you don't get to (or need to) specify
746// 'arg_type' as that's determined by the context in which the matcher
747// is used. You can assign the result of expression Foo(p1, ..., pk)
748// to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This
749// can be useful when composing matchers.
750//
751// While you can instantiate a matcher template with reference types,
752// passing the parameters by pointer usually makes your code more
753// readable. If, however, you still want to pass a parameter by
754// reference, be aware that in the failure message generated by the
755// matcher you will see the value of the referenced object but not its
756// address.
757//
758// You can overload matchers with different numbers of parameters:
759//
760// MATCHER_P(Blah, a, description_string1) { ... }
761// MATCHER_P2(Blah, a, b, description_string2) { ... }
762//
763// While it's tempting to always use the MATCHER* macros when defining
764// a new matcher, you should also consider implementing
765// MatcherInterface or using MakePolymorphicMatcher() instead,
766// especially if you need to use the matcher a lot. While these
767// approaches require more work, they give you more control on the
768// types of the value being matched and the matcher parameters, which
769// in general leads to better compiler error messages that pay off in
770// the long run. They also allow overloading matchers based on
771// parameter types (as opposed to just based on the number of
772// parameters).
773//
774// CAVEAT:
775//
776// MATCHER*() can only be used in a namespace scope. The reason is
777// that C++ doesn't yet allow function-local types to be used to
778// instantiate templates. The up-coming C++0x standard will fix this.
779// Once that's done, we'll consider supporting using MATCHER*() inside
780// a function.
781//
782// MORE INFORMATION:
783//
784// To learn more about using these macros, please search for 'MATCHER'
785// on http://code.google.com/p/googlemock/wiki/CookBook.
786
787#define MATCHER(name, description)\
788 class name##Matcher {\
789 public:\
790 template <typename arg_type>\
791 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
792 public:\
793 gmock_Impl() {}\
794 virtual bool Matches(arg_type arg) const;\
795 virtual void DescribeTo(::std::ostream* os) const {\
796 *os << ::testing::internal::ConvertIdentifierNameToWords(#name);\
797 }\
798 };\
799 template <typename arg_type>\
800 operator ::testing::Matcher<arg_type>() const {\
801 return ::testing::Matcher<arg_type>(new gmock_Impl<arg_type>());\
802 }\
803 name##Matcher() {\
804 ::testing::internal::ValidateMatcherDescription(description);\
805 }\
806 };\
807 inline name##Matcher name() {\
808 return name##Matcher();\
809 }\
810 template <typename arg_type>\
811 bool name##Matcher::\
812 gmock_Impl<arg_type>::Matches(arg_type arg) const
813
814#define MATCHER_P(name, p0, description)\
815 template <typename p0##_type>\
816 class name##MatcherP {\
817 public:\
818 template <typename arg_type>\
819 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
820 public:\
821 explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\
822 virtual bool Matches(arg_type arg) const;\
823 virtual void DescribeTo(::std::ostream* os) const {\
824 *os << ::testing::internal::ConvertIdentifierNameToWords(#name);\
825 *os << " ";\
826 ::testing::internal::UniversalPrint(p0, os);\
827 }\
828 p0##_type p0;\
829 };\
830 template <typename arg_type>\
831 operator ::testing::Matcher<arg_type>() const {\
832 return ::testing::Matcher<arg_type>(new gmock_Impl<arg_type>(p0));\
833 }\
834 name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\
835 ::testing::internal::ValidateMatcherDescription(description);\
836 }\
837 p0##_type p0;\
838 };\
839 template <typename p0##_type>\
840 inline name##MatcherP<p0##_type> name(p0##_type p0) {\
841 return name##MatcherP<p0##_type>(p0);\
842 }\
843 template <typename p0##_type>\
844 template <typename arg_type>\
845 bool name##MatcherP<p0##_type>::\
846 gmock_Impl<arg_type>::Matches(arg_type arg) const
847
848#define MATCHER_P2(name, p0, p1, description)\
849 template <typename p0##_type, typename p1##_type>\
850 class name##MatcherP2 {\
851 public:\
852 template <typename arg_type>\
853 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
854 public:\
855 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
856 p1(gmock_p1) {}\
857 virtual bool Matches(arg_type arg) const;\
858 virtual void DescribeTo(::std::ostream* os) const {\
859 *os << ::testing::internal::ConvertIdentifierNameToWords(#name);\
860 *os << " (";\
861 ::testing::internal::UniversalPrint(p0, os);\
862 *os << ", ";\
863 ::testing::internal::UniversalPrint(p1, os);\
864 *os << ")";\
865 }\
866 p0##_type p0;\
867 p1##_type p1;\
868 };\
869 template <typename arg_type>\
870 operator ::testing::Matcher<arg_type>() const {\
871 return ::testing::Matcher<arg_type>(new gmock_Impl<arg_type>(p0, p1));\
872 }\
873 name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
874 p1(gmock_p1) {\
875 ::testing::internal::ValidateMatcherDescription(description);\
876 }\
877 p0##_type p0;\
878 p1##_type p1;\
879 };\
880 template <typename p0##_type, typename p1##_type>\
881 inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \
882 p1##_type p1) {\
883 return name##MatcherP2<p0##_type, p1##_type>(p0, p1);\
884 }\
885 template <typename p0##_type, typename p1##_type>\
886 template <typename arg_type>\
887 bool name##MatcherP2<p0##_type, p1##_type>::\
888 gmock_Impl<arg_type>::Matches(arg_type arg) const
889
890#define MATCHER_P3(name, p0, p1, p2, description)\
891 template <typename p0##_type, typename p1##_type, typename p2##_type>\
892 class name##MatcherP3 {\
893 public:\
894 template <typename arg_type>\
895 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
896 public:\
897 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \
898 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
899 virtual bool Matches(arg_type arg) const;\
900 virtual void DescribeTo(::std::ostream* os) const {\
901 *os << ::testing::internal::ConvertIdentifierNameToWords(#name);\
902 *os << " (";\
903 ::testing::internal::UniversalPrint(p0, os);\
904 *os << ", ";\
905 ::testing::internal::UniversalPrint(p1, os);\
906 *os << ", ";\
907 ::testing::internal::UniversalPrint(p2, os);\
908 *os << ")";\
909 }\
910 p0##_type p0;\
911 p1##_type p1;\
912 p2##_type p2;\
913 };\
914 template <typename arg_type>\
915 operator ::testing::Matcher<arg_type>() const {\
916 return ::testing::Matcher<arg_type>(new gmock_Impl<arg_type>(p0, p1, \
917 p2));\
918 }\
919 name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \
920 p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\
921 ::testing::internal::ValidateMatcherDescription(description);\
922 }\
923 p0##_type p0;\
924 p1##_type p1;\
925 p2##_type p2;\
926 };\
927 template <typename p0##_type, typename p1##_type, typename p2##_type>\
928 inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
929 p1##_type p1, p2##_type p2) {\
930 return name##MatcherP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
931 }\
932 template <typename p0##_type, typename p1##_type, typename p2##_type>\
933 template <typename arg_type>\
934 bool name##MatcherP3<p0##_type, p1##_type, p2##_type>::\
935 gmock_Impl<arg_type>::Matches(arg_type arg) const
936
937#define MATCHER_P4(name, p0, p1, p2, p3, description)\
938 template <typename p0##_type, typename p1##_type, typename p2##_type, \
939 typename p3##_type>\
940 class name##MatcherP4 {\
941 public:\
942 template <typename arg_type>\
943 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
944 public:\
945 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
946 p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
947 p3(gmock_p3) {}\
948 virtual bool Matches(arg_type arg) const;\
949 virtual void DescribeTo(::std::ostream* os) const {\
950 *os << ::testing::internal::ConvertIdentifierNameToWords(#name);\
951 *os << " (";\
952 ::testing::internal::UniversalPrint(p0, os);\
953 *os << ", ";\
954 ::testing::internal::UniversalPrint(p1, os);\
955 *os << ", ";\
956 ::testing::internal::UniversalPrint(p2, os);\
957 *os << ", ";\
958 ::testing::internal::UniversalPrint(p3, os);\
959 *os << ")";\
960 }\
961 p0##_type p0;\
962 p1##_type p1;\
963 p2##_type p2;\
964 p3##_type p3;\
965 };\
966 template <typename arg_type>\
967 operator ::testing::Matcher<arg_type>() const {\
968 return ::testing::Matcher<arg_type>(new gmock_Impl<arg_type>(p0, p1, \
969 p2, p3));\
970 }\
971 name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \
972 p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
973 p2(gmock_p2), p3(gmock_p3) {\
974 ::testing::internal::ValidateMatcherDescription(description);\
975 }\
976 p0##_type p0;\
977 p1##_type p1;\
978 p2##_type p2;\
979 p3##_type p3;\
980 };\
981 template <typename p0##_type, typename p1##_type, typename p2##_type, \
982 typename p3##_type>\
983 inline name##MatcherP4<p0##_type, p1##_type, p2##_type, \
984 p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
985 p3##_type p3) {\
986 return name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \
987 p1, p2, p3);\
988 }\
989 template <typename p0##_type, typename p1##_type, typename p2##_type, \
990 typename p3##_type>\
991 template <typename arg_type>\
992 bool name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>::\
993 gmock_Impl<arg_type>::Matches(arg_type arg) const
994
995#define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\
996 template <typename p0##_type, typename p1##_type, typename p2##_type, \
997 typename p3##_type, typename p4##_type>\
998 class name##MatcherP5 {\
999 public:\
1000 template <typename arg_type>\
1001 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
1002 public:\
1003 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1004 p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \
1005 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\
1006 virtual bool Matches(arg_type arg) const;\
1007 virtual void DescribeTo(::std::ostream* os) const {\
1008 *os << ::testing::internal::ConvertIdentifierNameToWords(#name);\
1009 *os << " (";\
1010 ::testing::internal::UniversalPrint(p0, os);\
1011 *os << ", ";\
1012 ::testing::internal::UniversalPrint(p1, os);\
1013 *os << ", ";\
1014 ::testing::internal::UniversalPrint(p2, os);\
1015 *os << ", ";\
1016 ::testing::internal::UniversalPrint(p3, os);\
1017 *os << ", ";\
1018 ::testing::internal::UniversalPrint(p4, os);\
1019 *os << ")";\
1020 }\
1021 p0##_type p0;\
1022 p1##_type p1;\
1023 p2##_type p2;\
1024 p3##_type p3;\
1025 p4##_type p4;\
1026 };\
1027 template <typename arg_type>\
1028 operator ::testing::Matcher<arg_type>() const {\
1029 return ::testing::Matcher<arg_type>(new gmock_Impl<arg_type>(p0, p1, \
1030 p2, p3, p4));\
1031 }\
1032 name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \
1033 p2##_type gmock_p2, p3##_type gmock_p3, \
1034 p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1035 p3(gmock_p3), p4(gmock_p4) {\
1036 ::testing::internal::ValidateMatcherDescription(description);\
1037 }\
1038 p0##_type p0;\
1039 p1##_type p1;\
1040 p2##_type p2;\
1041 p3##_type p3;\
1042 p4##_type p4;\
1043 };\
1044 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1045 typename p3##_type, typename p4##_type>\
1046 inline name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
1047 p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
1048 p4##_type p4) {\
1049 return name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
1050 p4##_type>(p0, p1, p2, p3, p4);\
1051 }\
1052 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1053 typename p3##_type, typename p4##_type>\
1054 template <typename arg_type>\
1055 bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type>::\
1056 gmock_Impl<arg_type>::Matches(arg_type arg) const
1057
1058#define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\
1059 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1060 typename p3##_type, typename p4##_type, typename p5##_type>\
1061 class name##MatcherP6 {\
1062 public:\
1063 template <typename arg_type>\
1064 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
1065 public:\
1066 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1067 p3##_type gmock_p3, p4##_type gmock_p4, \
1068 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1069 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
1070 virtual bool Matches(arg_type arg) const;\
1071 virtual void DescribeTo(::std::ostream* os) const {\
1072 *os << ::testing::internal::ConvertIdentifierNameToWords(#name);\
1073 *os << " (";\
1074 ::testing::internal::UniversalPrint(p0, os);\
1075 *os << ", ";\
1076 ::testing::internal::UniversalPrint(p1, os);\
1077 *os << ", ";\
1078 ::testing::internal::UniversalPrint(p2, os);\
1079 *os << ", ";\
1080 ::testing::internal::UniversalPrint(p3, os);\
1081 *os << ", ";\
1082 ::testing::internal::UniversalPrint(p4, os);\
1083 *os << ", ";\
1084 ::testing::internal::UniversalPrint(p5, os);\
1085 *os << ")";\
1086 }\
1087 p0##_type p0;\
1088 p1##_type p1;\
1089 p2##_type p2;\
1090 p3##_type p3;\
1091 p4##_type p4;\
1092 p5##_type p5;\
1093 };\
1094 template <typename arg_type>\
1095 operator ::testing::Matcher<arg_type>() const {\
1096 return ::testing::Matcher<arg_type>(new gmock_Impl<arg_type>(p0, p1, \
1097 p2, p3, p4, p5));\
1098 }\
1099 name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \
1100 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
1101 p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1102 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\
1103 ::testing::internal::ValidateMatcherDescription(description);\
1104 }\
1105 p0##_type p0;\
1106 p1##_type p1;\
1107 p2##_type p2;\
1108 p3##_type p3;\
1109 p4##_type p4;\
1110 p5##_type p5;\
1111 };\
1112 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1113 typename p3##_type, typename p4##_type, typename p5##_type>\
1114 inline name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
1115 p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
1116 p3##_type p3, p4##_type p4, p5##_type p5) {\
1117 return name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
1118 p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
1119 }\
1120 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1121 typename p3##_type, typename p4##_type, typename p5##_type>\
1122 template <typename arg_type>\
1123 bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
1124 p5##_type>::\
1125 gmock_Impl<arg_type>::Matches(arg_type arg) const
1126
1127#define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\
1128 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1129 typename p3##_type, typename p4##_type, typename p5##_type, \
1130 typename p6##_type>\
1131 class name##MatcherP7 {\
1132 public:\
1133 template <typename arg_type>\
1134 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
1135 public:\
1136 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1137 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1138 p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1139 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
1140 virtual bool Matches(arg_type arg) const;\
1141 virtual void DescribeTo(::std::ostream* os) const {\
1142 *os << ::testing::internal::ConvertIdentifierNameToWords(#name);\
1143 *os << " (";\
1144 ::testing::internal::UniversalPrint(p0, os);\
1145 *os << ", ";\
1146 ::testing::internal::UniversalPrint(p1, os);\
1147 *os << ", ";\
1148 ::testing::internal::UniversalPrint(p2, os);\
1149 *os << ", ";\
1150 ::testing::internal::UniversalPrint(p3, os);\
1151 *os << ", ";\
1152 ::testing::internal::UniversalPrint(p4, os);\
1153 *os << ", ";\
1154 ::testing::internal::UniversalPrint(p5, os);\
1155 *os << ", ";\
1156 ::testing::internal::UniversalPrint(p6, os);\
1157 *os << ")";\
1158 }\
1159 p0##_type p0;\
1160 p1##_type p1;\
1161 p2##_type p2;\
1162 p3##_type p3;\
1163 p4##_type p4;\
1164 p5##_type p5;\
1165 p6##_type p6;\
1166 };\
1167 template <typename arg_type>\
1168 operator ::testing::Matcher<arg_type>() const {\
1169 return ::testing::Matcher<arg_type>(new gmock_Impl<arg_type>(p0, p1, \
1170 p2, p3, p4, p5, p6));\
1171 }\
1172 name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \
1173 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
1174 p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
1175 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
1176 p6(gmock_p6) {\
1177 ::testing::internal::ValidateMatcherDescription(description);\
1178 }\
1179 p0##_type p0;\
1180 p1##_type p1;\
1181 p2##_type p2;\
1182 p3##_type p3;\
1183 p4##_type p4;\
1184 p5##_type p5;\
1185 p6##_type p6;\
1186 };\
1187 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1188 typename p3##_type, typename p4##_type, typename p5##_type, \
1189 typename p6##_type>\
1190 inline name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
1191 p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
1192 p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
1193 p6##_type p6) {\
1194 return name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
1195 p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
1196 }\
1197 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1198 typename p3##_type, typename p4##_type, typename p5##_type, \
1199 typename p6##_type>\
1200 template <typename arg_type>\
1201 bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
1202 p5##_type, p6##_type>::\
1203 gmock_Impl<arg_type>::Matches(arg_type arg) const
1204
1205#define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\
1206 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1207 typename p3##_type, typename p4##_type, typename p5##_type, \
1208 typename p6##_type, typename p7##_type>\
1209 class name##MatcherP8 {\
1210 public:\
1211 template <typename arg_type>\
1212 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
1213 public:\
1214 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1215 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1216 p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), \
1217 p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \
1218 p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
1219 virtual bool Matches(arg_type arg) const;\
1220 virtual void DescribeTo(::std::ostream* os) const {\
1221 *os << ::testing::internal::ConvertIdentifierNameToWords(#name);\
1222 *os << " (";\
1223 ::testing::internal::UniversalPrint(p0, os);\
1224 *os << ", ";\
1225 ::testing::internal::UniversalPrint(p1, os);\
1226 *os << ", ";\
1227 ::testing::internal::UniversalPrint(p2, os);\
1228 *os << ", ";\
1229 ::testing::internal::UniversalPrint(p3, os);\
1230 *os << ", ";\
1231 ::testing::internal::UniversalPrint(p4, os);\
1232 *os << ", ";\
1233 ::testing::internal::UniversalPrint(p5, os);\
1234 *os << ", ";\
1235 ::testing::internal::UniversalPrint(p6, os);\
1236 *os << ", ";\
1237 ::testing::internal::UniversalPrint(p7, os);\
1238 *os << ")";\
1239 }\
1240 p0##_type p0;\
1241 p1##_type p1;\
1242 p2##_type p2;\
1243 p3##_type p3;\
1244 p4##_type p4;\
1245 p5##_type p5;\
1246 p6##_type p6;\
1247 p7##_type p7;\
1248 };\
1249 template <typename arg_type>\
1250 operator ::testing::Matcher<arg_type>() const {\
1251 return ::testing::Matcher<arg_type>(new gmock_Impl<arg_type>(p0, p1, \
1252 p2, p3, p4, p5, p6, p7));\
1253 }\
1254 name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \
1255 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
1256 p5##_type gmock_p5, p6##_type gmock_p6, \
1257 p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1258 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
1259 p7(gmock_p7) {\
1260 ::testing::internal::ValidateMatcherDescription(description);\
1261 }\
1262 p0##_type p0;\
1263 p1##_type p1;\
1264 p2##_type p2;\
1265 p3##_type p3;\
1266 p4##_type p4;\
1267 p5##_type p5;\
1268 p6##_type p6;\
1269 p7##_type p7;\
1270 };\
1271 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1272 typename p3##_type, typename p4##_type, typename p5##_type, \
1273 typename p6##_type, typename p7##_type>\
1274 inline name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
1275 p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
1276 p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
1277 p6##_type p6, p7##_type p7) {\
1278 return name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
1279 p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
1280 p6, p7);\
1281 }\
1282 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1283 typename p3##_type, typename p4##_type, typename p5##_type, \
1284 typename p6##_type, typename p7##_type>\
1285 template <typename arg_type>\
1286 bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
1287 p5##_type, p6##_type, p7##_type>::\
1288 gmock_Impl<arg_type>::Matches(arg_type arg) const
1289
1290#define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\
1291 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1292 typename p3##_type, typename p4##_type, typename p5##_type, \
1293 typename p6##_type, typename p7##_type, typename p8##_type>\
1294 class name##MatcherP9 {\
1295 public:\
1296 template <typename arg_type>\
1297 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
1298 public:\
1299 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1300 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1301 p6##_type gmock_p6, p7##_type gmock_p7, \
1302 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1303 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
1304 p7(gmock_p7), p8(gmock_p8) {}\
1305 virtual bool Matches(arg_type arg) const;\
1306 virtual void DescribeTo(::std::ostream* os) const {\
1307 *os << ::testing::internal::ConvertIdentifierNameToWords(#name);\
1308 *os << " (";\
1309 ::testing::internal::UniversalPrint(p0, os);\
1310 *os << ", ";\
1311 ::testing::internal::UniversalPrint(p1, os);\
1312 *os << ", ";\
1313 ::testing::internal::UniversalPrint(p2, os);\
1314 *os << ", ";\
1315 ::testing::internal::UniversalPrint(p3, os);\
1316 *os << ", ";\
1317 ::testing::internal::UniversalPrint(p4, os);\
1318 *os << ", ";\
1319 ::testing::internal::UniversalPrint(p5, os);\
1320 *os << ", ";\
1321 ::testing::internal::UniversalPrint(p6, os);\
1322 *os << ", ";\
1323 ::testing::internal::UniversalPrint(p7, os);\
1324 *os << ", ";\
1325 ::testing::internal::UniversalPrint(p8, os);\
1326 *os << ")";\
1327 }\
1328 p0##_type p0;\
1329 p1##_type p1;\
1330 p2##_type p2;\
1331 p3##_type p3;\
1332 p4##_type p4;\
1333 p5##_type p5;\
1334 p6##_type p6;\
1335 p7##_type p7;\
1336 p8##_type p8;\
1337 };\
1338 template <typename arg_type>\
1339 operator ::testing::Matcher<arg_type>() const {\
1340 return ::testing::Matcher<arg_type>(new gmock_Impl<arg_type>(p0, p1, \
1341 p2, p3, p4, p5, p6, p7, p8));\
1342 }\
1343 name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \
1344 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
1345 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
1346 p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1347 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
1348 p8(gmock_p8) {\
1349 ::testing::internal::ValidateMatcherDescription(description);\
1350 }\
1351 p0##_type p0;\
1352 p1##_type p1;\
1353 p2##_type p2;\
1354 p3##_type p3;\
1355 p4##_type p4;\
1356 p5##_type p5;\
1357 p6##_type p6;\
1358 p7##_type p7;\
1359 p8##_type p8;\
1360 };\
1361 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1362 typename p3##_type, typename p4##_type, typename p5##_type, \
1363 typename p6##_type, typename p7##_type, typename p8##_type>\
1364 inline name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
1365 p4##_type, p5##_type, p6##_type, p7##_type, \
1366 p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
1367 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
1368 p8##_type p8) {\
1369 return name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
1370 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
1371 p3, p4, p5, p6, p7, p8);\
1372 }\
1373 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1374 typename p3##_type, typename p4##_type, typename p5##_type, \
1375 typename p6##_type, typename p7##_type, typename p8##_type>\
1376 template <typename arg_type>\
1377 bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
1378 p5##_type, p6##_type, p7##_type, p8##_type>::\
1379 gmock_Impl<arg_type>::Matches(arg_type arg) const
1380
1381#define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)\
1382 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1383 typename p3##_type, typename p4##_type, typename p5##_type, \
1384 typename p6##_type, typename p7##_type, typename p8##_type, \
1385 typename p9##_type>\
1386 class name##MatcherP10 {\
1387 public:\
1388 template <typename arg_type>\
1389 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
1390 public:\
1391 gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
1392 p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
1393 p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
1394 p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
1395 p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
1396 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
1397 virtual bool Matches(arg_type arg) const;\
1398 virtual void DescribeTo(::std::ostream* os) const {\
1399 *os << ::testing::internal::ConvertIdentifierNameToWords(#name);\
1400 *os << " (";\
1401 ::testing::internal::UniversalPrint(p0, os);\
1402 *os << ", ";\
1403 ::testing::internal::UniversalPrint(p1, os);\
1404 *os << ", ";\
1405 ::testing::internal::UniversalPrint(p2, os);\
1406 *os << ", ";\
1407 ::testing::internal::UniversalPrint(p3, os);\
1408 *os << ", ";\
1409 ::testing::internal::UniversalPrint(p4, os);\
1410 *os << ", ";\
1411 ::testing::internal::UniversalPrint(p5, os);\
1412 *os << ", ";\
1413 ::testing::internal::UniversalPrint(p6, os);\
1414 *os << ", ";\
1415 ::testing::internal::UniversalPrint(p7, os);\
1416 *os << ", ";\
1417 ::testing::internal::UniversalPrint(p8, os);\
1418 *os << ", ";\
1419 ::testing::internal::UniversalPrint(p9, os);\
1420 *os << ")";\
1421 }\
1422 p0##_type p0;\
1423 p1##_type p1;\
1424 p2##_type p2;\
1425 p3##_type p3;\
1426 p4##_type p4;\
1427 p5##_type p5;\
1428 p6##_type p6;\
1429 p7##_type p7;\
1430 p8##_type p8;\
1431 p9##_type p9;\
1432 };\
1433 template <typename arg_type>\
1434 operator ::testing::Matcher<arg_type>() const {\
1435 return ::testing::Matcher<arg_type>(new gmock_Impl<arg_type>(p0, p1, \
1436 p2, p3, p4, p5, p6, p7, p8, p9));\
1437 }\
1438 name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \
1439 p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
1440 p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
1441 p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
1442 p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
1443 p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\
1444 ::testing::internal::ValidateMatcherDescription(description);\
1445 }\
1446 p0##_type p0;\
1447 p1##_type p1;\
1448 p2##_type p2;\
1449 p3##_type p3;\
1450 p4##_type p4;\
1451 p5##_type p5;\
1452 p6##_type p6;\
1453 p7##_type p7;\
1454 p8##_type p8;\
1455 p9##_type p9;\
1456 };\
1457 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1458 typename p3##_type, typename p4##_type, typename p5##_type, \
1459 typename p6##_type, typename p7##_type, typename p8##_type, \
1460 typename p9##_type>\
1461 inline name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
1462 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
1463 p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
1464 p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
1465 p9##_type p9) {\
1466 return name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
1467 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
1468 p1, p2, p3, p4, p5, p6, p7, p8, p9);\
1469 }\
1470 template <typename p0##_type, typename p1##_type, typename p2##_type, \
1471 typename p3##_type, typename p4##_type, typename p5##_type, \
1472 typename p6##_type, typename p7##_type, typename p8##_type, \
1473 typename p9##_type>\
1474 template <typename arg_type>\
1475 bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
1476 p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>::\
1477 gmock_Impl<arg_type>::Matches(arg_type arg) const
1478
shiqiane35fdd92008-12-10 05:08:54 +00001479#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_