OLD | NEW |
(Empty) | |
| 1 // 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 #include <gmock/gmock-printers.h> |
| 44 |
| 45 namespace testing { |
| 46 namespace internal { |
| 47 |
| 48 // Implements ElementsAre() and ElementsAreArray(). |
| 49 template <typename Container> |
| 50 class ElementsAreMatcherImpl : public MatcherInterface<Container> { |
| 51 public: |
| 52 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) RawContainer; |
| 53 typedef typename RawContainer::value_type Element; |
| 54 |
| 55 // Constructs the matcher from a sequence of element values or |
| 56 // element matchers. |
| 57 template <typename InputIter> |
| 58 ElementsAreMatcherImpl(InputIter first, size_t count) { |
| 59 matchers_.reserve(count); |
| 60 InputIter it = first; |
| 61 for (size_t i = 0; i != count; ++i, ++it) { |
| 62 matchers_.push_back(MatcherCast<const Element&>(*it)); |
| 63 } |
| 64 } |
| 65 |
| 66 // Returns true iff 'container' matches. |
| 67 virtual bool Matches(Container container) const { |
| 68 if (container.size() != count()) |
| 69 return false; |
| 70 |
| 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)) |
| 74 return false; |
| 75 } |
| 76 |
| 77 return true; |
| 78 } |
| 79 |
| 80 // Describes what this matcher does. |
| 81 virtual void DescribeTo(::std::ostream* os) const { |
| 82 if (count() == 0) { |
| 83 *os << "is empty"; |
| 84 } else if (count() == 1) { |
| 85 *os << "has 1 element that "; |
| 86 matchers_[0].DescribeTo(os); |
| 87 } else { |
| 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()) { |
| 93 *os << ",\n"; |
| 94 } |
| 95 } |
| 96 } |
| 97 } |
| 98 |
| 99 // Describes what the negation of this matcher does. |
| 100 virtual void DescribeNegationTo(::std::ostream* os) const { |
| 101 if (count() == 0) { |
| 102 *os << "is not empty"; |
| 103 return; |
| 104 } |
| 105 |
| 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()) { |
| 111 *os << ", or\n"; |
| 112 } |
| 113 } |
| 114 } |
| 115 |
| 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). |
| 122 |
| 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); |
| 128 |
| 129 const string s = ss.str(); |
| 130 if (!s.empty()) { |
| 131 if (reason_printed) { |
| 132 *os << ",\n"; |
| 133 } |
| 134 *os << "element " << i << " " << s; |
| 135 reason_printed = true; |
| 136 } |
| 137 } |
| 138 } else { |
| 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); |
| 148 } |
| 149 return; |
| 150 } |
| 151 |
| 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)) { |
| 158 continue; |
| 159 } |
| 160 |
| 161 *os << "element " << i << " doesn't match"; |
| 162 |
| 163 ::std::stringstream ss; |
| 164 matchers_[i].ExplainMatchResultTo(*container_iter, &ss); |
| 165 const string s = ss.str(); |
| 166 if (!s.empty()) { |
| 167 *os << " (" << s << ")"; |
| 168 } |
| 169 return; |
| 170 } |
| 171 } |
| 172 } |
| 173 |
| 174 private: |
| 175 static Message Elements(size_t count) { |
| 176 return Message() << count << (count == 1 ? " element" : " elements"); |
| 177 } |
| 178 |
| 179 size_t count() const { return matchers_.size(); } |
| 180 std::vector<Matcher<const Element&> > matchers_; |
| 181 }; |
| 182 |
| 183 // Implements ElementsAre() of 0-10 arguments. |
| 184 |
| 185 class ElementsAreMatcher0 { |
| 186 public: |
| 187 ElementsAreMatcher0() {} |
| 188 |
| 189 template <typename Container> |
| 190 operator Matcher<Container>() const { |
| 191 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) |
| 192 RawContainer; |
| 193 typedef typename RawContainer::value_type Element; |
| 194 |
| 195 const Matcher<const Element&>* const matchers = NULL; |
| 196 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 0)); |
| 197 } |
| 198 }; |
| 199 |
| 200 template <typename T1> |
| 201 class ElementsAreMatcher1 { |
| 202 public: |
| 203 explicit ElementsAreMatcher1(const T1& e1) : e1_(e1) {} |
| 204 |
| 205 template <typename Container> |
| 206 operator Matcher<Container>() const { |
| 207 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) |
| 208 RawContainer; |
| 209 typedef typename RawContainer::value_type Element; |
| 210 |
| 211 const Matcher<const Element&> matchers[] = { |
| 212 MatcherCast<const Element&>(e1_), |
| 213 }; |
| 214 |
| 215 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 1)); |
| 216 } |
| 217 |
| 218 private: |
| 219 const T1& e1_; |
| 220 }; |
| 221 |
| 222 template <typename T1, typename T2> |
| 223 class ElementsAreMatcher2 { |
| 224 public: |
| 225 ElementsAreMatcher2(const T1& e1, const T2& e2) : e1_(e1), e2_(e2) {} |
| 226 |
| 227 template <typename Container> |
| 228 operator Matcher<Container>() const { |
| 229 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) |
| 230 RawContainer; |
| 231 typedef typename RawContainer::value_type Element; |
| 232 |
| 233 const Matcher<const Element&> matchers[] = { |
| 234 MatcherCast<const Element&>(e1_), |
| 235 MatcherCast<const Element&>(e2_), |
| 236 }; |
| 237 |
| 238 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 2)); |
| 239 } |
| 240 |
| 241 private: |
| 242 const T1& e1_; |
| 243 const T2& e2_; |
| 244 }; |
| 245 |
| 246 template <typename T1, typename T2, typename T3> |
| 247 class ElementsAreMatcher3 { |
| 248 public: |
| 249 ElementsAreMatcher3(const T1& e1, const T2& e2, const T3& e3) : e1_(e1), |
| 250 e2_(e2), e3_(e3) {} |
| 251 |
| 252 template <typename Container> |
| 253 operator Matcher<Container>() const { |
| 254 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) |
| 255 RawContainer; |
| 256 typedef typename RawContainer::value_type Element; |
| 257 |
| 258 const Matcher<const Element&> matchers[] = { |
| 259 MatcherCast<const Element&>(e1_), |
| 260 MatcherCast<const Element&>(e2_), |
| 261 MatcherCast<const Element&>(e3_), |
| 262 }; |
| 263 |
| 264 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 3)); |
| 265 } |
| 266 |
| 267 private: |
| 268 const T1& e1_; |
| 269 const T2& e2_; |
| 270 const T3& e3_; |
| 271 }; |
| 272 |
| 273 template <typename T1, typename T2, typename T3, typename T4> |
| 274 class ElementsAreMatcher4 { |
| 275 public: |
| 276 ElementsAreMatcher4(const T1& e1, const T2& e2, const T3& e3, |
| 277 const T4& e4) : e1_(e1), e2_(e2), e3_(e3), e4_(e4) {} |
| 278 |
| 279 template <typename Container> |
| 280 operator Matcher<Container>() const { |
| 281 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) |
| 282 RawContainer; |
| 283 typedef typename RawContainer::value_type Element; |
| 284 |
| 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_), |
| 290 }; |
| 291 |
| 292 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 4)); |
| 293 } |
| 294 |
| 295 private: |
| 296 const T1& e1_; |
| 297 const T2& e2_; |
| 298 const T3& e3_; |
| 299 const T4& e4_; |
| 300 }; |
| 301 |
| 302 template <typename T1, typename T2, typename T3, typename T4, typename T5> |
| 303 class ElementsAreMatcher5 { |
| 304 public: |
| 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) {} |
| 307 |
| 308 template <typename Container> |
| 309 operator Matcher<Container>() const { |
| 310 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) |
| 311 RawContainer; |
| 312 typedef typename RawContainer::value_type Element; |
| 313 |
| 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_), |
| 320 }; |
| 321 |
| 322 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 5)); |
| 323 } |
| 324 |
| 325 private: |
| 326 const T1& e1_; |
| 327 const T2& e2_; |
| 328 const T3& e3_; |
| 329 const T4& e4_; |
| 330 const T5& e5_; |
| 331 }; |
| 332 |
| 333 template <typename T1, typename T2, typename T3, typename T4, typename T5, |
| 334 typename T6> |
| 335 class ElementsAreMatcher6 { |
| 336 public: |
| 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), |
| 339 e5_(e5), e6_(e6) {} |
| 340 |
| 341 template <typename Container> |
| 342 operator Matcher<Container>() const { |
| 343 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) |
| 344 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 |
| 368 template <typename T1, typename T2, typename T3, typename T4, typename T5, |
| 369 typename T6, typename T7> |
| 370 class 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)) |
| 379 RawContainer; |
| 380 typedef typename RawContainer::value_type Element; |
| 381 |
| 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_), |
| 390 }; |
| 391 |
| 392 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 7)); |
| 393 } |
| 394 |
| 395 private: |
| 396 const T1& e1_; |
| 397 const T2& e2_; |
| 398 const T3& e3_; |
| 399 const T4& e4_; |
| 400 const T5& e5_; |
| 401 const T6& e6_; |
| 402 const T7& e7_; |
| 403 }; |
| 404 |
| 405 template <typename T1, typename T2, typename T3, typename T4, typename T5, |
| 406 typename T6, typename T7, typename T8> |
| 407 class ElementsAreMatcher8 { |
| 408 public: |
| 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) {} |
| 412 |
| 413 template <typename Container> |
| 414 operator Matcher<Container>() const { |
| 415 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) |
| 416 RawContainer; |
| 417 typedef typename RawContainer::value_type Element; |
| 418 |
| 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_), |
| 428 }; |
| 429 |
| 430 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 8)); |
| 431 } |
| 432 |
| 433 private: |
| 434 const T1& e1_; |
| 435 const T2& e2_; |
| 436 const T3& e3_; |
| 437 const T4& e4_; |
| 438 const T5& e5_; |
| 439 const T6& e6_; |
| 440 const T7& e7_; |
| 441 const T8& e8_; |
| 442 }; |
| 443 |
| 444 template <typename T1, typename T2, typename T3, typename T4, typename T5, |
| 445 typename T6, typename T7, typename T8, typename T9> |
| 446 class ElementsAreMatcher9 { |
| 447 public: |
| 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) {} |
| 452 |
| 453 template <typename Container> |
| 454 operator Matcher<Container>() const { |
| 455 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) |
| 456 RawContainer; |
| 457 typedef typename RawContainer::value_type Element; |
| 458 |
| 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_), |
| 469 }; |
| 470 |
| 471 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 9)); |
| 472 } |
| 473 |
| 474 private: |
| 475 const T1& e1_; |
| 476 const T2& e2_; |
| 477 const T3& e3_; |
| 478 const T4& e4_; |
| 479 const T5& e5_; |
| 480 const T6& e6_; |
| 481 const T7& e7_; |
| 482 const T8& e8_; |
| 483 const T9& e9_; |
| 484 }; |
| 485 |
| 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 { |
| 489 public: |
| 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) {} |
| 494 |
| 495 template <typename Container> |
| 496 operator Matcher<Container>() const { |
| 497 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) |
| 498 RawContainer; |
| 499 typedef typename RawContainer::value_type Element; |
| 500 |
| 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_), |
| 512 }; |
| 513 |
| 514 return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 10)); |
| 515 } |
| 516 |
| 517 private: |
| 518 const T1& e1_; |
| 519 const T2& e2_; |
| 520 const T3& e3_; |
| 521 const T4& e4_; |
| 522 const T5& e5_; |
| 523 const T6& e6_; |
| 524 const T7& e7_; |
| 525 const T8& e8_; |
| 526 const T9& e9_; |
| 527 const T10& e10_; |
| 528 }; |
| 529 |
| 530 // Implements ElementsAreArray(). |
| 531 template <typename T> |
| 532 class ElementsAreArrayMatcher { |
| 533 public: |
| 534 ElementsAreArrayMatcher(const T* first, size_t count) : |
| 535 first_(first), count_(count) {} |
| 536 |
| 537 template <typename Container> |
| 538 operator Matcher<Container>() const { |
| 539 typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) |
| 540 RawContainer; |
| 541 typedef typename RawContainer::value_type Element; |
| 542 |
| 543 return MakeMatcher(new ElementsAreMatcherImpl<Container>(first_, count_)); |
| 544 } |
| 545 |
| 546 private: |
| 547 const T* const first_; |
| 548 const size_t count_; |
| 549 }; |
| 550 |
| 551 } // namespace internal |
| 552 |
| 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 |
| 557 // 10 arguments. |
| 558 // |
| 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). |
| 562 |
| 563 inline internal::ElementsAreMatcher0 ElementsAre() { |
| 564 return internal::ElementsAreMatcher0(); |
| 565 } |
| 566 |
| 567 template <typename T1> |
| 568 inline internal::ElementsAreMatcher1<T1> ElementsAre(const T1& e1) { |
| 569 return internal::ElementsAreMatcher1<T1>(e1); |
| 570 } |
| 571 |
| 572 template <typename T1, typename T2> |
| 573 inline internal::ElementsAreMatcher2<T1, T2> ElementsAre(const T1& e1, |
| 574 const T2& e2) { |
| 575 return internal::ElementsAreMatcher2<T1, T2>(e1, e2); |
| 576 } |
| 577 |
| 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); |
| 582 } |
| 583 |
| 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); |
| 588 } |
| 589 |
| 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, |
| 593 const T5& e5) { |
| 594 return internal::ElementsAreMatcher5<T1, T2, T3, T4, T5>(e1, e2, e3, e4, e5); |
| 595 } |
| 596 |
| 597 template <typename T1, typename T2, typename T3, typename T4, typename T5, |
| 598 typename T6> |
| 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, |
| 603 e5, e6); |
| 604 } |
| 605 |
| 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, |
| 612 e4, e5, e6, e7); |
| 613 } |
| 614 |
| 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); |
| 622 } |
| 623 |
| 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); |
| 631 } |
| 632 |
| 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, |
| 638 const T10& e10) { |
| 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); |
| 641 } |
| 642 |
| 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. |
| 648 |
| 649 template <typename T> |
| 650 inline internal::ElementsAreArrayMatcher<T> ElementsAreArray( |
| 651 const T* first, size_t count) { |
| 652 return internal::ElementsAreArrayMatcher<T>(first, count); |
| 653 } |
| 654 |
| 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); |
| 659 } |
| 660 |
| 661 } // namespace testing |
| 662 |
| 663 // The MATCHER* family of macros can be used in a namespace scope to |
| 664 // define custom matchers easily. The syntax: |
| 665 // |
| 666 // MATCHER(name, description_string) { statements; } |
| 667 // |
| 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'. |
| 672 // |
| 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 |
| 679 // description. |
| 680 // |
| 681 // For example: |
| 682 // |
| 683 // MATCHER(IsEven, "") { return (arg % 2) == 0; } |
| 684 // |
| 685 // allows you to write |
| 686 // |
| 687 // // Expects mock_foo.Bar(n) to be called where n is even. |
| 688 // EXPECT_CALL(mock_foo, Bar(IsEven())); |
| 689 // |
| 690 // or, |
| 691 // |
| 692 // // Verifies that the value of some_expression is even. |
| 693 // EXPECT_THAT(some_expression, IsEven()); |
| 694 // |
| 695 // If the above assertion fails, it will print something like: |
| 696 // |
| 697 // Value of: some_expression |
| 698 // Expected: is even |
| 699 // Actual: 7 |
| 700 // |
| 701 // where the description "is even" is automatically calculated from the |
| 702 // matcher name IsEven. |
| 703 // |
| 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. |
| 713 // |
| 714 // Sometimes you'll want to parameterize the matcher. For that you |
| 715 // can use another macro: |
| 716 // |
| 717 // MATCHER_P(name, param_name, description_string) { statements; } |
| 718 // |
| 719 // For example: |
| 720 // |
| 721 // MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; } |
| 722 // |
| 723 // will allow you to write: |
| 724 // |
| 725 // EXPECT_THAT(Blah("a"), HasAbsoluteValue(n)); |
| 726 // |
| 727 // which may lead to this message (assuming n is 10): |
| 728 // |
| 729 // Value of: Blah("a") |
| 730 // Expected: has absolute value 10 |
| 731 // Actual: -9 |
| 732 // |
| 733 // Note that both the matcher description and its parameter are |
| 734 // printed, making the message human-friendly. |
| 735 // |
| 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'. |
| 740 // |
| 741 // We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to |
| 742 // support multi-parameter matchers. |
| 743 // |
| 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: |
| 747 // |
| 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' |
| 751 // |
| 752 // For example, |
| 753 // |
| 754 // MATCHER_P2(InClosedRange, low, hi, "is in range [%(low)s, %(hi)s]") { |
| 755 // return low <= arg && arg <= hi; |
| 756 // } |
| 757 // ... |
| 758 // EXPECT_THAT(3, InClosedRange(4, 6)); |
| 759 // |
| 760 // would generate a failure that contains the message: |
| 761 // |
| 762 // Expected: is in range [4, 6] |
| 763 // |
| 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, |
| 767 // |
| 768 // MATCHER_P2(InClosedRange, low, hi, "") { ... } |
| 769 // ... |
| 770 // EXPECT_THAT(3, InClosedRange(4, 6)); |
| 771 // |
| 772 // would generate a failure that contains the text: |
| 773 // |
| 774 // Expected: in closed range (4, 6) |
| 775 // |
| 776 // For the purpose of typing, you can view |
| 777 // |
| 778 // MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... } |
| 779 // |
| 780 // as shorthand for |
| 781 // |
| 782 // template <typename p1_type, ..., typename pk_type> |
| 783 // FooMatcherPk<p1_type, ..., pk_type> |
| 784 // Foo(p1_type p1, ..., pk_type pk) { ... } |
| 785 // |
| 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. |
| 795 // |
| 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 |
| 801 // address. |
| 802 // |
| 803 // You can overload matchers with different numbers of parameters: |
| 804 // |
| 805 // MATCHER_P(Blah, a, description_string1) { ... } |
| 806 // MATCHER_P2(Blah, a, b, description_string2) { ... } |
| 807 // |
| 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 |
| 817 // parameters). |
| 818 // |
| 819 // CAVEAT: |
| 820 // |
| 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 |
| 825 // a function. |
| 826 // |
| 827 // MORE INFORMATION: |
| 828 // |
| 829 // To learn more about using these macros, please search for 'MATCHER' |
| 830 // on http://code.google.com/p/googlemock/wiki/CookBook. |
| 831 |
| 832 namespace testing { |
| 833 namespace internal { |
| 834 |
| 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 |
| 839 |
| 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) {} |
| 844 |
| 845 // Points to the start of the interpolation (the '%' character). |
| 846 const char* start_pos; |
| 847 // Points to the first character after the interpolation. |
| 848 const char* end_pos; |
| 849 // 0-based index of the interpolated matcher parameter; |
| 850 // kTupleInterpolation for "%(*)s"; kPercentInterpolation for "%%". |
| 851 int param_index; |
| 852 }; |
| 853 |
| 854 typedef ::std::vector<Interpolation> Interpolations; |
| 855 |
| 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); |
| 863 |
| 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); |
| 870 |
| 871 } // namespace internal |
| 872 } // namespace testing |
| 873 |
| 874 #define MATCHER(name, description)\ |
| 875 class name##Matcher {\ |
| 876 public:\ |
| 877 template <typename arg_type>\ |
| 878 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 879 public:\ |
| 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);\ |
| 889 }\ |
| 890 const ::testing::internal::Interpolations gmock_interp_;\ |
| 891 };\ |
| 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_));\ |
| 896 }\ |
| 897 name##Matcher() {\ |
| 898 const char* gmock_param_names[] = { NULL };\ |
| 899 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ |
| 900 gmock_param_names, ("" description ""));\ |
| 901 }\ |
| 902 ::testing::internal::Interpolations gmock_interp_;\ |
| 903 };\ |
| 904 inline name##Matcher name() {\ |
| 905 return name##Matcher();\ |
| 906 }\ |
| 907 template <typename arg_type>\ |
| 908 bool name##Matcher::\ |
| 909 gmock_Impl<arg_type>::Matches(arg_type arg) const |
| 910 |
| 911 #define MATCHER_P(name, p0, description)\ |
| 912 template <typename p0##_type>\ |
| 913 class name##MatcherP {\ |
| 914 public:\ |
| 915 template <typename arg_type>\ |
| 916 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 917 public:\ |
| 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);\ |
| 928 }\ |
| 929 p0##_type p0;\ |
| 930 const ::testing::internal::Interpolations gmock_interp_;\ |
| 931 };\ |
| 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_));\ |
| 936 }\ |
| 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 ""));\ |
| 941 }\ |
| 942 p0##_type p0;\ |
| 943 ::testing::internal::Interpolations gmock_interp_;\ |
| 944 };\ |
| 945 template <typename p0##_type>\ |
| 946 inline name##MatcherP<p0##_type> name(p0##_type p0) {\ |
| 947 return name##MatcherP<p0##_type>(p0);\ |
| 948 }\ |
| 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 |
| 953 |
| 954 #define MATCHER_P2(name, p0, p1, description)\ |
| 955 template <typename p0##_type, typename p1##_type>\ |
| 956 class name##MatcherP2 {\ |
| 957 public:\ |
| 958 template <typename arg_type>\ |
| 959 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 960 public:\ |
| 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);\ |
| 971 }\ |
| 972 p0##_type p0;\ |
| 973 p1##_type p1;\ |
| 974 const ::testing::internal::Interpolations gmock_interp_;\ |
| 975 };\ |
| 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_));\ |
| 980 }\ |
| 981 name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ |
| 982 p1(gmock_p1) {\ |
| 983 const char* gmock_param_names[] = { #p0, #p1, NULL };\ |
| 984 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ |
| 985 gmock_param_names, ("" description ""));\ |
| 986 }\ |
| 987 p0##_type p0;\ |
| 988 p1##_type p1;\ |
| 989 ::testing::internal::Interpolations gmock_interp_;\ |
| 990 };\ |
| 991 template <typename p0##_type, typename p1##_type>\ |
| 992 inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \ |
| 993 p1##_type p1) {\ |
| 994 return name##MatcherP2<p0##_type, p1##_type>(p0, p1);\ |
| 995 }\ |
| 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 |
| 1000 |
| 1001 #define MATCHER_P3(name, p0, p1, p2, description)\ |
| 1002 template <typename p0##_type, typename p1##_type, typename p2##_type>\ |
| 1003 class name##MatcherP3 {\ |
| 1004 public:\ |
| 1005 template <typename arg_type>\ |
| 1006 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 1007 public:\ |
| 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, \ |
| 1017 p2));\ |
| 1018 *gmock_os << ::testing::internal::FormatMatcherDescription(\ |
| 1019 #name, description, gmock_interp_, gmock_printed_params);\ |
| 1020 }\ |
| 1021 p0##_type p0;\ |
| 1022 p1##_type p1;\ |
| 1023 p2##_type p2;\ |
| 1024 const ::testing::internal::Interpolations gmock_interp_;\ |
| 1025 };\ |
| 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_));\ |
| 1030 }\ |
| 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 ""));\ |
| 1036 }\ |
| 1037 p0##_type p0;\ |
| 1038 p1##_type p1;\ |
| 1039 p2##_type p2;\ |
| 1040 ::testing::internal::Interpolations gmock_interp_;\ |
| 1041 };\ |
| 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);\ |
| 1046 }\ |
| 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 |
| 1051 |
| 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 {\ |
| 1056 public:\ |
| 1057 template <typename arg_type>\ |
| 1058 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 1059 public:\ |
| 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);\ |
| 1073 }\ |
| 1074 p0##_type p0;\ |
| 1075 p1##_type p1;\ |
| 1076 p2##_type p2;\ |
| 1077 p3##_type p3;\ |
| 1078 const ::testing::internal::Interpolations gmock_interp_;\ |
| 1079 };\ |
| 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_));\ |
| 1084 }\ |
| 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 ""));\ |
| 1091 }\ |
| 1092 p0##_type p0;\ |
| 1093 p1##_type p1;\ |
| 1094 p2##_type p2;\ |
| 1095 p3##_type p3;\ |
| 1096 ::testing::internal::Interpolations gmock_interp_;\ |
| 1097 };\ |
| 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, \ |
| 1102 p3##_type p3) {\ |
| 1103 return name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \ |
| 1104 p1, p2, p3);\ |
| 1105 }\ |
| 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 |
| 1111 |
| 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 {\ |
| 1116 public:\ |
| 1117 template <typename arg_type>\ |
| 1118 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 1119 public:\ |
| 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);\ |
| 1133 }\ |
| 1134 p0##_type p0;\ |
| 1135 p1##_type p1;\ |
| 1136 p2##_type p2;\ |
| 1137 p3##_type p3;\ |
| 1138 p4##_type p4;\ |
| 1139 const ::testing::internal::Interpolations gmock_interp_;\ |
| 1140 };\ |
| 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_));\ |
| 1145 }\ |
| 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 ""));\ |
| 1153 }\ |
| 1154 p0##_type p0;\ |
| 1155 p1##_type p1;\ |
| 1156 p2##_type p2;\ |
| 1157 p3##_type p3;\ |
| 1158 p4##_type p4;\ |
| 1159 ::testing::internal::Interpolations gmock_interp_;\ |
| 1160 };\ |
| 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, \ |
| 1165 p4##_type p4) {\ |
| 1166 return name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \ |
| 1167 p4##_type>(p0, p1, p2, p3, p4);\ |
| 1168 }\ |
| 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 |
| 1174 |
| 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 {\ |
| 1179 public:\ |
| 1180 template <typename arg_type>\ |
| 1181 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 1182 public:\ |
| 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);\ |
| 1196 }\ |
| 1197 p0##_type p0;\ |
| 1198 p1##_type p1;\ |
| 1199 p2##_type p2;\ |
| 1200 p3##_type p3;\ |
| 1201 p4##_type p4;\ |
| 1202 p5##_type p5;\ |
| 1203 const ::testing::internal::Interpolations gmock_interp_;\ |
| 1204 };\ |
| 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_));\ |
| 1209 }\ |
| 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 ""));\ |
| 1217 }\ |
| 1218 p0##_type p0;\ |
| 1219 p1##_type p1;\ |
| 1220 p2##_type p2;\ |
| 1221 p3##_type p3;\ |
| 1222 p4##_type p4;\ |
| 1223 p5##_type p5;\ |
| 1224 ::testing::internal::Interpolations gmock_interp_;\ |
| 1225 };\ |
| 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);\ |
| 1233 }\ |
| 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, \ |
| 1238 p5##_type>::\ |
| 1239 gmock_Impl<arg_type>::Matches(arg_type arg) const |
| 1240 |
| 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 {\ |
| 1246 public:\ |
| 1247 template <typename arg_type>\ |
| 1248 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 1249 public:\ |
| 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, \ |
| 1263 p6));\ |
| 1264 *gmock_os << ::testing::internal::FormatMatcherDescription(\ |
| 1265 #name, description, gmock_interp_, gmock_printed_params);\ |
| 1266 }\ |
| 1267 p0##_type p0;\ |
| 1268 p1##_type p1;\ |
| 1269 p2##_type p2;\ |
| 1270 p3##_type p3;\ |
| 1271 p4##_type p4;\ |
| 1272 p5##_type p5;\ |
| 1273 p6##_type p6;\ |
| 1274 const ::testing::internal::Interpolations gmock_interp_;\ |
| 1275 };\ |
| 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_));\ |
| 1280 }\ |
| 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), \ |
| 1285 p6(gmock_p6) {\ |
| 1286 const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, #p6, \ |
| 1287 NULL };\ |
| 1288 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ |
| 1289 gmock_param_names, ("" description ""));\ |
| 1290 }\ |
| 1291 p0##_type p0;\ |
| 1292 p1##_type p1;\ |
| 1293 p2##_type p2;\ |
| 1294 p3##_type p3;\ |
| 1295 p4##_type p4;\ |
| 1296 p5##_type p5;\ |
| 1297 p6##_type p6;\ |
| 1298 ::testing::internal::Interpolations gmock_interp_;\ |
| 1299 };\ |
| 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, \ |
| 1306 p6##_type p6) {\ |
| 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);\ |
| 1309 }\ |
| 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 |
| 1317 |
| 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 {\ |
| 1323 public:\ |
| 1324 template <typename arg_type>\ |
| 1325 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 1326 public:\ |
| 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);\ |
| 1343 }\ |
| 1344 p0##_type p0;\ |
| 1345 p1##_type p1;\ |
| 1346 p2##_type p2;\ |
| 1347 p3##_type p3;\ |
| 1348 p4##_type p4;\ |
| 1349 p5##_type p5;\ |
| 1350 p6##_type p6;\ |
| 1351 p7##_type p7;\ |
| 1352 const ::testing::internal::Interpolations gmock_interp_;\ |
| 1353 };\ |
| 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, \ |
| 1358 gmock_interp_));\ |
| 1359 }\ |
| 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), \ |
| 1365 p7(gmock_p7) {\ |
| 1366 const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, #p6, \ |
| 1367 #p7, NULL };\ |
| 1368 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ |
| 1369 gmock_param_names, ("" description ""));\ |
| 1370 }\ |
| 1371 p0##_type p0;\ |
| 1372 p1##_type p1;\ |
| 1373 p2##_type p2;\ |
| 1374 p3##_type p3;\ |
| 1375 p4##_type p4;\ |
| 1376 p5##_type p5;\ |
| 1377 p6##_type p6;\ |
| 1378 p7##_type p7;\ |
| 1379 ::testing::internal::Interpolations gmock_interp_;\ |
| 1380 };\ |
| 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, \ |
| 1390 p6, p7);\ |
| 1391 }\ |
| 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 |
| 1399 |
| 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 {\ |
| 1405 public:\ |
| 1406 template <typename arg_type>\ |
| 1407 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 1408 public:\ |
| 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);\ |
| 1425 }\ |
| 1426 p0##_type p0;\ |
| 1427 p1##_type p1;\ |
| 1428 p2##_type p2;\ |
| 1429 p3##_type p3;\ |
| 1430 p4##_type p4;\ |
| 1431 p5##_type p5;\ |
| 1432 p6##_type p6;\ |
| 1433 p7##_type p7;\ |
| 1434 p8##_type p8;\ |
| 1435 const ::testing::internal::Interpolations gmock_interp_;\ |
| 1436 };\ |
| 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, \ |
| 1441 gmock_interp_));\ |
| 1442 }\ |
| 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), \ |
| 1448 p8(gmock_p8) {\ |
| 1449 const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, #p6, \ |
| 1450 #p7, #p8, NULL };\ |
| 1451 gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ |
| 1452 gmock_param_names, ("" description ""));\ |
| 1453 }\ |
| 1454 p0##_type p0;\ |
| 1455 p1##_type p1;\ |
| 1456 p2##_type p2;\ |
| 1457 p3##_type p3;\ |
| 1458 p4##_type p4;\ |
| 1459 p5##_type p5;\ |
| 1460 p6##_type p6;\ |
| 1461 p7##_type p7;\ |
| 1462 p8##_type p8;\ |
| 1463 ::testing::internal::Interpolations gmock_interp_;\ |
| 1464 };\ |
| 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, \ |
| 1472 p8##_type p8) {\ |
| 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);\ |
| 1476 }\ |
| 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 |
| 1484 |
| 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 {\ |
| 1491 public:\ |
| 1492 template <typename arg_type>\ |
| 1493 class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ |
| 1494 public:\ |
| 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);\ |
| 1512 }\ |
| 1513 p0##_type p0;\ |
| 1514 p1##_type p1;\ |
| 1515 p2##_type p2;\ |
| 1516 p3##_type p3;\ |
| 1517 p4##_type p4;\ |
| 1518 p5##_type p5;\ |
| 1519 p6##_type p6;\ |
| 1520 p7##_type p7;\ |
| 1521 p8##_type p8;\ |
| 1522 p9##_type p9;\ |
| 1523 const ::testing::internal::Interpolations gmock_interp_;\ |
| 1524 };\ |
| 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, \ |
| 1529 gmock_interp_));\ |
| 1530 }\ |
| 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 ""));\ |
| 1541 }\ |
| 1542 p0##_type p0;\ |
| 1543 p1##_type p1;\ |
| 1544 p2##_type p2;\ |
| 1545 p3##_type p3;\ |
| 1546 p4##_type p4;\ |
| 1547 p5##_type p5;\ |
| 1548 p6##_type p6;\ |
| 1549 p7##_type p7;\ |
| 1550 p8##_type p8;\ |
| 1551 p9##_type p9;\ |
| 1552 ::testing::internal::Interpolations gmock_interp_;\ |
| 1553 };\ |
| 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, \ |
| 1562 p9##_type p9) {\ |
| 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);\ |
| 1566 }\ |
| 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 |
| 1575 |
| 1576 namespace testing { |
| 1577 namespace internal { |
| 1578 |
| 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) != |
| 1583 container.end(); |
| 1584 } |
| 1585 |
| 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; |
| 1590 } |
| 1591 |
| 1592 } // namespace internal |
| 1593 |
| 1594 // Matches an STL-style container or a C-style array that contains the given |
| 1595 // element. |
| 1596 // |
| 1597 // Examples: |
| 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))); |
| 1604 // |
| 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))); |
| 1608 // |
| 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); |
| 1613 } |
| 1614 |
| 1615 } // namespace testing |
| 1616 |
| 1617 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ |
OLD | NEW |